Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / custom / testutils.js
blob3b267c43b462a164f3ea0df86d1e96dd8913ab00
1 (function () {
3 function isParentFrame() {
4 return window.parent === window;
7 var childDoneMessage = 'PASS child done';
9 fork = function () {
10 if (isParentFrame()) {
11 window.addEventListener('message', function (event) {
12 debug(event.data);
13 if (event.data == childDoneMessage)
14 finishJSTest();
15 });
17 var iframe = document.createElement('iframe');
18 iframe.src = window.location;
19 document.body.appendChild(iframe);
20 iframe = null;
23 return isParentFrame();
26 if (!isParentFrame()) {
27 var parent = window.parent;
28 log = function (msg) {
29 parent.postMessage(msg, '*');
32 done = function () {
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');
39 if (frame) {
40 frame.remove();
41 log('PASS destroyed context');
46 withFrame = function (f) {
47 var frame = document.createElement('iframe');
48 frame.onload = function () {
49 try {
50 f(frame);
51 } catch (e) {
52 testFailed(e);
55 frame.src = 'about:blank';
56 document.body.appendChild(frame);
59 })();