OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "web/ExternalPopupMenu.h" | 6 #include "web/ExternalPopupMenu.h" |
7 | 7 |
8 #include "core/HTMLNames.h" | 8 #include "core/HTMLNames.h" |
9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
10 #include "core/frame/PinchViewport.h" | 10 #include "core/frame/PinchViewport.h" |
11 #include "core/html/HTMLSelectElement.h" | 11 #include "core/html/HTMLSelectElement.h" |
12 #include "core/html/forms/PopupMenuClient.h" | 12 #include "core/html/forms/PopupMenuClient.h" |
13 #include "core/page/Page.h" | 13 #include "core/page/Page.h" |
14 #include "core/rendering/RenderMenuList.h" | 14 #include "core/rendering/RenderMenuList.h" |
15 #include "core/testing/DummyPageHolder.h" | |
16 #include "core/testing/URLTestHelpers.h" | 15 #include "core/testing/URLTestHelpers.h" |
17 #include "platform/PopupMenu.h" | 16 #include "platform/PopupMenu.h" |
18 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
19 #include "public/platform/WebUnitTestSupport.h" | 18 #include "public/platform/WebUnitTestSupport.h" |
20 #include "public/web/WebExternalPopupMenu.h" | 19 #include "public/web/WebExternalPopupMenu.h" |
21 #include "public/web/WebPopupMenuInfo.h" | 20 #include "public/web/WebPopupMenuInfo.h" |
22 #include "public/web/WebSettings.h" | 21 #include "public/web/WebSettings.h" |
23 #include "web/WebLocalFrameImpl.h" | 22 #include "web/WebLocalFrameImpl.h" |
24 #include "web/tests/FrameTestHelpers.h" | 23 #include "web/tests/FrameTestHelpers.h" |
25 #include <gtest/gtest.h> | 24 #include <gtest/gtest.h> |
(...skipping 30 matching lines...) Expand all Loading... |
56 virtual LayoutUnit clientPaddingLeft() const override { return 0; } | 55 virtual LayoutUnit clientPaddingLeft() const override { return 0; } |
57 virtual LayoutUnit clientPaddingRight() const override { return 0; } | 56 virtual LayoutUnit clientPaddingRight() const override { return 0; } |
58 virtual int listSize() const override { return m_listSize; } | 57 virtual int listSize() const override { return m_listSize; } |
59 virtual int selectedIndex() const override { return 0; } | 58 virtual int selectedIndex() const override { return 0; } |
60 virtual void popupDidHide() override { } | 59 virtual void popupDidHide() override { } |
61 virtual bool itemIsSeparator(unsigned listIndex) const override { return fal
se;} | 60 virtual bool itemIsSeparator(unsigned listIndex) const override { return fal
se;} |
62 virtual bool itemIsLabel(unsigned listIndex) const override { return false;
} | 61 virtual bool itemIsLabel(unsigned listIndex) const override { return false;
} |
63 virtual bool itemIsSelected(unsigned listIndex) const override { return list
Index == 0;} | 62 virtual bool itemIsSelected(unsigned listIndex) const override { return list
Index == 0;} |
64 virtual void setTextFromItem(unsigned listIndex) override { } | 63 virtual void setTextFromItem(unsigned listIndex) override { } |
65 virtual bool multiple() const override { return false; } | 64 virtual bool multiple() const override { return false; } |
66 virtual IntRect elementRectRelativeToRootView() const override { return IntR
ect(); } | |
67 virtual Element& ownerElement() const override { return *m_ownerElement; } | |
68 virtual RenderStyle* renderStyleForItem(Element& element) const override { r
eturn nullptr; } | |
69 | 65 |
70 void setListSize(size_t size) { m_listSize = size; } | 66 void setListSize(size_t size) { m_listSize = size; } |
71 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde
x); } | 67 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde
x); } |
72 void setOwnerElement(PassRefPtrWillBeRawPtr<Element> element) { m_ownerEleme
nt = element; } | |
73 private: | 68 private: |
74 size_t m_listSize; | 69 size_t m_listSize; |
75 std::set<unsigned> m_displayNoneIndexSet; | 70 std::set<unsigned> m_displayNoneIndexSet; |
76 RefPtrWillBePersistent<Element> m_ownerElement; | |
77 }; | 71 }; |
78 | 72 |
79 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test { | 73 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test { |
80 public: | 74 public: |
81 ExternalPopupMenuDisplayNoneItemsTest() { } | 75 ExternalPopupMenuDisplayNoneItemsTest() { } |
82 | 76 |
83 protected: | 77 protected: |
84 virtual void SetUp() override | 78 virtual void SetUp() override |
85 { | 79 { |
86 m_popupMenuClient.setListSize(kListSize); | 80 m_popupMenuClient.setListSize(kListSize); |
87 | 81 |
88 // Set the 4th an 5th items to have "display: none" property | 82 // Set the 4th an 5th items to have "display: none" property |
89 m_popupMenuClient.setDisplayNoneIndex(3); | 83 m_popupMenuClient.setDisplayNoneIndex(3); |
90 m_popupMenuClient.setDisplayNoneIndex(4); | 84 m_popupMenuClient.setDisplayNoneIndex(4); |
91 | |
92 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz
e(800, 600)); | |
93 m_popupMenuClient.setOwnerElement(HTMLSelectElement::create(dummyPageHol
der->document())); | |
94 } | 85 } |
95 | 86 |
96 TestPopupMenuClient m_popupMenuClient; | 87 TestPopupMenuClient m_popupMenuClient; |
97 }; | 88 }; |
98 | 89 |
99 TEST_F(ExternalPopupMenuDisplayNoneItemsTest, PopupMenuInfoSizeTest) | 90 TEST_F(ExternalPopupMenuDisplayNoneItemsTest, PopupMenuInfoSizeTest) |
100 { | 91 { |
101 WebPopupMenuInfo info; | 92 WebPopupMenuInfo info; |
102 ExternalPopupMenu::getPopupMenuInfo(info, m_popupMenuClient); | 93 ExternalPopupMenu::getPopupMenuInfo(info, m_popupMenuClient); |
103 EXPECT_EQ(5U, info.items.size()); | 94 EXPECT_EQ(5U, info.items.size()); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 ASSERT_TRUE(menuList->popupIsVisible()); | 257 ASSERT_TRUE(menuList->popupIsVisible()); |
267 | 258 |
268 WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(menuLis
t->popup()); | 259 WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(menuLis
t->popup()); |
269 WebVector<int> indices; | 260 WebVector<int> indices; |
270 client->didAcceptIndices(indices); | 261 client->didAcceptIndices(indices); |
271 EXPECT_FALSE(menuList->popupIsVisible()); | 262 EXPECT_FALSE(menuList->popupIsVisible()); |
272 EXPECT_EQ(-1, select->selectedIndex()); | 263 EXPECT_EQ(-1, select->selectedIndex()); |
273 } | 264 } |
274 | 265 |
275 } // namespace | 266 } // namespace |
OLD | NEW |