browser/base/content/test/plugins/browser_bug812562.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 gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
     2 var gTestBrowser = null;
     3 var gNextTest = null;
     5 Components.utils.import("resource://gre/modules/Services.jsm");
     7 function test() {
     8   waitForExplicitFinish();
     9   registerCleanupFunction(function() {
    10     Services.prefs.clearUserPref("plugins.click_to_play");
    11   });
    12   Services.prefs.setBoolPref("plugins.click_to_play", true);
    13   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    15   var newTab = gBrowser.addTab();
    16   gBrowser.selectedTab = newTab;
    17   gTestBrowser = gBrowser.selectedBrowser;
    18   gTestBrowser.addEventListener("load", pageLoad, true);
    19   setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml",
    20   function() {
    21     prepareTest(function() {
    22         // Due to layout being async, "PluginBindAttached" may trigger later.
    23         // This forces a layout flush, thus triggering it, and schedules the
    24         // test so it is definitely executed afterwards.
    25         gTestBrowser.contentDocument.getElementById('test').clientTop;
    26         testPart1();
    27       },
    28       gHttpTestRoot + "plugin_test.html");
    29   });
    30 }
    32 function finishTest() {
    33   gTestBrowser.removeEventListener("load", pageLoad, true);
    34   gBrowser.removeCurrentTab();
    35   window.focus();
    36   setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml",
    37   function() {
    38     resetBlocklist();
    39     finish();
    40   });
    41 }
    43 function pageLoad(aEvent) {
    44   // The plugin events are async dispatched and can come after the load event
    45   // This just allows the events to fire before we then go on to test the states
    46   if (gNextTest != null)
    47     executeSoon(gNextTest);
    48 }
    50 function prepareTest(nextTest, url) {
    51   gNextTest = nextTest;
    52   gTestBrowser.contentWindow.location = url;
    53 }
    55 // Tests that the going back will reshow the notification for click-to-play
    56 // blocklisted plugins (part 1/4)
    57 function testPart1() {
    58   var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    59   ok(popupNotification, "test part 1: Should have a click-to-play notification");
    60   var plugin = gTestBrowser.contentDocument.getElementById("test");
    61   var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    62   is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "test part 1: plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE");
    63   ok(!objLoadingContent.activated, "test part 1: plugin should not be activated");
    65   prepareTest(testPart2, "about:blank");
    66 }
    68 function testPart2() {
    69   var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    70   ok(!popupNotification, "test part 2: Should not have a click-to-play notification");
    71   var plugin = gTestBrowser.contentDocument.getElementById("test");
    72   ok(!plugin, "test part 2: Should not have a plugin in this page");
    74   Services.obs.addObserver(testPart3, "PopupNotifications-updateNotShowing", false);
    75   gTestBrowser.contentWindow.history.back();
    76 }
    78 function testPart3() {
    79   Services.obs.removeObserver(testPart3, "PopupNotifications-updateNotShowing");
    80   var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    81   waitForCondition(condition, testPart4, "test part 3: waited too long for click-to-play-plugin notification");
    82 }
    84 function testPart4() {
    85   var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    86   ok(popupNotification, "test part 4: Should have a click-to-play notification");
    87   var plugin = gTestBrowser.contentDocument.getElementById("test");
    88   var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    89   is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "test part 4: plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE");
    90   ok(!objLoadingContent.activated, "test part 4: plugin should not be activated");
    92   finishTest();
    93 }

mercurial