Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 an iframe with the |mozbrowser| attribute emits mozbrowserloadX |
michael@0 | 5 | // events when this page is in the whitelist. |
michael@0 | 6 | |
michael@0 | 7 | "use strict"; |
michael@0 | 8 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 9 | browserElementTestHelpers.setEnabledPref(true); |
michael@0 | 10 | browserElementTestHelpers.addPermission(); |
michael@0 | 11 | |
michael@0 | 12 | function runTest() { |
michael@0 | 13 | // Load emptypage1 into the iframe, wait for that to finish loading, then |
michael@0 | 14 | // call runTest2. |
michael@0 | 15 | // |
michael@0 | 16 | // This should trigger loadstart, locationchange, and loadend events. |
michael@0 | 17 | |
michael@0 | 18 | var seenLoadEnd = false; |
michael@0 | 19 | var seenLoadStart = false; |
michael@0 | 20 | var seenLocationChange = false; |
michael@0 | 21 | |
michael@0 | 22 | var iframe = document.createElement('iframe'); |
michael@0 | 23 | SpecialPowers.wrap(iframe).mozbrowser = true; |
michael@0 | 24 | iframe.id = 'iframe'; |
michael@0 | 25 | iframe.src = 'http://example.com/tests/dom/browser-element/mochitest/file_browserElement_LoadEvents.html'; |
michael@0 | 26 | |
michael@0 | 27 | function loadstart(e) { |
michael@0 | 28 | ok(e.isTrusted, 'Event should be trusted.'); |
michael@0 | 29 | ok(!seenLoadEnd, 'loadstart before loadend.'); |
michael@0 | 30 | ok(!seenLoadStart, 'Just one loadstart event.'); |
michael@0 | 31 | ok(!seenLocationChange, 'loadstart before locationchange.'); |
michael@0 | 32 | seenLoadStart = true; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function locationchange(e) { |
michael@0 | 36 | ok(e.isTrusted, 'Event should be trusted.'); |
michael@0 | 37 | ok(!seenLocationChange, 'Just one locationchange event.'); |
michael@0 | 38 | seenLocationChange = true; |
michael@0 | 39 | ok(seenLoadStart, 'Location change after load start.'); |
michael@0 | 40 | ok(!seenLoadEnd, 'Location change before load end.'); |
michael@0 | 41 | ok(e.detail, browserElementTestHelpers.emptyPage1, "event's reported location"); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function loadend(e) { |
michael@0 | 45 | ok(e.isTrusted, 'Event should be trusted.'); |
michael@0 | 46 | ok(seenLoadStart, 'loadend after loadstart.'); |
michael@0 | 47 | ok(!seenLoadEnd, 'Just one loadend event.'); |
michael@0 | 48 | ok(seenLocationChange, 'loadend after locationchange.'); |
michael@0 | 49 | is(e.detail.backgroundColor, 'rgb(0, 128, 0)', 'Expected background color reported') |
michael@0 | 50 | seenLoadEnd = true; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | iframe.addEventListener('mozbrowserloadstart', loadstart); |
michael@0 | 54 | iframe.addEventListener('mozbrowserlocationchange', locationchange); |
michael@0 | 55 | iframe.addEventListener('mozbrowserloadend', loadend); |
michael@0 | 56 | |
michael@0 | 57 | function waitForAllCallbacks() { |
michael@0 | 58 | if (!seenLoadStart || !seenLoadEnd) { |
michael@0 | 59 | SimpleTest.executeSoon(waitForAllCallbacks); |
michael@0 | 60 | return; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | iframe.removeEventListener('mozbrowserloadstart', loadstart); |
michael@0 | 64 | iframe.removeEventListener('mozbrowserlocationchange', locationchange); |
michael@0 | 65 | iframe.removeEventListener('mozbrowserloadend', loadend); |
michael@0 | 66 | runTest2(); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | document.body.appendChild(iframe); |
michael@0 | 70 | waitForAllCallbacks(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function runTest2() { |
michael@0 | 74 | var seenLoadStart = false; |
michael@0 | 75 | var seenLoadEnd = false; |
michael@0 | 76 | var seenLocationChange = false; |
michael@0 | 77 | |
michael@0 | 78 | // Add this event listener to the document; the events should bubble. |
michael@0 | 79 | document.addEventListener('mozbrowserloadstart', function(e) { |
michael@0 | 80 | ok(e.isTrusted, 'Event should be trusted.'); |
michael@0 | 81 | ok(!seenLoadStart, 'Just one loadstart event.'); |
michael@0 | 82 | seenLoadStart = true; |
michael@0 | 83 | ok(!seenLoadEnd, 'Got mozbrowserloadstart before loadend.'); |
michael@0 | 84 | ok(!seenLocationChange, 'Got mozbrowserloadstart before locationchange.'); |
michael@0 | 85 | }); |
michael@0 | 86 | |
michael@0 | 87 | var iframe = document.getElementById('iframe'); |
michael@0 | 88 | iframe.addEventListener('mozbrowserlocationchange', function(e) { |
michael@0 | 89 | ok(e.isTrusted, 'Event should be trusted.'); |
michael@0 | 90 | ok(!seenLocationChange, 'Just one locationchange event.'); |
michael@0 | 91 | seenLocationChange = true; |
michael@0 | 92 | ok(seenLoadStart, 'Location change after load start.'); |
michael@0 | 93 | ok(!seenLoadEnd, 'Location change before load end.'); |
michael@0 | 94 | ok(e.detail, browserElementTestHelpers.emptyPage2, "event's reported location"); |
michael@0 | 95 | }); |
michael@0 | 96 | |
michael@0 | 97 | iframe.addEventListener('mozbrowserloadend', function(e) { |
michael@0 | 98 | ok(e.isTrusted, 'Event should be trusted.'); |
michael@0 | 99 | ok(!seenLoadEnd, 'Just one load end event.'); |
michael@0 | 100 | seenLoadEnd = true; |
michael@0 | 101 | ok(seenLoadStart, 'Load end after load start.'); |
michael@0 | 102 | ok(seenLocationChange, 'Load end after location change.'); |
michael@0 | 103 | is(e.detail.backgroundColor, 'transparent', 'Expected background color reported') |
michael@0 | 104 | }); |
michael@0 | 105 | |
michael@0 | 106 | iframe.src = browserElementTestHelpers.emptyPage2; |
michael@0 | 107 | |
michael@0 | 108 | function waitForAllCallbacks() { |
michael@0 | 109 | if (!seenLoadStart || !seenLoadEnd || !seenLocationChange) { |
michael@0 | 110 | SimpleTest.executeSoon(waitForAllCallbacks); |
michael@0 | 111 | return; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | SimpleTest.finish(); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | waitForAllCallbacks(); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | addEventListener('testready', runTest); |