browser/fuel/test/browser_Browser.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial