browser/base/content/test/plugins/browser_CTP_nonplugins.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;
michael@0 3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
michael@0 4
michael@0 5 var gTestBrowser = null;
michael@0 6 var gNextTest = null;
michael@0 7 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
michael@0 8 var gRunNextTestAfterPluginRemoved = false;
michael@0 9
michael@0 10 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 11
michael@0 12 function test() {
michael@0 13 waitForExplicitFinish();
michael@0 14 registerCleanupFunction(function() {
michael@0 15 clearAllPluginPermissions();
michael@0 16 Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
michael@0 17 gTestBrowser.removeEventListener("PluginRemoved", handlePluginRemoved, true, true);
michael@0 18 });
michael@0 19 Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
michael@0 20
michael@0 21 var newTab = gBrowser.addTab();
michael@0 22 gBrowser.selectedTab = newTab;
michael@0 23 gTestBrowser = gBrowser.selectedBrowser;
michael@0 24 gTestBrowser.addEventListener("load", pageLoad, true);
michael@0 25 gTestBrowser.addEventListener("PluginRemoved", handlePluginRemoved, true, true);
michael@0 26
michael@0 27 Services.prefs.setBoolPref("plugins.click_to_play", true);
michael@0 28 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
michael@0 29
michael@0 30 prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_two_types.html");
michael@0 31 }
michael@0 32
michael@0 33 function finishTest() {
michael@0 34 clearAllPluginPermissions();
michael@0 35 gTestBrowser.removeEventListener("load", pageLoad, true);
michael@0 36 gBrowser.removeCurrentTab();
michael@0 37 window.focus();
michael@0 38 finish();
michael@0 39 }
michael@0 40
michael@0 41 function pageLoad() {
michael@0 42 // The plugin events are async dispatched and can come after the load event
michael@0 43 // This just allows the events to fire before we then go on to test the states
michael@0 44 executeSoon(gNextTest);
michael@0 45 }
michael@0 46
michael@0 47 function prepareTest(nextTest, url) {
michael@0 48 gNextTest = nextTest;
michael@0 49 gTestBrowser.contentWindow.location = url;
michael@0 50 }
michael@0 51
michael@0 52 // Due to layout being async, "PluginBindAttached" may trigger later.
michael@0 53 // This wraps a function to force a layout flush, thus triggering it,
michael@0 54 // and schedules the function execution so they're definitely executed
michael@0 55 // afterwards.
michael@0 56 function runAfterPluginBindingAttached(func) {
michael@0 57 return function() {
michael@0 58 let doc = gTestBrowser.contentDocument;
michael@0 59 let elems = doc.getElementsByTagName('embed');
michael@0 60 if (elems.length < 1) {
michael@0 61 elems = doc.getElementsByTagName('object');
michael@0 62 }
michael@0 63 elems[0].clientTop;
michael@0 64 executeSoon(func);
michael@0 65 };
michael@0 66 }
michael@0 67
michael@0 68 function handlePluginRemoved() {
michael@0 69 if (gRunNextTestAfterPluginRemoved) {
michael@0 70 executeSoon(gNextTest);
michael@0 71 gRunNextTestAfterPluginRemoved = false;
michael@0 72 }
michael@0 73 }
michael@0 74
michael@0 75 function runAfterPluginRemoved(func) {
michael@0 76 gNextTest = func;
michael@0 77 gRunNextTestAfterPluginRemoved = true;
michael@0 78 }
michael@0 79
michael@0 80 // Test that the click-to-play notification is not shown for non-plugin object elements
michael@0 81
michael@0 82 function test1() {
michael@0 83 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 84 ok(popupNotification, "Test 1, Should have a click-to-play notification");
michael@0 85
michael@0 86 let plugin = gTestBrowser.contentDocument.getElementById("secondtestA");
michael@0 87 plugin.parentNode.removeChild(plugin);
michael@0 88 plugin = gTestBrowser.contentDocument.getElementById("secondtestB");
michael@0 89 plugin.parentNode.removeChild(plugin);
michael@0 90
michael@0 91 let image = gTestBrowser.contentDocument.createElement("object");
michael@0 92 image.type = "image/png";
michael@0 93 image.data = "moz.png";
michael@0 94 gTestBrowser.contentDocument.body.appendChild(image);
michael@0 95
michael@0 96 runAfterPluginRemoved(test2);
michael@0 97 }
michael@0 98
michael@0 99 function test2() {
michael@0 100 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 101 ok(popupNotification, "Test 2, Should have a click-to-play notification");
michael@0 102
michael@0 103 let plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 104 plugin.parentNode.removeChild(plugin);
michael@0 105
michael@0 106 executeSoon(test3);
michael@0 107 }
michael@0 108
michael@0 109 function test3() {
michael@0 110 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 111 ok(popupNotification, "Test 3, Should still have a click-to-play notification");
michael@0 112
michael@0 113 finishTest();
michael@0 114 }

mercurial