browser/base/content/test/plugins/browser_bug820497.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_bug820497.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + *  License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +var gTestBrowser = null;
     1.9 +var gNumPluginBindingsAttached = 0;
    1.10 +
    1.11 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.12 +
    1.13 +function test() {
    1.14 +  waitForExplicitFinish();
    1.15 +  registerCleanupFunction(function() {
    1.16 +    Services.prefs.clearUserPref("plugins.click_to_play");
    1.17 +    gTestBrowser.removeEventListener("PluginBindingAttached", pluginBindingAttached, true, true);
    1.18 +    gBrowser.removeCurrentTab();
    1.19 +    window.focus();
    1.20 +  });
    1.21 +
    1.22 +  Services.prefs.setBoolPref("plugins.click_to_play", true);
    1.23 +  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    1.24 +  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in");
    1.25 +
    1.26 +  gBrowser.selectedTab = gBrowser.addTab();
    1.27 +  gTestBrowser = gBrowser.selectedBrowser;
    1.28 +  gTestBrowser.addEventListener("PluginBindingAttached", pluginBindingAttached, true, true);
    1.29 +  var gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
    1.30 +  gTestBrowser.contentWindow.location = gHttpTestRoot + "plugin_bug820497.html";
    1.31 +}
    1.32 +
    1.33 +function pluginBindingAttached() {
    1.34 +  gNumPluginBindingsAttached++;
    1.35 +
    1.36 +  if (gNumPluginBindingsAttached == 1) {
    1.37 +    var doc = gTestBrowser.contentDocument;
    1.38 +    var testplugin = doc.getElementById("test");
    1.39 +    ok(testplugin, "should have test plugin");
    1.40 +    var secondtestplugin = doc.getElementById("secondtest");
    1.41 +    ok(!secondtestplugin, "should not yet have second test plugin");
    1.42 +    var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.43 +    ok(notification, "should have popup notification");
    1.44 +    // We don't set up the action list until the notification is shown
    1.45 +    notification.reshow();
    1.46 +    is(notification.options.pluginData.size, 1, "should be 1 type of plugin in the popup notification");
    1.47 +    XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addSecondPlugin();
    1.48 +  } else if (gNumPluginBindingsAttached == 2) {
    1.49 +    var doc = gTestBrowser.contentDocument;
    1.50 +    var testplugin = doc.getElementById("test");
    1.51 +    ok(testplugin, "should have test plugin");
    1.52 +    var secondtestplugin = doc.getElementById("secondtest");
    1.53 +    ok(secondtestplugin, "should have second test plugin");
    1.54 +    var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.55 +    ok(notification, "should have popup notification");
    1.56 +    notification.reshow();
    1.57 +    is(notification.options.pluginData.size, 2, "should be 2 types of plugin in the popup notification");
    1.58 +    finish();
    1.59 +  } else {
    1.60 +    ok(false, "if we've gotten here, something is quite wrong");
    1.61 +  }
    1.62 +}

mercurial