addon-sdk/source/test/sidebar/utils.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.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 'use strict';
michael@0 5
michael@0 6 module.metadata = {
michael@0 7 'engines': {
michael@0 8 'Firefox': '*'
michael@0 9 }
michael@0 10 };
michael@0 11
michael@0 12 const { Cu } = require('chrome');
michael@0 13 const { getMostRecentBrowserWindow } = require('sdk/window/utils');
michael@0 14 const { fromIterator } = require('sdk/util/array');
michael@0 15
michael@0 16 const BUILTIN_SIDEBAR_MENUITEMS = exports.BUILTIN_SIDEBAR_MENUITEMS = [
michael@0 17 'menu_socialSidebar',
michael@0 18 'menu_historySidebar',
michael@0 19 'menu_bookmarksSidebar'
michael@0 20 ];
michael@0 21
michael@0 22 function isSidebarShowing(window) {
michael@0 23 window = window || getMostRecentBrowserWindow();
michael@0 24 let sidebar = window.document.getElementById('sidebar-box');
michael@0 25 return !sidebar.hidden;
michael@0 26 }
michael@0 27 exports.isSidebarShowing = isSidebarShowing;
michael@0 28
michael@0 29 function getSidebarMenuitems(window) {
michael@0 30 window = window || getMostRecentBrowserWindow();
michael@0 31 return fromIterator(window.document.querySelectorAll('#viewSidebarMenu menuitem'));
michael@0 32 }
michael@0 33 exports.getSidebarMenuitems = getSidebarMenuitems;
michael@0 34
michael@0 35 function getExtraSidebarMenuitems() {
michael@0 36 let menuitems = getSidebarMenuitems();
michael@0 37 return menuitems.filter(function(mi) {
michael@0 38 return BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) < 0;
michael@0 39 });
michael@0 40 }
michael@0 41 exports.getExtraSidebarMenuitems = getExtraSidebarMenuitems;
michael@0 42
michael@0 43 function makeID(id) {
michael@0 44 return 'jetpack-sidebar-' + id;
michael@0 45 }
michael@0 46 exports.makeID = makeID;
michael@0 47
michael@0 48 function simulateCommand(ele) {
michael@0 49 let window = ele.ownerDocument.defaultView;
michael@0 50 let { document } = window;
michael@0 51 var evt = document.createEvent('XULCommandEvent');
michael@0 52 evt.initCommandEvent('command', true, true, window,
michael@0 53 0, false, false, false, false, null);
michael@0 54 ele.dispatchEvent(evt);
michael@0 55 }
michael@0 56 exports.simulateCommand = simulateCommand;
michael@0 57
michael@0 58 function simulateClick(ele) {
michael@0 59 let window = ele.ownerDocument.defaultView;
michael@0 60 let { document } = window;
michael@0 61 let evt = document.createEvent('MouseEvents');
michael@0 62 evt.initMouseEvent('click', true, true, window,
michael@0 63 0, 0, 0, 0, 0, false, false, false, false, 0, null);
michael@0 64 ele.dispatchEvent(evt);
michael@0 65 }
michael@0 66 exports.simulateClick = simulateClick;
michael@0 67
michael@0 68 // OSX and Windows exhibit different behaviors when 'checked' is false,
michael@0 69 // so compare against the consistent 'true'. See bug 894809.
michael@0 70 function isChecked(node) {
michael@0 71 return node.getAttribute('checked') === 'true';
michael@0 72 };
michael@0 73 exports.isChecked = isChecked;

mercurial