browser/base/content/test/plugins/browser_CTP_context_menu.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 var rootDir = getRootDirectory(gTestPath);
     2 const gTestRoot = rootDir;
     3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
     5 var gTestBrowser = null;
     6 var gNextTest = null;
     7 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
     9 Components.utils.import("resource://gre/modules/Services.jsm");
    11 function test() {
    12   waitForExplicitFinish();
    13   registerCleanupFunction(function() {
    14     clearAllPluginPermissions();
    15     Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
    16   });
    17   Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
    19   let newTab = gBrowser.addTab();
    20   gBrowser.selectedTab = newTab;
    21   gTestBrowser = gBrowser.selectedBrowser;
    22   gTestBrowser.addEventListener("load", pageLoad, true);
    24   Services.prefs.setBoolPref("plugins.click_to_play", true);
    25   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    27   prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_test.html");
    28 }
    30 function finishTest() {
    31   clearAllPluginPermissions();
    32   gTestBrowser.removeEventListener("load", pageLoad, true);
    33   gBrowser.removeCurrentTab();
    34   window.focus();
    35   finish();
    36 }
    38 function pageLoad() {
    39   // The plugin events are async dispatched and can come after the load event
    40   // This just allows the events to fire before we then go on to test the states
    41   executeSoon(gNextTest);
    42 }
    44 function prepareTest(nextTest, url) {
    45   gNextTest = nextTest;
    46   gTestBrowser.contentWindow.location = url;
    47 }
    49 // Due to layout being async, "PluginBindAttached" may trigger later.
    50 // This wraps a function to force a layout flush, thus triggering it,
    51 // and schedules the function execution so they're definitely executed
    52 // afterwards.
    53 function runAfterPluginBindingAttached(func) {
    54   return function() {
    55     let doc = gTestBrowser.contentDocument;
    56     let elems = doc.getElementsByTagName('embed');
    57     if (elems.length < 1) {
    58       elems = doc.getElementsByTagName('object');
    59     }
    60     elems[0].clientTop;
    61     executeSoon(func);
    62   };
    63 }
    65 // Test that the activate action in content menus for CTP plugins works
    66 function test1() {
    67   let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    68   ok(popupNotification, "Test 1, Should have a click-to-play notification");
    70   let plugin = gTestBrowser.contentDocument.getElementById("test");
    71   let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    72   ok(!objLoadingContent.activated, "Test 1, Plugin should not be activated");
    74   // When the popupshown DOM event is fired, the actual showing of the popup
    75   // may still be pending. Clear the event loop before continuing so that
    76   // subsequently-opened popups aren't cancelled by accident.
    77   let goToNext = function() {
    78     window.document.removeEventListener("popupshown", goToNext, false);
    79     executeSoon(test2);
    80   };
    81   window.document.addEventListener("popupshown", goToNext, false);
    82   EventUtils.synthesizeMouseAtCenter(plugin,
    83                                      { type: "contextmenu", button: 2 },
    84                                      gTestBrowser.contentWindow);
    85 }
    87 function test2() {
    88   let activate = window.document.getElementById("context-ctp-play");
    89   ok(activate, "Test 2, Should have a context menu entry for activating the plugin");
    91   let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    92   ok(notification, "Test 2, Should have a click-to-play notification");
    93   ok(notification.dismissed, "Test 2, notification should be dismissed");
    95   // Trigger the click-to-play popup
    96   activate.doCommand();
    98   waitForCondition(() => !notification.dismissed,
    99 		   test3, "Test 2, waited too long for context activation");
   100 }
   102 function test3() {
   103   // Activate the plugin
   104   PopupNotifications.panel.firstChild._primaryButton.click();
   106   let plugin = gTestBrowser.contentDocument.getElementById("test");
   107   let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   108   waitForCondition(() => objLoadingContent.activated, test4, "Waited too long for plugin to activate");
   109 }
   111 function test4() {
   112   finishTest();
   113 }

mercurial