OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
tkent
2014/07/25 04:42:39
We should remove web/ dependency from the test, an
pals
2014/07/30 09:47:45
Done.
| |
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 | |
7 #include "core/clipboard/DataTransfer.h" | |
8 #include "core/events/MouseEvent.h" | |
9 #include "core/page/ContextMenuController.h" | |
10 #include "core/page/Page.h" | |
11 #include "platform/ContextMenuItem.h" | |
12 #include "platform/ContextMenu.h" | |
13 #include "public/platform/Platform.h" | |
14 #include "public/platform/WebUnitTestSupport.h" | |
15 #include "public/web/WebSettings.h" | |
16 #include "web/WebLocalFrameImpl.h" | |
17 #include "web/WebViewImpl.h" | |
18 #include "web/tests/FrameTestHelpers.h" | |
19 #include "web/tests/URLTestHelpers.h" | |
20 #include <gtest/gtest.h> | |
21 | |
22 using namespace WebCore; | |
23 using namespace blink; | |
24 using blink::URLTestHelpers::toKURL; | |
25 | |
26 namespace { | |
27 | |
28 class CustomContextMenuTest : public testing::Test { | |
29 public: | |
30 CustomContextMenuTest() | |
31 : baseURL("http://www.test.com/") | |
32 { | |
33 } | |
34 | |
35 void registerMockedURLLoad(const std::string& fileName) | |
36 { | |
37 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + fileName), WebStr ing::fromUTF8(fileName.c_str()), WebString::fromUTF8("context_menu/"), WebString ::fromUTF8("text/html")); | |
38 } | |
39 | |
40 void loadFrame(WebFrame* frame, const std::string& fileName) | |
41 { | |
42 FrameTestHelpers::loadFrame(frame, baseURL + fileName); | |
43 } | |
44 | |
45 WebViewImpl* webView() const { return m_helper.webViewImpl(); } | |
46 WebLocalFrameImpl* mainFrame() const { return m_helper.webViewImpl()->mainFr ameImpl(); } | |
47 | |
48 protected: | |
49 virtual void SetUp() | |
50 { | |
51 m_helper.initialize(false, 0, &m_webviewClient); | |
52 } | |
53 | |
54 virtual void TearDown() | |
55 { | |
56 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | |
57 } | |
58 | |
59 protected: | |
60 FrameTestHelpers::TestWebViewClient m_webviewClient; | |
61 std::string baseURL; | |
62 | |
63 private: | |
64 FrameTestHelpers::WebViewHelper m_helper; | |
65 }; | |
66 | |
67 TEST_F(CustomContextMenuTest, TestCustomMenu) | |
68 { | |
69 // Load the the test page. | |
70 registerMockedURLLoad("custom_context_menu.html"); | |
71 webView()->settings()->setJavaScriptEnabled(true); | |
72 loadFrame(mainFrame(), "custom_context_menu.html"); | |
73 | |
74 // Create right button click event and pass it to context menu controller. | |
75 Document* document = mainFrame()->frame()->document(); | |
76 RefPtrWillBeRawPtr<WebCore::Event> event = WebCore::MouseEvent::create(WebCo re::EventTypeNames::click, false, false, | |
77 document->domWindow(), 50, 50, 0, 0, 0, 0, 0, false, false, false, false , 1, nullptr, nullptr); | |
78 event->setTarget(document->focusedElement()); | |
79 document->page()->contextMenuController().handleContextMenuEvent(event.get() ); | |
80 | |
81 // Item 1 | |
82 // Item 2 | |
83 // Item 3 | |
84 // Submenu > Item 4 | |
85 // Item 5 | |
86 // Item 6 | |
87 const Vector<ContextMenuItem>& items = document->page()->contextMenuControll er().contextMenu()->items(); | |
88 EXPECT_EQ(4u, items.size()); | |
89 EXPECT_EQ(ActionType, items[0].type()); | |
90 EXPECT_EQ(SubmenuType, items[3].type()); | |
91 EXPECT_STREQ("Submenu", items[3].title().utf8().data()); | |
92 document->page()->contextMenuController().contextMenuItemSelected(&items[0]) ; | |
93 EXPECT_STREQ("Title 1", document->title().utf8().data()); | |
94 const Vector<ContextMenuItem>& subMenuItems = items[3].subMenuItems(); | |
95 EXPECT_EQ(3u, subMenuItems.size()); | |
96 document->page()->contextMenuController().contextMenuItemSelected(&subMenuIt ems[2]); | |
97 EXPECT_STREQ("Title 6", document->title().utf8().data()); | |
98 } | |
99 | |
100 } | |
OLD | NEW |