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

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

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

Powered by Google App Engine
This is Rietveld 408576698