addon-sdk/source/test/sidebar/utils.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/sidebar/utils.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     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 +'use strict';
     1.8 +
     1.9 +module.metadata = {
    1.10 +  'engines': {
    1.11 +    'Firefox': '*'
    1.12 +  }
    1.13 +};
    1.14 +
    1.15 +const { Cu } = require('chrome');
    1.16 +const { getMostRecentBrowserWindow } = require('sdk/window/utils');
    1.17 +const { fromIterator } = require('sdk/util/array');
    1.18 +
    1.19 +const BUILTIN_SIDEBAR_MENUITEMS = exports.BUILTIN_SIDEBAR_MENUITEMS = [
    1.20 +  'menu_socialSidebar',
    1.21 +  'menu_historySidebar',
    1.22 +  'menu_bookmarksSidebar'
    1.23 +];
    1.24 +
    1.25 +function isSidebarShowing(window) {
    1.26 +  window = window || getMostRecentBrowserWindow();
    1.27 +  let sidebar = window.document.getElementById('sidebar-box');
    1.28 +  return !sidebar.hidden;
    1.29 +}
    1.30 +exports.isSidebarShowing = isSidebarShowing;
    1.31 +
    1.32 +function getSidebarMenuitems(window) {
    1.33 +  window = window || getMostRecentBrowserWindow();
    1.34 +  return fromIterator(window.document.querySelectorAll('#viewSidebarMenu menuitem'));
    1.35 +}
    1.36 +exports.getSidebarMenuitems = getSidebarMenuitems;
    1.37 +
    1.38 +function getExtraSidebarMenuitems() {
    1.39 +  let menuitems = getSidebarMenuitems();
    1.40 +  return menuitems.filter(function(mi) {
    1.41 +    return BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) < 0;
    1.42 +  });
    1.43 +}
    1.44 +exports.getExtraSidebarMenuitems = getExtraSidebarMenuitems;
    1.45 +
    1.46 +function makeID(id) {
    1.47 +  return 'jetpack-sidebar-' + id;
    1.48 +}
    1.49 +exports.makeID = makeID;
    1.50 +
    1.51 +function simulateCommand(ele) {
    1.52 +  let window = ele.ownerDocument.defaultView;
    1.53 +  let { document } = window;
    1.54 +  var evt = document.createEvent('XULCommandEvent');
    1.55 +  evt.initCommandEvent('command', true, true, window,
    1.56 +    0, false, false, false, false, null);
    1.57 +  ele.dispatchEvent(evt);
    1.58 +}
    1.59 +exports.simulateCommand = simulateCommand;
    1.60 +
    1.61 +function simulateClick(ele) {
    1.62 +  let window = ele.ownerDocument.defaultView;
    1.63 +  let { document } = window;
    1.64 +  let evt = document.createEvent('MouseEvents');
    1.65 +  evt.initMouseEvent('click', true, true, window,
    1.66 +    0, 0, 0, 0, 0, false, false, false, false, 0, null);
    1.67 +  ele.dispatchEvent(evt);
    1.68 +}
    1.69 +exports.simulateClick = simulateClick;
    1.70 +
    1.71 +// OSX and Windows exhibit different behaviors when 'checked' is false,
    1.72 +// so compare against the consistent 'true'. See bug 894809.
    1.73 +function isChecked(node) {
    1.74 +  return node.getAttribute('checked') === 'true';
    1.75 +};
    1.76 +exports.isChecked = isChecked;

mercurial