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

Unified Diff: LayoutTests/contextmenu/custom-context-menu.html

Issue 492753002: Add support to populate custom context menu items. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Menu builder algorithm Created 6 years, 4 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
Index: LayoutTests/contextmenu/custom-context-menu.html
diff --git a/LayoutTests/contextmenu/custom-context-menu.html b/LayoutTests/contextmenu/custom-context-menu.html
new file mode 100644
index 0000000000000000000000000000000000000000..884cfc1bcfc07c8f80abea481c2b60377669583c
--- /dev/null
+++ b/LayoutTests/contextmenu/custom-context-menu.html
@@ -0,0 +1,151 @@
+<!DOCTYPE html>
tkent 2014/08/25 23:07:41 Making LayoutTests/contextmenu/ only for this test
pals 2014/08/26 07:13:23 Done.
+<head>
+<script src="../resources/js-test.js"></script>
+</head>
+<button id="button" style="height: 100px; width: 100px;">
+</button>
+<button id="button_with_contextmenu" contextmenu="menu_id" style="height: 100px; width: 100px;">
+ <menu id="menu_id" type="PopUp">
+ <!-- Test removal of separator at the start. -->
+ <hr>
+ <menuitem label="Item1"></menuitem>
+ <menuitem label="Item2"></menuitem>
+ <!-- Test addition of separator for <hr>. -->
+ <hr>
+ <menuitem label="Item3"></menuitem>
+ <!-- Test child menu with label. -->
+ <menu label="Submenu">
+ <menuitem label="Item4"></menuitem>
+ <menu label="Deeper submenu">
+ <!-- Test removal of separator at the start inside submenu. -->
+ <hr>
+ <menuitem label="Item5"></menuitem>
+ <hr>
+ <menuitem label="Item6"></menuitem>
+ <!-- Test removal of separator at the end inside submenu. -->
+ <hr>
+ </menu>
+ </menu>
+ <menuitem label="Item7"></menuitem>
+ <!-- Test child menu without label. -->
+ <menu>
+ <menuitem label="Item8"></menuitem>
+ <!-- Test child menu with empty label. -->
+ <menu label="">
+ <menuitem label="Item9"></menuitem>
+ <menuitem label="Item10"></menuitem>
+ </menu>
+ <!-- Test collapsing two or more adjacent separators. -->
tkent 2014/08/25 23:07:41 Is this comment valid? Only single <hr> follows.
pals 2014/08/26 07:13:22 One more separator is added at the end of the abov
+ <hr>
+ <menuitem label="Item11"></menuitem>
+ <menuitem label="Item12"></menuitem>
+ </menu>
+ <!-- Test collapsing two or more adjacent separators. -->
+ <hr>
+ <hr>
+ <hr>
+ <hr>
+ <!-- Test menuitem menu without label. -->
tkent 2014/08/25 23:07:42 without label -> with empty label?
pals 2014/08/26 07:13:23 Done.
+ <menuitem label=""></menuitem>
+ <!-- Test menuitem menu with empty label. -->
tkent 2014/08/25 23:07:41 with empty label -> without label?
pals 2014/08/26 07:13:23 Done.
+ <menuitem></menuitem>
+ <menuitem label="Item13"></menuitem>
+ <!-- Test removal of separator at the end. -->
+ <hr>
+ </menu>
+</button>
+<!-- Test with menu element without type attribute specified. -->
+<button id="button_1" contextmenu="menu_without_type" style="height: 100px; width: 100px;">
+ <menu id="menu_without_type">
+ <menuitem label="Item1"></menuitem>
+ <menuitem label="Item2"></menuitem>
+ <menuitem label="Item3"></menuitem>
+ </menu>
+</button>
+<!-- Test cancelling show event. -->
+<button id="button_2" contextmenu="menu_2" style="height: 100px; width: 100px;">
+ <menu id="menu_2" type="popup">
+ <menuitem label="Item1"></menuitem>
+ <menuitem label="Item2"></menuitem>
+ <menuitem label="Item3"></menuitem>
+ </menu>
+</button>
+<!-- Test removing menu element inside show event handler. -->
+<button id="button_3" contextmenu="menu_3" style="height: 100px; width: 100px;">
+ <menu id="menu_3" type="popup">
+ <menuitem label="Item1"></menuitem>
+ <menuitem label="Item2"></menuitem>
+ <menuitem label="Item3"></menuitem>
+ </menu>
+</button>
+<script>
+if (!window.eventSender)
+ debug("This test requires window.eventSender.")
+
+function contextClickAndGetMenuItems(element)
+{
tkent 2014/08/25 23:07:41 Position of the '{' is inconsistent in this file.
pals 2014/08/26 07:13:23 Done.
+ var x = element.offsetParent.offsetLeft + element.offsetLeft + 4;
+ var y = element.offsetParent.offsetTop + element.offsetTop + element.offsetHeight / 2;
+ eventSender.mouseMoveTo(x, y);
+ var items = eventSender.contextClick();
tkent 2014/08/25 23:07:41 return eventSender.contextClick();
pals 2014/08/26 07:13:23 Done.
+ return items;
+}
+
+function cancel(event) {
+ event.preventDefault();
+}
+
+function removeMenu(event) {
+ parent = event.target.parentNode;
tkent 2014/08/25 23:07:41 event.target.remove();
pals 2014/08/26 07:13:22 Done.
+ parent.removeChild(event.target);
+}
+
+description("Tests the custom context menu items.");
+var button = document.getElementById("button");
+var items = contextClickAndGetMenuItems(button);
+
+// Esc key to hide the context menu.
+eventSender.keyDown(String.fromCharCode(0x001B), null);
tkent 2014/08/25 23:07:41 eventSender.keyDown("escape");
pals 2014/08/26 07:13:23 Done.
+
+var buttonWithContextMenu = document.getElementById("button_with_contextmenu");
+var itemsWithCustomContextMenu = contextClickAndGetMenuItems(buttonWithContextMenu);
+
+// Esc key to hide the context menu.
+eventSender.keyDown(String.fromCharCode(0x001B), null);
+
+var button1 = document.getElementById("button_1");
+var items1 = contextClickAndGetMenuItems(button1);
+
+// Esc key to hide the context menu.
+eventSender.keyDown(String.fromCharCode(0x001B), null);
+
+var button2 = document.getElementById("button_2");
+document.getElementById("menu_2").addEventListener("show", cancel, false);
+var items2 = contextClickAndGetMenuItems(button2);
+
+// Esc key to hide the context menu.
+eventSender.keyDown(String.fromCharCode(0x001B), null);
+
+var button3 = document.getElementById("button_3");
+document.getElementById("menu_3").addEventListener("show", removeMenu, false);
+var items3 = contextClickAndGetMenuItems(button3);
+
+shouldBeEqualToNumber("itemsWithCustomContextMenu.length - items.length", 21);
+shouldBeEqualToString("itemsWithCustomContextMenu[0]", "Item1");
+shouldBeEqualToString("itemsWithCustomContextMenu[4]", "Submenu >");
+shouldBeEqualToString("itemsWithCustomContextMenu[5]", "_Item4");
+shouldBeEqualToString("itemsWithCustomContextMenu[6]", "_Deeper submenu >");
+shouldBeEqualToString("itemsWithCustomContextMenu[7]", "__Item5");
+shouldBeEqualToString("itemsWithCustomContextMenu[8]", "__Separator");
+shouldBeEqualToString("itemsWithCustomContextMenu[10]", "Item7");
+shouldBeEqualToString("itemsWithCustomContextMenu[11]", "Separator");
+shouldBeEqualToString("itemsWithCustomContextMenu[12]", "Item8");
+shouldBeEqualToString("itemsWithCustomContextMenu[13]", "Separator");
+shouldBeEqualToString("itemsWithCustomContextMenu[14]", "Item9");
+shouldBeEqualToString("itemsWithCustomContextMenu[16]", "Separator");
+shouldBeEqualToString("itemsWithCustomContextMenu[19]", "Separator");
+shouldBeEqualToString("itemsWithCustomContextMenu[20]", "Item13");
+shouldBeEqualToNumber("items1.length - items.length", 0);
+shouldBeEqualToNumber("items2.length - items.length", 0);
+shouldBeEqualToNumber("items3.length - items.length", 0);
+</script>
« no previous file with comments | « no previous file | LayoutTests/contextmenu/custom-context-menu-expected.txt » ('j') | Source/core/page/ContextMenuController.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698