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

Side by Side Diff: chrome/test/data/webui/menu_test.html

Issue 1358893003: Ignore mouseup shortly after showing cr.ui.Menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix context menus Created 5 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
« no previous file with comments | « no previous file | ui/webui/resources/js/cr/ui/context_menu_handler.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <body> 3 <body>
4 <script> 4 <script>
5 5
6 /** @type {cr.ui.Menu} */
7 var menu;
8
9 /**
10 * @param {number} x The screenX coord of the mouseup event.
11 * @param {number} y The screenY coord of the mouseup event.
12 */
13 function mouseUpAt(x, y) {
14 var mouseUpEvent = new MouseEvent('mouseup', {
15 bubbles: true,
16 cancelable: true,
17 target: menu,
18 screenX: x,
19 screenY: y,
20 });
21 mouseUpEvent.isTrustedForTesting = true;
22 return menu.dispatchEvent(mouseUpEvent);
23 }
24
25 function setUp() {
26 menu = new cr.ui.Menu;
27 }
28
6 function testHandleMouseOver() { 29 function testHandleMouseOver() {
7 var menu = new cr.ui.Menu;
8
9 var called = false; 30 var called = false;
10 menu.findMenuItem_ = function() { 31 menu.findMenuItem_ = function() {
11 called = true; 32 called = true;
12 return cr.ui.Menu.prototype.findMenuItem_.apply(this, arguments); 33 return cr.ui.Menu.prototype.findMenuItem_.apply(this, arguments);
13 }; 34 };
14 35
15 var over = new MouseEvent('mouseover', {bubbles: true, target: cr.doc.body}); 36 var over = new MouseEvent('mouseover', {bubbles: true, target: cr.doc.body});
16 assertFalse(called); 37 assertFalse(called);
17 menu.dispatchEvent(over); 38 menu.dispatchEvent(over);
18 assertTrue(called); 39 assertTrue(called);
19 } 40 }
20 41
42 function testHandleMouseUp() {
43 var realNow = Date.now;
44 Date.now = function() { return 10; };
45
46 menu.show({x: 5, y: 5});
47
48 // Stop mouseups at the same time and position.
49 assertFalse(mouseUpAt(5, 5));
50
51 // Allow mouseups with different positions but the same time.
52 assertTrue(mouseUpAt(50, 50));
53
54 // Alow mouseups with the same position but different times.
55 Date.now = function() { return 1000; };
56 assertTrue(mouseUpAt(5, 5));
57
58 Date.now = realNow;
59 }
60
61 function testShowViaKeyboardIgnoresMouseUps() {
62 menu.show();
63 assertTrue(mouseUpAt(0, 0));
64 }
65
21 </script> 66 </script>
22 </body> 67 </body>
23 </html> 68 </html>
OLDNEW
« no previous file with comments | « no previous file | ui/webui/resources/js/cr/ui/context_menu_handler.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698