browser/base/content/test/general/browser_bug423833.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 /* Tests for proper behaviour of "Show this frame" context menu options */
     3 // Two frames, one with text content, the other an error page
     4 var invalidPage = 'http://127.0.0.1:55555/';
     5 var validPage = 'http://example.com/';
     6 var testPage = 'data:text/html,<frameset cols="400,400"><frame src="' + validPage + '"><frame src="' + invalidPage + '"></frameset>';
     8 // Store the tab and window created in tests 2 and 3 respectively
     9 var test2tab;
    10 var test3window;
    12 // We use setInterval instead of setTimeout to avoid race conditions on error doc loads
    13 var intervalID;
    15 function test() {
    16   waitForExplicitFinish();
    18   gBrowser.selectedTab = gBrowser.addTab();
    19   gBrowser.selectedBrowser.addEventListener("load", test1Setup, true);
    20   content.location = testPage;
    21 }
    23 function test1Setup() {
    24   if (content.frames.length < 2 ||
    25       content.frames[1].location != invalidPage)
    26     // The error frame hasn't loaded yet
    27     return;
    29   gBrowser.selectedBrowser.removeEventListener("load", test1Setup, true);
    31   var badFrame = content.frames[1];
    32   document.popupNode = badFrame.document.firstChild;
    34   var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
    35   var contextMenu = new nsContextMenu(contentAreaContextMenu);
    37   // We'd like to use another load listener here, but error pages don't fire load events
    38   contextMenu.showOnlyThisFrame();
    39   intervalID = setInterval(testShowOnlyThisFrame, 3000);
    40 }
    42 function testShowOnlyThisFrame() {
    43   if (content.location.href == testPage)
    44     // This is a stale event from the original page loading
    45     return;
    47   // We should now have loaded the error page frame content directly
    48   // in the tab, make sure the URL is right.
    49   clearInterval(intervalID);
    51   is(content.location.href, invalidPage, "Should navigate to page url, not about:neterror");
    53   // Go back to the frames page
    54   gBrowser.addEventListener("load", test2Setup, true);
    55   content.location = testPage;
    56 }
    58 function test2Setup() {
    59   if (content.frames.length < 2 ||
    60       content.frames[1].location != invalidPage)
    61     // The error frame hasn't loaded yet
    62     return;
    64   gBrowser.removeEventListener("load", test2Setup, true);
    66   // Now let's do the whole thing again, but this time for "Open frame in new tab"
    67   var badFrame = content.frames[1];
    69   document.popupNode = badFrame.document.firstChild;
    71   var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
    72   var contextMenu = new nsContextMenu(contentAreaContextMenu);
    74   gBrowser.tabContainer.addEventListener("TabOpen", function (event) {
    75     test2tab = event.target;
    76     gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, false);
    77   }, false);
    78   contextMenu.openFrameInTab();
    79   ok(test2tab, "openFrameInTab() opened a tab");
    81   gBrowser.selectedTab = test2tab;
    83   intervalID = setInterval(testOpenFrameInTab, 3000);
    84 }
    86 function testOpenFrameInTab() {
    87   if (gBrowser.contentDocument.location.href == "about:blank")
    88     // Wait another cycle
    89     return;
    91   clearInterval(intervalID);
    93   // We should now have the error page in a new, active tab.
    94   is(gBrowser.contentDocument.location.href, invalidPage, "New tab should have page url, not about:neterror");
    96   // Clear up the new tab, and punt to test 3
    97   gBrowser.removeCurrentTab();
    99   test3Setup();
   100 }
   102 function test3Setup() {
   103   // One more time, for "Open frame in new window"
   104   var badFrame = content.frames[1];
   105   document.popupNode = badFrame.document.firstChild;
   107   var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
   108   var contextMenu = new nsContextMenu(contentAreaContextMenu);
   110   Services.ww.registerNotification(function (aSubject, aTopic, aData) {
   111     if (aTopic == "domwindowopened")
   112       test3window = aSubject;
   113     Services.ww.unregisterNotification(arguments.callee);
   114   });
   116   contextMenu.openFrame();
   118   intervalID = setInterval(testOpenFrame, 3000);
   119 }
   121 function testOpenFrame() {
   122   if (!test3window || test3window.content.location.href == "about:blank") {
   123     info("testOpenFrame: Wait another cycle");
   124     return;
   125   }
   127   clearInterval(intervalID);
   129   is(test3window.content.location.href, invalidPage, "New window should have page url, not about:neterror");
   131   test3window.close();
   132   cleanup();
   133 }
   135 function cleanup() {
   136   gBrowser.removeCurrentTab();
   137   finish();
   138 }

mercurial