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 <body> is clicked', function() {
44 var menu
= menuButton
.menu();
45 menuButton
.button().click();
46 document
.body
.click();
47 ok(menu
.offsetWidth
== 0 && menu
.offsetHeight
== 0);
50 test('should dismiss when button is clicked', function() {
51 var menu
= menuButton
.menu();
52 menuButton
.button().click();
53 menuButton
.button().click();
54 ok(menu
.offsetWidth
== 0 && menu
.offsetHeight
== 0);
57 test('should dismiss when menu item is clicked', function() {
58 var menu
= menuButton
.menu();
59 menuButton
.button().click();
60 var element
= document
.getElementById('menu-option-1');
62 ok(menu
.offsetWidth
== 0 && menu
.offsetHeight
== 0);
65 test('should invoke callbacks', function() {
67 menuButton
.button().click();
70 document
.body
.click();
74 test('select method should set/unset background image', function() {
75 var element
= document
.getElementById('menu-option-1');
76 var style
= window
.getComputedStyle(element
);
77 ok(style
.backgroundImage
== 'none');
78 remoting
.MenuButton
.select(element
, true);
79 style
= window
.getComputedStyle(element
);
80 ok(style
.backgroundImage
!= 'none');
81 remoting
.MenuButton
.select(element
, false);
82 style
= window
.getComputedStyle(element
);
83 ok(style
.backgroundImage
== 'none');