browser/base/content/test/plugins/browser_plugins_added_dynamically.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 var rootDir = getRootDirectory(gTestPath);
michael@0 2 const gTestRoot = rootDir.replace("chrome://mochitests/content/", "http://mochi.test:8888/");
michael@0 3
michael@0 4 let gTestBrowser = null;
michael@0 5 let gNextTest = null;
michael@0 6 let gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
michael@0 7
michael@0 8 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 9
michael@0 10 // Let's do the XPCNativeWrapper dance!
michael@0 11 function addPlugin(browser, type) {
michael@0 12 let contentWindow = XPCNativeWrapper.unwrap(browser.contentWindow);
michael@0 13 contentWindow.addPlugin(type);
michael@0 14 }
michael@0 15
michael@0 16 function test() {
michael@0 17 waitForExplicitFinish();
michael@0 18 registerCleanupFunction(function() {
michael@0 19 clearAllPluginPermissions();
michael@0 20 Services.prefs.clearUserPref("plugins.click_to_play");
michael@0 21 });
michael@0 22 Services.prefs.setBoolPref("plugins.click_to_play", true);
michael@0 23 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
michael@0 24 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in");
michael@0 25
michael@0 26 let newTab = gBrowser.addTab();
michael@0 27 gBrowser.selectedTab = newTab;
michael@0 28 gTestBrowser = gBrowser.selectedBrowser;
michael@0 29 gTestBrowser.addEventListener("load", pageLoad, true);
michael@0 30 prepareTest(testActivateAddSameTypePart1, gTestRoot + "plugin_add_dynamically.html");
michael@0 31 }
michael@0 32
michael@0 33 function finishTest() {
michael@0 34 gTestBrowser.removeEventListener("load", pageLoad, true);
michael@0 35 gBrowser.removeCurrentTab();
michael@0 36 window.focus();
michael@0 37 finish();
michael@0 38 }
michael@0 39
michael@0 40 function pageLoad() {
michael@0 41 // The plugin events are async dispatched and can come after the load event
michael@0 42 // This just allows the events to fire before we then go on to test the states
michael@0 43 executeSoon(gNextTest);
michael@0 44 }
michael@0 45
michael@0 46 function prepareTest(nextTest, url) {
michael@0 47 gNextTest = nextTest;
michael@0 48 gTestBrowser.contentWindow.location = url;
michael@0 49 }
michael@0 50
michael@0 51 // "Activate" of a given type -> plugins of that type dynamically added should
michael@0 52 // automatically play.
michael@0 53 function testActivateAddSameTypePart1() {
michael@0 54 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 55 ok(!popupNotification, "testActivateAddSameTypePart1: should not have a click-to-play notification");
michael@0 56 addPlugin(gTestBrowser);
michael@0 57 let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 58 waitForCondition(condition, testActivateAddSameTypePart2, "testActivateAddSameTypePart1: waited too long for click-to-play-plugin notification");
michael@0 59 }
michael@0 60
michael@0 61 function testActivateAddSameTypePart2() {
michael@0 62 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 63 ok(popupNotification, "testActivateAddSameTypePart2: should have a click-to-play notification");
michael@0 64
michael@0 65 popupNotification.reshow();
michael@0 66 testActivateAddSameTypePart3();
michael@0 67 }
michael@0 68
michael@0 69 function testActivateAddSameTypePart3() {
michael@0 70 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 71 let centerAction = null;
michael@0 72 for (let action of popupNotification.options.pluginData.values()) {
michael@0 73 if (action.pluginName == "Test") {
michael@0 74 centerAction = action;
michael@0 75 break;
michael@0 76 }
michael@0 77 }
michael@0 78 ok(centerAction, "testActivateAddSameTypePart3: found center action for the Test plugin");
michael@0 79
michael@0 80 let centerItem = null;
michael@0 81 for (let item of PopupNotifications.panel.firstChild.childNodes) {
michael@0 82 if (item.action && item.action == centerAction) {
michael@0 83 centerItem = item;
michael@0 84 break;
michael@0 85 }
michael@0 86 }
michael@0 87 ok(centerItem, "testActivateAddSameTypePart3: found center item for the Test plugin");
michael@0 88
michael@0 89 let plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
michael@0 90 ok(!plugin.activated, "testActivateAddSameTypePart3: plugin should not be activated");
michael@0 91
michael@0 92 // Change the state and click the ok button to activate the Test plugin
michael@0 93 centerItem.value = "allownow";
michael@0 94 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 95
michael@0 96 let condition = function() plugin.activated;
michael@0 97 waitForCondition(condition, testActivateAddSameTypePart4, "testActivateAddSameTypePart3: waited too long for plugin to activate");
michael@0 98 }
michael@0 99
michael@0 100 function testActivateAddSameTypePart4() {
michael@0 101 let plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
michael@0 102 ok(plugin.activated, "testActivateAddSameTypePart4: plugin should be activated");
michael@0 103
michael@0 104 addPlugin(gTestBrowser);
michael@0 105 let condition = function() {
michael@0 106 let embeds = gTestBrowser.contentDocument.getElementsByTagName("embed");
michael@0 107 let allActivated = true;
michael@0 108 for (let embed of embeds) {
michael@0 109 if (!embed.activated)
michael@0 110 allActivated = false;
michael@0 111 }
michael@0 112 return allActivated && embeds.length == 2;
michael@0 113 };
michael@0 114 waitForCondition(condition, testActivateAddSameTypePart5, "testActivateAddSameTypePart4: waited too long for second plugin to activate"); }
michael@0 115
michael@0 116 function testActivateAddSameTypePart5() {
michael@0 117 let embeds = gTestBrowser.contentDocument.getElementsByTagName("embed");
michael@0 118 for (let embed of embeds) {
michael@0 119 ok(embed.activated, "testActivateAddSameTypePart5: all plugins should be activated");
michael@0 120 }
michael@0 121 clearAllPluginPermissions();
michael@0 122 prepareTest(testActivateAddDifferentTypePart1, gTestRoot + "plugin_add_dynamically.html");
michael@0 123 }
michael@0 124
michael@0 125 // "Activate" of a given type -> plugins of other types dynamically added
michael@0 126 // should not automatically play.
michael@0 127 function testActivateAddDifferentTypePart1() {
michael@0 128 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 129 ok(!popupNotification, "testActivateAddDifferentTypePart1: should not have a click-to-play notification");
michael@0 130 addPlugin(gTestBrowser);
michael@0 131 let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 132 waitForCondition(condition, testActivateAddDifferentTypePart2, "testActivateAddDifferentTypePart1: waited too long for click-to-play-plugin notification");
michael@0 133 }
michael@0 134
michael@0 135 function testActivateAddDifferentTypePart2() {
michael@0 136 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 137 ok(popupNotification, "testActivateAddDifferentTypePart2: should have a click-to-play notification");
michael@0 138
michael@0 139 // we have to actually show the panel to get the bindings to instantiate
michael@0 140 popupNotification.reshow();
michael@0 141 testActivateAddDifferentTypePart3();
michael@0 142 }
michael@0 143
michael@0 144 function testActivateAddDifferentTypePart3() {
michael@0 145 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 146 is(popupNotification.options.pluginData.size, 1, "Should be one plugin action");
michael@0 147
michael@0 148 let plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
michael@0 149 ok(!plugin.activated, "testActivateAddDifferentTypePart3: plugin should not be activated");
michael@0 150
michael@0 151 // "click" the button to activate the Test plugin
michael@0 152 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 153
michael@0 154 let condition = function() plugin.activated;
michael@0 155 waitForCondition(condition, testActivateAddDifferentTypePart4, "testActivateAddDifferentTypePart3: waited too long for plugin to activate");
michael@0 156 }
michael@0 157
michael@0 158 function testActivateAddDifferentTypePart4() {
michael@0 159 let plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
michael@0 160 ok(plugin.activated, "testActivateAddDifferentTypePart4: plugin should be activated");
michael@0 161
michael@0 162 addPlugin(gTestBrowser);
michael@0 163 let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 164 waitForCondition(condition, testActivateAddDifferentTypePart5, "testActivateAddDifferentTypePart5: waited too long for popup notification");
michael@0 165 }
michael@0 166
michael@0 167 function testActivateAddDifferentTypePart5() {
michael@0 168 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "testActivateAddDifferentTypePart5: should have popup notification");
michael@0 169 let embeds = gTestBrowser.contentDocument.getElementsByTagName("embed");
michael@0 170 for (let embed of embeds) {
michael@0 171 if (embed.type == "application/x-test")
michael@0 172 ok(embed.activated, "testActivateAddDifferentTypePart5: Test plugin should be activated");
michael@0 173 else if (embed.type == "application/x-second-test")
michael@0 174 ok(!embed.activated, "testActivateAddDifferentTypePart5: Second Test plugin should not be activated");
michael@0 175 }
michael@0 176
michael@0 177 finishTest();
michael@0 178 }

mercurial