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

Unified Diff: third_party/WebKit/LayoutTests/fast/events/contextmenu-follows-focus.html

Issue 2880313002: Correct logic "Should ContextMenu target the selection?" (Closed)
Patch Set: Add a const Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/input/EventHandler.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/fast/events/contextmenu-follows-focus.html
diff --git a/third_party/WebKit/LayoutTests/fast/events/contextmenu-follows-focus.html b/third_party/WebKit/LayoutTests/fast/events/contextmenu-follows-focus.html
index 2ae04bc5cddeaab04a6eed3adfa59fddc7388c13..d0070130d6bfc8a2df88ed42bea5f71766533701 100644
--- a/third_party/WebKit/LayoutTests/fast/events/contextmenu-follows-focus.html
+++ b/third_party/WebKit/LayoutTests/fast/events/contextmenu-follows-focus.html
@@ -6,8 +6,19 @@ var contextForMenu;
function catchContextMenu(event) {
contextForMenu = event.currentTarget.tagName;
}
+
+function focusLinkAndAssertLinkIsTargetOfContextMenu() {
+ eventSender.keyDown('Escape'); // Hide menu.
+ document.querySelector('A').focus();
+ contextForMenu = undefined;
+ eventSender.keyDown('ContextMenu');
+ assert_equals(contextForMenu, 'A',
+ 'ContextMenu should use the focused link as target.');
+}
</script>
+<div contenteditable oncontextmenu="catchContextMenu(event);">Some editable text.</div>
+<span oncontextmenu="catchContextMenu(event);">Some text to select.</span>
<input oncontextmenu="catchContextMenu(event);">
<a href="www" oncontextmenu="catchContextMenu(event);">A link</a>
@@ -18,15 +29,37 @@ test(function() {
document.querySelector('INPUT').focus();
eventSender.keyDown('ContextMenu');
assert_equals(contextForMenu, 'INPUT',
- 'ContextMenu should use the focused input field as context.');
+ 'ContextMenu should use the focused input field as target.');
+ focusLinkAndAssertLinkIsTargetOfContextMenu();
+}, 'ContextMenu should target the focused link (not the unfocused field).');
- // Hide INPUT's context menu before we display A's context menu.
- eventSender.keyDown('Escape');
+test(function() {
+ assert_exists(window, 'eventSender', 'This test requires eventSender.');
- document.querySelector('A').focus();
+ document.querySelector('div').focus();
eventSender.keyDown('ContextMenu');
- assert_equals(contextForMenu, 'A',
- 'ContextMenu should use the focused link as context.');
+ assert_equals(contextForMenu, 'DIV',
+ 'ContextMenu should use the editable div\'s caret as target.');
+ focusLinkAndAssertLinkIsTargetOfContextMenu();
+}, 'ContextMenu should target the focused link (not the div\'s caret).');
+
+test(function() {
+ assert_exists(window, 'eventSender', 'This test requires eventSender.');
+
+ const div = document.querySelector('div');
+ div.focus();
+ window.getSelection().selectAllChildren(div);
+ eventSender.keyDown('ContextMenu');
+ assert_equals(contextForMenu, 'DIV',
+ 'ContextMenu should use the editable div\'s range selection as target.');
+ focusLinkAndAssertLinkIsTargetOfContextMenu();
+}, 'ContextMenu should target the focused link (not the div\'s selection).');
+
+test(function() {
+ assert_exists(window, 'eventSender', 'This test requires eventSender.');
-}, 'ContextMenu should always follow focused element.');
+ const span = document.querySelector('span');
+ window.getSelection().selectAllChildren(span);
+ focusLinkAndAssertLinkIsTargetOfContextMenu();
+}, 'ContextMenu should target the focused link (not the unfocused selection).');
</script>
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/input/EventHandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698