1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/plugins/browser_CTP_nonplugins.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +var rootDir = getRootDirectory(gTestPath); 1.5 +const gTestRoot = rootDir; 1.6 +const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); 1.7 + 1.8 +var gTestBrowser = null; 1.9 +var gNextTest = null; 1.10 +var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost); 1.11 +var gRunNextTestAfterPluginRemoved = false; 1.12 + 1.13 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.14 + 1.15 +function test() { 1.16 + waitForExplicitFinish(); 1.17 + registerCleanupFunction(function() { 1.18 + clearAllPluginPermissions(); 1.19 + Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); 1.20 + gTestBrowser.removeEventListener("PluginRemoved", handlePluginRemoved, true, true); 1.21 + }); 1.22 + Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); 1.23 + 1.24 + var newTab = gBrowser.addTab(); 1.25 + gBrowser.selectedTab = newTab; 1.26 + gTestBrowser = gBrowser.selectedBrowser; 1.27 + gTestBrowser.addEventListener("load", pageLoad, true); 1.28 + gTestBrowser.addEventListener("PluginRemoved", handlePluginRemoved, true, true); 1.29 + 1.30 + Services.prefs.setBoolPref("plugins.click_to_play", true); 1.31 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); 1.32 + 1.33 + prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_two_types.html"); 1.34 +} 1.35 + 1.36 +function finishTest() { 1.37 + clearAllPluginPermissions(); 1.38 + gTestBrowser.removeEventListener("load", pageLoad, true); 1.39 + gBrowser.removeCurrentTab(); 1.40 + window.focus(); 1.41 + finish(); 1.42 +} 1.43 + 1.44 +function pageLoad() { 1.45 + // The plugin events are async dispatched and can come after the load event 1.46 + // This just allows the events to fire before we then go on to test the states 1.47 + executeSoon(gNextTest); 1.48 +} 1.49 + 1.50 +function prepareTest(nextTest, url) { 1.51 + gNextTest = nextTest; 1.52 + gTestBrowser.contentWindow.location = url; 1.53 +} 1.54 + 1.55 +// Due to layout being async, "PluginBindAttached" may trigger later. 1.56 +// This wraps a function to force a layout flush, thus triggering it, 1.57 +// and schedules the function execution so they're definitely executed 1.58 +// afterwards. 1.59 +function runAfterPluginBindingAttached(func) { 1.60 + return function() { 1.61 + let doc = gTestBrowser.contentDocument; 1.62 + let elems = doc.getElementsByTagName('embed'); 1.63 + if (elems.length < 1) { 1.64 + elems = doc.getElementsByTagName('object'); 1.65 + } 1.66 + elems[0].clientTop; 1.67 + executeSoon(func); 1.68 + }; 1.69 +} 1.70 + 1.71 +function handlePluginRemoved() { 1.72 + if (gRunNextTestAfterPluginRemoved) { 1.73 + executeSoon(gNextTest); 1.74 + gRunNextTestAfterPluginRemoved = false; 1.75 + } 1.76 +} 1.77 + 1.78 +function runAfterPluginRemoved(func) { 1.79 + gNextTest = func; 1.80 + gRunNextTestAfterPluginRemoved = true; 1.81 +} 1.82 + 1.83 +// Test that the click-to-play notification is not shown for non-plugin object elements 1.84 + 1.85 +function test1() { 1.86 + let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.87 + ok(popupNotification, "Test 1, Should have a click-to-play notification"); 1.88 + 1.89 + let plugin = gTestBrowser.contentDocument.getElementById("secondtestA"); 1.90 + plugin.parentNode.removeChild(plugin); 1.91 + plugin = gTestBrowser.contentDocument.getElementById("secondtestB"); 1.92 + plugin.parentNode.removeChild(plugin); 1.93 + 1.94 + let image = gTestBrowser.contentDocument.createElement("object"); 1.95 + image.type = "image/png"; 1.96 + image.data = "moz.png"; 1.97 + gTestBrowser.contentDocument.body.appendChild(image); 1.98 + 1.99 + runAfterPluginRemoved(test2); 1.100 +} 1.101 + 1.102 +function test2() { 1.103 + let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.104 + ok(popupNotification, "Test 2, Should have a click-to-play notification"); 1.105 + 1.106 + let plugin = gTestBrowser.contentDocument.getElementById("test"); 1.107 + plugin.parentNode.removeChild(plugin); 1.108 + 1.109 + executeSoon(test3); 1.110 +} 1.111 + 1.112 +function test3() { 1.113 + let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.114 + ok(popupNotification, "Test 3, Should still have a click-to-play notification"); 1.115 + 1.116 + finishTest(); 1.117 +}