Innovenergy_trunk/frontend/node_modules/testcafe/lib/test-run/session-controller.js

123 lines
16 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const testcafe_hammerhead_1 = require("testcafe-hammerhead");
const _1 = __importDefault(require("./"));
const ACTIVE_SESSIONS_MAP = {};
const UPLOADS_DIR_NAME = '_uploads_';
// NOTE: Proxyless cookie implementation doesn't require client-server communication.
// This stub was created to reduce conditional logic in connected classes.
class ProxylessCookieStub {
getClientString() {
return '';
}
takePendingSyncCookies() {
return [];
}
}
class SessionController extends testcafe_hammerhead_1.Session {
constructor(uploadRoots, options) {
super(uploadRoots, options);
this.currentTestRun = null;
}
// Hammerhead payload
async getPayloadScript() {
return this.currentTestRun.getPayloadScript();
}
async getIframePayloadScript() {
return this.currentTestRun.getIframePayloadScript();
}
// Hammerhead handlers
handleServiceMessage(msg, serverInfo) {
if (this.currentTestRun[msg.cmd])
return super.handleServiceMessage.call(this.currentTestRun, msg, serverInfo);
return super.handleServiceMessage(msg, serverInfo);
}
getAuthCredentials() {
return this.currentTestRun.getAuthCredentials();
}
handleFileDownload() {
return this.currentTestRun.handleFileDownload();
}
handleAttachment(data) {
return this.currentTestRun.handleAttachment(data);
}
handlePageError(ctx, err) {
return this.currentTestRun.handlePageError(ctx, err);
}
createCookies() {
return this.options.proxyless ? new ProxylessCookieStub() : super.createCookies();
}
// API
static getSession(testRun) {
let sessionInfo = ACTIVE_SESSIONS_MAP[testRun.browserConnection.id];
if (!sessionInfo || !testRun.disablePageReloads) {
if (sessionInfo && sessionInfo.url)
SessionController.closeSession(testRun);
let session = null;
if (testRun.test.isLegacy)
session = testRun;
else {
const fixtureDir = path_1.default.dirname(testRun.test.fixture.path);
const uploadRoots = [
path_1.default.resolve(UPLOADS_DIR_NAME),
path_1.default.resolve(fixtureDir, UPLOADS_DIR_NAME),
fixtureDir,
];
const options = {
disablePageCaching: testRun.disablePageCaching,
allowMultipleWindows: _1.default.isMultipleWindowsAllowed(testRun),
requestTimeout: testRun.requestTimeout,
proxyless: testRun.opts.proxyless,
};
if (options.allowMultipleWindows)
options.windowId = testRun.browserConnection.activeWindowId;
session = new SessionController(uploadRoots, options);
session.currentTestRun = testRun;
}
sessionInfo = {
session: session,
proxy: null,
url: null,
};
ACTIVE_SESSIONS_MAP[testRun.browserConnection.id] = sessionInfo;
}
else if (!testRun.test.isLegacy)
sessionInfo.session.currentTestRun = testRun;
return sessionInfo.session;
}
static getSessionUrl(testRun, proxy) {
let sessionInfo = ACTIVE_SESSIONS_MAP[testRun.browserConnection.id];
if (!sessionInfo || testRun.test.isLegacy) {
SessionController.getSession(testRun);
sessionInfo = ACTIVE_SESSIONS_MAP[testRun.browserConnection.id];
}
if (!sessionInfo.url) {
const pageUrl = testRun.test.pageUrl;
const externalProxyHost = testRun.opts.proxy;
let externalProxySettings = null;
if (externalProxyHost) {
externalProxySettings = {
url: externalProxyHost,
bypassRules: testRun.opts.proxyBypass,
};
}
sessionInfo.proxy = proxy;
sessionInfo.url = proxy.openSession(pageUrl, sessionInfo.session, externalProxySettings);
}
return sessionInfo.url;
}
static closeSession(testRun) {
const sessionInfo = ACTIVE_SESSIONS_MAP[testRun.browserConnection.id];
if (!sessionInfo || !sessionInfo.url || !sessionInfo.proxy)
return;
sessionInfo.proxy.closeSession(sessionInfo.session);
delete ACTIVE_SESSIONS_MAP[testRun.browserConnection.id];
}
}
exports.default = SessionController;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2Vzc2lvbi1jb250cm9sbGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Rlc3QtcnVuL3Nlc3Npb24tY29udHJvbGxlci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLGdEQUF3QjtBQUN4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Nsb3NlU2Vzc2lvbih0ZXN0UnVuKTtcblxuICAgICAgICAgICAgbGV0IHNlc3Npb24gPSBudWxsO1xuXG4gICAgICAgICAgICBpZiAodGVzdFJ1bi50ZXN0LmlzTGVnYWN5KVxuICAgICAgICAgICAgICAgIHNlc3Npb24gPSB0ZXN0UnVuO1xuICAgICAgICAgICAgZWxzZSB7XG4gICAgICAgICAgICAgICAgY29uc3QgZml4dHVyZURpciA9IHBhdGguZGlybmFtZSh0ZXN0UnVuLnRlc3QuZml4dHVyZS5wYXRoKTtcblxuICAgICAgICAgICAgICAgIGNvbnN0IHVwbG9hZFJvb3RzID0gW1xuICAgICAgICAgICAgICAgICAgICBwYXRoLnJlc29sdmUoVVBMT0FEU19ESVJfTkFNRSksXG4gICAgICAgICAgICAgICAgICAgIHBhdGgucmVzb2x2ZShmaXh0dXJlRGlyLCBVUExPQURTX0RJUl9OQU1FKSxcbiAgICAgICAgICAgICAgICAgICAgZml4dHVyZURpcixcbiAgICAgICAgICAgICAgICBdO1xuXG4gICAgICAgICAgICAgICAgY29uc3Qgb3B0aW9ucyA9IHtcbiAgICAgICAgICAgICAgICAgICAgZGlzYWJsZVBhZ2VDYWNoaW5nOiAgIHRlc3RSdW4uZGlzYWJsZVBhZ2VDYWNoaW5nLFxuICAgICAgICAgICAgICAgICAgICBhbGxvd011bHRpcGxlV2luZG93czogVGVzdFJ1bi5pc011bHRpcGxlV2luZG93c0FsbG93ZWQodGVzdFJ1biksXG4gICAgICAgICAgICAgICAgICAgIHJlcXVlc3RUaW1lb3V0OiAgICAgICB0ZXN0UnVuLnJlcXVlc3RUaW1lb3V0LFxuICAgICAgICAgICAgICAgICAgICBwcm94eWxlc3M6ICAgICAgICAgICAgdGVzdFJ1bi5vcHRzLnByb3h5bGVzcyxcbiAgICAgICAgICAgICAgICB9O1xuXG4gICAgICAgICAgICAgICAgaWYgKG9wdGlvbnMuYWxsb3dNdWx0aXBsZVdpbmRvd3MpXG4gICAgICAgICAgICAgICAgICAgI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ZXNzaW9uSW5mbyA9IEFDVElWRV9TRVNTSU9OU19NQVBbdGVzdFJ1bi5icm93c2VyQ29ubmVjdGlvbi5pZF07XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoIXNlc3Npb25JbmZvLnVybCkge1xuICAgICAgICAgICAgY29uc3QgcGFnZVVybCAgICAgICAgICAgICA9IHRlc3RSdW4udGVzdC5wYWdlVXJsO1xuICAgICAgICAgICAgY29uc3QgZXh0ZXJuYWxQcm94eUhvc3QgICA9IHRlc3RSdW4ub3B0cy5wcm94eTtcbiAgICAgICAgICAgIGxldCBleHRlcm5hbFByb3h5U2V0dGluZ3MgPSBudWxsO1xuXG4gICAgICAgICAgICBpZiAoZXh0ZXJuYWxQcm94eUhvc3QpIHtcbiAgICAgICAgICAgICAgICBleHRlcm5hbFByb3h5U2V0dGluZ3MgPSB7XG4gICAgICAgICAgICAgICAgICAgIHVybDogICAgICAgICBleHRlcm5hbFByb3h5SG9zdCxcbiAgICAgICAgICAgICAgICAgICAgYnlwYXNzUnVsZXM6IHRlc3RSdW4ub3B0cy5wcm94eUJ5cGFzcyxcbiAgICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBzZXNzaW9uSW5mby5wcm94eSA9IHByb3h5O1xuICAgICAgICAgICAgc2Vzc2lvbkluZm8udXJsICAgPSBwcm94eS5vcGVuU2Vzc2lvbihwYWdlVXJsLCBzZXNzaW9uSW5mby5zZXNzaW9uLCBleHRlcm5hbFByb3h5U2V0dGluZ3MpO1xuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIHNlc3Npb25JbmZvLnVybDtcbiAgICB9XG5cbiAgICBzdGF0aWMgY2xvc2VTZXNzaW9uICh0ZXN0UnVuKSB7XG4gICAgICAgIGNvbnN0IHNlc3Npb25JbmZvID0gQUNUSVZFX1NFU1NJT05TX01BUFt0ZXN0UnVuLmJyb3dzZXJDb25uZWN0aW9uLmlkXTtcblxuICAgICAgICBpZiAoIXNlc3Npb25JbmZvIHx8ICFzZXNzaW9uSW5mby51cmwgfHwgIXNlc3Npb25JbmZvLnByb3h5KVxuICAgICAgICAgICAgcmV0dXJuO1xuXG4gICAgICAgIHNlc3Npb25JbmZvLnByb3h5LmNsb3NlU2Vzc2lvbihzZXNzaW9uSW5mby5zZXNzaW9uKTtcblxuICAgICAgICBkZWxldGUgQUNUSVZFX1NFU1NJT05TX01BUFt0ZXN0UnVuLmJyb3dzZXJDb25uZWN0aW9uLmlkXTtcbiAgICB9XG59XG5cbiJdfQ==