browser/base/content/test/plugins/browser_bug812562.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/plugins/browser_bug812562.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +var gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
     1.5 +var gTestBrowser = null;
     1.6 +var gNextTest = null;
     1.7 +
     1.8 +Components.utils.import("resource://gre/modules/Services.jsm");
     1.9 +
    1.10 +function test() {
    1.11 +  waitForExplicitFinish();
    1.12 +  registerCleanupFunction(function() {
    1.13 +    Services.prefs.clearUserPref("plugins.click_to_play");
    1.14 +  });
    1.15 +  Services.prefs.setBoolPref("plugins.click_to_play", true);
    1.16 +  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    1.17 +
    1.18 +  var newTab = gBrowser.addTab();
    1.19 +  gBrowser.selectedTab = newTab;
    1.20 +  gTestBrowser = gBrowser.selectedBrowser;
    1.21 +  gTestBrowser.addEventListener("load", pageLoad, true);
    1.22 +  setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml",
    1.23 +  function() {
    1.24 +    prepareTest(function() {
    1.25 +        // Due to layout being async, "PluginBindAttached" may trigger later.
    1.26 +        // This forces a layout flush, thus triggering it, and schedules the
    1.27 +        // test so it is definitely executed afterwards.
    1.28 +        gTestBrowser.contentDocument.getElementById('test').clientTop;
    1.29 +        testPart1();
    1.30 +      },
    1.31 +      gHttpTestRoot + "plugin_test.html");
    1.32 +  });
    1.33 +}
    1.34 +
    1.35 +function finishTest() {
    1.36 +  gTestBrowser.removeEventListener("load", pageLoad, true);
    1.37 +  gBrowser.removeCurrentTab();
    1.38 +  window.focus();
    1.39 +  setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml",
    1.40 +  function() {
    1.41 +    resetBlocklist();
    1.42 +    finish();
    1.43 +  });
    1.44 +}
    1.45 +
    1.46 +function pageLoad(aEvent) {
    1.47 +  // The plugin events are async dispatched and can come after the load event
    1.48 +  // This just allows the events to fire before we then go on to test the states
    1.49 +  if (gNextTest != null)
    1.50 +    executeSoon(gNextTest);
    1.51 +}
    1.52 +
    1.53 +function prepareTest(nextTest, url) {
    1.54 +  gNextTest = nextTest;
    1.55 +  gTestBrowser.contentWindow.location = url;
    1.56 +}
    1.57 +
    1.58 +// Tests that the going back will reshow the notification for click-to-play
    1.59 +// blocklisted plugins (part 1/4)
    1.60 +function testPart1() {
    1.61 +  var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.62 +  ok(popupNotification, "test part 1: Should have a click-to-play notification");
    1.63 +  var plugin = gTestBrowser.contentDocument.getElementById("test");
    1.64 +  var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    1.65 +  is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "test part 1: plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE");
    1.66 +  ok(!objLoadingContent.activated, "test part 1: plugin should not be activated");
    1.67 +
    1.68 +  prepareTest(testPart2, "about:blank");
    1.69 +}
    1.70 +
    1.71 +function testPart2() {
    1.72 +  var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.73 +  ok(!popupNotification, "test part 2: Should not have a click-to-play notification");
    1.74 +  var plugin = gTestBrowser.contentDocument.getElementById("test");
    1.75 +  ok(!plugin, "test part 2: Should not have a plugin in this page");
    1.76 +
    1.77 +  Services.obs.addObserver(testPart3, "PopupNotifications-updateNotShowing", false);
    1.78 +  gTestBrowser.contentWindow.history.back();
    1.79 +}
    1.80 +
    1.81 +function testPart3() {
    1.82 +  Services.obs.removeObserver(testPart3, "PopupNotifications-updateNotShowing");
    1.83 +  var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.84 +  waitForCondition(condition, testPart4, "test part 3: waited too long for click-to-play-plugin notification");
    1.85 +}
    1.86 +
    1.87 +function testPart4() {
    1.88 +  var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.89 +  ok(popupNotification, "test part 4: Should have a click-to-play notification");
    1.90 +  var plugin = gTestBrowser.contentDocument.getElementById("test");
    1.91 +  var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    1.92 +  is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "test part 4: plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE");
    1.93 +  ok(!objLoadingContent.activated, "test part 4: plugin should not be activated");
    1.94 +
    1.95 +  finishTest();
    1.96 +}

mercurial