summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/plugins/browser_bug743421.js
blob: 966e7b01299ace691a191726a3f43b46ffca3fbc (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
var gTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
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;
  }));
});

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");

  // Prime the blocklist service, the remote service doesn't launch on startup.
  yield promiseTabLoadEvent(gBrowser.selectedTab, "data:text/html,<html></html>");

  let exmsg = yield promiseInitContentBlocklistSvc(gBrowser.selectedBrowser);
  ok(!exmsg, "exception: " + exmsg);

  yield asyncSetAndUpdateBlocklist(gTestRoot + "blockNoPlugins.xml", gTestBrowser);
});

// Tests that navigation within the page and the window.history API doesn't break click-to-play state.
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");

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

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

add_task(function* () {
  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    let plugin = content.document.getElementsByTagName("embed")[0];
    let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    Assert.ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated");
  });

  // Click the activate button on doorhanger to make sure it works
  let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);

  yield promiseForNotificationShown(notification);

  PopupNotifications.panel.firstChild._primaryButton.click();

  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    let plugin = content.document.getElementsByTagName("embed")[0];
    let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    Assert.ok(objLoadingContent.activated, "Test 1b, Plugin should be activated");
  });
});

add_task(function* () {
  let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
  ok(notification, "Test 1c, Should still have a click-to-play notification");

  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    new XPCNativeWrapper(XPCNativeWrapper.unwrap(content).addPlugin());
    let plugin = content.document.getElementsByTagName("embed")[1];
    let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    Assert.ok(objLoadingContent.activated,
      "Test 1c, Newly inserted plugin in activated page should be activated");
  });
});

add_task(function* () {
  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    let plugin = content.document.getElementsByTagName("embed")[1];
    let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    Assert.ok(objLoadingContent.activated, "Test 1d, Plugin should be activated");

    let promise = ContentTaskUtils.waitForEvent(content, "hashchange");
    content.location += "#anchorNavigation";
    yield promise;
  });
});

add_task(function* () {
  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    new XPCNativeWrapper(XPCNativeWrapper.unwrap(content).addPlugin());
    let plugin = content.document.getElementsByTagName("embed")[2];
    let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    Assert.ok(objLoadingContent.activated, "Test 1e, Plugin should be activated");
  });
});

add_task(function* () {
  yield ContentTask.spawn(gTestBrowser, {}, function* () {
    let plugin = content.document.getElementsByTagName("embed")[2];
    let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    Assert.ok(objLoadingContent.activated, "Test 1f, Plugin should be activated");

    content.history.replaceState({}, "", "replacedState");
    new XPCNativeWrapper(XPCNativeWrapper.unwrap(content).addPlugin());
    plugin = content.document.getElementsByTagName("embed")[3];
    objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    Assert.ok(objLoadingContent.activated, "Test 1g, Plugin should be activated");
  });
});