3 function isParentFrame() {
4 return window.parent === window;
7 var childDoneMessage = 'PASS child done';
10 if (isParentFrame()) {
11 window.addEventListener('message', function (event) {
13 if (event.data == childDoneMessage)
17 var iframe = document.createElement('iframe');
18 iframe.src = window.location;
19 document.body.appendChild(iframe);
23 return isParentFrame();
26 if (!isParentFrame()) {
27 var parent = window.parent;
28 log = function (msg) {
29 parent.postMessage(msg, '*');
33 log(childDoneMessage);
36 destroyContext = function () {
37 // This function can be called more than once so we need to check whether the iframe exists.
38 var frame = parent.document.querySelector('iframe');
41 log('PASS destroyed context');
46 withFrame = function (f) {
47 var frame = document.createElement('iframe');
48 frame.onload = function () {
55 frame.src = 'about:blank';
56 document.body.appendChild(frame);