dom/indexedDB/test/head.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/test/head.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,168 @@
     1.4 +/**
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +let gActiveListeners = {};
    1.10 +
    1.11 +function registerPopupEventHandler(eventName, callback) {
    1.12 +  gActiveListeners[eventName] = function (event) {
    1.13 +    if (event.target != PopupNotifications.panel)
    1.14 +      return;
    1.15 +    PopupNotifications.panel.removeEventListener(eventName,
    1.16 +                                                 gActiveListeners[eventName],
    1.17 +                                                 false);
    1.18 +    delete gActiveListeners[eventName];
    1.19 +
    1.20 +    callback.call(PopupNotifications.panel);
    1.21 +  }
    1.22 +  PopupNotifications.panel.addEventListener(eventName,
    1.23 +                                            gActiveListeners[eventName],
    1.24 +                                            false);
    1.25 +}
    1.26 +
    1.27 +function unregisterPopupEventHandler(eventName)
    1.28 +{
    1.29 +  PopupNotifications.panel.removeEventListener(eventName,
    1.30 +                                               gActiveListeners[eventName],
    1.31 +                                               false);
    1.32 +  delete gActiveListeners[eventName];
    1.33 +}
    1.34 +
    1.35 +function unregisterAllPopupEventHandlers()
    1.36 +{
    1.37 +  for (let eventName in gActiveListeners) {
    1.38 +    PopupNotifications.panel.removeEventListener(eventName,
    1.39 +                                                 gActiveListeners[eventName],
    1.40 +                                                 false);
    1.41 +  }
    1.42 +  gActiveListeners = {};
    1.43 +}
    1.44 +
    1.45 +function triggerMainCommand(popup)
    1.46 +{
    1.47 +  info("triggering main command");
    1.48 +  let notifications = popup.childNodes;
    1.49 +  ok(notifications.length > 0, "at least one notification displayed");
    1.50 +  let notification = notifications[0];
    1.51 +  info("triggering command: " + notification.getAttribute("buttonlabel"));
    1.52 +
    1.53 +  // 20, 10 so that the inner button is hit
    1.54 +  EventUtils.synthesizeMouse(notification.button, 20, 10, {});
    1.55 +}
    1.56 +
    1.57 +function triggerSecondaryCommand(popup, index)
    1.58 +{
    1.59 +  info("triggering secondary command, " + index);
    1.60 +  let notifications = popup.childNodes;
    1.61 +  ok(notifications.length > 0, "at least one notification displayed");
    1.62 +  let notification = notifications[0];
    1.63 +
    1.64 +  // Cancel the arrow panel slide-in transition (bug 767133) such that
    1.65 +  // it won't interfere with us interacting with the dropdown.
    1.66 +  SpecialPowers.wrap(document).getAnonymousNodes(popup)[0].style.transition = "none";
    1.67 +
    1.68 +  notification.button.focus();
    1.69 +
    1.70 +  popup.addEventListener("popupshown", function () {
    1.71 +    popup.removeEventListener("popupshown", arguments.callee, false);
    1.72 +
    1.73 +    // Press down until the desired command is selected
    1.74 +    for (let i = 0; i <= index; i++)
    1.75 +      EventUtils.synthesizeKey("VK_DOWN", {});
    1.76 +
    1.77 +    // Activate
    1.78 +    EventUtils.synthesizeKey("VK_RETURN", {});
    1.79 +  }, false);
    1.80 +
    1.81 +  // One down event to open the popup
    1.82 +  EventUtils.synthesizeKey("VK_DOWN", { altKey: (navigator.platform.indexOf("Mac") == -1) });
    1.83 +}
    1.84 +
    1.85 +function dismissNotification(popup)
    1.86 +{
    1.87 +  info("dismissing notification");
    1.88 +  executeSoon(function () {
    1.89 +    EventUtils.synthesizeKey("VK_ESCAPE", {});
    1.90 +  });
    1.91 +}
    1.92 +
    1.93 +function setFinishedCallback(callback, win)
    1.94 +{
    1.95 +  if (!win) {
    1.96 +    win = window;
    1.97 +  }
    1.98 +  let testPage = win.gBrowser.selectedBrowser.contentWindow.wrappedJSObject;
    1.99 +  testPage.testFinishedCallback = function(result, exception) {
   1.100 +    setTimeout(function() {
   1.101 +      info("got finished callback");
   1.102 +      callback(result, exception);
   1.103 +    }, 0);
   1.104 +  }
   1.105 +}
   1.106 +
   1.107 +function dispatchEvent(eventName)
   1.108 +{
   1.109 +  info("dispatching event: " + eventName);
   1.110 +  let event = document.createEvent("Events");
   1.111 +  event.initEvent(eventName, false, false);
   1.112 +  gBrowser.selectedBrowser.contentWindow.dispatchEvent(event);
   1.113 +}
   1.114 +
   1.115 +function setPermission(url, permission, value)
   1.116 +{
   1.117 +  const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
   1.118 +
   1.119 +  switch (value) {
   1.120 +    case "allow":
   1.121 +      value = nsIPermissionManager.ALLOW_ACTION;
   1.122 +      break;
   1.123 +    case "deny":
   1.124 +      value = nsIPermissionManager.DENY_ACTION;
   1.125 +      break;
   1.126 +    case "unknown":
   1.127 +      value = nsIPermissionManager.UNKNOWN_ACTION;
   1.128 +      break;
   1.129 +    default:
   1.130 +      throw new Error("No idea what to set here!");
   1.131 +  }
   1.132 +
   1.133 +  let uri = Components.classes["@mozilla.org/network/io-service;1"]
   1.134 +                      .getService(Components.interfaces.nsIIOService)
   1.135 +                      .newURI(url, null, null);
   1.136 +  let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
   1.137 +                    .getService(Ci.nsIScriptSecurityManager)
   1.138 +                    .getNoAppCodebasePrincipal(uri);
   1.139 +
   1.140 +  Components.classes["@mozilla.org/permissionmanager;1"]
   1.141 +            .getService(Components.interfaces.nsIPermissionManager)
   1.142 +            .addFromPrincipal(principal, permission, value);
   1.143 +}
   1.144 +
   1.145 +function removePermission(url, permission)
   1.146 +{
   1.147 +  let uri = Components.classes["@mozilla.org/network/io-service;1"]
   1.148 +                      .getService(Components.interfaces.nsIIOService)
   1.149 +                      .newURI(url, null, null);
   1.150 +  let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
   1.151 +                    .getService(Ci.nsIScriptSecurityManager)
   1.152 +                    .getNoAppCodebasePrincipal(uri);
   1.153 +
   1.154 +  Components.classes["@mozilla.org/permissionmanager;1"]
   1.155 +            .getService(Components.interfaces.nsIPermissionManager)
   1.156 +            .removeFromPrincipal(principal, permission);
   1.157 +}
   1.158 +
   1.159 +function getPermission(url, permission)
   1.160 +{
   1.161 +  let uri = Components.classes["@mozilla.org/network/io-service;1"]
   1.162 +                      .getService(Components.interfaces.nsIIOService)
   1.163 +                      .newURI(url, null, null);
   1.164 +  let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
   1.165 +                    .getService(Ci.nsIScriptSecurityManager)
   1.166 +                    .getNoAppCodebasePrincipal(uri);
   1.167 +
   1.168 +  return Components.classes["@mozilla.org/permissionmanager;1"]
   1.169 +                   .getService(Components.interfaces.nsIPermissionManager)
   1.170 +                   .testPermissionFromPrincipal(principal, permission);
   1.171 +}

mercurial