dom/indexedDB/test/head.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /**
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 let gActiveListeners = {};
     8 function registerPopupEventHandler(eventName, callback) {
     9   gActiveListeners[eventName] = function (event) {
    10     if (event.target != PopupNotifications.panel)
    11       return;
    12     PopupNotifications.panel.removeEventListener(eventName,
    13                                                  gActiveListeners[eventName],
    14                                                  false);
    15     delete gActiveListeners[eventName];
    17     callback.call(PopupNotifications.panel);
    18   }
    19   PopupNotifications.panel.addEventListener(eventName,
    20                                             gActiveListeners[eventName],
    21                                             false);
    22 }
    24 function unregisterPopupEventHandler(eventName)
    25 {
    26   PopupNotifications.panel.removeEventListener(eventName,
    27                                                gActiveListeners[eventName],
    28                                                false);
    29   delete gActiveListeners[eventName];
    30 }
    32 function unregisterAllPopupEventHandlers()
    33 {
    34   for (let eventName in gActiveListeners) {
    35     PopupNotifications.panel.removeEventListener(eventName,
    36                                                  gActiveListeners[eventName],
    37                                                  false);
    38   }
    39   gActiveListeners = {};
    40 }
    42 function triggerMainCommand(popup)
    43 {
    44   info("triggering main command");
    45   let notifications = popup.childNodes;
    46   ok(notifications.length > 0, "at least one notification displayed");
    47   let notification = notifications[0];
    48   info("triggering command: " + notification.getAttribute("buttonlabel"));
    50   // 20, 10 so that the inner button is hit
    51   EventUtils.synthesizeMouse(notification.button, 20, 10, {});
    52 }
    54 function triggerSecondaryCommand(popup, index)
    55 {
    56   info("triggering secondary command, " + index);
    57   let notifications = popup.childNodes;
    58   ok(notifications.length > 0, "at least one notification displayed");
    59   let notification = notifications[0];
    61   // Cancel the arrow panel slide-in transition (bug 767133) such that
    62   // it won't interfere with us interacting with the dropdown.
    63   SpecialPowers.wrap(document).getAnonymousNodes(popup)[0].style.transition = "none";
    65   notification.button.focus();
    67   popup.addEventListener("popupshown", function () {
    68     popup.removeEventListener("popupshown", arguments.callee, false);
    70     // Press down until the desired command is selected
    71     for (let i = 0; i <= index; i++)
    72       EventUtils.synthesizeKey("VK_DOWN", {});
    74     // Activate
    75     EventUtils.synthesizeKey("VK_RETURN", {});
    76   }, false);
    78   // One down event to open the popup
    79   EventUtils.synthesizeKey("VK_DOWN", { altKey: (navigator.platform.indexOf("Mac") == -1) });
    80 }
    82 function dismissNotification(popup)
    83 {
    84   info("dismissing notification");
    85   executeSoon(function () {
    86     EventUtils.synthesizeKey("VK_ESCAPE", {});
    87   });
    88 }
    90 function setFinishedCallback(callback, win)
    91 {
    92   if (!win) {
    93     win = window;
    94   }
    95   let testPage = win.gBrowser.selectedBrowser.contentWindow.wrappedJSObject;
    96   testPage.testFinishedCallback = function(result, exception) {
    97     setTimeout(function() {
    98       info("got finished callback");
    99       callback(result, exception);
   100     }, 0);
   101   }
   102 }
   104 function dispatchEvent(eventName)
   105 {
   106   info("dispatching event: " + eventName);
   107   let event = document.createEvent("Events");
   108   event.initEvent(eventName, false, false);
   109   gBrowser.selectedBrowser.contentWindow.dispatchEvent(event);
   110 }
   112 function setPermission(url, permission, value)
   113 {
   114   const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
   116   switch (value) {
   117     case "allow":
   118       value = nsIPermissionManager.ALLOW_ACTION;
   119       break;
   120     case "deny":
   121       value = nsIPermissionManager.DENY_ACTION;
   122       break;
   123     case "unknown":
   124       value = nsIPermissionManager.UNKNOWN_ACTION;
   125       break;
   126     default:
   127       throw new Error("No idea what to set here!");
   128   }
   130   let uri = Components.classes["@mozilla.org/network/io-service;1"]
   131                       .getService(Components.interfaces.nsIIOService)
   132                       .newURI(url, null, null);
   133   let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
   134                     .getService(Ci.nsIScriptSecurityManager)
   135                     .getNoAppCodebasePrincipal(uri);
   137   Components.classes["@mozilla.org/permissionmanager;1"]
   138             .getService(Components.interfaces.nsIPermissionManager)
   139             .addFromPrincipal(principal, permission, value);
   140 }
   142 function removePermission(url, permission)
   143 {
   144   let uri = Components.classes["@mozilla.org/network/io-service;1"]
   145                       .getService(Components.interfaces.nsIIOService)
   146                       .newURI(url, null, null);
   147   let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
   148                     .getService(Ci.nsIScriptSecurityManager)
   149                     .getNoAppCodebasePrincipal(uri);
   151   Components.classes["@mozilla.org/permissionmanager;1"]
   152             .getService(Components.interfaces.nsIPermissionManager)
   153             .removeFromPrincipal(principal, permission);
   154 }
   156 function getPermission(url, permission)
   157 {
   158   let uri = Components.classes["@mozilla.org/network/io-service;1"]
   159                       .getService(Components.interfaces.nsIIOService)
   160                       .newURI(url, null, null);
   161   let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
   162                     .getService(Ci.nsIScriptSecurityManager)
   163                     .getNoAppCodebasePrincipal(uri);
   165   return Components.classes["@mozilla.org/permissionmanager;1"]
   166                    .getService(Components.interfaces.nsIPermissionManager)
   167                    .testPermissionFromPrincipal(principal, permission);
   168 }

mercurial