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

Side by Side 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, 7 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 | chrome/test/data/webui/webui_resource_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script>
5
6 function testShowAndHideEvents() {
7 // Keep original Date.now not to affect other code.
8 var originalDateNow = Date.now;
9
10 // Initial value is 1 since 0 becomes false.
11 var currentTime = 1;
12
13 // Overrides Date.now to simulate time.
14 Date.now = function() { return currentTime; };
15
16 var cmh = cr.ui.contextMenuHandler;
17
18 // Create context menu.
19 var menu = document.createElement('div');
20 cr.ui.decorate(menu, cr.ui.Menu);
21 document.body.appendChild(menu);
22
23 var menuItem = document.createElement('div');
24 menu.addMenuItem(menuItem);
25
26 // Create target elements.
27 var elem1 = document.createElement('div');
28 var elem2 = document.createElement('div');
29
30 cmh.setContextMenu(elem1, menu);
31 cmh.setContextMenu(elem2, menu);
32
33 var events = [];
34 cmh.addEventListener('show', function(e) { events.push(e); });
35 cmh.addEventListener('hide', function(e) { events.push(e); });
36
37 // Show context menu of elem1.
38 elem1.dispatchEvent(new MouseEvent('contextmenu'));
39 assertEquals(1, events.length);
40 assertEquals('show', events[0].type);
41 assertEquals(elem1, events[0].element);
42 assertEquals(menu, events[0].menu);
43
44 // Show context menu of elem2.
45 document.dispatchEvent(new MouseEvent('mousedown'));
46
47 // On Windows to prevent context menu show again by mouse right button up,
48 // we need to wait at least 50ms from the last hide of context menu.
49 currentTime += 51; // ms
50
51 elem2.dispatchEvent(new MouseEvent('contextmenu'));
52 assertEquals(3, events.length);
53 assertEquals('hide', events[1].type);
54 assertEquals(elem1, events[1].element);
55 assertEquals(menu, events[1].menu);
56 assertEquals('show', events[2].type);
57 assertEquals(elem2, events[2].element);
58 assertEquals(menu, events[2].menu);
59
60 Date.now = originalDateNow;
61 }
62
63 </script>
64 </body>
65 </html>
OLDNEW
« 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