From b3e66e79ab1217dc353022d2a303538fb863337e Mon Sep 17 00:00:00 2001 From: Matt Henkes Date: Thu, 31 Mar 2022 09:25:28 -0500 Subject: [PATCH] chore: [Multi-domain]: Support spec bridges with same domain (#20829) * chore: [Multi-domain]: Support spec bridges with same domain * Add a little test * Fix spec bridge tests * make sure we grab the origin policy * Update tests and origin policy * moving tests Co-authored-by: Bill Glesias --- .../e2e/multi-domain/multi_domain_spec.ts | 49 ----------- .../multi_domain_validation_specs.ts | 86 ++++++++++++++++--- .../e2e/multi-domain/navigation_spec.ts | 14 +-- packages/driver/src/cy/commands/navigation.ts | 4 +- packages/driver/src/cy/multi-domain/index.ts | 12 +-- packages/driver/src/cypress/error_messages.ts | 2 +- .../driver/src/multi-domain/communicator.ts | 11 ++- packages/driver/types/internal-types.d.ts | 15 ++-- packages/runner-shared/src/event-manager.js | 21 +++-- packages/runner/src/iframe/iframes.jsx | 4 +- 10 files changed, 117 insertions(+), 101 deletions(-) diff --git a/packages/driver/cypress/integration/e2e/multi-domain/multi_domain_spec.ts b/packages/driver/cypress/integration/e2e/multi-domain/multi_domain_spec.ts index db7458939a3d..73ffd77f8b24 100644 --- a/packages/driver/cypress/integration/e2e/multi-domain/multi_domain_spec.ts +++ b/packages/driver/cypress/integration/e2e/multi-domain/multi_domain_spec.ts @@ -227,52 +227,3 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { }) }) }) - -// @ts-ignore -describe('domain validation', { experimentalSessionSupport: true }, () => { - it('finds the right spec bridge with a subdomain', () => { - cy.visit('/fixtures/auth/index.html') // Establishes Primary Domain - cy.window().then((win) => { - win.location.href = 'http://baz.foobar.com:3500/fixtures/auth/idp.html' - }) - - cy.switchToDomain('http://foobar.com:3500', () => { - cy.get('[data-cy="username"]').type('TJohnson') - cy.get('[data-cy="login"]').click() - }) - - cy.get('[data-cy="welcome"]') - .invoke('text') - .should('equal', 'Welcome TJohnson') - }) - - it('uses switchToDomain twice', () => { - cy.visit('/fixtures/auth/index.html') // Establishes Primary Domain - cy.get('[data-cy="login-idp"]').click() // Takes you to idp.com - cy.switchToDomain('http://idp.com:3500', () => { - cy.get('[data-cy="username"]').type('BJohnson') - cy.get('[data-cy="login"]').click() - }) // Trailing edge wait, waiting to return to the primary domain - - // Verify that the user has logged in on /siteA - cy.get('[data-cy="welcome"]') - .invoke('text') - .should('equal', 'Welcome BJohnson') - - cy.get('[data-cy="logout"]').click() - - cy.window().then((win) => { - win.location.href = 'http://baz.foobar.com:3500/fixtures/auth/idp.html' - }) - - cy.switchToDomain('http://foobar.com:3500', () => { - cy.get('[data-cy="username"]').type('TJohnson') - cy.get('[data-cy="login"]').click() - }) // Trailing edge wait, waiting to return to the primary domain - - // Verify that the user has logged in on /siteA - cy.get('[data-cy="welcome"]') - .invoke('text') - .should('equal', 'Welcome TJohnson') - }) -}) diff --git a/packages/driver/cypress/integration/e2e/multi-domain/multi_domain_validation_specs.ts b/packages/driver/cypress/integration/e2e/multi-domain/multi_domain_validation_specs.ts index 17d70a8fbf9d..e0cfb5375519 100644 --- a/packages/driver/cypress/integration/e2e/multi-domain/multi_domain_validation_specs.ts +++ b/packages/driver/cypress/integration/e2e/multi-domain/multi_domain_validation_specs.ts @@ -5,7 +5,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('localhost', () => undefined) cy.then(() => { const expectedSrc = `https://localhost/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ localhost') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://localhost') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -15,7 +15,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('127.0.0.1', () => undefined) cy.then(() => { const expectedSrc = `https://127.0.0.1/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ 127.0.0.1') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://127.0.0.1') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -26,7 +26,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('0000:0000:0000:0000:0000:0000:0000:0001', () => undefined) cy.then(() => { const expectedSrc = `https://[::1]/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ [::1]') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://[::1]') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -36,7 +36,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('はじめよう.みんな', () => undefined) cy.then(() => { const expectedSrc = `https://xn--p8j9a0d9c9a.xn--q9jyb4c/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ xn--p8j9a0d9c9a.xn--q9jyb4c') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://xn--p8j9a0d9c9a.xn--q9jyb4c') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -46,7 +46,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('http://foobar1.com:3500', () => {}) cy.then(() => { const expectedSrc = `http://foobar1.com:3500/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ foobar1.com') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ http://foobar1.com:3500') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -56,7 +56,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('https://foobar2.com:3500', () => {}) cy.then(() => { const expectedSrc = `https://foobar2.com:3500/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ foobar2.com') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://foobar2.com:3500') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -66,7 +66,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('foobar3.com:3500', () => {}) cy.then(() => { const expectedSrc = `https://foobar3.com:3500/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ foobar3.com') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://foobar3.com:3500') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -76,7 +76,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('http://foobar4.com', () => {}) cy.then(() => { const expectedSrc = `http://foobar4.com/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ foobar4.com') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ http://foobar4.com') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -86,7 +86,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('app.foobar5.com', () => {}) cy.then(() => { const expectedSrc = `https://foobar5.com/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ foobar5.com') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://foobar5.com') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -96,7 +96,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('foobar6.com', () => undefined) cy.then(() => { const expectedSrc = `https://foobar6.com/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ foobar6.com') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://foobar6.com') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -106,7 +106,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('app.foobar.herokuapp.com', () => {}) cy.then(() => { const expectedSrc = `https://foobar.herokuapp.com/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ foobar.herokuapp.com') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://foobar.herokuapp.com') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) @@ -116,11 +116,73 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => { cy.switchToDomain('machine-name', () => undefined) cy.then(() => { const expectedSrc = `https://machine-name/__cypress/multi-domain-iframes` - const iframe = window.top?.document.getElementById('Spec\ Bridge:\ machine-name') as HTMLIFrameElement + const iframe = window.top?.document.getElementById('Spec\ Bridge:\ https://machine-name') as HTMLIFrameElement expect(iframe.src).to.equal(expectedSrc) }) }) + + it('finds the right spec bridge with a subdomain', () => { + cy.visit('/fixtures/auth/index.html') // Establishes Primary Domain + cy.window().then((win) => { + win.location.href = 'http://baz.foobar.com:3500/fixtures/auth/idp.html' + }) + + cy.switchToDomain('http://foobar.com:3500', () => { + cy.get('[data-cy="username"]').type('TJohnson') + cy.get('[data-cy="login"]').click() + }) + + cy.get('[data-cy="welcome"]') + .invoke('text') + .should('equal', 'Welcome TJohnson') + }) + + it('uses switchToDomain twice', () => { + cy.visit('/fixtures/auth/index.html') // Establishes Primary Domain + cy.get('[data-cy="login-idp"]').click() // Takes you to idp.com + cy.switchToDomain('http://idp.com:3500', () => { + cy.get('[data-cy="username"]').type('BJohnson') + cy.get('[data-cy="login"]').click() + }) // Trailing edge wait, waiting to return to the primary domain + + // Verify that the user has logged in on /siteA + cy.get('[data-cy="welcome"]') + .invoke('text') + .should('equal', 'Welcome BJohnson') + + cy.get('[data-cy="logout"]').click() + + cy.window().then((win) => { + win.location.href = 'http://baz.foobar.com:3500/fixtures/auth/idp.html' + }) + + cy.switchToDomain('http://foobar.com:3500', () => { + cy.get('[data-cy="username"]').type('TJohnson') + cy.get('[data-cy="login"]').click() + }) // Trailing edge wait, waiting to return to the primary domain + + // Verify that the user has logged in on /siteA + cy.get('[data-cy="welcome"]') + .invoke('text') + .should('equal', 'Welcome TJohnson') + }) + + it('creates a spec bridge for https://idp.com:3502', () => { + cy.visit('/fixtures/auth/index.html') // Establishes Primary Domain + cy.switchToDomain('idp.com:3502', () => { + cy.visit('https://www.idp.com:3502/fixtures/auth/index.html') + cy.get('[data-cy="login-idp"]').invoke('text').should('equal', 'Login IDP') + }) + }) + + it('creates a spec bridge for http://idp.com:3500', () => { + cy.visit('/fixtures/auth/index.html') // Establishes Primary Domain + cy.switchToDomain('http://idp.com:3500', () => { + cy.visit('http://www.idp.com:3500/fixtures/auth/index.html') + cy.get('[data-cy="login-idp"]').invoke('text').should('equal', 'Login IDP') + }) + }) }) describe('errors', () => { diff --git a/packages/driver/cypress/integration/e2e/multi-domain/navigation_spec.ts b/packages/driver/cypress/integration/e2e/multi-domain/navigation_spec.ts index 8e3652901d18..6c7421cf2f10 100644 --- a/packages/driver/cypress/integration/e2e/multi-domain/navigation_spec.ts +++ b/packages/driver/cypress/integration/e2e/multi-domain/navigation_spec.ts @@ -247,7 +247,7 @@ describe('errors', { experimentalSessionSupport: true }, () => { expect(err.message).to.include(`Your page did not fire its \`load\` event within \`5000ms\`.`) expect(err.message).to.include(`A cross origin request for \`http://www.foobar.com:3500/fixtures/auth/idp.html?redirect=http%3A%2F%2Flocalhost%3A3500%2Ffixtures%2Fauth%2Findex.html\` was detected.`) expect(err.message).to.include(`A command that triggers cross origin navigation must be immediately followed by a \`cy.switchToDomain()\` command:`) - expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://www.foobar.com:3500\', () => {\n \n})\n\``) + expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://foobar.com:3500\', () => {\n \n})\n\``) expect(err.message).to.include(`If the cross origin request was an intermediary state, you can try increasing the \`pageLoadTimeout\` value in \`cypress.json\` to wait longer`) expect(err.message).not.to.include(`The following error originated from your test code, not from Cypress`) @@ -285,9 +285,9 @@ describe('errors', { experimentalSessionSupport: true }, () => { it('redirects to the wrong subdomain', { pageLoadTimeout: 5000 }, (done) => { cy.on('fail', (err) => { expect(err.message).to.include(`Timed out after waiting \`5000ms\` for your remote page to load on origin(s):`) - expect(err.message).to.include(`\n- \`idp.com\`\n`) + expect(err.message).to.include(`\n- \`http://idp.com:3500\`\n`) expect(err.message).to.include(`A cross origin request for \`http://www.foobar.com:3500/fixtures/auth/idp.html?redirect=http%3A%2F%2Flocalhost%3A3500%2Ffixtures%2Fauth%2Findex.html\` was detected.`) - expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://www.foobar.com:3500\', () => {\n \n})\n\``) + expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://foobar.com:3500\', () => {\n \n})\n\``) expect(err.message).not.to.include(`The following error originated from your test code, not from Cypress`) expect(err.message).not.to.include(`The following error originated from your application code, not from Cypress`) @@ -334,7 +334,7 @@ describe('errors', { experimentalSessionSupport: true }, () => { expect(err.message).to.include(`Timed out after waiting \`5000ms\` for your remote page to load on origin(s):`) expect(err.message).to.include(`\n- \`http://localhost:3500\`\n`) expect(err.message).to.include(`A cross origin request for \`http://www.foobar.com:3500/fixtures/auth/index.html\` was detected.`) - expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://www.foobar.com:3500\', () => {\n \n})\n\``) + expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://foobar.com:3500\', () => {\n \n})\n\``) expect(err.message).not.to.include(`The following error originated from your test code, not from Cypress`) expect(err.message).not.to.include(`The following error originated from your application code, not from Cypress`) @@ -361,7 +361,7 @@ describe('errors', { experimentalSessionSupport: true }, () => { expect(err.message).to.include(`Timed out after waiting \`5000ms\` for your remote page to load on origin(s):`) expect(err.message).to.include(`\n- \`http://idp.com:3500\`\n`) expect(err.message).to.include(`A cross origin request for \`http://www.foobar.com:3500/fixtures/auth/index.html\` was detected.`) - expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://www.foobar.com:3500\', () => {\n \n})\n\``) + expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://foobar.com:3500\', () => {\n \n})\n\``) expect(err.message).not.to.include(`The following error originated from your test code, not from Cypress`) expect(err.message).not.to.include(`The following error originated from your application code, not from Cypress`) @@ -434,7 +434,7 @@ describe('errors', { experimentalSessionSupport: true }, () => { expect(err.message).to.include(`Timed out after waiting \`5000ms\` for your remote page to load on origin(s):`) expect(err.message).to.include(`\n- \`http://localhost:3500\`\n`) expect(err.message).to.include(`A cross origin request for \`http://www.foobar.com:3500/fixtures/auth/index.html\` was detected.`) - expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://www.foobar.com:3500\', () => {\n \n})\n\``) + expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://foobar.com:3500\', () => {\n \n})\n\``) expect(err.message).not.to.include(`The following error originated from your test code, not from Cypress`) expect(err.message).not.to.include(`The following error originated from your application code, not from Cypress`) @@ -483,7 +483,7 @@ describe('errors', { experimentalSessionSupport: true }, () => { expect(err.message).to.include(`Timed out after waiting \`5000ms\` for your remote page to load on origin(s):`) expect(err.message).to.include(`\n- \`http://localhost:3500\`\n`) expect(err.message).to.include(`A cross origin request for \`http://www.foobar.com:3500/fixtures/auth/index.html\` was detected.`) - expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://www.foobar.com:3500\', () => {\n \n})\n\``) + expect(err.message).to.include(`\`\ncy.switchToDomain(\'http://foobar.com:3500\', () => {\n \n})\n\``) expect(err.message).not.to.include(`The following error originated from your test code, not from Cypress`) expect(err.message).not.to.include(`The following error originated from your application code, not from Cypress`) diff --git a/packages/driver/src/cy/commands/navigation.ts b/packages/driver/src/cy/commands/navigation.ts index 0ad14471c08e..f34908bb661e 100644 --- a/packages/driver/src/cy/commands/navigation.ts +++ b/packages/driver/src/cy/commands/navigation.ts @@ -58,7 +58,7 @@ const timedOutWaitingForPageLoad = (ms, log) => { cy.isAnticipatingMultiDomainFor(undefined) // By default origins is just this location. - let origins = [location.origin] + let origins = [$Location.create(location.href).originPolicy] const currentCommand = cy.queue.state('current') @@ -74,7 +74,7 @@ const timedOutWaitingForPageLoad = (ms, log) => { args: { configFile: Cypress.config('configFile'), ms, - crossOriginUrl: new URL(anticipatedCrossOriginHref), + crossOriginUrl: $Location.create(anticipatedCrossOriginHref), origins, }, onFail: log, diff --git a/packages/driver/src/cy/multi-domain/index.ts b/packages/driver/src/cy/multi-domain/index.ts index 2ec25ab0540a..7195a26bb9d8 100644 --- a/packages/driver/src/cy/multi-domain/index.ts +++ b/packages/driver/src/cy/multi-domain/index.ts @@ -93,9 +93,9 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, validator.validateLocation(location, originOrDomain) - const domain = location.superDomain + const originPolicy = location.originPolicy - cy.state('latestActiveDomain', domain) + cy.state('latestActiveDomain', originPolicy) return new Bluebird((resolve, reject, onCancel) => { const cleanup = () => { @@ -172,9 +172,9 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, // fired once the spec bridge is set up and ready to receive messages communicator.once('bridge:ready', (_data, bridgeReadyDomain) => { - if (bridgeReadyDomain === domain) { + if (bridgeReadyDomain === originPolicy) { // now that the spec bridge is ready, instantiate Cypress with the current app config and environment variables for initial sync when creating the instance - communicator.toSpecBridge(domain, 'initialize:cypress', { + communicator.toSpecBridge(originPolicy, 'initialize:cypress', { config: preprocessConfig(Cypress.config()), env: preprocessEnv(Cypress.env()), }) @@ -182,7 +182,7 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, // once the secondary domain page loads, send along the // user-specified callback to run in that domain try { - communicator.toSpecBridge(domain, 'run:domain:fn', { + communicator.toSpecBridge(originPolicy, 'run:domain:fn', { args: options?.args || undefined, fn: callbackFn.toString(), // let the spec bridge version of Cypress know if config read-only values can be overwritten since window.top cannot be accessed in cross-origin iframes @@ -197,7 +197,7 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, hookId: state('hookId'), hasVisitedAboutBlank: state('hasVisitedAboutBlank'), multiDomainBaseUrl: location.origin, - parentOrigins: [window.location.origin], + parentOrigins: [cy.getRemoteLocation('originPolicy')], isStable: state('isStable'), autOrigin: state('autOrigin'), }, diff --git a/packages/driver/src/cypress/error_messages.ts b/packages/driver/src/cypress/error_messages.ts index 2f689ac478a2..4f503dc97294 100644 --- a/packages/driver/src/cypress/error_messages.ts +++ b/packages/driver/src/cypress/error_messages.ts @@ -1000,7 +1000,7 @@ export default { A command that triggers cross origin navigation must be immediately followed by a ${cmd('switchToDomain')} command: \`\`\` - cy.switchToDomain('${crossOriginUrl.origin}', () => { + cy.switchToDomain('${crossOriginUrl.originPolicy}', () => { }) \`\`\` diff --git a/packages/driver/src/multi-domain/communicator.ts b/packages/driver/src/multi-domain/communicator.ts index 6ceb3c03fa7b..9f05802089c6 100644 --- a/packages/driver/src/multi-domain/communicator.ts +++ b/packages/driver/src/multi-domain/communicator.ts @@ -2,6 +2,7 @@ import debugFn from 'debug' import { EventEmitter } from 'events' import { preprocessConfig, preprocessEnv } from '../util/config' import { preprocessForSerialization, reifyCrossDomainError } from '../util/serialization' +import { $Location } from '../cypress/location' const debug = debugFn('cypress:driver:multi-domain') @@ -38,14 +39,14 @@ export class PrimaryDomainCommunicator extends EventEmitter { // where we need to set the crossDomainDriverWindow to source to // communicate back to the iframe if (messageName === 'bridge:ready' && source) { - this.crossDomainDriverWindows[data.domain] = source as Window + this.crossDomainDriverWindows[data.originPolicy] = source as Window } if (data?.data?.err) { data.data.err = reifyCrossDomainError(data.data.err, this.userInvocationStack as string) } - this.emit(messageName, data.data, data.domain) + this.emit(messageName, data.data, data.originPolicy) return } @@ -169,14 +170,16 @@ export class SpecBridgeDomainCommunicator extends EventEmitter { * @param {Cypress.ObjectLike} data - any meta data to be sent with the event. */ toPrimary (event: string, data?: Cypress.ObjectLike, options: { syncGlobals: boolean } = { syncGlobals: false }) { - debug('<= to Primary ', event, data, document.domain) + const { originPolicy } = $Location.create(window.location.href) + + debug('<= to Primary ', event, data, originPolicy) if (options.syncGlobals) this.syncGlobalsToPrimary() this.handleSubjectAndErr(data, (data: Cypress.ObjectLike) => { window.top?.postMessage({ event: `${CROSS_DOMAIN_PREFIX}${event}`, data, - domain: document.domain, + originPolicy, }, '*') }) } diff --git a/packages/driver/types/internal-types.d.ts b/packages/driver/types/internal-types.d.ts index 00798c915719..2dbc8d87da4f 100644 --- a/packages/driver/types/internal-types.d.ts +++ b/packages/driver/types/internal-types.d.ts @@ -28,19 +28,20 @@ declare namespace Cypress { /** * If `as` is chained to the current command, return the alias name used. */ - getNextAlias: () => string | undefined + getNextAlias: IAliases['getNextAlias'] noop: (v: T) => Cypress.Chainable - queue: any - retry: (fn: () => any, opts: any) => any + queue: CommandQueue + retry: IRetries['retry'] state: State - pauseTimers: (shouldPause: boolean) => Cypress.Chainable + pauseTimers: ITimer['pauseTimers'] // TODO: this function refers to clearTimeout at cy/timeouts.ts, which doesn't have any argument. // But in many cases like cy/commands/screenshot.ts, it's called with a timeout id string. // We should decide whether calling with id is correct or not. - clearTimeout: (timeoutId?: string) => Cypress.Chainable - isStable: (boolean, string) => void - isAnticipatingMultiDomainFor: (string) => void + clearTimeout: ITimeouts['clearTimeout'] + isStable: IStability['isStable'] + isAnticipatingMultiDomainFor: IStability['isAnticipatingMultiDomainFor'] fail: (err: Error, options:{ async?: boolean }) => Error + getRemoteLocation: ILocation['getRemoteLocation'] } interface Cypress { diff --git a/packages/runner-shared/src/event-manager.js b/packages/runner-shared/src/event-manager.js index 90fa42f1710c..23792395e861 100644 --- a/packages/runner-shared/src/event-manager.js +++ b/packages/runner-shared/src/event-manager.js @@ -532,11 +532,11 @@ export const eventManager = { Cypress.multiDomainCommunicator.toAllSpecBridges('before:unload') }) - Cypress.multiDomainCommunicator.on('window:load', ({ url }, domain) => { + Cypress.multiDomainCommunicator.on('window:load', ({ url }, originPolicy) => { // Sync stable if the expected domain has loaded. // Only listen to window load events from the most recent secondary domain, This prevents nondeterminism in the case where we redirect to an already // established spec bridge, but one that is not the current or next switchToDomain command. - if (cy.state('latestActiveDomain') === domain) { + if (cy.state('latestActiveDomain') === originPolicy) { // We remain in an anticipating state until either a load even happens or a timeout. cy.state('autOrigin', cy.state('autOrigin', cors.getOriginPolicy(url))) cy.isAnticipatingMultiDomainFor(undefined) @@ -556,23 +556,22 @@ export const eventManager = { Cypress.multiDomainCommunicator.toAllSpecBridges('before:unload') }) - Cypress.multiDomainCommunicator.on('expect:domain', (domain) => { - localBus.emit('expect:domain', domain) + Cypress.multiDomainCommunicator.on('expect:domain', (originPolicy) => { + localBus.emit('expect:domain', originPolicy) }) - Cypress.multiDomainCommunicator.on('viewport:changed', (viewport, domain) => { + Cypress.multiDomainCommunicator.on('viewport:changed', (viewport, originPolicy) => { const callback = () => { - Cypress.multiDomainCommunicator.toSpecBridge(domain, 'viewport:changed:end') + Cypress.multiDomainCommunicator.toSpecBridge(originPolicy, 'viewport:changed:end') } - // TODO: Do we want to use the multiDomainCommunicator to send these types of messages or Cypress itself? Cypress.multiDomainCommunicator.emit('sync:viewport', viewport) localBus.emit('viewport:changed', viewport, callback) }) - Cypress.multiDomainCommunicator.on('before:screenshot', (config, domain) => { + Cypress.multiDomainCommunicator.on('before:screenshot', (config, originPolicy) => { const callback = () => { - Cypress.multiDomainCommunicator.toSpecBridge(domain, 'before:screenshot:end') + Cypress.multiDomainCommunicator.toSpecBridge(originPolicy, 'before:screenshot:end') } handleBeforeScreenshot(config, callback) @@ -693,9 +692,9 @@ export const eventManager = { ws.emit('spec:changed', specFile) }, - notifyCrossDomainBridgeReady (domain) { + notifyCrossDomainBridgeReady (originPolicy) { // Any multi-domain event appends the domain as the third parameter and we do the same here for this short circuit - Cypress.multiDomainCommunicator.emit('bridge:ready', undefined, domain) + Cypress.multiDomainCommunicator.emit('bridge:ready', undefined, originPolicy) }, focusTests () { diff --git a/packages/runner/src/iframe/iframes.jsx b/packages/runner/src/iframe/iframes.jsx index 8361cd74297e..ef451a7a5221 100644 --- a/packages/runner/src/iframe/iframes.jsx +++ b/packages/runner/src/iframe/iframes.jsx @@ -171,11 +171,11 @@ export default class Iframes extends Component { } _addCrossDomainIframe = (location) => { - const id = `Spec Bridge: ${location.superDomain}` + const id = `Spec Bridge: ${location.originPolicy}` // if it already exists, don't add another one if (document.getElementById(id)) { - this.props.eventManager.notifyCrossDomainBridgeReady(location.superDomain) + this.props.eventManager.notifyCrossDomainBridgeReady(location.originPolicy) return }