1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/fuel/test/browser_Browser.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,148 @@ 1.4 +var gPageA = null; 1.5 +var gPageB = null; 1.6 + 1.7 +// cached data from events 1.8 +var gTabOpenPageA = null; 1.9 +var gTabOpenPageB = null; 1.10 +var gTabOpenCount = 0; 1.11 +var gTabCloseCount = 0; 1.12 +var gTabMoveCount = 0; 1.13 +var gPageLoadCount = 0; 1.14 + 1.15 +var rootDir = getRootDirectory(gTestPath); 1.16 +const CHROMEROOT = rootDir; 1.17 + 1.18 +function test() { 1.19 + waitForExplicitFinish(); 1.20 + 1.21 + var windows = Application.windows; 1.22 + ok(windows, "Check access to browser windows"); 1.23 + is(windows.length, 1, "There should be one browser window open"); 1.24 + 1.25 + var activeWin = Application.activeWindow; 1.26 + activeWin.events.addListener("TabOpen", onTabOpen); 1.27 + activeWin.events.addListener("TabClose", onTabClose); 1.28 + activeWin.events.addListener("TabMove", onTabMove); 1.29 + 1.30 + gPageA = activeWin.open(makeURI(CHROMEROOT + "ContentA.html")); 1.31 + gPageA.events.addListener("load", onPageAFirstLoad); 1.32 + 1.33 + is(activeWin.tabs.length, 2, "Checking length of 'Browser.tabs' after opening 1 additional tab"); 1.34 + 1.35 + function onPageAFirstLoad(event) { 1.36 + gPageA.events.removeListener("load", onPageAFirstLoad); 1.37 + is(gPageA.uri.spec, event.data.uri.spec, "Checking event browser tab is equal to page A"); 1.38 + 1.39 + gPageB = activeWin.open(makeURI(CHROMEROOT + "ContentB.html")); 1.40 + gPageB.events.addListener("load", delayAfterOpen); 1.41 + gPageB.focus(); 1.42 + 1.43 + is(activeWin.tabs.length, 3, "Checking length of 'Browser.tabs' after opening a second additional tab"); 1.44 + is(activeWin.activeTab.index, gPageB.index, "Checking 'Browser.activeTab' after setting focus"); 1.45 + } 1.46 + 1.47 + function delayAfterOpen() { 1.48 + executeSoon(afterOpen); 1.49 + } 1.50 + 1.51 + // need to wait for the url's to be refreshed during the load 1.52 + function afterOpen(event) { 1.53 + gPageB.events.removeListener("load", delayAfterOpen); 1.54 + // check actuals 1.55 + is(gPageA.uri.spec, CHROMEROOT + "ContentA.html", "Checking 'BrowserTab.uri' after opening"); 1.56 + is(gPageB.uri.spec, CHROMEROOT + "ContentB.html", "Checking 'BrowserTab.uri' after opening"); 1.57 + 1.58 + // check event 1.59 + is(gTabOpenCount, 2, "Checking event handler for tab open"); 1.60 + // check cached values from TabOpen event 1.61 + is(gPageA.uri.spec, gTabOpenPageA.uri.spec, "Checking first browser tab open is equal to page A"); 1.62 + is(gPageB.uri.spec, gTabOpenPageB.uri.spec, "Checking second browser tab open is equal to page B"); 1.63 + 1.64 + // test document access 1.65 + var test1 = gPageA.document.getElementById("test1"); 1.66 + ok(test1, "Checking existence of element in content DOM"); 1.67 + is(test1.innerHTML, "A", "Checking content of element in content DOM"); 1.68 + 1.69 + // test moving tab 1.70 + is(gTabMoveCount, 0, "Checking initial tab move count"); 1.71 + 1.72 + // move the tab 1.73 + gPageA.moveToEnd(); 1.74 + is(gPageA.index, 2, "Checking index after moving tab"); 1.75 + 1.76 + // check event 1.77 + is(gTabMoveCount, 1, "Checking event handler for tab move"); 1.78 + 1.79 + gBrowser.addProgressListener({ 1.80 + onStateChange: function (webProgress, request, stateFlags, status) { 1.81 + info("onStateChange: " + stateFlags); 1.82 + 1.83 + const complete = Ci.nsIWebProgressListener.STATE_IS_WINDOW + 1.84 + Ci.nsIWebProgressListener.STATE_IS_NETWORK + 1.85 + Ci.nsIWebProgressListener.STATE_STOP; 1.86 + if ((stateFlags & complete) == complete) { 1.87 + gBrowser.removeProgressListener(this); 1.88 + onPageBLoadComplete(); 1.89 + } 1.90 + }, 1.91 + onLocationChange: function () 0, 1.92 + onProgressChange: function () 0, 1.93 + onStatusChange: function () 0, 1.94 + onSecurityChange: function () 0 1.95 + }); 1.96 + 1.97 + // test loading new content with a frame into a tab 1.98 + // the event will be checked in onPageBLoadComplete 1.99 + gPageB.events.addListener("load", onPageBLoadWithFrames); 1.100 + gPageB.load(makeURI(CHROMEROOT + "ContentWithFrames.html")); 1.101 + } 1.102 + 1.103 + function onPageBLoadWithFrames(event) { 1.104 + gPageLoadCount++; 1.105 + info("onPageBLoadWithFrames: " + gPageLoadCount); 1.106 + } 1.107 + 1.108 + function onPageBLoadComplete() { 1.109 + gPageB.events.removeListener("load", onPageBLoadWithFrames); 1.110 + // check page load with frame event 1.111 + is(gPageLoadCount, 1, "Checking load count after loading new content with a frame"); 1.112 + 1.113 + // test loading new content into a tab 1.114 + // the event will be checked in onPageASecondLoad 1.115 + gPageA.events.addListener("load", onPageASecondLoad); 1.116 + gPageA.load(makeURI(CHROMEROOT + "ContentB.html")); 1.117 + } 1.118 + 1.119 + function onPageASecondLoad(event) { 1.120 + gPageA.events.removeListener("load", onPageASecondLoad); 1.121 + is(gPageA.uri.spec, CHROMEROOT + "ContentB.html", "Checking 'BrowserTab.uri' after loading new content"); 1.122 + 1.123 + // start testing closing tabs 1.124 + // the event will be checked in afterClose 1.125 + // use executeSoon so the onPageASecondLoad 1.126 + // has a chance to finish first 1.127 + gPageA.close(); 1.128 + gPageB.close(); 1.129 + 1.130 + is(gTabCloseCount, 2, "Checking that tabs closed"); 1.131 + is(activeWin.tabs.length, 1, "Checking length of 'Browser.tabs' after closing 2 tabs"); 1.132 + finish(); 1.133 + } 1.134 +} 1.135 +function onTabOpen(event) { 1.136 + gTabOpenCount++; 1.137 + 1.138 + // cache these values so we can check them later (after loading completes) 1.139 + if (gTabOpenCount == 1) 1.140 + gTabOpenPageA = event.data; 1.141 + 1.142 + if (gTabOpenCount == 2) 1.143 + gTabOpenPageB = event.data; 1.144 +} 1.145 +function onTabClose(event) { 1.146 + gTabCloseCount++; 1.147 +} 1.148 + 1.149 +function onTabMove(event) { 1.150 + gTabMoveCount++; 1.151 +}