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

Side by Side Diff: Source/core/page/ContextMenuControllerTest.cpp

Issue 243403006: Implement contextmenu attribute with basic support of <menu> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Reflect HTMLMenuElement as per spec 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/clipboard/DataTransfer.h"
7 #include "core/events/MouseEvent.h"
8 #include "core/frame/FrameView.h"
9 #include "core/html/HTMLElement.h"
10 #include "core/page/ContextMenuController.h"
11 #include "core/testing/DummyPageHolder.h"
12 #include "platform/ContextMenu.h"
13 #include "wtf/OwnPtr.h"
14 #include <gtest/gtest.h>
15
16 namespace blink {
17
18 class ContextMenuControllerTest : public testing::Test {
19 protected:
20 virtual void SetUp()
21 {
22 m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
23 }
24
25 Document& document() const { return m_pageHolder->document(); }
26
27 void setBodyInnerHTML(const char* htmlContent)
28 {
29 document().body()->setInnerHTML(String::fromUTF8(htmlContent), ASSERT_NO _EXCEPTION);
30 document().view()->updateLayoutAndStyleIfNeededRecursive();
31 }
32
33 private:
34 OwnPtr<DummyPageHolder> m_pageHolder;
35 };
36
37 TEST_F(ContextMenuControllerTest, TestCustomMenu)
38 {
39 // Load the the test page.
40 setBodyInnerHTML(
41 "<button id=\"button_id\" contextmenu=\"menu_id\" style=\"height: 100px; width: 100px;\">"
42 "<menu id=\"menu_id\">"
43 "<menuitem label=\"Item1\"></menuitem>"
44 "<menuitem label=\"Item2\"></menuitem>"
45 "<menuitem label=\"Item3\"></menuitem>"
46 "<menu label='Submenu'>"
47 "<menuitem label=\"Item4\"></menuitem>"
48 "<menuitem label=\"Item5\"></menuitem>"
49 "<menuitem label=\"Item6\"></menuitem>"
50 "</menu>"
51 "</menu>"
52 "</button>");
53
54 // Create right button click event and pass it to context menu controller.
55 RefPtrWillBeRawPtr<Event> event = MouseEvent::create(EventTypeNames::click, false, false,
56 document().domWindow(), 50, 50, 0, 0, 0, 0, 0, false, false, false, fals e, 1, nullptr, nullptr);
57 document().getElementById("button_id")->focus();
58 event->setTarget(document().getElementById("button_id"));
59 document().page()->contextMenuController().handleContextMenuEvent(event.get( ));
60
61 // Item 1
62 // Item 2
63 // Item 3
64 // Submenu > Item 4
65 // Item 5
66 // Item 6
67 const Vector<ContextMenuItem>& items = document().page()->contextMenuControl ler().contextMenu()->items();
68 EXPECT_EQ(4u, items.size());
69 EXPECT_EQ(ActionType, items[0].type());
70 EXPECT_EQ(SubmenuType, items[3].type());
71 EXPECT_STREQ("Item1", items[0].title().utf8().data());
72 EXPECT_STREQ("Submenu", items[3].title().utf8().data());
73 EXPECT_STREQ("Submenu", items[3].title().utf8().data());
74 const Vector<ContextMenuItem>& subMenuItems = items[3].subMenuItems();
75 EXPECT_EQ(3u, subMenuItems.size());
76 EXPECT_STREQ("Item6", subMenuItems[2].title().utf8().data());
77 }
78
79 }
OLDNEW
« no previous file with comments | « Source/core/page/ContextMenuController.cpp ('k') | Source/core/page/CustomContextMenuProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698