Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / remoting / webapp / unittests / menu_button_unittest.js
blob48728f8a0f47948e546fcc1f0a756e21273168f0
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.
5 (function() {
7 'use strict';
9 var onShow = null;
10 var onHide = null;
11 var menuButton = null;
13 module('MenuButton', {
14 setup: function() {
15 var fixture = document.getElementById('qunit-fixture');
16 fixture.innerHTML =
17 '<span class="menu-button" id="menu-button-container">' +
18 '<button class="menu-button-activator">Click me</button>' +
19 '<ul>' +
20 '<li id="menu-option-1">Option 1</li>' +
21 '</ul>' +
22 '</span>';
23 onShow = sinon.spy();
24 onHide = sinon.spy();
25 menuButton = new remoting.MenuButton(
26 document.getElementById('menu-button-container'),
27 onShow, onHide);
29 teardown: function() {
30 onShow = null;
31 onHide = null;
32 menuButton = null;
34 });
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);
41 });
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);
48 });
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);
55 });
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');
61 element.click();
62 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
63 });
65 test('should invoke callbacks', function() {
66 ok(!onShow.called);
67 menuButton.button().click();
68 ok(onShow.called);
69 ok(!onHide.called);
70 document.body.click();
71 ok(onHide.called);
72 });
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');
84 });
86 }());