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 | var gPageA = null; |
michael@0 | 2 | var gPageB = null; |
michael@0 | 3 | |
michael@0 | 4 | // cached data from events |
michael@0 | 5 | var gTabOpenPageA = null; |
michael@0 | 6 | var gTabOpenPageB = null; |
michael@0 | 7 | var gTabOpenCount = 0; |
michael@0 | 8 | var gTabCloseCount = 0; |
michael@0 | 9 | var gTabMoveCount = 0; |
michael@0 | 10 | var gPageLoadCount = 0; |
michael@0 | 11 | |
michael@0 | 12 | var rootDir = getRootDirectory(gTestPath); |
michael@0 | 13 | const CHROMEROOT = rootDir; |
michael@0 | 14 | |
michael@0 | 15 | function test() { |
michael@0 | 16 | waitForExplicitFinish(); |
michael@0 | 17 | |
michael@0 | 18 | var windows = Application.windows; |
michael@0 | 19 | ok(windows, "Check access to browser windows"); |
michael@0 | 20 | is(windows.length, 1, "There should be one browser window open"); |
michael@0 | 21 | |
michael@0 | 22 | var activeWin = Application.activeWindow; |
michael@0 | 23 | activeWin.events.addListener("TabOpen", onTabOpen); |
michael@0 | 24 | activeWin.events.addListener("TabClose", onTabClose); |
michael@0 | 25 | activeWin.events.addListener("TabMove", onTabMove); |
michael@0 | 26 | |
michael@0 | 27 | gPageA = activeWin.open(makeURI(CHROMEROOT + "ContentA.html")); |
michael@0 | 28 | gPageA.events.addListener("load", onPageAFirstLoad); |
michael@0 | 29 | |
michael@0 | 30 | is(activeWin.tabs.length, 2, "Checking length of 'Browser.tabs' after opening 1 additional tab"); |
michael@0 | 31 | |
michael@0 | 32 | function onPageAFirstLoad(event) { |
michael@0 | 33 | gPageA.events.removeListener("load", onPageAFirstLoad); |
michael@0 | 34 | is(gPageA.uri.spec, event.data.uri.spec, "Checking event browser tab is equal to page A"); |
michael@0 | 35 | |
michael@0 | 36 | gPageB = activeWin.open(makeURI(CHROMEROOT + "ContentB.html")); |
michael@0 | 37 | gPageB.events.addListener("load", delayAfterOpen); |
michael@0 | 38 | gPageB.focus(); |
michael@0 | 39 | |
michael@0 | 40 | is(activeWin.tabs.length, 3, "Checking length of 'Browser.tabs' after opening a second additional tab"); |
michael@0 | 41 | is(activeWin.activeTab.index, gPageB.index, "Checking 'Browser.activeTab' after setting focus"); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function delayAfterOpen() { |
michael@0 | 45 | executeSoon(afterOpen); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | // need to wait for the url's to be refreshed during the load |
michael@0 | 49 | function afterOpen(event) { |
michael@0 | 50 | gPageB.events.removeListener("load", delayAfterOpen); |
michael@0 | 51 | // check actuals |
michael@0 | 52 | is(gPageA.uri.spec, CHROMEROOT + "ContentA.html", "Checking 'BrowserTab.uri' after opening"); |
michael@0 | 53 | is(gPageB.uri.spec, CHROMEROOT + "ContentB.html", "Checking 'BrowserTab.uri' after opening"); |
michael@0 | 54 | |
michael@0 | 55 | // check event |
michael@0 | 56 | is(gTabOpenCount, 2, "Checking event handler for tab open"); |
michael@0 | 57 | // check cached values from TabOpen event |
michael@0 | 58 | is(gPageA.uri.spec, gTabOpenPageA.uri.spec, "Checking first browser tab open is equal to page A"); |
michael@0 | 59 | is(gPageB.uri.spec, gTabOpenPageB.uri.spec, "Checking second browser tab open is equal to page B"); |
michael@0 | 60 | |
michael@0 | 61 | // test document access |
michael@0 | 62 | var test1 = gPageA.document.getElementById("test1"); |
michael@0 | 63 | ok(test1, "Checking existence of element in content DOM"); |
michael@0 | 64 | is(test1.innerHTML, "A", "Checking content of element in content DOM"); |
michael@0 | 65 | |
michael@0 | 66 | // test moving tab |
michael@0 | 67 | is(gTabMoveCount, 0, "Checking initial tab move count"); |
michael@0 | 68 | |
michael@0 | 69 | // move the tab |
michael@0 | 70 | gPageA.moveToEnd(); |
michael@0 | 71 | is(gPageA.index, 2, "Checking index after moving tab"); |
michael@0 | 72 | |
michael@0 | 73 | // check event |
michael@0 | 74 | is(gTabMoveCount, 1, "Checking event handler for tab move"); |
michael@0 | 75 | |
michael@0 | 76 | gBrowser.addProgressListener({ |
michael@0 | 77 | onStateChange: function (webProgress, request, stateFlags, status) { |
michael@0 | 78 | info("onStateChange: " + stateFlags); |
michael@0 | 79 | |
michael@0 | 80 | const complete = Ci.nsIWebProgressListener.STATE_IS_WINDOW + |
michael@0 | 81 | Ci.nsIWebProgressListener.STATE_IS_NETWORK + |
michael@0 | 82 | Ci.nsIWebProgressListener.STATE_STOP; |
michael@0 | 83 | if ((stateFlags & complete) == complete) { |
michael@0 | 84 | gBrowser.removeProgressListener(this); |
michael@0 | 85 | onPageBLoadComplete(); |
michael@0 | 86 | } |
michael@0 | 87 | }, |
michael@0 | 88 | onLocationChange: function () 0, |
michael@0 | 89 | onProgressChange: function () 0, |
michael@0 | 90 | onStatusChange: function () 0, |
michael@0 | 91 | onSecurityChange: function () 0 |
michael@0 | 92 | }); |
michael@0 | 93 | |
michael@0 | 94 | // test loading new content with a frame into a tab |
michael@0 | 95 | // the event will be checked in onPageBLoadComplete |
michael@0 | 96 | gPageB.events.addListener("load", onPageBLoadWithFrames); |
michael@0 | 97 | gPageB.load(makeURI(CHROMEROOT + "ContentWithFrames.html")); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function onPageBLoadWithFrames(event) { |
michael@0 | 101 | gPageLoadCount++; |
michael@0 | 102 | info("onPageBLoadWithFrames: " + gPageLoadCount); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | function onPageBLoadComplete() { |
michael@0 | 106 | gPageB.events.removeListener("load", onPageBLoadWithFrames); |
michael@0 | 107 | // check page load with frame event |
michael@0 | 108 | is(gPageLoadCount, 1, "Checking load count after loading new content with a frame"); |
michael@0 | 109 | |
michael@0 | 110 | // test loading new content into a tab |
michael@0 | 111 | // the event will be checked in onPageASecondLoad |
michael@0 | 112 | gPageA.events.addListener("load", onPageASecondLoad); |
michael@0 | 113 | gPageA.load(makeURI(CHROMEROOT + "ContentB.html")); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function onPageASecondLoad(event) { |
michael@0 | 117 | gPageA.events.removeListener("load", onPageASecondLoad); |
michael@0 | 118 | is(gPageA.uri.spec, CHROMEROOT + "ContentB.html", "Checking 'BrowserTab.uri' after loading new content"); |
michael@0 | 119 | |
michael@0 | 120 | // start testing closing tabs |
michael@0 | 121 | // the event will be checked in afterClose |
michael@0 | 122 | // use executeSoon so the onPageASecondLoad |
michael@0 | 123 | // has a chance to finish first |
michael@0 | 124 | gPageA.close(); |
michael@0 | 125 | gPageB.close(); |
michael@0 | 126 | |
michael@0 | 127 | is(gTabCloseCount, 2, "Checking that tabs closed"); |
michael@0 | 128 | is(activeWin.tabs.length, 1, "Checking length of 'Browser.tabs' after closing 2 tabs"); |
michael@0 | 129 | finish(); |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | function onTabOpen(event) { |
michael@0 | 133 | gTabOpenCount++; |
michael@0 | 134 | |
michael@0 | 135 | // cache these values so we can check them later (after loading completes) |
michael@0 | 136 | if (gTabOpenCount == 1) |
michael@0 | 137 | gTabOpenPageA = event.data; |
michael@0 | 138 | |
michael@0 | 139 | if (gTabOpenCount == 2) |
michael@0 | 140 | gTabOpenPageB = event.data; |
michael@0 | 141 | } |
michael@0 | 142 | function onTabClose(event) { |
michael@0 | 143 | gTabCloseCount++; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | function onTabMove(event) { |
michael@0 | 147 | gTabMoveCount++; |
michael@0 | 148 | } |