browser/devtools/webconsole/test/browser_bug664688_sandbox_update_after_navigation.js

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 /* vim:set ts=2 sw=2 sts=2 et: */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 // Tests if the JSTerm sandbox is updated when the user navigates from one
     7 // domain to another, in order to avoid permission denied errors with a sandbox
     8 // created for a different origin.
    10 function test()
    11 {
    12   const TEST_URI1 = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
    13   const TEST_URI2 = "http://example.org/browser/browser/devtools/webconsole/test/test-console.html";
    15   let hud;
    16   let msgForLocation1;
    18   waitForExplicitFinish();
    20   gBrowser.selectedTab = gBrowser.addTab(TEST_URI1);
    21   gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
    22     gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
    23     openConsole(gBrowser.selectedTab, pageLoad1);
    24   }, true);
    26   function pageLoad1(aHud)
    27   {
    28     hud = aHud;
    30     hud.jsterm.clearOutput();
    31     hud.jsterm.execute("window.location.href");
    33     info("wait for window.location.href");
    35     msgForLocation1 = {
    36       webconsole: hud,
    37       messages: [
    38         {
    39           name: "window.location.href jsterm input",
    40           text: "window.location.href",
    41           category: CATEGORY_INPUT,
    42         },
    43         {
    44           name: "window.location.href result is displayed",
    45           text: TEST_URI1,
    46           category: CATEGORY_OUTPUT,
    47         },
    48       ]
    49     };
    51     waitForMessages(msgForLocation1).then(() => {
    52       gBrowser.selectedBrowser.addEventListener("load", onPageLoad2, true);
    53       content.location = TEST_URI2;
    54     });
    55   }
    57   function onPageLoad2() {
    58     gBrowser.selectedBrowser.removeEventListener("load", onPageLoad2, true);
    60     is(hud.outputNode.textContent.indexOf("Permission denied"), -1,
    61        "no permission denied errors");
    63     hud.jsterm.clearOutput();
    64     hud.jsterm.execute("window.location.href");
    66     info("wait for window.location.href after page navigation");
    68     waitForMessages({
    69       webconsole: hud,
    70       messages: [
    71         {
    72           name: "window.location.href jsterm input",
    73           text: "window.location.href",
    74           category: CATEGORY_INPUT,
    75         },
    76         {
    77           name: "window.location.href result is displayed",
    78           text: TEST_URI2,
    79           category: CATEGORY_OUTPUT,
    80         },
    81       ]
    82     }).then(() => {
    83       is(hud.outputNode.textContent.indexOf("Permission denied"), -1,
    84          "no permission denied errors");
    86       gBrowser.goBack();
    87       waitForSuccess(waitForBack);
    88     });
    89   }
    91   let waitForBack = {
    92     name: "go back",
    93     validatorFn: function()
    94     {
    95       return content.location.href == TEST_URI1;
    96     },
    97     successFn: function()
    98     {
    99       hud.jsterm.clearOutput();
   100       executeSoon(() => {
   101         hud.jsterm.execute("window.location.href");
   102       });
   104       info("wait for window.location.href after goBack()");
   105       waitForMessages(msgForLocation1).then(() => executeSoon(() => {
   106         is(hud.outputNode.textContent.indexOf("Permission denied"), -1,
   107            "no permission denied errors");
   108         finishTest();
   109       }));
   110     },
   111     failureFn: finishTest,
   112   };
   113 }

mercurial