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

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

Issue 592793003: Make pop-up menus more easily dismissable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comment and fixed unit tests. Created 6 years, 3 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 var onShow = null; 9 var onShow = null;
10 var onHide = null; 10 var onHide = null;
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 }); 34 });
35 35
36 test('should display on click', function() { 36 test('should display on click', function() {
37 var menu = menuButton.menu(); 37 var menu = menuButton.menu();
38 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0); 38 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
39 menuButton.button().click(); 39 menuButton.button().click();
40 ok(menu.offsetWidth != 0 && menu.offsetHeight != 0); 40 ok(menu.offsetWidth != 0 && menu.offsetHeight != 0);
41 }); 41 });
42 42
43 test('should dismiss when <body> is clicked', function() { 43 test('should dismiss when the menu is clicked', function() {
44 var menu = menuButton.menu(); 44 var menu = menuButton.menu();
45 menuButton.button().click(); 45 menuButton.button().click();
46 document.body.click(); 46 menu.click();
47 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0); 47 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
48 }); 48 });
49 49
50 /* 50 test('should dismiss when anything outside the menu is clicked', function() {
51 TODO(jamiewalch): Reinstate this once MenuButton is fixed properly.
52 test('should dismiss when button is clicked', function() {
53 var menu = menuButton.menu(); 51 var menu = menuButton.menu();
54 menuButton.button().click(); 52 menuButton.button().click();
55 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);
57 notMenu.click();
56 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0); 58 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
57 }); 59 });
58 */
59 60
60 test('should dismiss when menu item is clicked', function() { 61 test('should dismiss when menu item is clicked', function() {
61 var menu = menuButton.menu(); 62 var menu = menuButton.menu();
62 menuButton.button().click(); 63 menuButton.button().click();
63 var element = document.getElementById('menu-option-1'); 64 var element = document.getElementById('menu-option-1');
64 element.click(); 65 element.click();
65 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0); 66 ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
66 }); 67 });
67 68
68 test('should invoke callbacks', function() { 69 test('should invoke callbacks', function() {
69 ok(!onShow.called); 70 ok(!onShow.called);
70 menuButton.button().click(); 71 menuButton.button().click();
71 ok(onShow.called); 72 ok(onShow.called);
72 ok(!onHide.called); 73 ok(!onHide.called);
73 document.body.click(); 74 menuButton.menu().click();
74 ok(onHide.called); 75 ok(onHide.called);
75 }); 76 });
76 77
77 test('select method should set/unset background image', function() { 78 test('select method should set/unset background image', function() {
78 var element = document.getElementById('menu-option-1'); 79 var element = document.getElementById('menu-option-1');
79 var style = window.getComputedStyle(element); 80 var style = window.getComputedStyle(element);
80 ok(style.backgroundImage == 'none'); 81 ok(style.backgroundImage == 'none');
81 remoting.MenuButton.select(element, true); 82 remoting.MenuButton.select(element, true);
82 style = window.getComputedStyle(element); 83 style = window.getComputedStyle(element);
83 ok(style.backgroundImage != 'none'); 84 ok(style.backgroundImage != 'none');
84 remoting.MenuButton.select(element, false); 85 remoting.MenuButton.select(element, false);
85 style = window.getComputedStyle(element); 86 style = window.getComputedStyle(element);
86 ok(style.backgroundImage == 'none'); 87 ok(style.backgroundImage == 'none');
87 }); 88 });
88 89
89 }()); 90 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698