summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/plugins/browser_plugins_added_dynamically.js
blob: 22077a54dddf3474afe98b10487f06c2a0048ff2 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
var rootDir = getRootDirectory(gTestPath);
const gTestRoot = rootDir.replace("chrome://mochitests/content/", "http://mochi.test:8888/");
var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);

var gTestBrowser = null;

add_task(function* () {
  registerCleanupFunction(Task.async(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");
    yield asyncSetAndUpdateBlocklist(gTestRoot + "blockNoPlugins.xml", gTestBrowser);
    resetBlocklist();
    gBrowser.removeCurrentTab();
    window.focus();
    gTestBrowser = null;
  }));
});

// "Activate" of a given type -> plugins of that type dynamically added should
// automatically play.
add_task(function* () {
  let newTab = gBrowser.addTab();
  gBrowser.selectedTab = newTab;
  gTestBrowser = gBrowser.selectedBrowser;

  Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
  Services.prefs.setBoolPref("plugins.click_to_play", true);

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

add_task(function* () {
  yield promiseTabLoadEvent(gBrowser.selectedTab, gTestRoot + "plugin_add_dynamically.html");

  let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
  ok(!notification, "Test 1a, Should not have a click-to-play notification");

  // Add a plugin of type test
  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    new XPCNativeWrapper(XPCNativeWrapper.unwrap(content).addPlugin("pluginone", "application/x-test"));
  });

  yield promisePopupNotification("click-to-play-plugins");

  notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
  ok(notification, "Test 1a, Should not have a click-to-play notification");

  yield promiseForNotificationShown(notification);

  let centerAction = null;
  for (let action of notification.options.pluginData.values()) {
    if (action.pluginName == "Test") {
      centerAction = action;
      break;
    }
  }
  ok(centerAction, "Test 2, found center action for the Test plugin");

  let centerItem = null;
  for (let item of PopupNotifications.panel.firstChild.childNodes) {
    is(item.value, "block", "Test 3, all plugins should start out blocked");
    if (item.action == centerAction) {
      centerItem = item;
      break;
    }
  }
  ok(centerItem, "Test 4, found center item for the Test plugin");

  // Select the allow now option in the select drop down for Test Plugin
  centerItem.value = "allownow";

  // "click" the button to activate the Test plugin
  PopupNotifications.panel.firstChild._primaryButton.click();

  let pluginInfo = yield promiseForPluginInfo("pluginone");
  ok(pluginInfo.activated, "Test 5, plugin should be activated");

  // Add another plugin of type test
  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    new XPCNativeWrapper(XPCNativeWrapper.unwrap(content).addPlugin("plugintwo", "application/x-test"));
  });

  pluginInfo = yield promiseForPluginInfo("plugintwo");
  ok(pluginInfo.activated, "Test 6, plugins should be activated");
});

// "Activate" of a given type -> plugins of other types dynamically added
// should not automatically play.
add_task(function* () {
  clearAllPluginPermissions();

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

  let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
  ok(!notification, "Test 7, Should not have a click-to-play notification");

  // Add a plugin of type test
  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    new XPCNativeWrapper(XPCNativeWrapper.unwrap(content).addPlugin("pluginone", "application/x-test"));
  });

  yield promisePopupNotification("click-to-play-plugins");

  notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
  ok(notification, "Test 8, Should not have a click-to-play notification");

  yield promiseForNotificationShown(notification);

  is(notification.options.pluginData.size, 1, "Should be one plugin action");

  let pluginInfo = yield promiseForPluginInfo("pluginone");
  ok(!pluginInfo.activated, "Test 8, test plugin should be activated");

  let condition = () => !notification.dismissed &&
    PopupNotifications.panel.firstChild;
  yield promiseForCondition(condition);

  // "click" the button to activate the Test plugin
  PopupNotifications.panel.firstChild._primaryButton.click();

  pluginInfo = yield promiseForPluginInfo("pluginone");
  ok(pluginInfo.activated, "Test 9, test plugin should be activated");

  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    new XPCNativeWrapper(XPCNativeWrapper.unwrap(content).addPlugin("plugintwo", "application/x-second-test"));
  });

  yield promisePopupNotification("click-to-play-plugins");

  pluginInfo = yield promiseForPluginInfo("pluginone");
  ok(pluginInfo.activated, "Test 10, plugins should be activated");
  pluginInfo = yield promiseForPluginInfo("plugintwo");
  ok(!pluginInfo.activated, "Test 11, plugins should be activated");
});