Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: remoting/webapp/unittests/menu_button_unittest.js

Issue 401623004: Add unit-tests for MenuButton and simplify implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing file. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 var menuButton = null;
10 var menuShown = false;
11
12 module('MenuButton', {
13 setup: function() {
14 var fixture = document.getElementById('qunit-fixture');
15 fixture.innerHTML =
16 '<span class="menu-button" id="menu-button-container">' +
17 '<button class="menu-button-activator">Click me</button>' +
18 '<ul>' +
19 '<li id="menu-option-1">Option 1</li>' +
20 '</ul>' +
21 '</span>';
22 menuButton = new remoting.MenuButton(
23 document.getElementById('menu-button-container'),
24 function() { menuShown = true; });
25 menuShown = false;
26 },
27 teardown: function() {
28 }
29 });
30
31 test('should display on click', function() {
32 var menu = menuButton.menu();
33 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
34 menuButton.button().click();
35 ok(menu.offsetWidth != 0 && menu.offsetHeight != 0);
36 });
37
38 test('should dismiss when <body> is clicked', function() {
39 var menu = menuButton.menu();
40 menuButton.button().click();
41 document.body.click();
42 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
43 });
44
45 test('should dismiss when button is clicked', function() {
46 var menu = menuButton.menu();
47 menuButton.button().click();
48 menuButton.button().click();
49 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
50 });
51
52 test('should dismiss when menu item is clicked', function() {
53 var menu = menuButton.menu();
54 menuButton.button().click();
55 var element = document.getElementById('menu-option-1');
56 element.click();
57 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
58 });
59
60 test('should invoke callback', function() {
61 ok(!menuShown);
62 menuButton.button().click();
63 ok(menuShown);
64 });
65
66 test('select method should set/unset background image', function() {
67 var element = document.getElementById('menu-option-1');
68 var style = window.getComputedStyle(element);
69 ok(style.backgroundImage == 'none');
70 remoting.MenuButton.select(element, true);
71 style = window.getComputedStyle(element);
72 ok(style.backgroundImage != 'none');
73 remoting.MenuButton.select(element, false);
74 style = window.getComputedStyle(element);
75 ok(style.backgroundImage == 'none');
76 });
77
78 }());
OLDNEW
« remoting/webapp/menu_button.css ('K') | « remoting/webapp/menu_button.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698