browser/devtools/webconsole/test/browser_bug664688_sandbox_update_after_navigation.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_bug664688_sandbox_update_after_navigation.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,113 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +// Tests if the JSTerm sandbox is updated when the user navigates from one
    1.10 +// domain to another, in order to avoid permission denied errors with a sandbox
    1.11 +// created for a different origin.
    1.12 +
    1.13 +function test()
    1.14 +{
    1.15 +  const TEST_URI1 = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
    1.16 +  const TEST_URI2 = "http://example.org/browser/browser/devtools/webconsole/test/test-console.html";
    1.17 +
    1.18 +  let hud;
    1.19 +  let msgForLocation1;
    1.20 +
    1.21 +  waitForExplicitFinish();
    1.22 +
    1.23 +  gBrowser.selectedTab = gBrowser.addTab(TEST_URI1);
    1.24 +  gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
    1.25 +    gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
    1.26 +    openConsole(gBrowser.selectedTab, pageLoad1);
    1.27 +  }, true);
    1.28 +
    1.29 +  function pageLoad1(aHud)
    1.30 +  {
    1.31 +    hud = aHud;
    1.32 +
    1.33 +    hud.jsterm.clearOutput();
    1.34 +    hud.jsterm.execute("window.location.href");
    1.35 +
    1.36 +    info("wait for window.location.href");
    1.37 +
    1.38 +    msgForLocation1 = {
    1.39 +      webconsole: hud,
    1.40 +      messages: [
    1.41 +        {
    1.42 +          name: "window.location.href jsterm input",
    1.43 +          text: "window.location.href",
    1.44 +          category: CATEGORY_INPUT,
    1.45 +        },
    1.46 +        {
    1.47 +          name: "window.location.href result is displayed",
    1.48 +          text: TEST_URI1,
    1.49 +          category: CATEGORY_OUTPUT,
    1.50 +        },
    1.51 +      ]
    1.52 +    };
    1.53 +
    1.54 +    waitForMessages(msgForLocation1).then(() => {
    1.55 +      gBrowser.selectedBrowser.addEventListener("load", onPageLoad2, true);
    1.56 +      content.location = TEST_URI2;
    1.57 +    });
    1.58 +  }
    1.59 +
    1.60 +  function onPageLoad2() {
    1.61 +    gBrowser.selectedBrowser.removeEventListener("load", onPageLoad2, true);
    1.62 +
    1.63 +    is(hud.outputNode.textContent.indexOf("Permission denied"), -1,
    1.64 +       "no permission denied errors");
    1.65 +
    1.66 +    hud.jsterm.clearOutput();
    1.67 +    hud.jsterm.execute("window.location.href");
    1.68 +
    1.69 +    info("wait for window.location.href after page navigation");
    1.70 +
    1.71 +    waitForMessages({
    1.72 +      webconsole: hud,
    1.73 +      messages: [
    1.74 +        {
    1.75 +          name: "window.location.href jsterm input",
    1.76 +          text: "window.location.href",
    1.77 +          category: CATEGORY_INPUT,
    1.78 +        },
    1.79 +        {
    1.80 +          name: "window.location.href result is displayed",
    1.81 +          text: TEST_URI2,
    1.82 +          category: CATEGORY_OUTPUT,
    1.83 +        },
    1.84 +      ]
    1.85 +    }).then(() => {
    1.86 +      is(hud.outputNode.textContent.indexOf("Permission denied"), -1,
    1.87 +         "no permission denied errors");
    1.88 +
    1.89 +      gBrowser.goBack();
    1.90 +      waitForSuccess(waitForBack);
    1.91 +    });
    1.92 +  }
    1.93 +
    1.94 +  let waitForBack = {
    1.95 +    name: "go back",
    1.96 +    validatorFn: function()
    1.97 +    {
    1.98 +      return content.location.href == TEST_URI1;
    1.99 +    },
   1.100 +    successFn: function()
   1.101 +    {
   1.102 +      hud.jsterm.clearOutput();
   1.103 +      executeSoon(() => {
   1.104 +        hud.jsterm.execute("window.location.href");
   1.105 +      });
   1.106 +
   1.107 +      info("wait for window.location.href after goBack()");
   1.108 +      waitForMessages(msgForLocation1).then(() => executeSoon(() => {
   1.109 +        is(hud.outputNode.textContent.indexOf("Permission denied"), -1,
   1.110 +           "no permission denied errors");
   1.111 +        finishTest();
   1.112 +      }));
   1.113 +    },
   1.114 +    failureFn: finishTest,
   1.115 +  };
   1.116 +}

mercurial