dom/browser-element/mochitest/browserElement_DataURI.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* Any copyright is dedicated to the public domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 // Test that data: URIs work with mozbrowserlocationchange events.
michael@0 5
michael@0 6 "use strict";
michael@0 7 SimpleTest.waitForExplicitFinish();
michael@0 8 browserElementTestHelpers.setEnabledPref(true);
michael@0 9 browserElementTestHelpers.addPermission();
michael@0 10
michael@0 11 function runTest() {
michael@0 12 var iframe1 = document.createElement('iframe');
michael@0 13 SpecialPowers.wrap(iframe1).mozbrowser = true;
michael@0 14 iframe1.id = 'iframe1';
michael@0 15 iframe1.addEventListener('mozbrowserloadend', function if1_loadend() {
michael@0 16 iframe1.removeEventListener('mozbrowserloadend', if1_loadend);
michael@0 17 ok(true, 'Got first loadend event.');
michael@0 18 SimpleTest.executeSoon(runTest2);
michael@0 19 });
michael@0 20 iframe1.src = browserElementTestHelpers.emptyPage1;
michael@0 21 document.body.appendChild(iframe1);
michael@0 22
michael@0 23 var iframe2 = document.createElement('iframe');
michael@0 24 iframe2.id = 'iframe2';
michael@0 25 document.body.appendChild(iframe2);
michael@0 26 }
michael@0 27
michael@0 28 function runTest2() {
michael@0 29 var iframe1 = document.getElementById('iframe1');
michael@0 30 var iframe2 = document.getElementById('iframe2');
michael@0 31
michael@0 32 var sawLoadEnd = false;
michael@0 33 var sawLocationChange = false;
michael@0 34
michael@0 35 iframe1.addEventListener('mozbrowserlocationchange', function(e) {
michael@0 36 ok(e.isTrusted, 'Event should be trusted.');
michael@0 37 ok(!sawLocationChange, 'Just one locationchange event.');
michael@0 38 ok(!sawLoadEnd, 'locationchange before load.');
michael@0 39 is(e.detail, 'data:text/html,1', "event's reported location");
michael@0 40 sawLocationChange = true;
michael@0 41 });
michael@0 42
michael@0 43 iframe1.addEventListener('mozbrowserloadend', function() {
michael@0 44 ok(sawLocationChange, 'Loadend after locationchange.');
michael@0 45 ok(!sawLoadEnd, 'Just one loadend event.');
michael@0 46 sawLoadEnd = true;
michael@0 47 });
michael@0 48
michael@0 49 function iframe2Load() {
michael@0 50 if (!sawLoadEnd || !sawLocationChange) {
michael@0 51 // Spin if iframe1 hasn't loaded yet.
michael@0 52 SimpleTest.executeSoon(iframe2Load);
michael@0 53 return;
michael@0 54 }
michael@0 55 ok(true, 'Got iframe2 load.');
michael@0 56 SimpleTest.finish();
michael@0 57 }
michael@0 58 iframe2.addEventListener('load', iframe2Load);
michael@0 59
michael@0 60
michael@0 61 iframe1.src = 'data:text/html,1';
michael@0 62
michael@0 63 // Load something into iframe2 to check that it doesn't trigger a
michael@0 64 // locationchange for our iframe1 listener.
michael@0 65 iframe2.src = browserElementTestHelpers.emptyPage2;
michael@0 66 }
michael@0 67
michael@0 68 addEventListener('testready', runTest);

mercurial