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

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: Addressed review comments 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 using namespace WebCore;
tkent 2014/07/31 06:07:56 This is unnecessary.
pals 2014/08/01 10:03:08 Done.
17
18 namespace {
tkent 2014/07/31 06:07:56 We should use |namespace blink| instead of anonymo
pals 2014/08/01 10:03:08 Done.
19
20 class ContextMenuControllerTest : public testing::Test {
21 protected:
22 virtual void SetUp()
23 {
24 m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
25 }
26
27 Document& document() const { return m_pageHolder->document(); }
28
29 void setBodyInnerHTML(const char* htmlContent)
30 {
31 document().body()->setInnerHTML(String::fromUTF8(htmlContent), ASSERT_NO _EXCEPTION);
32 document().view()->updateLayoutAndStyleIfNeededRecursive();
33 }
34
35 private:
36 OwnPtr<DummyPageHolder> m_pageHolder;
37 };
38
39 TEST_F(ContextMenuControllerTest, TestCustomMenu)
40 {
41 // Load the the test page.
42 setBodyInnerHTML(
43 "<button id=\"button_id\" contextmenu=\"menu_id\" style=\"height: 100px; width: 100px;\">"
44 "<menu id=\"menu_id\">"
45 "<menuitem label=\"Item1\"></menuitem>"
46 "<menuitem label=\"Item2\"></menuitem>"
47 "<menuitem label=\"Item3\"></menuitem>"
48 "<menu label='Submenu'>"
49 "<menuitem label=\"Item4\"></menuitem>"
50 "<menuitem label=\"Item5\"></menuitem>"
51 "<menuitem label=\"Item6\"></menuitem>"
52 "</menu>"
53 "</menu>"
54 "</button>");
55
56 // Create right button click event and pass it to context menu controller.
57 RefPtrWillBeRawPtr<WebCore::Event> event = WebCore::MouseEvent::create(WebCo re::EventTypeNames::click, false, false,
58 document().domWindow(), 50, 50, 0, 0, 0, 0, 0, false, false, false, fals e, 1, nullptr, nullptr);
59 document().getElementById("button_id")->focus();
60 event->setTarget(document().getElementById("button_id"));
61 document().page()->contextMenuController().handleContextMenuEvent(event.get( ));
62
63 // Item 1
64 // Item 2
65 // Item 3
66 // Submenu > Item 4
67 // Item 5
68 // Item 6
69 const Vector<ContextMenuItem>& items = document().page()->contextMenuControl ler().contextMenu()->items();
70 EXPECT_EQ(4u, items.size());
71 EXPECT_EQ(ActionType, items[0].type());
72 EXPECT_EQ(SubmenuType, items[3].type());
73 EXPECT_STREQ("Item1", items[0].title().utf8().data());
74 EXPECT_STREQ("Submenu", items[3].title().utf8().data());
75 EXPECT_STREQ("Submenu", items[3].title().utf8().data());
76 const Vector<ContextMenuItem>& subMenuItems = items[3].subMenuItems();
77 EXPECT_EQ(3u, subMenuItems.size());
78 EXPECT_STREQ("Item6", subMenuItems[2].title().utf8().data());
79 }
80
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698