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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/menu_test.html
diff --git a/chrome/test/data/webui/menu_test.html b/chrome/test/data/webui/menu_test.html
index 7e0e9205a06d1766491e64abf1a9c0e387aebfd6..6d26cc3f7fa8e821f5eaf92c6b1cfc2996c860d8 100644
--- a/chrome/test/data/webui/menu_test.html
+++ b/chrome/test/data/webui/menu_test.html
@@ -3,9 +3,30 @@
<body>
<script>
-function testHandleMouseOver() {
- var menu = new cr.ui.Menu;
+/** @type {cr.ui.Menu} */
+var menu;
+
+/**
+ * @param {number} x The screenX coord of the mouseup event.
+ * @param {number} y The screenY coord of the mouseup event.
+ */
+function mouseUpAt(x, y) {
+ var mouseUpEvent = new MouseEvent('mouseup', {
+ bubbles: true,
+ cancelable: true,
+ target: menu,
+ screenX: x,
+ screenY: y,
+ });
+ mouseUpEvent.isTrustedForTesting = true;
+ return menu.dispatchEvent(mouseUpEvent);
+}
+
+function setUp() {
+ menu = new cr.ui.Menu;
+}
+function testHandleMouseOver() {
var called = false;
menu.findMenuItem_ = function() {
called = true;
@@ -18,6 +39,30 @@ function testHandleMouseOver() {
assertTrue(called);
}
+function testHandleMouseUp() {
+ var realNow = Date.now;
+ Date.now = function() { return 10; };
+
+ menu.show({x: 5, y: 5});
+
+ // Stop mouseups at the same time and position.
+ assertFalse(mouseUpAt(5, 5));
+
+ // Allow mouseups with different positions but the same time.
+ assertTrue(mouseUpAt(50, 50));
+
+ // Alow mouseups with the same position but different times.
+ Date.now = function() { return 1000; };
+ assertTrue(mouseUpAt(5, 5));
+
+ Date.now = realNow;
+}
+
+function testShowViaKeyboardIgnoresMouseUps() {
+ menu.show();
+ assertTrue(mouseUpAt(0, 0));
+}
+
</script>
</body>
</html>
« 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