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