Index: Source/core/page/ContextMenuControllerTest.cpp |
diff --git a/Source/core/page/ContextMenuControllerTest.cpp b/Source/core/page/ContextMenuControllerTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8b36500c6ecb6efe8995ac41001cc6d25c470ef9 |
--- /dev/null |
+++ b/Source/core/page/ContextMenuControllerTest.cpp |
@@ -0,0 +1,81 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "core/clipboard/DataTransfer.h" |
+#include "core/events/MouseEvent.h" |
+#include "core/frame/FrameView.h" |
+#include "core/html/HTMLElement.h" |
+#include "core/page/ContextMenuController.h" |
+#include "core/testing/DummyPageHolder.h" |
+#include "platform/ContextMenu.h" |
+#include "wtf/OwnPtr.h" |
+#include <gtest/gtest.h> |
+ |
+using namespace WebCore; |
tkent
2014/07/31 06:07:56
This is unnecessary.
pals
2014/08/01 10:03:08
Done.
|
+ |
+namespace { |
tkent
2014/07/31 06:07:56
We should use |namespace blink| instead of anonymo
pals
2014/08/01 10:03:08
Done.
|
+ |
+class ContextMenuControllerTest : public testing::Test { |
+protected: |
+ virtual void SetUp() |
+ { |
+ m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); |
+ } |
+ |
+ Document& document() const { return m_pageHolder->document(); } |
+ |
+ void setBodyInnerHTML(const char* htmlContent) |
+ { |
+ document().body()->setInnerHTML(String::fromUTF8(htmlContent), ASSERT_NO_EXCEPTION); |
+ document().view()->updateLayoutAndStyleIfNeededRecursive(); |
+ } |
+ |
+private: |
+ OwnPtr<DummyPageHolder> m_pageHolder; |
+}; |
+ |
+TEST_F(ContextMenuControllerTest, TestCustomMenu) |
+{ |
+ // Load the the test page. |
+ setBodyInnerHTML( |
+ "<button id=\"button_id\" contextmenu=\"menu_id\" style=\"height: 100px; width: 100px;\">" |
+ "<menu id=\"menu_id\">" |
+ "<menuitem label=\"Item1\"></menuitem>" |
+ "<menuitem label=\"Item2\"></menuitem>" |
+ "<menuitem label=\"Item3\"></menuitem>" |
+ "<menu label='Submenu'>" |
+ "<menuitem label=\"Item4\"></menuitem>" |
+ "<menuitem label=\"Item5\"></menuitem>" |
+ "<menuitem label=\"Item6\"></menuitem>" |
+ "</menu>" |
+ "</menu>" |
+ "</button>"); |
+ |
+ // Create right button click event and pass it to context menu controller. |
+ RefPtrWillBeRawPtr<WebCore::Event> event = WebCore::MouseEvent::create(WebCore::EventTypeNames::click, false, false, |
+ document().domWindow(), 50, 50, 0, 0, 0, 0, 0, false, false, false, false, 1, nullptr, nullptr); |
+ document().getElementById("button_id")->focus(); |
+ event->setTarget(document().getElementById("button_id")); |
+ document().page()->contextMenuController().handleContextMenuEvent(event.get()); |
+ |
+ // Item 1 |
+ // Item 2 |
+ // Item 3 |
+ // Submenu > Item 4 |
+ // Item 5 |
+ // Item 6 |
+ const Vector<ContextMenuItem>& items = document().page()->contextMenuController().contextMenu()->items(); |
+ EXPECT_EQ(4u, items.size()); |
+ EXPECT_EQ(ActionType, items[0].type()); |
+ EXPECT_EQ(SubmenuType, items[3].type()); |
+ EXPECT_STREQ("Item1", items[0].title().utf8().data()); |
+ EXPECT_STREQ("Submenu", items[3].title().utf8().data()); |
+ EXPECT_STREQ("Submenu", items[3].title().utf8().data()); |
+ const Vector<ContextMenuItem>& subMenuItems = items[3].subMenuItems(); |
+ EXPECT_EQ(3u, subMenuItems.size()); |
+ EXPECT_STREQ("Item6", subMenuItems[2].title().utf8().data()); |
+} |
+ |
+} |