diff --git a/src/child/child.js b/src/child/child.js index 7b68df3c..e7d32e2c 100644 --- a/src/child/child.js +++ b/src/child/child.js @@ -1,22 +1,19 @@ /* @flow */ /* eslint max-lines: 0 */ -import { isSameDomain, matchDomain, getDomain, getOpener, - getNthParentFromTop, getAncestor, getAllFramesInWindow, - type CrossDomainWindowType, onCloseWindow, assertSameDomain } from 'cross-domain-utils/src'; -import { markWindowKnown, deserializeMessage, type CrossDomainFunctionType } from 'post-robot/src'; +import { isSameDomain, matchDomain, getAllFramesInWindow, type CrossDomainWindowType, + onCloseWindow, assertSameDomain } from 'cross-domain-utils/src'; +import { markWindowKnown, type CrossDomainFunctionType } from 'post-robot/src'; import { ZalgoPromise } from 'zalgo-promise/src'; -import { extend, onResize, elementReady, assertExists, noop } from 'belter/src'; +import { extend, onResize, elementReady, noop } from 'belter/src'; -import { getGlobal, tryGlobal } from '../lib'; -import { CONTEXT, INITIAL_PROPS, WINDOW_REFERENCES } from '../constants'; +import { getGlobal, tryGlobal, getInitialParentPayload } from '../lib'; +import { CONTEXT } from '../constants'; import type { NormalizedComponentOptionsType, getSiblingsPropType } from '../component'; import type { PropsType, ChildPropsType } from '../component/props'; -import type { WindowRef, PropRef, ParentExportsType } from '../parent'; import type { StringMatcherType } from '../types'; import { normalizeChildProps } from './props'; -import { getChildPayload } from './window'; export type ChildExportsType

