browser/base/content/test/plugins/browser_bug743421.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_bug743421.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     1.4 +var rootDir = getRootDirectory(gTestPath);
     1.5 +const gTestRoot = rootDir.replace("chrome://mochitests/content/", "http://mochi.test:8888/");
     1.6 +
     1.7 +var gTestBrowser = null;
     1.8 +var gNextTest = null;
     1.9 +
    1.10 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.11 +
    1.12 +function test() {
    1.13 +  waitForExplicitFinish();
    1.14 +  registerCleanupFunction(function() {
    1.15 +    clearAllPluginPermissions();
    1.16 +    Services.prefs.clearUserPref("plugins.click_to_play");
    1.17 +  });
    1.18 +  Services.prefs.setBoolPref("plugins.click_to_play", true);
    1.19 +  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    1.20 +
    1.21 +  var newTab = gBrowser.addTab();
    1.22 +  gBrowser.selectedTab = newTab;
    1.23 +  gTestBrowser = gBrowser.selectedBrowser;
    1.24 +  gTestBrowser.addEventListener("load", pageLoad, true);
    1.25 +  prepareTest(test1a, gTestRoot + "plugin_add_dynamically.html");
    1.26 +}
    1.27 +
    1.28 +function finishTest() {
    1.29 +  gTestBrowser.removeEventListener("load", pageLoad, true);
    1.30 +  gBrowser.removeCurrentTab();
    1.31 +  window.focus();
    1.32 +  finish();
    1.33 +}
    1.34 +
    1.35 +function pageLoad() {
    1.36 +  // The plugin events are async dispatched and can come after the load event
    1.37 +  // This just allows the events to fire before we then go on to test the states
    1.38 +  executeSoon(gNextTest);
    1.39 +}
    1.40 +
    1.41 +function prepareTest(nextTest, url) {
    1.42 +  gNextTest = nextTest;
    1.43 +  gTestBrowser.contentWindow.location = url;
    1.44 +}
    1.45 +
    1.46 +// Tests that navigation within the page and the window.history API doesn't break click-to-play state.
    1.47 +function test1a() {
    1.48 +  var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.49 +  ok(!popupNotification, "Test 1a, Should not have a click-to-play notification");
    1.50 +  var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
    1.51 +
    1.52 +  var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.53 +  waitForCondition(condition, test1b, "Test 1a, Waited too long for plugin notification");
    1.54 +}
    1.55 +
    1.56 +function test1b() {
    1.57 +  var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.58 +  ok(popupNotification, "Test 1b, Should have a click-to-play notification");
    1.59 +  var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
    1.60 +  var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    1.61 +  ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated");
    1.62 +
    1.63 +  // Click the activate button on doorhanger to make sure it works
    1.64 +  popupNotification.reshow();
    1.65 +  PopupNotifications.panel.firstChild._primaryButton.click();
    1.66 +
    1.67 +  ok(objLoadingContent.activated, "Test 1b, Doorhanger should activate plugin");
    1.68 +
    1.69 +  test1c();
    1.70 +}
    1.71 +
    1.72 +function test1c() {
    1.73 +  var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.74 +  ok(popupNotification, "Test 1c, Should still have a click-to-play notification");
    1.75 +  var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
    1.76 +
    1.77 +  var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    1.78 +  var condition = function() objLoadingContent.activated;
    1.79 +  waitForCondition(condition, test1d, "Test 1c, Waited too long for plugin activation");
    1.80 +}
    1.81 +
    1.82 +function test1d() {
    1.83 +  var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[1];
    1.84 +  var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    1.85 +  ok(objLoadingContent.activated, "Test 1d, Plugin should be activated");
    1.86 +
    1.87 +  gNextTest = test1e;
    1.88 +  gTestBrowser.contentWindow.addEventListener("hashchange", test1e, false);
    1.89 +  gTestBrowser.contentWindow.location += "#anchorNavigation";
    1.90 +}
    1.91 +
    1.92 +function test1e() {
    1.93 +  gTestBrowser.contentWindow.removeEventListener("hashchange", test1e, false);
    1.94 +
    1.95 +  var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
    1.96 +
    1.97 +  var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    1.98 +  var condition = function() objLoadingContent.activated;
    1.99 +  waitForCondition(condition, test1f, "Test 1e, Waited too long for plugin activation");
   1.100 +}
   1.101 +
   1.102 +function test1f() {
   1.103 +  var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[2];
   1.104 +  var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   1.105 +  ok(objLoadingContent.activated, "Test 1f, Plugin should be activated");
   1.106 +
   1.107 +  gTestBrowser.contentWindow.history.replaceState({}, "", "replacedState");
   1.108 +  var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
   1.109 +  var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   1.110 +  var condition = function() objLoadingContent.activated;
   1.111 +  waitForCondition(condition, test1g, "Test 1f, Waited too long for plugin activation");
   1.112 +}
   1.113 +
   1.114 +function test1g() {
   1.115 +  var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[3];
   1.116 +  var objLoadingContent2 = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   1.117 +  ok(objLoadingContent2.activated, "Test 1g, Plugin should be activated");
   1.118 +  finishTest();
   1.119 +}

mercurial