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

Side by Side Diff: Source/web/tests/ContextMenuTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698