| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 (function() { | |
| 6 | |
| 7 'use strict'; | |
| 8 | |
| 9 /** @type {(sinon.Spy|function():void)} */ | |
| 10 var onShow = null; | |
| 11 /** @type {(sinon.Spy|function():void)} */ | |
| 12 var onHide = null; | |
| 13 /** @type {remoting.MenuButton} */ | |
| 14 var menuButton = null; | |
| 15 | |
| 16 module('MenuButton', { | |
| 17 setup: function() { | |
| 18 var fixture = document.getElementById('qunit-fixture'); | |
| 19 fixture.innerHTML = | |
| 20 '<span class="menu-button" id="menu-button-container">' + | |
| 21 '<button class="menu-button-activator">Click me</button>' + | |
| 22 '<ul>' + | |
| 23 '<li id="menu-option-1">Option 1</li>' + | |
| 24 '</ul>' + | |
| 25 '</span>'; | |
| 26 onShow = /** @type {(sinon.Spy|function():void)} */ (sinon.spy()); | |
| 27 onHide = /** @type {(sinon.Spy|function():void)} */ (sinon.spy()); | |
| 28 menuButton = new remoting.MenuButton( | |
| 29 document.getElementById('menu-button-container'), | |
| 30 /** @type {function():void} */ (onShow), | |
| 31 /** @type {function():void} */ (onHide)); | |
| 32 }, | |
| 33 teardown: function() { | |
| 34 onShow = null; | |
| 35 onHide = null; | |
| 36 menuButton = null; | |
| 37 } | |
| 38 }); | |
| 39 | |
| 40 test('should display on click', function() { | |
| 41 var menu = menuButton.menu(); | |
| 42 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0); | |
| 43 menuButton.button().click(); | |
| 44 ok(menu.offsetWidth != 0 && menu.offsetHeight != 0); | |
| 45 }); | |
| 46 | |
| 47 test('should dismiss when the menu is clicked', function() { | |
| 48 var menu = menuButton.menu(); | |
| 49 menuButton.button().click(); | |
| 50 menu.click(); | |
| 51 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0); | |
| 52 }); | |
| 53 | |
| 54 test('should dismiss when anything outside the menu is clicked', function() { | |
| 55 var menu = menuButton.menu(); | |
| 56 menuButton.button().click(); | |
| 57 var x = menu.offsetRight + 1; | |
| 58 var y = menu.offsetBottom + 1; | |
| 59 var notMenu = document.elementFromPoint(x, y); | |
| 60 base.debug.assert(notMenu != menu); | |
| 61 notMenu.click(); | |
| 62 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0); | |
| 63 }); | |
| 64 | |
| 65 test('should dismiss when menu item is clicked', function() { | |
| 66 var menu = menuButton.menu(); | |
| 67 menuButton.button().click(); | |
| 68 var element = document.getElementById('menu-option-1'); | |
| 69 element.click(); | |
| 70 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0); | |
| 71 }); | |
| 72 | |
| 73 test('should invoke callbacks', function() { | |
| 74 ok(!onShow.called); | |
| 75 menuButton.button().click(); | |
| 76 ok(onShow.called); | |
| 77 ok(!onHide.called); | |
| 78 menuButton.menu().click(); | |
| 79 ok(onHide.called); | |
| 80 }); | |
| 81 | |
| 82 test('select method should set/unset background image', function() { | |
| 83 var element = document.getElementById('menu-option-1'); | |
| 84 var style = window.getComputedStyle(element); | |
| 85 ok(style.backgroundImage == 'none'); | |
| 86 remoting.MenuButton.select(element, true); | |
| 87 style = window.getComputedStyle(element); | |
| 88 ok(style.backgroundImage != 'none'); | |
| 89 remoting.MenuButton.select(element, false); | |
| 90 style = window.getComputedStyle(element); | |
| 91 ok(style.backgroundImage == 'none'); | |
| 92 }); | |
| 93 | |
| 94 }()); | |
| OLD | NEW |