summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/plugins/browser_bug820497.js
blob: b2e0f52685d6ee33d1fb30fdfe8fbe0599579369 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var gTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
var gTestBrowser = null;
var gNumPluginBindingsAttached = 0;

add_task(function* () {
  registerCleanupFunction(function () {
    clearAllPluginPermissions();
    Services.prefs.clearUserPref("plugins.click_to_play");
    setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");
    setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Second Test Plug-in");
    gBrowser.removeCurrentTab();
    window.focus();
    gTestBrowser = null;
  });
});

add_task(function* () {
  Services.prefs.setBoolPref("plugins.click_to_play", true);

  gBrowser.selectedTab = gBrowser.addTab();
  gTestBrowser = gBrowser.selectedBrowser;

  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Test Plug-in");
  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in");

  gTestBrowser.addEventListener("PluginBindingAttached", function () { gNumPluginBindingsAttached++ }, true, true);

  yield promiseTabLoadEvent(gBrowser.selectedTab, gTestRoot + "plugin_bug820497.html");

  yield promiseForCondition(function () { return gNumPluginBindingsAttached == 1; });

  yield ContentTask.spawn(gTestBrowser, null, () => {
    // Note we add the second plugin in the code farther down, so there's
    // no way we got here with anything but one plugin loaded.
    let doc = content.document;
    let testplugin = doc.getElementById("test");
    ok(testplugin, "should have test plugin");
    let secondtestplugin = doc.getElementById("secondtest");
    ok(!secondtestplugin, "should not yet have second test plugin");
  });

  yield promisePopupNotification("click-to-play-plugins");
  let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
  ok(notification, "should have a click-to-play notification");

  yield promiseForNotificationShown(notification);

  is(notification.options.pluginData.size, 1, "should be 1 type of plugin in the popup notification");

  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    XPCNativeWrapper.unwrap(content).addSecondPlugin();
  });

  yield promiseForCondition(function () { return gNumPluginBindingsAttached == 2; });

  yield ContentTask.spawn(gTestBrowser, null, () => {
    let doc = content.document;
    let testplugin = doc.getElementById("test");
    ok(testplugin, "should have test plugin");
    let secondtestplugin = doc.getElementById("secondtest");
    ok(secondtestplugin, "should have second test plugin");
  });

  notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);

  ok(notification, "should have popup notification");

  yield promiseForNotificationShown(notification);

  is(notification.options.pluginData.size, 2, "aited too long for 2 types of plugins in popup notification");
});