browser/base/content/test/plugins/browser_CTP_nonplugins.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 var rootDir = getRootDirectory(gTestPath);
     2 const gTestRoot = rootDir;
     3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
     5 var gTestBrowser = null;
     6 var gNextTest = null;
     7 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
     8 var gRunNextTestAfterPluginRemoved = false;
    10 Components.utils.import("resource://gre/modules/Services.jsm");
    12 function test() {
    13   waitForExplicitFinish();
    14   registerCleanupFunction(function() {
    15     clearAllPluginPermissions();
    16     Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
    17     gTestBrowser.removeEventListener("PluginRemoved", handlePluginRemoved, true, true);
    18   });
    19   Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
    21   var newTab = gBrowser.addTab();
    22   gBrowser.selectedTab = newTab;
    23   gTestBrowser = gBrowser.selectedBrowser;
    24   gTestBrowser.addEventListener("load", pageLoad, true);
    25   gTestBrowser.addEventListener("PluginRemoved", handlePluginRemoved, true, true);
    27   Services.prefs.setBoolPref("plugins.click_to_play", true);
    28   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    30   prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_two_types.html");
    31 }
    33 function finishTest() {
    34   clearAllPluginPermissions();
    35   gTestBrowser.removeEventListener("load", pageLoad, true);
    36   gBrowser.removeCurrentTab();
    37   window.focus();
    38   finish();
    39 }
    41 function pageLoad() {
    42   // The plugin events are async dispatched and can come after the load event
    43   // This just allows the events to fire before we then go on to test the states
    44   executeSoon(gNextTest);
    45 }
    47 function prepareTest(nextTest, url) {
    48   gNextTest = nextTest;
    49   gTestBrowser.contentWindow.location = url;
    50 }
    52 // Due to layout being async, "PluginBindAttached" may trigger later.
    53 // This wraps a function to force a layout flush, thus triggering it,
    54 // and schedules the function execution so they're definitely executed
    55 // afterwards.
    56 function runAfterPluginBindingAttached(func) {
    57   return function() {
    58     let doc = gTestBrowser.contentDocument;
    59     let elems = doc.getElementsByTagName('embed');
    60     if (elems.length < 1) {
    61       elems = doc.getElementsByTagName('object');
    62     }
    63     elems[0].clientTop;
    64     executeSoon(func);
    65   };
    66 }
    68 function handlePluginRemoved() {
    69   if (gRunNextTestAfterPluginRemoved) {
    70     executeSoon(gNextTest);
    71     gRunNextTestAfterPluginRemoved = false;
    72   }
    73 }
    75 function runAfterPluginRemoved(func) {
    76   gNextTest = func;
    77   gRunNextTestAfterPluginRemoved = true;
    78 }
    80 // Test that the click-to-play notification is not shown for non-plugin object elements
    82 function test1() {
    83   let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    84   ok(popupNotification, "Test 1, Should have a click-to-play notification");
    86   let plugin = gTestBrowser.contentDocument.getElementById("secondtestA");
    87   plugin.parentNode.removeChild(plugin);
    88   plugin = gTestBrowser.contentDocument.getElementById("secondtestB");
    89   plugin.parentNode.removeChild(plugin);
    91   let image = gTestBrowser.contentDocument.createElement("object");
    92   image.type = "image/png";
    93   image.data = "moz.png";
    94   gTestBrowser.contentDocument.body.appendChild(image);
    96   runAfterPluginRemoved(test2);
    97 }
    99 function test2() {
   100   let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
   101   ok(popupNotification, "Test 2, Should have a click-to-play notification");
   103   let plugin = gTestBrowser.contentDocument.getElementById("test");
   104   plugin.parentNode.removeChild(plugin);
   106   executeSoon(test3);
   107 }
   109 function test3() {
   110   let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
   111   ok(popupNotification, "Test 3, Should still have a click-to-play notification");
   113   finishTest();
   114 }

mercurial