browser/devtools/framework/test/browser_toolbox_options_disable_js.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 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Tests that disabling JavaScript for a tab works as it should.
     6 const TEST_URI = "http://example.com/browser/browser/devtools/framework/" +
     7                  "test/browser_toolbox_options_disable_js.html";
     9 let doc;
    10 let toolbox;
    12 function test() {
    13   waitForExplicitFinish();
    15   gBrowser.selectedTab = gBrowser.addTab();
    16   let target = TargetFactory.forTab(gBrowser.selectedTab);
    18   gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
    19     gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
    20     doc = content.document;
    21     gDevTools.showToolbox(target).then(testSelectTool);
    22   }, true);
    24   content.location = TEST_URI;
    25 }
    27 function testSelectTool(aToolbox) {
    28   toolbox = aToolbox;
    29   toolbox.once("options-selected", testJSEnabled);
    30   toolbox.selectTool("options");
    31 }
    33 function testJSEnabled(event, tool, secondPass) {
    34   ok(true, "Toolbox selected via selectTool method");
    35   info("Testing that JS is enabled");
    37   let logJSEnabled = doc.getElementById("logJSEnabled");
    38   let output = doc.getElementById("output");
    40   // We use executeSoon here because switching docSehll.allowJavascript to true
    41   // takes a while to become live.
    42   executeSoon(function() {
    43     EventUtils.synthesizeMouseAtCenter(logJSEnabled, {}, doc.defaultView);
    44     is(output.textContent, "JavaScript Enabled", 'Output is "JavaScript Enabled"');
    45     testJSEnabledIframe(secondPass);
    46   });
    47 }
    49 function testJSEnabledIframe(secondPass) {
    50   info("Testing that JS is enabled in the iframe");
    52   let iframe = doc.querySelector("iframe");
    53   let iframeDoc = iframe.contentDocument;
    54   let logJSEnabled = iframeDoc.getElementById("logJSEnabled");
    55   let output = iframeDoc.getElementById("output");
    57   EventUtils.synthesizeMouseAtCenter(logJSEnabled, {}, iframe.contentWindow);
    58   is(output.textContent, "JavaScript Enabled",
    59                          'Output is "JavaScript Enabled" in iframe');
    60   if (secondPass) {
    61     finishUp();
    62   } else {
    63     toggleJS().then(testJSDisabled);
    64   }
    65 }
    67 function toggleJS() {
    68   let deferred = promise.defer();
    69   let panel = toolbox.getCurrentPanel();
    70   let cbx = panel.panelDoc.getElementById("devtools-disable-javascript");
    72   cbx.scrollIntoView();
    74   if (cbx.checked) {
    75     info("Clearing checkbox to re-enable JS");
    76   } else {
    77     info("Checking checkbox to disable JS");
    78   }
    80   // After uising scrollIntoView() we need to use executeSoon() to wait for the
    81   // browser to scroll.
    82   executeSoon(function() {
    83     gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
    84       gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
    85       doc = content.document;
    87       deferred.resolve();
    88     }, true);
    90     EventUtils.synthesizeMouseAtCenter(cbx, {}, panel.panelWin);
    91   });
    93   return deferred.promise;
    94 }
    96 function testJSDisabled() {
    97   info("Testing that JS is disabled");
    99   let logJSDisabled = doc.getElementById("logJSDisabled");
   100   let output = doc.getElementById("output");
   102   EventUtils.synthesizeMouseAtCenter(logJSDisabled, {}, doc.defaultView);
   103   ok(output.textContent !== "JavaScript Disabled",
   104      'output is not "JavaScript Disabled"');
   106   testJSDisabledIframe();
   107 }
   109 function testJSDisabledIframe() {
   110   info("Testing that JS is disabled in the iframe");
   112   let iframe = doc.querySelector("iframe");
   113   let iframeDoc = iframe.contentDocument;
   114   let logJSDisabled = iframeDoc.getElementById("logJSDisabled");
   115   let output = iframeDoc.getElementById("output");
   117   EventUtils.synthesizeMouseAtCenter(logJSDisabled, {}, iframe.contentWindow);
   118   ok(output.textContent !== "JavaScript Disabled",
   119      'output is not "JavaScript Disabled" in iframe');
   120   toggleJS().then(function() {
   121     testJSEnabled(null, null, true);
   122   });
   123 }
   125 function finishUp() {
   126   toolbox.destroy().then(function() {
   127     gBrowser.removeCurrentTab();
   128     toolbox = doc = null;
   129     finish();
   130   });
   131 }

mercurial