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

Unified Diff: chrome/test/data/webui/context_menu_handler_test.html

Issue 647483006: Fixed to return original context element. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 8 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 | chrome/test/data/webui/webui_resource_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/context_menu_handler_test.html
diff --git a/chrome/test/data/webui/context_menu_handler_test.html b/chrome/test/data/webui/context_menu_handler_test.html
new file mode 100644
index 0000000000000000000000000000000000000000..366ed0e9e8835b49efedc8b2a31d38f749ac9f95
--- /dev/null
+++ b/chrome/test/data/webui/context_menu_handler_test.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+
+function testShowAndHideEvents() {
+ // Keep original Date.now not to affect other code.
+ var originalDateNow = Date.now;
+
+ // Initial value is 1 since 0 becomes false.
+ var currentTime = 1;
+
+ // Overrides Date.now to simulate time.
+ Date.now = function() { return currentTime; };
+
+ var cmh = cr.ui.contextMenuHandler;
+
+ // Create context menu.
+ var menu = document.createElement('div');
+ cr.ui.decorate(menu, cr.ui.Menu);
+ document.body.appendChild(menu);
+
+ var menuItem = document.createElement('div');
+ menu.addMenuItem(menuItem);
+
+ // Create target elements.
+ var elem1 = document.createElement('div');
+ var elem2 = document.createElement('div');
+
+ cmh.setContextMenu(elem1, menu);
+ cmh.setContextMenu(elem2, menu);
+
+ var events = [];
+ cmh.addEventListener('show', function(e) { events.push(e); });
+ cmh.addEventListener('hide', function(e) { events.push(e); });
+
+ // Show context menu of elem1.
+ elem1.dispatchEvent(new MouseEvent('contextmenu'));
+ assertEquals(1, events.length);
+ assertEquals('show', events[0].type);
+ assertEquals(elem1, events[0].element);
+ assertEquals(menu, events[0].menu);
+
+ // Show context menu of elem2.
+ document.dispatchEvent(new MouseEvent('mousedown'));
+
+ // On Windows to prevent context menu show again by mouse right button up,
+ // we need to wait at least 50ms from the last hide of context menu.
+ currentTime += 51; // ms
+
+ elem2.dispatchEvent(new MouseEvent('contextmenu'));
+ assertEquals(3, events.length);
+ assertEquals('hide', events[1].type);
+ assertEquals(elem1, events[1].element);
+ assertEquals(menu, events[1].menu);
+ assertEquals('show', events[2].type);
+ assertEquals(elem2, events[2].element);
+ assertEquals(menu, events[2].menu);
+
+ Date.now = originalDateNow;
+}
+
+</script>
+</body>
+</html>
« no previous file with comments | « no previous file | chrome/test/data/webui/webui_resource_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698