= {| updateProps : CrossDomainFunctionType<[ PropsType

], void>, @@ -39,37 +36,6 @@ export type ChildHelpers = {| getSiblings : getSiblingsPropType |}; -function getParentComponentWindow(ref : WindowRef) : CrossDomainWindowType { - const { type } = ref; - - if (type === WINDOW_REFERENCES.OPENER) { - return assertExists('opener', getOpener(window)); - - } else if (type === WINDOW_REFERENCES.PARENT && typeof ref.distance === 'number') { - return assertExists('parent', getNthParentFromTop(window, ref.distance)); - - } else if (type === WINDOW_REFERENCES.GLOBAL && ref.uid && typeof ref.uid === 'string') { - const { uid } = ref; - const ancestor = getAncestor(window); - - if (!ancestor) { - throw new Error(`Can not find ancestor window`); - } - - for (const frame of getAllFramesInWindow(ancestor)) { - if (isSameDomain(frame)) { - const win = tryGlobal(frame, global => global.windows && global.windows[uid]); - - if (win) { - return win; - } - } - } - } - - throw new Error(`Unable to find ${ type } parent component window`); -} - function checkParentDomain(allowedParentDomains : StringMatcherType, domain : string) { if (!matchDomain(allowedParentDomains, domain)) { throw new Error(`Can not be rendered by domain: ${ domain }`); @@ -88,27 +54,6 @@ function destroy() : ZalgoPromise { }); } -function getPropsByRef

(parentComponentWindow : CrossDomainWindowType, domain : string, propRef : PropRef) : (PropsType

) { - let props; - - if (propRef.type === INITIAL_PROPS.RAW) { - props = propRef.value; - } else if (propRef.type === INITIAL_PROPS.UID) { - if (!isSameDomain(parentComponentWindow)) { - throw new Error(`Parent component window is on a different domain - expected ${ getDomain() } - can not retrieve props`); - } - - const global = getGlobal(parentComponentWindow); - props = assertExists('props', global && global.props[propRef.uid]); - } - - if (!props) { - throw new Error(`Could not find props`); - } - - return deserializeMessage(parentComponentWindow, domain, props); -} - export type ChildComponent = {| getProps : () => ChildPropsType, init : () => ZalgoPromise @@ -118,23 +63,20 @@ export function childComponent(options : NormalizedComponentOptionsType const { tag, propsDef, autoResize, allowedParentDomains } = options; const onPropHandlers = []; - const childPayload = getChildPayload(); + + const { parent, payload } = getInitialParentPayload(); + const { win: parentComponentWindow, domain: parentDomain } = parent; + let props : ChildPropsType; const exportsPromise = new ZalgoPromise(); - if (!childPayload) { - throw new Error(`No child payload found`); - } + const { version, uid, exports: parentExports, context, props: initialProps } = payload; - if (childPayload.version !== __ZOID__.__VERSION__) { - throw new Error(`Parent window has zoid version ${ childPayload.version }, child window has version ${ __ZOID__.__VERSION__ }`); + if (version !== __ZOID__.__VERSION__) { + throw new Error(`Parent window has zoid version ${ version }, child window has version ${ __ZOID__.__VERSION__ }`); } - const { uid, parent: parentRef, parentDomain, exports: parentExports, context, props: propsRef } = childPayload; - const parentComponentWindow = getParentComponentWindow(parentRef); - const parent : ParentExportsType = deserializeMessage(parentComponentWindow, parentDomain, parentExports); - - const { show, hide, close } = parent; + const { show, hide, close, onError, checkClose, export: parentExport, resize: parentResize, init: parentInit } = parentExports; const getParent = () => parentComponentWindow; const getParentDomain = () => parentDomain; @@ -143,23 +85,13 @@ export function childComponent(options : NormalizedComponentOptionsType onPropHandlers.push(handler); }; - const onError = (err : mixed) : ZalgoPromise => { - return ZalgoPromise.try(() => { - if (parent && parent.onError) { - return parent.onError(err); - } else { - throw err; - } - }); - }; - const resize = ({ width, height } : {| width : ?number, height : ?number |}) : ZalgoPromise => { - return parent.resize.fireAndForget({ width, height }); + return parentResize.fireAndForget({ width, height }); }; const xport = (xports : X) : ZalgoPromise => { exportsPromise.resolve(xports); - return parent.export(xports); + return parentExport(xports); }; const getSiblings = ({ anyParent } = {}) => { @@ -213,11 +145,11 @@ export function childComponent(options : NormalizedComponentOptionsType const watchForClose = () => { window.addEventListener('beforeunload', () => { - parent.checkClose.fireAndForget(); + checkClose.fireAndForget(); }); window.addEventListener('unload', () => { - parent.checkClose.fireAndForget(); + checkClose.fireAndForget(); }); onCloseWindow(parentComponentWindow, () => { @@ -276,7 +208,7 @@ export function childComponent(options : NormalizedComponentOptionsType markWindowKnown(parentComponentWindow); watchForClose(); - return parent.init({ updateProps, close: destroy }); + return parentInit({ updateProps, close: destroy }); }).then(() => { return watchForResize(); @@ -289,10 +221,10 @@ export function childComponent(options : NormalizedComponentOptionsType const getProps = () => { if (props) { return props; + } else { + setProps(initialProps, parentDomain); + return props; } - - setProps(getPropsByRef(parentComponentWindow, parentDomain, propsRef), parentDomain); - return props; }; return { diff --git a/src/child/index.js b/src/child/index.js index 859299b5..9ba72a04 100644 --- a/src/child/index.js +++ b/src/child/index.js @@ -1,4 +1,4 @@ /* @flow */ export * from './child'; -export * from './window'; + diff --git a/src/child/window.js b/src/child/window.js deleted file mode 100644 index 171f0644..00000000 --- a/src/child/window.js +++ /dev/null @@ -1,42 +0,0 @@ -/* @flow */ - -import { inlineMemoize, stringifyError, base64decode } from 'belter/src'; - -import { ZOID } from '../constants'; -import type { ChildPayload } from '../parent'; - -function parseChildWindowName(windowName : string) : ChildPayload { - return inlineMemoize(parseChildWindowName, () => { - if (!windowName) { - throw new Error(`No window name`); - } - - const [ , zoidcomp, name, encodedPayload ] = windowName.split('__'); - - if (zoidcomp !== ZOID) { - throw new Error(`Window not rendered by zoid - got ${ zoidcomp }`); - } - - if (!name) { - throw new Error(`Expected component name`); - } - - if (!encodedPayload) { - throw new Error(`Expected encoded payload`); - } - - try { - return JSON.parse(base64decode(encodedPayload)); - } catch (err) { - throw new Error(`Can not decode window name payload: ${ encodedPayload }: ${ stringifyError(err) }`); - } - }, [ windowName ]); -} - -export function getChildPayload() : ?ChildPayload { - try { - return parseChildWindowName(window.name); - } catch (err) { - // pass - } -} diff --git a/src/component/component.js b/src/component/component.js index b4e3eb2c..d6e52791 100644 --- a/src/component/component.js +++ b/src/component/component.js @@ -3,14 +3,14 @@ import { setup as setupPostRobot, on, send, bridge, toProxyWindow, destroy as destroyPostRobot } from 'post-robot/src'; import { ZalgoPromise } from 'zalgo-promise/src'; -import { isWindow, getDomain, type CrossDomainWindowType } from 'cross-domain-utils/src'; +import { isWindow, getDomain, matchDomain, type CrossDomainWindowType, type DomainMatcher } from 'cross-domain-utils/src'; import { noop, isElement, cleanup, memoize, identity, extend, uniqueID } from 'belter/src'; -import { getChildPayload, childComponent, type ChildComponent } from '../child'; +import { childComponent, type ChildComponent } from '../child'; import { type RenderOptionsType, type ParentHelpers, parentComponent } from '../parent/parent'; import { ZOID, CONTEXT, POST_MESSAGE, WILDCARD, METHOD, PROP_TYPE } from '../constants'; import { react, angular, vue, vue3, angular2 } from '../drivers'; -import { getGlobal, destroyGlobal } from '../lib'; +import { getGlobal, destroyGlobal, getInitialParentPayload, isChildComponentWindow } from '../lib'; import type { CssDimensionsType, StringMatcherType } from '../types'; import { validateOptions } from './validate'; @@ -57,7 +57,7 @@ export type ComponentOptionsType = {| tag : string, url : string | ({| props : PropsType

|}) => string, - domain? : string | RegExp, + domain? : DomainMatcher, bridgeUrl? : string, method? : $Values, @@ -102,7 +102,7 @@ export type NormalizedComponentOptionsType = {| name : string, url : string | ({| props : PropsType

|}) => string, - domain : ?(string | RegExp), + domain : ?DomainMatcher, bridgeUrl : ?string, method : ?$Values, @@ -287,8 +287,14 @@ export function component(opts : ComponentOptionsType) : Compo const instances = []; const isChild = () : boolean => { - const payload = getChildPayload(); - return Boolean(payload && payload.tag === tag && payload.childDomain === getDomain()); + if (isChildComponentWindow()) { + const { payload } = getInitialParentPayload(); + if (payload.tag === tag && matchDomain(payload.childDomainMatch, getDomain())) { + return true; + } + } + + return false; }; const registerChild = memoize(() : ?ChildComponent => { diff --git a/src/constants.js b/src/constants.js index 2cf3e0a0..26a5e6f7 100644 --- a/src/constants.js +++ b/src/constants.js @@ -18,15 +18,11 @@ export const PROP_TYPE = { ARRAY: ('array' : 'array') }; -export const INITIAL_PROPS = { - RAW: 'raw', - UID: 'uid' -}; - -export const WINDOW_REFERENCES = { +export const WINDOW_REFERENCE = { OPENER: ('opener' : 'opener'), PARENT: ('parent' : 'parent'), - GLOBAL: ('global' : 'global') + GLOBAL: ('global' : 'global'), + NAME: ('name' : 'name') }; export const PROP_SERIALIZATION = { diff --git a/src/lib/index.js b/src/lib/index.js index b1a63ddf..56b6d32e 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -2,3 +2,4 @@ export * from './global'; export * from './serialize'; +export * from './window'; diff --git a/src/lib/serialize.js b/src/lib/serialize.js index 6c7145bd..2f8d5a31 100644 --- a/src/lib/serialize.js +++ b/src/lib/serialize.js @@ -1,6 +1,11 @@ /* @flow */ import { ZalgoPromise } from 'zalgo-promise/src'; +import { serializeMessage, deserializeMessage, toProxyWindow, type ProxyWindow } from 'post-robot/src'; +import { uniqueID, base64encode, base64decode } from 'belter/src'; +import type { CrossDomainWindowType, DomainMatcher } from 'cross-domain-utils/src'; + +import { getGlobal } from './global'; export type ProxyObject = {| get : () => ZalgoPromise @@ -20,3 +25,156 @@ export function getProxyObject(obj : T) : ProxyObject { } }; } + +export function basicSerialize(data : T) : string { + return base64encode(JSON.stringify(data)); +} + +export function basicDeserialize(serializedData : string) : T { + return JSON.parse(base64decode(serializedData)); +} + +export const REFERENCE_TYPE = { + UID: ('uid' : 'uid'), + RAW: ('raw' : 'raw') +}; + +export type ReferenceType = + {| type : typeof REFERENCE_TYPE.UID, uid : string |} | + {| type : typeof REFERENCE_TYPE.RAW, val : T |}; + +export function getUIDRefStore(win : CrossDomainWindowType) : { [string] : T } { + const global = getGlobal(win); + global.references = global.references || {}; + return global.references; +} + +export function getUIDRef(val : T) : ReferenceType { + const uid = uniqueID(); + const references = getUIDRefStore(window); + references[uid] = val; + return { type: REFERENCE_TYPE.UID, uid }; +} + +export function getRawRef(val : T) : ReferenceType { + return { type: REFERENCE_TYPE.RAW, val }; +} + +export function getRefValue(win : CrossDomainWindowType, ref : ReferenceType) : T { + if (ref.type === REFERENCE_TYPE.RAW) { + return ref.val; + } + + if (ref.type === REFERENCE_TYPE.UID) { + const references = getUIDRefStore(win); + return references[ref.uid]; + } + + throw new Error(`Unsupported ref type: ${ ref.type }`); +} + +export function cleanupRef(win : CrossDomainWindowType, ref : ReferenceType) { + if (ref.type === REFERENCE_TYPE.UID) { + const references = getUIDRefStore(win); + delete references[ref.uid]; + } +} + +type Message = {| + sender : {| + domain : string + |}, + metaData : M, + reference : ReferenceType +|}; + +type CrossDomainSerializeOptions = {| + data : T, + metaData : M, + sender : {| + domain : string + |}, + receiver : {| + win : ProxyWindow | CrossDomainWindowType, + domain : DomainMatcher + |}, + passByReference? : boolean +|}; + +type CrossDomainSerializedMessage = {| + serializedData : string, + cleanReference : () => void +|}; + +export function crossDomainSerialize({ data, metaData, sender, receiver, passByReference = false } : CrossDomainSerializeOptions) : CrossDomainSerializedMessage { + const proxyWin = toProxyWindow(receiver.win); + const serializedMessage = serializeMessage(proxyWin, receiver.domain, data); + + const reference = passByReference + ? getUIDRef(serializedMessage) + : getRawRef(serializedMessage); + + const message : Message = { + sender: { + domain: sender.domain + }, + metaData, + reference + }; + + const cleanReference = () => { + cleanupRef(window, reference); + }; + + return { + serializedData: basicSerialize(message), + cleanReference + }; +} + +type CrossDomainDeserializeOptions = {| + data : string, + sender : {| + win : CrossDomainWindowType | ({| metaData : M |}) => CrossDomainWindowType, + domain? : string | ({| metaData : M |}) => string + |} +|}; + +type CrossDomainDeserializedMessage = {| + data : T, + metaData : M, + sender : {| + domain : string, + win : CrossDomainWindowType + |} +|}; + +export function crossDomainDeserialize({ data, sender } : CrossDomainDeserializeOptions) : CrossDomainDeserializedMessage { + const message : Message = basicDeserialize(data); + + const { reference, metaData } = message; + + let win; + if (typeof sender.win === 'function') { + win = sender.win({ metaData }); + } else { + win = sender.win; + } + + let domain; + if (typeof sender.domain === 'function') { + domain = sender.domain({ metaData }); + } else if (typeof sender.domain === 'string') { + domain = sender.domain; + } else { + domain = message.sender.domain; + } + + const serializedData = getRefValue(win, reference); + + return { + data: deserializeMessage(win, domain, serializedData), + metaData, + sender: { win, domain } + }; +} diff --git a/src/lib/window.js b/src/lib/window.js new file mode 100644 index 00000000..66277a0a --- /dev/null +++ b/src/lib/window.js @@ -0,0 +1,100 @@ +/* @flow */ + +import { assertExists, memoize } from 'belter/src'; +import { isSameDomain, getOpener, getNthParentFromTop, getAncestor, getAllFramesInWindow, + type CrossDomainWindowType } from 'cross-domain-utils/src'; + +import { ZOID, WINDOW_REFERENCE } from '../constants'; +import type { InitialChildPayload, WindowRef } from '../parent'; + +import { crossDomainDeserialize } from './serialize'; +import { tryGlobal } from './global'; + +function getWindowByRef(windowRef : WindowRef) : CrossDomainWindowType { + if (windowRef.type === WINDOW_REFERENCE.OPENER) { + return assertExists('opener', getOpener(window)); + + } else if (windowRef.type === WINDOW_REFERENCE.PARENT && typeof windowRef.distance === 'number') { + return assertExists('parent', getNthParentFromTop(window, windowRef.distance)); + + } else if (windowRef.type === WINDOW_REFERENCE.GLOBAL && windowRef.uid && typeof windowRef.uid === 'string') { + const { uid } = windowRef; + const ancestor = getAncestor(window); + + if (!ancestor) { + throw new Error(`Can not find ancestor window`); + } + + for (const frame of getAllFramesInWindow(ancestor)) { + if (isSameDomain(frame)) { + const win = tryGlobal(frame, global => global.windows && global.windows[uid]); + + if (win) { + return win; + } + } + } + } + + throw new Error(`Unable to find ${ windowRef.type } parent component window`); +} + +export function buildChildWindowName({ name, serializedPayload } : {| name : string, serializedPayload : string |}) : string { + return `__${ ZOID }__${ name }__${ serializedPayload }__`; +} + +export type InitialParentPayload = {| + parent : {| + domain : string, + win : CrossDomainWindowType + |}, + payload : InitialChildPayload +|}; + +const parseInitialParentPayload = memoize((windowName : string) : InitialParentPayload => { + if (!windowName) { + throw new Error(`No window name`); + } + + const [ , zoidcomp, name, serializedInitialPayload ] = windowName.split('__'); + + if (zoidcomp !== ZOID) { + throw new Error(`Window not rendered by zoid - got ${ zoidcomp }`); + } + + if (!name) { + throw new Error(`Expected component name`); + } + + if (!serializedInitialPayload) { + throw new Error(`Expected serialized payload ref`); + } + + const { data: payload, sender: parent } = crossDomainDeserialize({ + data: serializedInitialPayload, + sender: { + win: ({ metaData: { windowRef } }) => getWindowByRef(windowRef) + } + }); + + return { + parent, + payload + }; +}); + +export function getInitialParentPayload() : InitialParentPayload { + return parseInitialParentPayload(window.name); +} + +export function isChildComponentWindow() : boolean { + try { + if (getInitialParentPayload()) { + return true; + } + } catch (err) { + // pass + } + + return false; +} diff --git a/src/parent/parent.js b/src/parent/parent.js index 244fb1b1..f53ca60a 100644 --- a/src/parent/parent.js +++ b/src/parent/parent.js @@ -1,19 +1,19 @@ /* @flow */ /* eslint max-lines: 0 */ -import { send, bridge, serializeMessage, ProxyWindow, toProxyWindow, type CrossDomainFunctionType, cleanUpWindow } from 'post-robot/src'; -import { isSameDomain, matchDomain, getDomainFromUrl, isBlankDomain, - getDomain, type CrossDomainWindowType, - getDistanceFromTop, normalizeMockUrl, assertSameDomain, closeWindow, onCloseWindow, isWindowClosed, isSameTopWindow } from 'cross-domain-utils/src'; +import { send, bridge, ProxyWindow, toProxyWindow, type CrossDomainFunctionType, cleanUpWindow } from 'post-robot/src'; +import { isSameDomain, matchDomain, getDomainFromUrl, isBlankDomain, getAncestor, getDomain, type CrossDomainWindowType, + getDistanceFromTop, normalizeMockUrl, assertSameDomain, closeWindow, onCloseWindow, isWindowClosed, isSameTopWindow, + type DomainMatcher } from 'cross-domain-utils/src'; import { ZalgoPromise } from 'zalgo-promise/src'; import { addEventListener, uniqueID, elementReady, writeElementToWindow, eventEmitter, type EventEmitterType, - noop, onResize, extendUrl, appendChild, cleanup, base64encode, isRegex, + noop, onResize, extendUrl, appendChild, cleanup, once, stringifyError, destroyElement, getElementSafe, showElement, hideElement, iframe, memoize, isElementClosed, awaitFrameWindow, popup, normalizeDimension, watchElementForClose, isShadowElement, insertShadowSlot } from 'belter/src'; import { ZOID, POST_MESSAGE, CONTEXT, EVENT, METHOD, - INITIAL_PROPS, WINDOW_REFERENCES, DEFAULT_DIMENSIONS } from '../constants'; -import { getGlobal, getProxyObject, type ProxyObject } from '../lib'; + WINDOW_REFERENCE, DEFAULT_DIMENSIONS } from '../constants'; +import { getGlobal, getProxyObject, crossDomainSerialize, buildChildWindowName, type ProxyObject } from '../lib'; import type { PropsInputType, PropsType } from '../component/props'; import type { ChildExportsType } from '../child'; import type { CssDimensionsType } from '../types'; @@ -48,25 +48,24 @@ export type ParentExportsType = {| export : (X) => ZalgoPromise |}; -export type PropRef = - {| type : typeof INITIAL_PROPS.RAW, value : string |} | - {| type : typeof INITIAL_PROPS.UID, uid : string |}; - export type WindowRef = - {| type : typeof WINDOW_REFERENCES.OPENER |} | - {| type : typeof WINDOW_REFERENCES.PARENT, distance : number |} | - {| type : typeof WINDOW_REFERENCES.GLOBAL, uid : string |}; + {| type : typeof WINDOW_REFERENCE.OPENER |} | + {| type : typeof WINDOW_REFERENCE.PARENT, distance : number |} | + {| type : typeof WINDOW_REFERENCE.GLOBAL, uid : string |} | + {| type : typeof WINDOW_REFERENCE.NAME, name : string |}; -export type ChildPayload = {| +export type InitialChildPayload = {| uid : string, tag : string, version : string, context : $Values, - parentDomain : string, - childDomain : string, - parent : WindowRef, - props : PropRef, - exports : string + childDomainMatch : DomainMatcher, + props : PropsType

, + exports : ParentExportsType +|}; + +export type InitialChildPayloadMetadata = {| + windowRef : WindowRef |}; export type StateType = Object; @@ -205,6 +204,7 @@ export function parentComponent({ uid, options, overrides = getDefaultO let currentProxyWin : ?ProxyWindow; let currentProxyContainer : ?ProxyObject; let childComponent : ?ChildExportsType

; + let currentChildDomain : ?string; const onErrorOverride : ?OnError = overrides.onError; let getProxyContainerOverride : ?GetProxyContainer = overrides.getProxyContainer; @@ -250,7 +250,7 @@ export function parentComponent({ uid, options, overrides = getDefaultO }); }; - const getPropsForChild = (domain : string | RegExp) : ZalgoPromise> => { + const getPropsForChild = (initialChildDomain : string) : ZalgoPromise> => { const result = {}; for (const key of Object.keys(props)) { @@ -260,7 +260,7 @@ export function parentComponent({ uid, options, overrides = getDefaultO continue; } - if (prop && prop.sameDomain && !matchDomain(domain, getDomain(window))) { + if (prop && prop.sameDomain && !matchDomain(initialChildDomain, getDomain(window))) { continue; } @@ -350,28 +350,6 @@ export function parentComponent({ uid, options, overrides = getDefaultO }); }; - const getPropsRef = (proxyWin : ProxyWindow, childDomain : string, domain : string | RegExp) : ZalgoPromise => { - return getPropsForChild(domain).then(childProps => { - const value = serializeMessage(proxyWin, domain, childProps); - - const propRef = (childDomain === getDomain()) - ? { type: INITIAL_PROPS.UID, uid } - : { type: INITIAL_PROPS.RAW, value }; - - if (propRef.type === INITIAL_PROPS.UID) { - const global = getGlobal(window); - global.props = global.props || {}; - global.props[uid] = value; - - clean.register(() => { - delete global.props[uid]; - }); - } - - return propRef; - }); - }; - const setProxyWin = (proxyWin : ProxyWindow) : ZalgoPromise => { if (setProxyWinOverride) { return setProxyWinOverride(proxyWin); @@ -434,20 +412,16 @@ export function parentComponent({ uid, options, overrides = getDefaultO }); }; - const getChildDomain = () : string => { - if (domainMatch && typeof domainMatch === 'string') { - return domainMatch; - } - + const getInitialChildDomain = () : string => { return getDomainFromUrl(getUrl()); }; - const getDomainMatcher = () : string | RegExp => { - if (domainMatch && isRegex(domainMatch)) { + const getDomainMatcher = () : DomainMatcher => { + if (domainMatch) { return domainMatch; } - return getChildDomain(); + return getInitialChildDomain(); }; const openFrame = (context : $Values, { windowName } : {| windowName : string |}) : ZalgoPromise> => { @@ -529,24 +503,43 @@ export function parentComponent({ uid, options, overrides = getDefaultO }); }; - const getWindowRef = (target : CrossDomainWindowType, domain : string, context : $Values) : WindowRef => { - - if (domain === getDomain(window)) { - const global = getGlobal(window); - global.windows = global.windows || {}; - global.windows[uid] = window; - clean.register(() => { - delete global.windows[uid]; - }); - - return { type: WINDOW_REFERENCES.GLOBAL, uid }; + const getCurrentWindowReferenceUID = () : string => { + const global = getGlobal(window); + global.windows = global.windows || {}; + global.windows[uid] = window; + clean.register(() => { + delete global.windows[uid]; + }); + return uid; + }; + + const getWindowRef = (target : CrossDomainWindowType, initialChildDomain : string, context : $Values, proxyWin : ProxyWindow) : WindowRef => { + if (initialChildDomain === getDomain(window)) { + return { type: WINDOW_REFERENCE.GLOBAL, uid: getCurrentWindowReferenceUID() }; + } + + if (target !== window) { + throw new Error(`Can not construct cross-domain window reference for different target window`); + } + + if (props.window) { + const actualComponentWindow = proxyWin.getWindow(); + if (!actualComponentWindow) { + throw new Error(`Can not construct cross-domain window reference for lazy window prop`); + } + + if (getAncestor(actualComponentWindow) !== window) { + throw new Error(`Can not construct cross-domain window reference for window prop with different ancestor`); + } } if (context === CONTEXT.POPUP) { - return { type: WINDOW_REFERENCES.OPENER }; + return { type: WINDOW_REFERENCE.OPENER }; + } else if (context === CONTEXT.IFRAME) { + return { type: WINDOW_REFERENCE.PARENT, distance: getDistanceFromTop(window) }; } - return { type: WINDOW_REFERENCES.PARENT, distance: getDistanceFromTop(window) }; + throw new Error(`Can not construct window reference for child`); }; const runTimeout = () : ZalgoPromise => { @@ -559,8 +552,9 @@ export function parentComponent({ uid, options, overrides = getDefaultO }); }; - const initChild = (childExports : ChildExportsType

) : ZalgoPromise => { + const initChild = (childDomain : string, childExports : ChildExportsType

) : ZalgoPromise => { return ZalgoPromise.try(() => { + currentChildDomain = childDomain; childComponent = childExports; resolveInitPromise(); clean.register(() => childExports.close.fireAndForget().catch(noop)); @@ -749,28 +743,51 @@ export function parentComponent({ uid, options, overrides = getDefaultO const buildParentExports = (win : ProxyWindow) : ParentExportsType => { const checkClose = () => checkWindowClose(win); - return { init: initChild, close, checkClose, resize, onError, show, hide, export: xport }; + function init(childExports : ChildExportsType

) : ZalgoPromise { + return initChild(this.origin, childExports); + } + return { init, close, checkClose, resize, onError, show, hide, export: xport }; }; - const buildChildPayload = ({ proxyWin, childDomain, domain, target = window, context } : {| proxyWin : ProxyWindow, childDomain : string, domain : string | RegExp, target : CrossDomainWindowType, context : $Values|} = {}) : ZalgoPromise => { - return getPropsRef(proxyWin, childDomain, domain).then(propsRef => { + const buildInitialChildPayload = ({ proxyWin, initialChildDomain, childDomainMatch, context } : {| proxyWin : ProxyWindow, initialChildDomain : string, childDomainMatch : DomainMatcher, context : $Values|} = {}) : ZalgoPromise> => { + return getPropsForChild(initialChildDomain).then(childProps => { return { uid, context, tag, + childDomainMatch, version: __ZOID__.__VERSION__, - childDomain, - parentDomain: getDomain(window), - parent: getWindowRef(target, childDomain, context), - props: propsRef, - exports: serializeMessage(proxyWin, domain, buildParentExports(proxyWin)) + props: childProps, + exports: buildParentExports(proxyWin) }; }); }; - const buildWindowName = ({ proxyWin, childDomain, domain, target, context } : {| proxyWin : ProxyWindow, childDomain : string, domain : string | RegExp, target : CrossDomainWindowType, context : $Values|}) : ZalgoPromise => { - return buildChildPayload({ proxyWin, childDomain, domain, target, context }).then(childPayload => { - return `__${ ZOID }__${ name }__${ base64encode(JSON.stringify(childPayload)) }__`; + const buildSerializedChildPayload = ({ proxyWin, initialChildDomain, childDomainMatch, target = window, context } : {| proxyWin : ProxyWindow, initialChildDomain : string, childDomainMatch : DomainMatcher, target : CrossDomainWindowType, context : $Values|} = {}) : ZalgoPromise => { + return buildInitialChildPayload({ proxyWin, initialChildDomain, childDomainMatch, context }).then(childPayload => { + const { serializedData, cleanReference } = crossDomainSerialize({ + data: childPayload, + metaData: { + windowRef: getWindowRef(target, initialChildDomain, context, proxyWin) + }, + sender: { + domain: getDomain(window) + }, + receiver: { + win: proxyWin, + domain: childDomainMatch + }, + passByReference: initialChildDomain === getDomain() + }); + + clean.register(cleanReference); + return serializedData; + }); + }; + + const buildWindowName = ({ proxyWin, initialChildDomain, childDomainMatch, target, context } : {| proxyWin : ProxyWindow, initialChildDomain : string, childDomainMatch : DomainMatcher, target : CrossDomainWindowType, context : $Values|}) : ZalgoPromise => { + return buildSerializedChildPayload({ proxyWin, initialChildDomain, childDomainMatch, target, context }).then(serializedPayload => { + return buildChildWindowName({ name, serializedPayload }); }); }; @@ -876,13 +893,13 @@ export function parentComponent({ uid, options, overrides = getDefaultO return options.bridgeUrl; }; - const openBridge = (proxyWin : ProxyWindow, domain : string, context : $Values) : ?ZalgoPromise => { + const openBridge = (proxyWin : ProxyWindow, initialChildDomain : string, context : $Values) : ?ZalgoPromise => { if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) { return ZalgoPromise.try(() => { return proxyWin.awaitWindow(); }).then(win => { - if (!bridge || !bridge.needsBridge({ win, domain }) || bridge.hasBridge(domain, domain)) { + if (!bridge || !bridge.needsBridge({ win, domain: initialChildDomain }) || bridge.hasBridge(initialChildDomain, initialChildDomain)) { return; } @@ -893,7 +910,7 @@ export function parentComponent({ uid, options, overrides = getDefaultO } const bridgeDomain = getDomainFromUrl(bridgeUrl); - bridge.linkUrl(win, domain); + bridge.linkUrl(win, initialChildDomain); return bridge.openBridge(normalizeMockUrl(bridgeUrl), bridgeDomain); }); } @@ -924,12 +941,13 @@ export function parentComponent({ uid, options, overrides = getDefaultO return initPromise.then(() => { const child = childComponent; const proxyWin = currentProxyWin; + const childDomain = currentChildDomain; - if (!child || !proxyWin) { + if (!child || !proxyWin || !childDomain) { return; } - return getPropsForChild(getDomainMatcher()).then(childProps => { + return getPropsForChild(childDomain).then(childProps => { return child.updateProps(childProps).catch(err => { return checkWindowClose(proxyWin).then(closed => { if (!closed) { @@ -999,7 +1017,7 @@ export function parentComponent({ uid, options, overrides = getDefaultO }); }; - const checkAllowRender = (target : CrossDomainWindowType, domain : string | RegExp, container : string | HTMLElement) => { + const checkAllowRender = (target : CrossDomainWindowType, childDomainMatch : DomainMatcher, container : string | HTMLElement) => { if (target === window) { return; } @@ -1010,8 +1028,8 @@ export function parentComponent({ uid, options, overrides = getDefaultO const origin = getDomain(); - if (!matchDomain(domain, origin) && !isSameDomain(target)) { - throw new Error(`Can not render remotely to ${ domain.toString() } - can only render to ${ origin }`); + if (!matchDomain(childDomainMatch, origin) && !isSameDomain(target)) { + throw new Error(`Can not render remotely to ${ childDomainMatch.toString() } - can only render to ${ origin }`); } if (container && typeof container !== 'string') { @@ -1025,10 +1043,10 @@ export function parentComponent({ uid, options, overrides = getDefaultO const render = ({ target, container, context, rerender } : RenderOptions) : ZalgoPromise => { return ZalgoPromise.try(() => { - const domain = getDomainMatcher(); - const childDomain = getChildDomain(); + const initialChildDomain = getInitialChildDomain(); + const childDomainMatch = getDomainMatcher(); - checkAllowRender(target, domain, container); + checkAllowRender(target, childDomainMatch, container); const delegatePromise = ZalgoPromise.try(() => { if (target !== window) { @@ -1048,7 +1066,7 @@ export function parentComponent({ uid, options, overrides = getDefaultO const getProxyWindowPromise = getProxyWindow(); const buildWindowNamePromise = getProxyWindowPromise.then(proxyWin => { - return buildWindowName({ proxyWin, childDomain, domain, target, context }); + return buildWindowName({ proxyWin, initialChildDomain, childDomainMatch, target, context }); }); const openFramePromise = buildWindowNamePromise.then(windowName => openFrame(context, { windowName })); @@ -1111,7 +1129,7 @@ export function parentComponent({ uid, options, overrides = getDefaultO }); const openBridgePromise = openPromise.then(proxyWin => { - return openBridge(proxyWin, childDomain, context); + return openBridge(proxyWin, initialChildDomain, context); }); const runTimeoutPromise = loadUrlPromise.then(() => { diff --git a/test/tests/actions.jsx b/test/tests/actions.jsx index 9d02fce5..2eb09034 100644 --- a/test/tests/actions.jsx +++ b/test/tests/actions.jsx @@ -18,7 +18,7 @@ describe('zoid actions', () => { window.__component__ = () => { return zoid.create({ tag: 'test-container-close-iframe', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', containerTemplate: ({ doc, close, frame, prerenderFrame }) => { closeComponent = close; @@ -53,7 +53,7 @@ describe('zoid actions', () => { window.__component__ = () => { return zoid.create({ tag: 'test-container-close-popup', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', containerTemplate: ({ doc, close }) => { closeComponent = close; @@ -89,7 +89,7 @@ describe('zoid actions', () => { window.__component__ = () => { return zoid.create({ tag: 'test-container-close-popup-from-child', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', containerTemplate: ({ doc, close }) => { closeComponent = close; @@ -129,7 +129,7 @@ describe('zoid actions', () => { window.__component__ = () => { return zoid.create({ tag: 'test-container-focus-popup', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', containerTemplate: ({ doc, focus }) => { focusComponent = focus; @@ -164,7 +164,7 @@ describe('zoid actions', () => { window.__component__ = () => { return zoid.create({ tag: 'test-container-helper-close-iframe', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); }; @@ -189,7 +189,7 @@ describe('zoid actions', () => { window.__component__ = () => { return zoid.create({ tag: 'test-container-helper-focus-popup', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); }; diff --git a/test/tests/attributes.js b/test/tests/attributes.js index d1ab9894..31d9bbb8 100644 --- a/test/tests/attributes.js +++ b/test/tests/attributes.js @@ -13,7 +13,7 @@ describe('zoid attributes cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-static-attributes', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', attributes: { iframe: { @@ -47,7 +47,7 @@ describe('zoid attributes cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-dynamic-attributes', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', attributes: ({ props }) => ({ iframe: { diff --git a/test/tests/children.jsx b/test/tests/children.jsx index f986c54f..4f50823a 100644 --- a/test/tests/children.jsx +++ b/test/tests/children.jsx @@ -16,25 +16,25 @@ describe('zoid children cases', () => { window.__component__ = () => { const CardNumberField = zoid.create({ tag: 'test-multiple-children-card-field-number', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); const CardCVVField = zoid.create({ tag: 'test-multiple-children-card-field-cvv', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); const CardExpiryField = zoid.create({ tag: 'test-multiple-children-card-field-expiry', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); const CardFields = zoid.create({ tag: 'test-multiple-children-card-fields', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', children: () => { return { @@ -116,7 +116,7 @@ describe('zoid children cases', () => { window.__component__ = () => { const CardFields = zoid.create({ tag: 'test-multiple-children-card-fields-isolation', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', children: () => { return { @@ -168,25 +168,25 @@ describe('zoid children cases', () => { window.__component__ = () => { const CardNumberField = zoid.create({ tag: 'test-multiple-children-card-field-number-export', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); const CardCVVField = zoid.create({ tag: 'test-multiple-children-card-field-cvv-export', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); const CardExpiryField = zoid.create({ tag: 'test-multiple-children-card-field-expiry-export', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); const CardFields = zoid.create({ tag: 'test-multiple-children-card-fields-export', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', children: () => { return { @@ -272,7 +272,7 @@ describe('zoid children cases', () => { window.__component__ = () => { const Button = zoid.create({ tag: 'test-multiple-children-card-button-inherit-prop', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', props: { fundingSource: { @@ -285,7 +285,7 @@ describe('zoid children cases', () => { const CardFields = zoid.create({ tag: 'test-multiple-children-card-fields-inherit-prop', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', props: { fundingSource: { @@ -347,7 +347,7 @@ describe('zoid children cases', () => { window.__component__ = () => { const CardNumberField = zoid.create({ tag: 'test-multiple-children-card-field-number-getsiblings', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -358,7 +358,7 @@ describe('zoid children cases', () => { const CardCVVField = zoid.create({ tag: 'test-multiple-children-card-field-cvv-getsiblings', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -369,7 +369,7 @@ describe('zoid children cases', () => { const CardExpiryField = zoid.create({ tag: 'test-multiple-children-card-field-expiry-getsiblings', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -380,7 +380,7 @@ describe('zoid children cases', () => { const CardFields = zoid.create({ tag: 'test-multiple-children-card-fields-getsiblings', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', children: () => { return { @@ -393,7 +393,7 @@ describe('zoid children cases', () => { const OtherComponent = zoid.create({ tag: 'test-multiple-children-other-component-getsiblings', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -521,7 +521,7 @@ describe('zoid children cases', () => { window.__component__ = () => { const CardNumberField = zoid.create({ tag: 'test-multiple-children-card-field-number-getsiblings-sameparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -532,7 +532,7 @@ describe('zoid children cases', () => { const CardCVVField = zoid.create({ tag: 'test-multiple-children-card-field-cvv-getsiblings-sameparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -543,7 +543,7 @@ describe('zoid children cases', () => { const CardExpiryField = zoid.create({ tag: 'test-multiple-children-card-field-expiry-getsiblings-sameparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -554,7 +554,7 @@ describe('zoid children cases', () => { const CardFields = zoid.create({ tag: 'test-multiple-children-card-fields-getsiblings-sameparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', children: () => { return { @@ -567,7 +567,7 @@ describe('zoid children cases', () => { const OtherComponent = zoid.create({ tag: 'test-multiple-children-other-component-getsiblings-sameparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -691,7 +691,7 @@ describe('zoid children cases', () => { window.__component__ = () => { const CardNumberField = zoid.create({ tag: 'test-multiple-children-card-field-number-getsiblings-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -702,7 +702,7 @@ describe('zoid children cases', () => { const CardCVVField = zoid.create({ tag: 'test-multiple-children-card-field-cvv-getsiblings-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -713,7 +713,7 @@ describe('zoid children cases', () => { const CardExpiryField = zoid.create({ tag: 'test-multiple-children-card-field-expiry-getsiblings-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -724,7 +724,7 @@ describe('zoid children cases', () => { const CardFields = zoid.create({ tag: 'test-multiple-children-card-fields-getsiblings-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', children: () => { return { @@ -737,7 +737,7 @@ describe('zoid children cases', () => { const OtherComponent = zoid.create({ tag: 'test-multiple-children-other-component-getsiblings-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -748,7 +748,7 @@ describe('zoid children cases', () => { const OtherComponentParent = zoid.create({ tag: 'test-multiple-children-other-component-parent-getsiblings-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', children: () => { return { @@ -872,7 +872,7 @@ describe('zoid children cases', () => { window.__component__ = () => { const CardNumberField = zoid.create({ tag: 'test-multiple-children-card-field-number-getsiblings-anyparent-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -883,7 +883,7 @@ describe('zoid children cases', () => { const CardCVVField = zoid.create({ tag: 'test-multiple-children-card-field-cvv-getsiblings-anyparent-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -894,7 +894,7 @@ describe('zoid children cases', () => { const CardExpiryField = zoid.create({ tag: 'test-multiple-children-card-field-expiry-getsiblings-anyparent-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -905,7 +905,7 @@ describe('zoid children cases', () => { const CardFields = zoid.create({ tag: 'test-multiple-children-card-fields-getsiblings-anyparent-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', children: () => { return { @@ -918,7 +918,7 @@ describe('zoid children cases', () => { const OtherComponent = zoid.create({ tag: 'test-multiple-children-other-component-getsiblings-anyparent-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { submit: { @@ -929,7 +929,7 @@ describe('zoid children cases', () => { const OtherComponentParent = zoid.create({ tag: 'test-multiple-children-other-component-parent-getsiblings-anyparent-sameparent-diffparent', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', children: () => { return { diff --git a/test/tests/dimensions.jsx b/test/tests/dimensions.jsx index f4b9aeb4..a931e0d3 100644 --- a/test/tests/dimensions.jsx +++ b/test/tests/dimensions.jsx @@ -21,7 +21,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-dimensions', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', dimensions: { width: '178px', @@ -65,7 +65,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-popup-dimensions', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', dimensions: { width: '178px', @@ -114,7 +114,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-resize', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', attributes: { iframe: { @@ -159,7 +159,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-popup-dimensions-func', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', dimensions: ({ props }) => ({ width: props.dimensions.width, @@ -207,7 +207,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-resize-from-child', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', attributes: { iframe: { @@ -255,7 +255,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-autoresize-from-child', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', autoResize: { height: true, @@ -309,7 +309,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-autoresize-width-from-child', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', autoResize: { height: false, @@ -366,7 +366,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-autoresize-height-from-child', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', autoResize: { height: true, @@ -423,7 +423,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-autoresize-custom-from-child', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', autoResize: { height: true, @@ -478,7 +478,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-autoresize-from-prerender', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', autoResize: { height: true, @@ -539,7 +539,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-autoresize-width-from-prerender', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', autoResize: { height: false, @@ -604,7 +604,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-autoresize-height-from-prerender', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', autoResize: { height: true, @@ -669,7 +669,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-autoresize-custom-from-prerender', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', autoResize: { height: true, @@ -743,7 +743,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-100-percent-dimensions', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', dimensions: { width: '100%', @@ -798,7 +798,7 @@ describe('zoid dimensions cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-iframe-50-percent-dimensions', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', dimensions: { width: '50%', diff --git a/test/tests/domain.js b/test/tests/domain.js index 8590b979..4f3e5a5b 100644 --- a/test/tests/domain.js +++ b/test/tests/domain.js @@ -14,7 +14,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-parent-domain-wildcard', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', allowedParentDomains: '*' }); @@ -29,7 +29,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-parent-domain-string', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', allowedParentDomains: getDomain() }); @@ -45,7 +45,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-parent-domain-array', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', allowedParentDomains: [ getDomain(), 'https://www.foo.com' ] }); @@ -60,7 +60,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-parent-domain-array-wildcard', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', allowedParentDomains: [ '*', 'https://www.foo.com' ] }); @@ -74,7 +74,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-parent-domain-regex', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', allowedParentDomains: /.+/ }); @@ -92,7 +92,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-parent-domain-string-nomatch', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', allowedParentDomains: 'https://www.foo.com' }); @@ -108,7 +108,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-parent-domain-array-nomatch', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', allowedParentDomains: [ 'https://www.foo.com', 'https://www.bar.com' ] }); @@ -124,7 +124,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-parent-domain-regex-nomatch', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', allowedParentDomains: /^https:\/\/www\.foo\.com$/ }); @@ -140,7 +140,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-get-parent-domain', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); }; @@ -166,7 +166,7 @@ describe('parent domain check', () => { window.__component__ = () => { return zoid.create({ tag: 'test-get-parent', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); }; diff --git a/test/tests/error.js b/test/tests/error.js index 6481bd66..7fb83d7e 100644 --- a/test/tests/error.js +++ b/test/tests/error.js @@ -152,7 +152,7 @@ describe('zoid error cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-error-validate', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', validate: expectError('validate', () => { throw new Error(`Invalid component`); @@ -173,7 +173,7 @@ describe('zoid error cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-error-validate-onerror', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', validate: expectError('validate', () => { throw new Error(`Invalid component`); diff --git a/test/tests/exports.js b/test/tests/exports.js index 1b88e206..6063d70c 100644 --- a/test/tests/exports.js +++ b/test/tests/exports.js @@ -16,7 +16,7 @@ describe('zoid export cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-export-function-instance', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: ({ getExports }) => { return { @@ -60,7 +60,7 @@ describe('zoid export cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-export-value-instance', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: ({ getExports }) => { return { @@ -102,7 +102,7 @@ describe('zoid export cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-export-function-instance-defined', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { doSomething: { @@ -142,7 +142,7 @@ describe('zoid export cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-export-value-instance-defined', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: { value: { diff --git a/test/tests/happy.jsx b/test/tests/happy.jsx index 71f209f8..dd38204c 100644 --- a/test/tests/happy.jsx +++ b/test/tests/happy.jsx @@ -17,7 +17,7 @@ describe('zoid happy cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-url-function', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); }; @@ -254,7 +254,7 @@ describe('zoid happy cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-ischild', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); }; @@ -281,7 +281,7 @@ describe('zoid happy cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-render-ischild-negative', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); }; @@ -297,7 +297,7 @@ describe('zoid happy cases', () => { return ` const component = zoid.create({ tag: 'test-render-ischild-negative-second', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); diff --git a/test/tests/method.jsx b/test/tests/method.jsx index f33d5ee0..3eb36613 100644 --- a/test/tests/method.jsx +++ b/test/tests/method.jsx @@ -14,7 +14,7 @@ describe('zoid url method cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-post-props', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', props: { diff --git a/test/tests/remove.jsx b/test/tests/remove.jsx index 60665d0e..8b443750 100644 --- a/test/tests/remove.jsx +++ b/test/tests/remove.jsx @@ -19,7 +19,7 @@ describe('zoid remove cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-remove-destroy', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); }; @@ -66,7 +66,7 @@ describe('zoid remove cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-remove-destroy-shadow', - url: () => '/base/test/windows/child/index.htm', + url: () => 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com' }); }; diff --git a/test/tests/renderto.jsx b/test/tests/renderto.jsx index e83aceac..c8fa7379 100644 --- a/test/tests/renderto.jsx +++ b/test/tests/renderto.jsx @@ -115,7 +115,7 @@ describe('zoid renderto cases', () => { remote: zoid.create({ tag: 'test-renderto-prerender-popup-remote', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', prerenderTemplate: ({ doc }) => { const html = doc.createElement('html'); @@ -166,7 +166,7 @@ describe('zoid renderto cases', () => { remote: zoid.create({ tag: 'test-renderto-prerender-iframe-remote', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', prerenderTemplate: ({ doc }) => { const html = doc.createElement('html'); @@ -323,7 +323,7 @@ describe('zoid renderto cases', () => { remote: zoid.create({ tag: 'test-renderto-prerender-close-iframe-remote', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', prerenderTemplate: ({ close, doc }) => { const html = doc.createElement('html'); @@ -363,7 +363,7 @@ describe('zoid renderto cases', () => { remote: zoid.create({ tag: 'test-renderto-prerender-close-popup-remote', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', prerenderTemplate: ({ close, doc }) => { const html = doc.createElement('html'); @@ -406,7 +406,7 @@ describe('zoid renderto cases', () => { remote: zoid.create({ tag: 'test-renderto-container-focus-popup-remote', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', containerTemplate: ({ doc, focus }) => { doFocus = focus; @@ -457,7 +457,7 @@ describe('zoid renderto cases', () => { remote: zoid.create({ tag: 'test-renderto-prerender-focus-popup-remote', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', prerenderTemplate: ({ doc, focus }) => { const html = doc.createElement('html'); diff --git a/test/tests/rerender.js b/test/tests/rerender.js index 28b3cdef..fb3dd92f 100644 --- a/test/tests/rerender.js +++ b/test/tests/rerender.js @@ -15,7 +15,7 @@ describe('zoid rerender cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-rerender', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: ({ getExports }) => { return { @@ -67,7 +67,7 @@ describe('zoid rerender cases', () => { window.__component__ = () => { return zoid.create({ tag: 'test-rerender-during-render', - url: '/base/test/windows/child/index.htm', + url: 'mock://www.child.com/base/test/windows/child/index.htm', domain: 'mock://www.child.com', exports: ({ getExports }) => { return { diff --git a/test/windows/child/index.htm b/test/windows/child/index.htm index 232aaf97..c77c6f55 100644 --- a/test/windows/child/index.htm +++ b/test/windows/child/index.htm @@ -33,8 +33,10 @@