1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/plugins/browser_pluginplaypreview2.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,176 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +var rootDir = getRootDirectory(gTestPath); 1.9 +const gTestRoot = rootDir; 1.10 + 1.11 +var gTestBrowser = null; 1.12 +var gNextTest = null; 1.13 +var gNextTestSkip = 0; 1.14 +var gPlayPreviewPluginActualEvents = 0; 1.15 +var gPlayPreviewPluginExpectedEvents = 1; 1.16 + 1.17 +var gPlayPreviewRegistration = null; 1.18 + 1.19 +function registerPlayPreview(mimeType, targetUrl) { 1.20 + var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); 1.21 + ph.registerPlayPreviewMimeType(mimeType, false, targetUrl); 1.22 + 1.23 + return (gPlayPreviewRegistration = { 1.24 + unregister: function() { 1.25 + ph.unregisterPlayPreviewMimeType(mimeType); 1.26 + gPlayPreviewRegistration = null; 1.27 + } 1.28 + }); 1.29 +} 1.30 + 1.31 +function unregisterPlayPreview() { 1.32 + gPlayPreviewRegistration.unregister(); 1.33 +} 1.34 + 1.35 +Components.utils.import('resource://gre/modules/XPCOMUtils.jsm'); 1.36 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.37 + 1.38 + 1.39 +function test() { 1.40 + waitForExplicitFinish(); 1.41 + registerCleanupFunction(function() { 1.42 + if (gPlayPreviewRegistration) 1.43 + gPlayPreviewRegistration.unregister(); 1.44 + Services.prefs.clearUserPref("plugins.click_to_play"); 1.45 + }); 1.46 + 1.47 + var newTab = gBrowser.addTab(); 1.48 + gBrowser.selectedTab = newTab; 1.49 + gTestBrowser = gBrowser.selectedBrowser; 1.50 + gTestBrowser.addEventListener("load", pageLoad, true); 1.51 + gTestBrowser.addEventListener("PluginBindingAttached", handleBindingAttached, true, true); 1.52 + 1.53 + Services.prefs.setBoolPref("plugins.click_to_play", true); 1.54 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); 1.55 + 1.56 + registerPlayPreview('application/x-test', 'about:'); 1.57 + prepareTest(test1a, gTestRoot + "plugin_test.html", 1); 1.58 +} 1.59 + 1.60 +function finishTest() { 1.61 + gTestBrowser.removeEventListener("load", pageLoad, true); 1.62 + gTestBrowser.removeEventListener("PluginBindingAttached", handleBindingAttached, true, true); 1.63 + gBrowser.removeCurrentTab(); 1.64 + window.focus(); 1.65 + finish(); 1.66 +} 1.67 + 1.68 +function handleBindingAttached(evt) { 1.69 + if (evt.target instanceof Ci.nsIObjectLoadingContent && 1.70 + evt.target.pluginFallbackType == Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW) 1.71 + gPlayPreviewPluginActualEvents++; 1.72 +} 1.73 + 1.74 +function pageLoad() { 1.75 + // The plugin events are async dispatched and can come after the load event 1.76 + // This just allows the events to fire before we then go on to test the states 1.77 + 1.78 + // iframe might triggers load event as well, making sure we skip some to let 1.79 + // all iframes on the page be loaded as well 1.80 + if (gNextTestSkip) { 1.81 + gNextTestSkip--; 1.82 + return; 1.83 + } 1.84 + executeSoon(gNextTest); 1.85 +} 1.86 + 1.87 +function prepareTest(nextTest, url, skip) { 1.88 + gNextTest = nextTest; 1.89 + gNextTestSkip = skip; 1.90 + gTestBrowser.contentWindow.location = url; 1.91 +} 1.92 + 1.93 +// Tests a page with normal play preview registration (1/2) 1.94 +function test1a() { 1.95 + var notificationBox = gBrowser.getNotificationBox(gTestBrowser); 1.96 + ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 1a, Should not have displayed the missing plugin notification"); 1.97 + ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 1a, Should not have displayed the blocked plugin notification"); 1.98 + 1.99 + var pluginInfo = getTestPlugin(); 1.100 + ok(pluginInfo, "Should have a test plugin"); 1.101 + 1.102 + var doc = gTestBrowser.contentDocument; 1.103 + var plugin = doc.getElementById("test"); 1.104 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.105 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW, "Test 1a, plugin fallback type should be PLUGIN_PLAY_PREVIEW"); 1.106 + ok(!objLoadingContent.activated, "Test 1a, Plugin should not be activated"); 1.107 + 1.108 + var overlay = doc.getAnonymousElementByAttribute(plugin, "class", "previewPluginContent"); 1.109 + ok(overlay, "Test 1a, the overlay div is expected"); 1.110 + 1.111 + var iframe = overlay.getElementsByClassName("previewPluginContentFrame")[0]; 1.112 + ok(iframe && iframe.localName == "iframe", "Test 1a, the overlay iframe is expected"); 1.113 + var iframeHref = iframe.contentWindow.location.href; 1.114 + ok(iframeHref == "about:", "Test 1a, the overlay about: content is expected"); 1.115 + 1.116 + var rect = iframe.getBoundingClientRect(); 1.117 + ok(rect.width == 200, "Test 1a, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being replaced by actual plugin"); 1.118 + ok(rect.height == 200, "Test 1a, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being replaced by actual plugin"); 1.119 + 1.120 + var e = overlay.ownerDocument.createEvent("CustomEvent"); 1.121 + e.initCustomEvent("MozPlayPlugin", true, true, null); 1.122 + overlay.dispatchEvent(e); 1.123 + var condition = function() objLoadingContent.activated; 1.124 + waitForCondition(condition, test1b, "Test 1a, Waited too long for plugin to stop play preview"); 1.125 +} 1.126 + 1.127 +// Tests that activating via MozPlayPlugin through the notification works (part 2/2) 1.128 +function test1b() { 1.129 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.130 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.131 + ok(objLoadingContent.activated, "Test 1b, Plugin should be activated"); 1.132 + 1.133 + is(gPlayPreviewPluginActualEvents, gPlayPreviewPluginExpectedEvents, 1.134 + "There should be exactly one PluginPlayPreview event"); 1.135 + 1.136 + unregisterPlayPreview(); 1.137 + 1.138 + prepareTest(test2, gTestRoot + "plugin_test.html"); 1.139 +} 1.140 + 1.141 +// Tests a page with a working plugin in it -- the mime type was just unregistered. 1.142 +function test2() { 1.143 + var doc = gTestBrowser.contentDocument; 1.144 + var plugin = doc.getElementById("test"); 1.145 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.146 + ok(objLoadingContent.pluginFallbackType != Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW, "Test 2, plugin fallback type should not be PLUGIN_PLAY_PREVIEW"); 1.147 + ok(!objLoadingContent.activated, "Test 2, Plugin should not be activated"); 1.148 + 1.149 + registerPlayPreview('application/x-unknown', 'about:'); 1.150 + 1.151 + prepareTest(test3, gTestRoot + "plugin_test.html"); 1.152 +} 1.153 + 1.154 +// Tests a page with a working plugin in it -- diffent play preview type is reserved. 1.155 +function test3() { 1.156 + var doc = gTestBrowser.contentDocument; 1.157 + var plugin = doc.getElementById("test"); 1.158 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.159 + ok(objLoadingContent.pluginFallbackType != Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW, "Test 3, plugin fallback type should not be PLUGIN_PLAY_PREVIEW"); 1.160 + ok(!objLoadingContent.activated, "Test 3, Plugin should not be activated"); 1.161 + 1.162 + unregisterPlayPreview(); 1.163 + 1.164 + registerPlayPreview('application/x-test', 'about:'); 1.165 + Services.prefs.setBoolPref("plugins.click_to_play", false); 1.166 + var plugin = getTestPlugin(); 1.167 + plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED; 1.168 + prepareTest(test4, gTestRoot + "plugin_test.html"); 1.169 +} 1.170 + 1.171 +// Tests a page with a working plugin in it -- click-to-play is off 1.172 +function test4() { 1.173 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.174 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.175 + ok(objLoadingContent.activated, "Test 4, Plugin should be activated"); 1.176 + 1.177 + finishTest(); 1.178 +} 1.179 +