docshell/test/chrome/bug396519_window.xul

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

     1 <?xml version="1.0"?>
     3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     4    - License, v. 2.0. If a copy of the MPL was not distributed with this
     5    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     9 <window id="396519Test"
    10         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    11         width="600"
    12         height="600"
    13         onload="onLoad();"
    14         title="396519 test">
    16   <script type="application/javascript"><![CDATA[
    18     const LISTEN_EVENTS = ["pageshow"];
    20     const Cc = Components.classes;
    21     const Ci = Components.interfaces;
    23     var gBrowser;
    24     var gTestCount = 0;
    25     var gTestsIterator;
    26     var gExpected = [];
    28     function ok(condition, message) {
    29       window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
    30     }
    31     function is(a, b, message) {
    32       window.opener.wrappedJSObject.SimpleTest.is(a, b, message);
    33     }
    34     function finish() {
    35       for each (let eventType in LISTEN_EVENTS) {
    36         gBrowser.removeEventListener(eventType, eventListener, true);
    37       }
    39       window.close();
    40       window.opener.wrappedJSObject.SimpleTest.finish();
    41     }
    43     function onLoad() {
    44       gBrowser = document.getElementById("content");
    46       for each (let eventType in LISTEN_EVENTS) {
    47         gBrowser.addEventListener(eventType, eventListener, true);
    48       }
    50       gTestsIterator = testsIterator();
    51       nextTest();
    52     }
    54     function eventListener(event) {
    55       // we're in pageshow, but we need to let that finish
    56       // content eviction and saving happen during pageshow, so when doTest
    57       // runs, we should should be in a testable state
    58       setTimeout(doTest, 0);
    59     }
    61     function doTest() {
    62       var history = gBrowser.webNavigation.sessionHistory;
    63       if (history.count == gExpected.length) {
    64         for (var i=0; i<history.count; i++) {
    65           var shEntry = history.getEntryAtIndex(i,false).
    66                           QueryInterface(Components.interfaces.nsISHEntry);
    67           is(!!shEntry.contentViewer, gExpected[i], "content viewer "+i+", test "+gTestCount);
    68         }
    70         // Make sure none of the SHEntries share bfcache entries with one
    71         // another.
    72         for (var i = 0; i < history.count; i++) {
    73           for (var j = 0; j < history.count; j++) {
    74             if (j == i)
    75               continue;
    77             let shentry1 = history.getEntryAtIndex(i, false)
    78                                   .QueryInterface(Ci.nsISHEntry);
    79             let shentry2 = history.getEntryAtIndex(j, false)
    80                                   .QueryInterface(Ci.nsISHEntry);
    81             ok(!shentry1.sharesDocumentWith(shentry2),
    82                'Test ' + gTestCount + ': shentry[' + i + "] shouldn't " +
    83                "share document with shentry[" + j + ']');
    84           }
    85         }
    86       }
    87       else {
    88         is(history.count, gExpected.length, "Wrong history length in test "+gTestCount);
    89       }
    91       setTimeout(nextTest, 0);
    92     }
    94     function nextTest() {
    95       try {
    96         gTestsIterator.next();
    97       } catch (err if err instanceof StopIteration) {
    98         finish();
    99       }
   100     }
   102     function testsIterator() {
   104       // Tests 1 + 2:
   105       //  Back/forward between two simple documents. Bfcache will be used.
   107       var test1Doc = "data:text/html,<html><head><title>test1</title></head>" +
   108                      "<body>test1</body></html>";
   110       gTestCount++;
   111       gExpected = [false];
   112       gBrowser.loadURI(test1Doc);
   113       yield undefined;
   115       gTestCount++;
   116       gExpected = [true, false];
   117       var test2Doc = test1Doc.replace(/1/,"2");
   118       gBrowser.loadURI(test2Doc);
   119       yield undefined;
   121       gTestCount++;
   122       gExpected = [true, true, false];
   123       gBrowser.loadURI(test1Doc);
   124       yield undefined;
   126       gTestCount++;
   127       gExpected = [true, true, true, false];
   128       gBrowser.loadURI(test2Doc);
   129       yield undefined;
   131       gTestCount++;
   132       gExpected = [false, true, true, true, false];
   133       gBrowser.loadURI(test1Doc);
   134       yield undefined;
   136       gTestCount++;
   137       gExpected = [false, false, true, true, true, false];
   138       gBrowser.loadURI(test2Doc);
   139       yield undefined;
   141       gTestCount++;
   142       gExpected = [false, false, true, true, false, true];
   143       gBrowser.goBack();
   144       yield undefined;
   146       gTestCount++;
   147       gExpected = [false, false, true, true, true, false];
   148       gBrowser.goForward();
   149       yield undefined;
   151       gTestCount++;
   152       gExpected = [false, false, true, true, true, false];
   153       gBrowser.gotoIndex(1);
   154       yield undefined;
   156       gTestCount++;
   157       gExpected = [false, true, true, true, false, false];
   158       gBrowser.goBack();
   159       yield undefined;
   161       gTestCount++;
   162       gExpected = [false, false, true, true, false, false];
   163       gBrowser.gotoIndex(5);
   164       yield undefined;
   165     }
   166   ]]></script>
   168   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   169 </window>

mercurial