addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js

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

mercurial