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.
11 var menuButton = null;
13 module('MenuButton', {
15 var fixture = document.getElementById('qunit-fixture');
17 '<span class="menu-button" id="menu-button-container">' +
18 '<button class="menu-button-activator">Click me</button>' +
20 '<li id="menu-option-1">Option 1</li>' +
25 menuButton = new remoting.MenuButton(
26 document.getElementById('menu-button-container'),
29 teardown: function() {
36 test('should display on click', function() {
37 var menu = menuButton.menu();
38 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
39 menuButton.button().click();
40 ok(menu.offsetWidth != 0 && menu.offsetHeight != 0);
43 test('should dismiss when the menu is clicked', function() {
44 var menu = menuButton.menu();
45 menuButton.button().click();
47 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
50 test('should dismiss when anything outside the menu is clicked', function() {
51 var menu = menuButton.menu();
52 menuButton.button().click();
53 var x = menu.offsetRight + 1;
54 var y = menu.offsetBottom + 1;
55 var notMenu = document.elementFromPoint(x, y);
56 base.debug.assert(notMenu != menu);
58 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
61 test('should dismiss when menu item is clicked', function() {
62 var menu = menuButton.menu();
63 menuButton.button().click();
64 var element = document.getElementById('menu-option-1');
66 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
69 test('should invoke callbacks', function() {
71 menuButton.button().click();
74 menuButton.menu().click();
78 test('select method should set/unset background image', function() {
79 var element = document.getElementById('menu-option-1');
80 var style = window.getComputedStyle(element);
81 ok(style.backgroundImage == 'none');
82 remoting.MenuButton.select(element, true);
83 style = window.getComputedStyle(element);
84 ok(style.backgroundImage != 'none');
85 remoting.MenuButton.select(element, false);
86 style = window.getComputedStyle(element);
87 ok(style.backgroundImage == 'none');