| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/page/ContextMenuController.h" | 5 #include "core/page/ContextMenuController.h" |
| 6 | 6 |
| 7 #include "core/clipboard/DataTransfer.h" | 7 #include "core/clipboard/DataTransfer.h" |
| 8 #include "core/events/MouseEvent.h" | 8 #include "core/events/MouseEvent.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 TEST_F(ContextMenuControllerTest, TestCustomMenu) { | 36 TEST_F(ContextMenuControllerTest, TestCustomMenu) { |
| 37 GetDocument().GetSettings()->SetScriptEnabled(true); | 37 GetDocument().GetSettings()->SetScriptEnabled(true); |
| 38 // Load the the test page. | 38 // Load the the test page. |
| 39 SetBodyInnerHTML( | 39 SetBodyInnerHTML( |
| 40 "<button id=\"button_id\" contextmenu=\"menu_id\" style=\"height: 100px; " | 40 "<button id=\"button_id\" contextmenu=\"menu_id\" style=\"height: 100px; " |
| 41 "width: 100px;\">" | 41 "width: 100px;\">" |
| 42 "<menu type=\"context\" id=\"menu_id\">" | 42 "<menu type=\"context\" id=\"menu_id\">" |
| 43 "<menuitem label=\"Item1\" onclick='document.title = \"Title 1\";'>" | 43 "<menuitem label=\"Item1\" onclick='document.title = \"Title 1\";'>" |
| 44 "</menuitem>" |
| 44 "<menuitem label=\"Item2\" onclick='document.title = \"Title 2\";'>" | 45 "<menuitem label=\"Item2\" onclick='document.title = \"Title 2\";'>" |
| 46 "</menuitem>" |
| 45 "<menuitem label=\"Item3\" onclick='document.title = \"Title 3\";'>" | 47 "<menuitem label=\"Item3\" onclick='document.title = \"Title 3\";'>" |
| 48 "</menuitem>" |
| 46 "<menu label='Submenu'>" | 49 "<menu label='Submenu'>" |
| 47 "<menuitem label=\"Item4\" onclick='document.title = \"Title 4\";'>" | 50 "<menuitem label=\"Item4\" onclick='document.title = \"Title 4\";'>" |
| 51 "</menuitem>" |
| 48 "<menuitem label=\"Item5\" onclick='document.title = \"Title 5\";'>" | 52 "<menuitem label=\"Item5\" onclick='document.title = \"Title 5\";'>" |
| 53 "</menuitem>" |
| 49 "<menuitem label=\"Item6\" onclick='document.title = \"Title 6\";'>" | 54 "<menuitem label=\"Item6\" onclick='document.title = \"Title 6\";'>" |
| 55 "</menuitem>" |
| 50 "</menu>" | 56 "</menu>" |
| 51 "<menuitem id=\"item7\" type=\"checkbox\" checked label=\"Item7\"" | 57 "<menuitem id=\"item7\" type=\"checkbox\" checked label=\"Item7\"" |
| 52 "onclick='if " | 58 "onclick='if " |
| 53 "(document.getElementById(\"item7\").hasAttribute(\"checked\"))" | 59 "(document.getElementById(\"item7\").hasAttribute(\"checked\"))" |
| 54 "document.title = \"Title 7 checked\"; else document.title = \"Title 7 " | 60 "document.title = \"Title 7 checked\"; else document.title = \"Title 7 " |
| 55 "not checked\";'>" | 61 "not checked\";'>" |
| 62 "</menuitem>" |
| 56 "<menuitem id=\"item8\" type=\"radio\" radiogroup=\"group\" " | 63 "<menuitem id=\"item8\" type=\"radio\" radiogroup=\"group\" " |
| 57 "label=\"Item8\"" | 64 "label=\"Item8\"" |
| 58 "onclick='if " | 65 "onclick='if " |
| 59 "(document.getElementById(\"item8\").hasAttribute(\"checked\"))" | 66 "(document.getElementById(\"item8\").hasAttribute(\"checked\"))" |
| 60 "document.title = \"Title 8 checked\"; else if " | 67 "document.title = \"Title 8 checked\"; else if " |
| 61 "(document.getElementById(\"item9\").hasAttribute(\"checked\"))" | 68 "(document.getElementById(\"item9\").hasAttribute(\"checked\"))" |
| 62 "document.title = \"Title 8 not checked and Title 9 checked\";'>" | 69 "document.title = \"Title 8 not checked and Title 9 checked\";'>" |
| 70 "</menuitem>" |
| 63 "<menuitem id=\"item9\" type=\"radio\" radiogroup=\"group\" checked " | 71 "<menuitem id=\"item9\" type=\"radio\" radiogroup=\"group\" checked " |
| 64 "label=\"Item9\"" | 72 "label=\"Item9\"" |
| 65 "onclick='if " | 73 "onclick='if " |
| 66 "(document.getElementById(\"item9\").hasAttribute(\"checked\"))" | 74 "(document.getElementById(\"item9\").hasAttribute(\"checked\"))" |
| 67 "document.title = \"Title 9 checked\"; else document.title = \"Title 9 " | 75 "document.title = \"Title 9 checked\"; else document.title = \"Title 9 " |
| 68 "not checked\";'>" | 76 "not checked\";'>" |
| 77 "</menuitem>" |
| 69 "<menuitem id=\"item10\" type=\"radio\" radiogroup=\"group\" " | 78 "<menuitem id=\"item10\" type=\"radio\" radiogroup=\"group\" " |
| 70 "label=\"Item10\"" | 79 "label=\"Item10\"" |
| 71 "onclick='if " | 80 "onclick='if " |
| 72 "(document.getElementById(\"item10\").hasAttribute(\"checked\"))" | 81 "(document.getElementById(\"item10\").hasAttribute(\"checked\"))" |
| 73 "document.title = \"Title 10 checked\"; else if " | 82 "document.title = \"Title 10 checked\"; else if " |
| 74 "(document.getElementById(\"item8\").hasAttribute(\"checked\"))" | 83 "(document.getElementById(\"item8\").hasAttribute(\"checked\"))" |
| 75 "document.title = \"Title 10 not checked and Title 8 checked\";'>" | 84 "document.title = \"Title 10 not checked and Title 8 checked\";'>" |
| 85 "</menuitem>" |
| 76 "</menu>" | 86 "</menu>" |
| 77 "</button>"); | 87 "</button>"); |
| 78 | 88 |
| 79 MouseEventInit mouse_initializer; | 89 MouseEventInit mouse_initializer; |
| 80 mouse_initializer.setView(GetDocument().domWindow()); | 90 mouse_initializer.setView(GetDocument().domWindow()); |
| 81 mouse_initializer.setScreenX(50); | 91 mouse_initializer.setScreenX(50); |
| 82 mouse_initializer.setScreenY(50); | 92 mouse_initializer.setScreenY(50); |
| 83 mouse_initializer.setButton(1); | 93 mouse_initializer.setButton(1); |
| 84 | 94 |
| 85 // Create right button click event and pass it to context menu controller. | 95 // Create right button click event and pass it to context menu controller. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 &items[5]); | 139 &items[5]); |
| 130 EXPECT_STREQ("Title 8 not checked and Title 9 checked", | 140 EXPECT_STREQ("Title 8 not checked and Title 9 checked", |
| 131 GetDocument().title().Utf8().Data()); | 141 GetDocument().title().Utf8().Data()); |
| 132 GetDocument().GetPage()->GetContextMenuController().ContextMenuItemSelected( | 142 GetDocument().GetPage()->GetContextMenuController().ContextMenuItemSelected( |
| 133 &items[7]); | 143 &items[7]); |
| 134 EXPECT_STREQ("Title 10 not checked and Title 8 checked", | 144 EXPECT_STREQ("Title 10 not checked and Title 8 checked", |
| 135 GetDocument().title().Utf8().Data()); | 145 GetDocument().title().Utf8().Data()); |
| 136 } | 146 } |
| 137 | 147 |
| 138 } // namespace blink | 148 } // namespace blink |
| OLD | NEW |