browser/base/content/test/plugins/browser_pluginplaypreview2.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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 var rootDir = getRootDirectory(gTestPath);
     6 const gTestRoot = rootDir;
     8 var gTestBrowser = null;
     9 var gNextTest = null;
    10 var gNextTestSkip = 0;
    11 var gPlayPreviewPluginActualEvents = 0;
    12 var gPlayPreviewPluginExpectedEvents = 1;
    14 var gPlayPreviewRegistration = null;
    16 function registerPlayPreview(mimeType, targetUrl) {
    17   var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
    18   ph.registerPlayPreviewMimeType(mimeType, false, targetUrl);
    20   return (gPlayPreviewRegistration = {
    21     unregister: function() {
    22       ph.unregisterPlayPreviewMimeType(mimeType);
    23       gPlayPreviewRegistration = null;
    24     }
    25   });
    26 }
    28 function unregisterPlayPreview() {
    29   gPlayPreviewRegistration.unregister();
    30 }
    32 Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
    33 Components.utils.import("resource://gre/modules/Services.jsm");
    36 function test() {
    37   waitForExplicitFinish();
    38   registerCleanupFunction(function() {
    39     if (gPlayPreviewRegistration)
    40       gPlayPreviewRegistration.unregister();
    41     Services.prefs.clearUserPref("plugins.click_to_play");
    42   });
    44   var newTab = gBrowser.addTab();
    45   gBrowser.selectedTab = newTab;
    46   gTestBrowser = gBrowser.selectedBrowser;
    47   gTestBrowser.addEventListener("load", pageLoad, true);
    48   gTestBrowser.addEventListener("PluginBindingAttached", handleBindingAttached, true, true);
    50   Services.prefs.setBoolPref("plugins.click_to_play", true);
    51   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    53   registerPlayPreview('application/x-test', 'about:');
    54   prepareTest(test1a, gTestRoot + "plugin_test.html", 1);
    55 }
    57 function finishTest() {
    58   gTestBrowser.removeEventListener("load", pageLoad, true);
    59   gTestBrowser.removeEventListener("PluginBindingAttached", handleBindingAttached, true, true);
    60   gBrowser.removeCurrentTab();
    61   window.focus();
    62   finish();
    63 }
    65 function handleBindingAttached(evt) {
    66   if (evt.target instanceof Ci.nsIObjectLoadingContent &&
    67       evt.target.pluginFallbackType == Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW)
    68     gPlayPreviewPluginActualEvents++;
    69 }
    71 function pageLoad() {
    72   // The plugin events are async dispatched and can come after the load event
    73   // This just allows the events to fire before we then go on to test the states
    75   // iframe might triggers load event as well, making sure we skip some to let
    76   // all iframes on the page be loaded as well
    77   if (gNextTestSkip) {
    78     gNextTestSkip--;
    79     return;
    80   }
    81   executeSoon(gNextTest);
    82 }
    84 function prepareTest(nextTest, url, skip) {
    85   gNextTest = nextTest;
    86   gNextTestSkip = skip;
    87   gTestBrowser.contentWindow.location = url;
    88 }
    90 // Tests a page with normal play preview registration (1/2)
    91 function test1a() {
    92   var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
    93   ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 1a, Should not have displayed the missing plugin notification");
    94   ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 1a, Should not have displayed the blocked plugin notification");
    96   var pluginInfo = getTestPlugin();
    97   ok(pluginInfo, "Should have a test plugin");
    99   var doc = gTestBrowser.contentDocument;
   100   var plugin = doc.getElementById("test");
   101   var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   102   is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW, "Test 1a, plugin fallback type should be PLUGIN_PLAY_PREVIEW");
   103   ok(!objLoadingContent.activated, "Test 1a, Plugin should not be activated");
   105   var overlay = doc.getAnonymousElementByAttribute(plugin, "class", "previewPluginContent");
   106   ok(overlay, "Test 1a, the overlay div is expected");
   108   var iframe = overlay.getElementsByClassName("previewPluginContentFrame")[0];
   109   ok(iframe && iframe.localName == "iframe", "Test 1a, the overlay iframe is expected");
   110   var iframeHref = iframe.contentWindow.location.href;
   111   ok(iframeHref == "about:", "Test 1a, the overlay about: content is expected");
   113   var rect = iframe.getBoundingClientRect();
   114   ok(rect.width == 200, "Test 1a, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being replaced by actual plugin");
   115   ok(rect.height == 200, "Test 1a, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being replaced by actual plugin");
   117   var e = overlay.ownerDocument.createEvent("CustomEvent");
   118   e.initCustomEvent("MozPlayPlugin", true, true, null);
   119   overlay.dispatchEvent(e);
   120   var condition = function() objLoadingContent.activated;
   121   waitForCondition(condition, test1b, "Test 1a, Waited too long for plugin to stop play preview");
   122 }
   124 // Tests that activating via MozPlayPlugin through the notification works (part 2/2)
   125 function test1b() {
   126   var plugin = gTestBrowser.contentDocument.getElementById("test");
   127   var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   128   ok(objLoadingContent.activated, "Test 1b, Plugin should be activated");
   130   is(gPlayPreviewPluginActualEvents, gPlayPreviewPluginExpectedEvents,
   131      "There should be exactly one PluginPlayPreview event");
   133   unregisterPlayPreview();
   135   prepareTest(test2, gTestRoot + "plugin_test.html");
   136 }
   138 // Tests a page with a working plugin in it -- the mime type was just unregistered.
   139 function test2() {
   140   var doc = gTestBrowser.contentDocument;
   141   var plugin = doc.getElementById("test");
   142   var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   143   ok(objLoadingContent.pluginFallbackType != Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW, "Test 2, plugin fallback type should not be PLUGIN_PLAY_PREVIEW");
   144   ok(!objLoadingContent.activated, "Test 2, Plugin should not be activated");
   146   registerPlayPreview('application/x-unknown', 'about:');
   148   prepareTest(test3, gTestRoot + "plugin_test.html");
   149 }
   151 // Tests a page with a working plugin in it -- diffent play preview type is reserved.
   152 function test3() {
   153   var doc = gTestBrowser.contentDocument;
   154   var plugin = doc.getElementById("test");
   155   var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   156   ok(objLoadingContent.pluginFallbackType != Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW, "Test 3, plugin fallback type should not be PLUGIN_PLAY_PREVIEW");
   157   ok(!objLoadingContent.activated, "Test 3, Plugin should not be activated");
   159   unregisterPlayPreview();
   161   registerPlayPreview('application/x-test', 'about:');
   162   Services.prefs.setBoolPref("plugins.click_to_play", false);
   163   var plugin = getTestPlugin();
   164   plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
   165   prepareTest(test4, gTestRoot + "plugin_test.html");
   166 }
   168 // Tests a page with a working plugin in it -- click-to-play is off
   169 function test4() {
   170   var plugin = gTestBrowser.contentDocument.getElementById("test");
   171   var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   172   ok(objLoadingContent.activated, "Test 4, Plugin should be activated");
   174   finishTest();
   175 }

mercurial