1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/plugins/browser_CTP_drag_drop.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); 1.8 + 1.9 +let gNextTest = null; 1.10 +let gNewWindow = null; 1.11 + 1.12 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.13 + 1.14 +function test() { 1.15 + waitForExplicitFinish(); 1.16 + registerCleanupFunction(function() { 1.17 + clearAllPluginPermissions(); 1.18 + Services.prefs.clearUserPref("plugins.click_to_play"); 1.19 + }); 1.20 + Services.prefs.setBoolPref("plugins.click_to_play", true); 1.21 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); 1.22 + 1.23 + gBrowser.selectedTab = gBrowser.addTab(); 1.24 + gBrowser.selectedBrowser.addEventListener("PluginBindingAttached", handleEvent, true, true); 1.25 + gNextTest = part1; 1.26 + gBrowser.selectedBrowser.contentDocument.location = gHttpTestRoot + "plugin_test.html"; 1.27 +} 1.28 + 1.29 +function handleEvent() { 1.30 + gNextTest(); 1.31 +} 1.32 + 1.33 +function part1() { 1.34 + gBrowser.selectedBrowser.removeEventListener("PluginBindingAttached", handleEvent); 1.35 + ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab"); 1.36 + 1.37 + gNextTest = part2; 1.38 + gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); 1.39 + gNewWindow.addEventListener("load", handleEvent, true); 1.40 +} 1.41 + 1.42 +function part2() { 1.43 + gNewWindow.removeEventListener("load", handleEvent); 1.44 + let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser); 1.45 + waitForCondition(condition, part3, "Waited too long for click-to-play notification"); 1.46 +} 1.47 + 1.48 +function part3() { 1.49 + ok(PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser), "Should have a click-to-play notification in the tab in the new window"); 1.50 + ok(!PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should not have a click-to-play notification in the old window now"); 1.51 + 1.52 + gBrowser.selectedTab = gBrowser.addTab(); 1.53 + gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, gNewWindow.gBrowser.selectedTab); 1.54 + let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser); 1.55 + waitForCondition(condition, part4, "Waited too long for click-to-play notification"); 1.56 +} 1.57 + 1.58 +function part4() { 1.59 + ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab again"); 1.60 + 1.61 + gBrowser.selectedBrowser.addEventListener("PluginBindingAttached", handleEvent, true, true); 1.62 + gNextTest = part5; 1.63 + gBrowser.selectedBrowser.contentDocument.location = gHttpTestRoot + "plugin_test.html"; 1.64 +} 1.65 + 1.66 +function part5() { 1.67 + gBrowser.selectedBrowser.removeEventListener("PluginBindingAttached", handleEvent); 1.68 + ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab"); 1.69 + 1.70 + gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); 1.71 + waitForFocus(part6, gNewWindow); 1.72 +} 1.73 + 1.74 +function part6() { 1.75 + let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser); 1.76 + waitForCondition(condition, part7, "Waited too long for click-to-play notification"); 1.77 +} 1.78 + 1.79 +function part7() { 1.80 + ok(PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser), "Should have a click-to-play notification in the tab in the new window"); 1.81 + ok(!PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should not have a click-to-play notification in the old window now"); 1.82 + 1.83 + let plugin = gNewWindow.gBrowser.selectedBrowser.contentDocument.getElementById("test"); 1.84 + let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.85 + ok(!objLoadingContent.activated, "plugin should not be activated"); 1.86 + 1.87 + EventUtils.synthesizeMouseAtCenter(plugin, {}, gNewWindow.gBrowser.selectedBrowser.contentWindow); 1.88 + let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser).dismissed && gNewWindow.PopupNotifications.panel.firstChild; 1.89 + waitForCondition(condition, part8, "waited too long for plugin to activate"); 1.90 +} 1.91 + 1.92 +function part8() { 1.93 + // Click the activate button on doorhanger to make sure it works 1.94 + gNewWindow.PopupNotifications.panel.firstChild._primaryButton.click(); 1.95 + 1.96 + let plugin = gNewWindow.gBrowser.selectedBrowser.contentDocument.getElementById("test"); 1.97 + let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.98 + ok(objLoadingContent.activated, "plugin should be activated now"); 1.99 + 1.100 + gNewWindow.close(); 1.101 + gNewWindow = null; 1.102 + finish(); 1.103 +}