forked from DevExpress/testcafe-hammerhead
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iframe-test.js
693 lines (534 loc) · 25.4 KB
/
iframe-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
var settings = hammerhead.settings;
var overriding = hammerhead.utils.overriding;
var DomProcessor = hammerhead.processors.DomProcessor;
var htmlUtils = hammerhead.utils.html;
var iframeSandbox = hammerhead.sandbox.iframe;
var cookieSandbox = hammerhead.sandbox.cookie;
var browserUtils = hammerhead.utils.browser;
var domUtils = hammerhead.utils.dom;
var shadowUI = hammerhead.sandbox.shadowUI;
var Promise = hammerhead.Promise;
var nativeMethods = hammerhead.nativeMethods;
test('should not miss the Hammerhead instance after the iframe.contentDocument.close function calling (GH-1821)', function () {
function checkIframe (iframe) {
iframe.contentDocument.open();
iframe.contentDocument.write('Hello!');
iframe.contentDocument.close();
var iframeHammerhead = iframe.contentWindow['%hammerhead%'];
ok(iframeHammerhead);
}
return Promise.all([
createTestIframe(),
createTestIframe({ src: getSameDomainPageUrl('../../data/iframe/simple-iframe.html') })
])
.then(function (iframes) {
var iframeWithoutSrc = iframes[0];
var iframeWithSrc = iframes[1];
checkIframe(iframeWithoutSrc);
// NOTE: Both IE11 and Edge don't support this test scenario
if (!browserUtils.isIE)
checkIframe(iframeWithSrc);
});
});
test('event should not raise before iframe is appended to DOM', function () {
var eventRaised = false;
var handler = function () {
eventRaised = true;
};
iframeSandbox.on(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler);
document.createElement('iframe');
ok(!eventRaised);
iframeSandbox.off(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler);
});
test('event should not raise if a cross-domain iframe is appended', function () {
var eventRaised = false;
var handler = function () {
eventRaised = true;
};
iframeSandbox.on(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler);
var $iframe = $('<iframe id="test7" src="http://cross.domain.com">').appendTo('body');
ok(!eventRaised);
iframeSandbox.off(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler);
$iframe.remove();
});
test('document.write', function () {
var iframe = document.createElement('iframe');
iframe.id = 'test' + Date.now();
document.body.appendChild(iframe);
iframe.contentDocument.write('<script>window.tempTestValue = !!__call$;<' + '/script>');
ok(iframe.contentWindow.tempTestValue);
iframe.parentNode.removeChild(iframe);
});
if (nativeMethods.iframeSrcdocGetter) {
module('srcdoc');
test('process html with iframe with srcdoc', function () {
document.body.insertAdjacentHTML('beforeend', '<iframe id="test' + Date.now() + '" srcdoc="' +
'<a href=\'http://domain.com/\'>Link</a><script>document.write(location.href)<' + '/script>"></iframe>');
var iframe = document.body.lastChild;
return window.QUnitGlobals.wait(function () {
return true;
})
.then(function () {
return window.QUnitGlobals.waitForIframe(iframe);
})
.then(function () {
var anchor = iframe.contentDocument.querySelector('a');
strictEqual(nativeMethods.anchorHrefGetter.call(anchor), 'http://' + location.host + '/sessionId!i/http://domain.com/');
strictEqual(nativeMethods.getAttribute.call(anchor, DomProcessor.getStoredAttrName('href')), 'http://domain.com/');
strictEqual(anchor.href, 'http://domain.com/');
strictEqual(anchor.getAttribute('href'), 'http://domain.com/');
iframe.contentDocument.body.removeChild(anchor);
strictEqual(iframe.contentDocument.body.lastChild.textContent, 'https://example.com/');
document.body.removeChild(iframe);
});
});
test('the srcdoc property', function () {
var iframe = document.createElement('iframe');
var html = '<body><script>document.write(location.href)<' + '/script>';
iframe.srcdoc = html;
iframe.id = 'test' + Date.now();
document.body.appendChild(iframe);
return window.QUnitGlobals.wait(function () {
return true;
})
.then(function () {
return window.QUnitGlobals.waitForIframe(iframe);
})
.then(function () {
strictEqual(iframe.srcdoc, html);
ok(nativeMethods.iframeSrcdocGetter.call(iframe).indexOf('__get$Loc') > -1);
strictEqual(iframe.contentDocument.body.lastChild.textContent, 'https://example.com/');
document.body.removeChild(iframe);
});
});
test('the srcdoc attribute', function () {
var iframe = document.createElement('iframe');
var html = '<a href="123"></a>';
iframe.setAttribute('srcdoc', html);
strictEqual(iframe.getAttribute('srcdoc'), html);
strictEqual(nativeMethods.getAttribute.call(iframe, 'srcdoc'), htmlUtils.processHtml(html, { isPage: true }).replace(/(sessionId)/, '$1!i'));
});
test('ready to init event should be raised after the document was initialized (added to dom)', function () {
var iframeLoadingEventRaised = false;
var handler = function (iframe) {
iframeLoadingEventRaised = true;
strictEqual(iframe.contentDocument.location.href, 'about:srcdoc');
};
iframeSandbox.on(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler);
return createTestIframe({ srcdoc: '<h1>simple markup</h1>' })
.then(function () {
ok(iframeLoadingEventRaised);
iframeSandbox.off(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler);
});
});
test('ready to init event should be raised after the document was initialized (already in dom)', function () {
createTestIframe({ src: getSameDomainPageUrl('../../data/iframe/iframe-with-srcdoc.html') });
return waitForMessage(window)
.then(function (iframeRunTaskScriptEventUrl) {
strictEqual(iframeRunTaskScriptEventUrl, 'about:srcdoc');
});
});
test('document\'s methods should be rewritten immediately after an iframe added to dom (GH-2647)', function () {
var iframe = document.createElement('iframe');
iframe.id = 'test' + Date.now();
iframe.srcdoc = '<h1>test</h1>';
document.body.appendChild(iframe);
iframe.contentDocument.open();
iframe.contentDocument.write('<script>parent.postMessage("message", "*")<' + '/script>');
iframe.contentDocument.close();
return new Promise(function (resolve) {
window.addEventListener('message', function onMessage (e) {
strictEqual(e.data, 'message');
window.removeEventListener('message', onMessage);
document.body.removeChild(iframe);
resolve();
});
});
});
}
test('should not call the contentWindow getter while cloning iframe/frame from XMLDocument (GH-2554)', function () {
expect(0);
var str = '<document><iframe /><frame /></document>';
var parser = new DOMParser();
var xmlDocument = parser.parseFromString(str, 'text/xml');
var iframe = xmlDocument.childNodes[0].childNodes[0];
var frame = xmlDocument.childNodes[0].childNodes[1];
try {
// NOTE: in this case we have the "Element" iframe/frame prototype that doesn't have the contentWindow getter.
iframe.cloneNode(true);
frame.cloneNode(true);
}
catch (e) {
ok(false, e);
}
});
module('regression');
test('take sequences starting with "$" into account when generating task scripts (GH-389)', function () {
expect(1);
var iframeTemplate = '$$ $& $` $\' $n $nn {{{cookie}}}{{{referer}}}{{{iframeTaskScriptTemplate}}}';
return createTestIframe()
.then(function (iframe) {
iframe.contentWindow.eval = function (processed) {
strictEqual(processed, '$$ $& $` $\' $n $nn "' + cookieSandbox.getCookie() + '""' +
window.location.toString() + '""' + iframeTemplate + '"');
};
var templateSettings = settings.get();
var storedTemplate = templateSettings.iframeTaskScriptTemplate;
templateSettings.iframeTaskScriptTemplate = iframeTemplate;
iframeSandbox.iframeReadyToInitHandler(iframe);
templateSettings.iframeTaskScriptTemplate = storedTemplate;
});
});
test('ready to init event must not raise for added iframe(B239643)', function () {
var container = document.createElement('div');
document.body.appendChild(container);
return createTestIframe(null, container)
.then(function () {
var iframeLoadingEventRaised = false;
var handler = function () {
iframeLoadingEventRaised = true;
};
iframeSandbox.on(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler);
// eslint-disable-next-line no-unused-vars
var dummy = container.innerHTML;
ok(!iframeLoadingEventRaised);
iframeSandbox.off(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler);
});
});
test('the AMD module loader disturbs proxying an iframe without src (GH-127)', function () {
var amdModuleLoaderMock = function () {
};
amdModuleLoaderMock.amd = {};
window.define = amdModuleLoaderMock;
return createTestIframe()
.then(function (iframe) {
ok(iframe.contentWindow['%hammerhead%']);
delete window.define;
});
});
test('native methods are properly initialized in an iframe without src (GH-279)', function () {
return createTestIframe()
.then(function (iframe) {
var iframeDocument = iframe.contentDocument;
var iframeWindow = iframe.contentWindow;
var iframeHammerhead = iframeWindow['%hammerhead%'];
var overriddenCreateElement = iframeDocument.createElement;
var overriddenAppendChild = iframeDocument.createElement('div').appendChild;
ok(!overriding.isNativeFunction(overriddenCreateElement));
ok(!overriding.isNativeFunction(overriddenAppendChild));
var nativeImage = new iframeHammerhead.sandbox.nativeMethods.Image(10, 10);
var overridedImage = new iframeWindow.Image(10, 10);
var nativeSrcGetter = iframeHammerhead.sandbox.nativeMethods.imageSrcGetter;
var imageSrc = 'test.jpg';
nativeImage.src = imageSrc;
overridedImage.src = imageSrc;
ok(nativeSrcGetter.call(nativeImage) !== nativeSrcGetter.call(overridedImage));
});
});
test('quotes in the cookies are not escaped when a task script for an iframe is built on the client (GH-366)', function () {
var cookie = '""\'\'';
settings.get().cookie = cookie;
return createTestIframe()
.then(function (iframe) {
strictEqual(iframe.contentWindow['%hammerhead%'].settings.get().cookie, cookie);
});
});
asyncTest('an error occurs when proxing two nested iframes (a top iframe has src with javascript protocol) (GH-125)', function () {
var iframe = document.createElement('iframe');
var countNestedIframeLoadEvents = 0;
var maxCountNestedIframeLoadEvents = browserUtils.isWebKit && (!browserUtils.isChrome || browserUtils.isAndroid) ? 2 : 1; // GH-1966
var countXhrLoadEvents = 0;
var validCountXhrLoadEvents = browserUtils.isWebKit && (!browserUtils.isChrome || browserUtils.isAndroid) ? 2 : 1; // GH-1966
// NOTE: NetworkError occurs in IE11 after some Windows 10 update (iframe without src case) (GH-1837)
var skipIframeCheck = false;
iframe.id = 'test_iframe_id_96ljkls';
iframe.setAttribute('src', 'javascript:"<html><body><h1>test</h1></body></html>"');
iframe.addEventListener('load', function () {
var iframeHammerhead = iframe.contentWindow['%hammerhead%'];
var iframeIframeSandbox = iframeHammerhead.sandbox.iframe;
var iframeDocument = iframe.contentDocument;
var nestedIframe = iframeDocument.createElement('iframe');
var checkXhrEventListeners = function () {
var xhr = new iframe.contentWindow.XMLHttpRequest();
xhr.addEventListener('load', function () {
countXhrLoadEvents++;
ok(this.responseText, 'test');
});
xhr.addEventListener('error', function () {
ok(false, 'error event must not be raised');
});
xhr.open('post', '/get-script/test', false);
try {
xhr.send();
}
catch (e) {
if (e.name === 'NetworkError') {
skipIframeCheck = true;
expect(0);
}
}
};
iframeIframeSandbox.off(iframeIframeSandbox.RUN_TASK_SCRIPT_EVENT, iframeIframeSandbox.iframeReadyToInitHandler);
iframeIframeSandbox.on(iframeIframeSandbox.RUN_TASK_SCRIPT_EVENT, initIframeTestHandler);
checkXhrEventListeners();
nestedIframe.id = 'test_nestedIframe_klshgfn111';
nestedIframe.setAttribute('src', 'about:blank');
window.QUnitGlobals.waitForIframe(nestedIframe)
.then(function () {
countNestedIframeLoadEvents++;
if (countNestedIframeLoadEvents === maxCountNestedIframeLoadEvents) {
if (!skipIframeCheck)
strictEqual(countXhrLoadEvents, validCountXhrLoadEvents);
iframe.parentNode.removeChild(iframe);
start();
}
});
iframeDocument.body.appendChild(nestedIframe);
});
document.body.appendChild(iframe);
});
asyncTest('native methods of the iframe document aren`t overridden for iframe with javascript src (GH-358)', function () {
var iframe = document.createElement('iframe');
var loadEventCount = 0;
var maxLoadEventCount = browserUtils.isWebKit && (!browserUtils.isChrome || browserUtils.isAndroid) ? 2 : 1; // GH-1966
iframe.id = 'test_nmsghf';
iframe.setAttribute('src', 'javascript:"<html><body>test</body></html>"');
iframe.addEventListener('load', function () {
var iframeHammerhead = iframe.contentWindow['%hammerhead%'];
var iframeNativeMethods = iframeHammerhead.nativeMethods;
ok(iframeNativeMethods.createElement.toString().indexOf('native code') !== -1);
loadEventCount++;
if (loadEventCount >= maxLoadEventCount) {
iframe.parentNode.removeChild(iframe);
start();
}
});
document.body.appendChild(iframe);
});
test('native methods of the iframe document aren`t overridden for iframe with javascript src (GH-358)', function () {
var iframe = document.createElement('iframe');
ok(!iframeSandbox._shouldSaveIframeNativeMethods(iframe));
iframe.setAttribute('src', '');
ok(!iframeSandbox._shouldSaveIframeNativeMethods(iframe));
iframe.setAttribute('src', 'javascript:false');
strictEqual(iframeSandbox._shouldSaveIframeNativeMethods(iframe), browserUtils.isWebKit);
iframe.setAttribute('src', 'javascript:"<html><body></body></html>"');
strictEqual(iframeSandbox._shouldSaveIframeNativeMethods(iframe), browserUtils.isWebKit);
});
test("'body.appendChild' method works incorrectly in the particular case (GH-421)", function () {
var iframes = [];
var countIframes = 2;
var createIframes = function () {
for (var i = 0; i < countIframes; i++) {
var iframe = document.createElement('iframe');
iframes.push(iframe);
iframe.id = 'test_GH_i_421_' + i;
iframe.setAttribute('src', 'javascript:false');
document.body.appendChild(iframe);
}
};
var performDocumentWriteInIframes = function () {
for (var i = 0; i < countIframes; i++) {
var iframe = iframes[i];
iframe.contentDocument.open();
iframe.contentDocument.write('<html><head><style></style><title>title</title></head><body></body></html>');
iframe.contentDocument.close();
}
};
var checkIframes = function () {
for (var i = 0; i < countIframes; i++) {
var iframe = iframes[i];
ok(!iframe.contentWindow['%hammerhead%'].sandbox.shadowUI.root);
iframe.parentNode.removeChild(iframe);
}
};
createIframes();
performDocumentWriteInIframes();
var container = document.createElement('div');
document.body.appendChild(container);
var child = document.createElement('p');
container.appendChild(child);
document.body.removeChild(container);
ok(shadowUI.root);
checkIframes();
});
if (browserUtils.isWebKit) {
test('event listeners added twice in an iframe after document.write (GH-839)', function () {
var internalClickEventCounter = 0;
return createTestIframe({ src: getSameDomainPageUrl('../../data/iframe/window-event-listeners.html') })
.then(function (iframe) {
iframe.contentWindow.performWrite();
iframe.contentWindow['%hammerhead%'].eventSandbox.listeners.addInternalEventBeforeListener(iframe.contentWindow, ['click'], function () {
++internalClickEventCounter;
});
iframe.contentDocument.body.click();
return window.wait(500);
})
.then(function () {
strictEqual(internalClickEventCounter, 1);
});
});
}
test('self-removing script shouldn\'t throw an error (GH-TC-2469)', function () {
var iframe = document.createElement('iframe');
expect(0);
iframe.id = 'test' + Date.now();
iframe.src = 'javascript:""';
document.body.appendChild(iframe);
var iframeDocument = iframe.contentDocument;
iframeDocument.open();
iframe.contentWindow.onerror = function (e) {
ok(false, e);
};
iframeDocument.write('<html><head></head><body></body></html>');
iframeDocument.close();
document.body.removeChild(iframe);
});
test('write "doctype" markup without head and body tags (GH-TC-2639)', function () {
var iframe = document.createElement('iframe');
expect(0);
iframe.id = 'test' + Date.now();
document.body.appendChild(iframe);
try {
iframe.contentDocument.write('<!DOCTYPE html><div>x</div>');
}
catch (e) {
ok(false, e);
}
iframe.contentDocument.close();
iframe.parentNode.removeChild(iframe);
});
test('should not throw an exception if `Array.prototype.filter` was overriden (GH-1395)', function () {
expect(0);
var storedArrayFilter = Array.prototype.filter;
// eslint-disable-next-line no-extend-native
Array.prototype.filter = function () {
throw new Error('Should not use the `Array.prototype.filter` method for internal purposes.');
};
return createTestIframe()
.then(function () {
// eslint-disable-next-line no-extend-native
Array.prototype.filter = storedArrayFilter;
});
});
// NOTE: https://github.com/DevExpress/testcafe-hammerhead/issues/1821
if (!browserUtils.isFirefox) {
test('should not dublicate internal handlers after `Sandbox.reattach` call', function () {
return createTestIframe()
.then(function (iframe) {
var checkDublicatedEventListeners = function (sandbox) {
var eventListeners = sandbox.eventsListeners;
Object.keys(eventListeners).forEach(function (event) {
var listenersArr = eventListeners[event].map(function (item) {
return item.toString();
});
var uniqueListenerArr = listenersArr.filter(function (element, index, arr) {
return arr.indexOf(element) === index;
});
strictEqual(listenersArr.length, uniqueListenerArr.length);
});
};
iframe.contentDocument.open();
iframe.contentDocument.write('Hello!');
iframe.contentDocument.close();
var iframeHammerhead = iframe.contentWindow['%hammerhead%'];
var testedSandboxes = [
iframeHammerhead.shadowUI._iframeSandbox,
iframeHammerhead.shadowUI._nodeMutation,
iframeHammerhead.sandbox.codeInstrumentation._locationAccessorsInstrumentation
];
testedSandboxes.forEach(function (sandbox) {
checkDublicatedEventListeners(sandbox);
});
});
});
}
test('overridden functions should have the right prototype in an iframe without src (GH-1824)', function () {
return createTestIframe()
.then(function (iframe) {
iframe.contentWindow.eval('Function.prototype.testFn = function () { return true; }');
ok(iframe.contentWindow.Function.testFn());
ok(iframe.contentWindow.Image.testFn());
ok(iframe.contentDocument.body.appendChild.testFn());
notOk(window.Function.testFn);
});
});
test('hammerhead should not use overridden contentWindow, contentDocument getters (GH-1850)', function () {
return createTestIframe()
.then(function (iframe) {
Object.defineProperties(iframe, {
contentWindow: {
get: function () { /* eslint-disable-line getter-return */
ok('false', 'contentWindow');
},
enumerable: true,
configurable: true
},
contentDocument: {
get: function () { /* eslint-disable-line getter-return */
ok('false', 'contentDocument');
},
enumerable: true,
configurable: true
}
});
ok(domUtils.isIframeWithoutSrc(iframe));
strictEqual(domUtils.getIframeLocation(iframe).documentLocation, 'about:blank');
});
});
test('a self-removing script should not stop the parsing stream (GH-2000)', function () {
return createTestIframe()
.then(function (iframe) {
var iframeDoc = iframe.contentDocument;
iframeDoc.open('text/html', 'replace');
iframeDoc.write('<!DOCTYPE html><html><head><link rel="stylesheet" href="./style.css"></head>',
'<body><div id="mountPoint"></div></body></html>');
iframeDoc.close();
notEqual(iframeDoc.querySelector('#mountPoint'), null);
iframeDoc.open('text/html', 'replace');
iframeDoc.write('<!DOCTYPE html><html><head><link rel="stylesheet" href="./style.css"></head>',
'<body><div id="mountPoint"></div><script>var x = 5;<' + '/script></body></html>');
iframeDoc.close();
notEqual(iframeDoc.querySelector('#mountPoint'), null);
iframeDoc.open('text/html', 'replace');
iframeDoc.write('<!DOCTYPE html><html><head><link rel="stylesheet" href="./style.css"></head>',
'<body><script>var x = 5;<' + '/script><div id="mountPoint"></div></body></html>');
iframeDoc.close();
strictEqual(iframeDoc.querySelector('#mountPoint'),
browserUtils.isChrome || browserUtils.isSafari ? null : iframeDoc.body.children[1]);
});
});
test('the internal anchor element should be restored after the reusing hammerhead in iframe (GH-2461)', function () {
var iframe;
return createTestIframe({ src: 'javascript:"<p></p>"' })
.then(function (createdIframe) {
iframe = createdIframe;
iframe.src = getSameDomainPageUrl('../../data/iframe/simple-iframe.html');
return window.QUnitGlobals.waitForIframe(iframe);
})
.then(function () {
var anchor = iframe.contentDocument.createElement('a');
anchor.href = 'http://example.com/';
strictEqual(anchor.hostname, 'example.com');
});
});
test('Uninitialized iframes should correctly behave when they are rewritten (GH-2694 & GH-2693)', function () {
return createTestIframe({ src: getSameDomainPageUrl('../../data/iframe/multi-write.html') })
.then(function (iframe) {
var idoc = iframe.contentDocument;
var iframe1 = idoc.querySelector('#first-iframe');
var iframe2 = idoc.querySelector('#second-iframe');
strictEqual(idoc.body.lastElementChild.textContent, 'Current iframe!');
strictEqual(iframe1.contentDocument.body.lastChild.textContent, 'First iframe!');
strictEqual(iframe2.contentDocument.body.lastChild.textContent, 'Second iframe!');
});
});
if (browserUtils.isChrome && browserUtils.version > 88 || browserUtils.isFirefox) {
test('the correct referrer for cross-domain iframes', function () {
createTestIframe({ src: getCrossDomainPageUrl('../../data/cross-domain/get-referrer.html') });
return waitForMessage(window)
.then(function (referrer) {
strictEqual(referrer, 'https://example.com/');
});
});
}