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" |
15 #include "core/testing/URLTestHelpers.h" | 16 #include "core/testing/URLTestHelpers.h" |
16 #include "platform/PopupMenu.h" | 17 #include "platform/PopupMenu.h" |
17 #include "public/platform/Platform.h" | 18 #include "public/platform/Platform.h" |
18 #include "public/platform/WebUnitTestSupport.h" | 19 #include "public/platform/WebUnitTestSupport.h" |
19 #include "public/web/WebExternalPopupMenu.h" | 20 #include "public/web/WebExternalPopupMenu.h" |
20 #include "public/web/WebPopupMenuInfo.h" | 21 #include "public/web/WebPopupMenuInfo.h" |
21 #include "public/web/WebSettings.h" | 22 #include "public/web/WebSettings.h" |
22 #include "web/WebLocalFrameImpl.h" | 23 #include "web/WebLocalFrameImpl.h" |
23 #include "web/tests/FrameTestHelpers.h" | 24 #include "web/tests/FrameTestHelpers.h" |
24 #include <gtest/gtest.h> | 25 #include <gtest/gtest.h> |
(...skipping 30 matching lines...) Expand all Loading... |
55 virtual LayoutUnit clientPaddingLeft() const override { return 0; } | 56 virtual LayoutUnit clientPaddingLeft() const override { return 0; } |
56 virtual LayoutUnit clientPaddingRight() const override { return 0; } | 57 virtual LayoutUnit clientPaddingRight() const override { return 0; } |
57 virtual int listSize() const override { return m_listSize; } | 58 virtual int listSize() const override { return m_listSize; } |
58 virtual int selectedIndex() const override { return 0; } | 59 virtual int selectedIndex() const override { return 0; } |
59 virtual void popupDidHide() override { } | 60 virtual void popupDidHide() override { } |
60 virtual bool itemIsSeparator(unsigned listIndex) const override { return fal
se;} | 61 virtual bool itemIsSeparator(unsigned listIndex) const override { return fal
se;} |
61 virtual bool itemIsLabel(unsigned listIndex) const override { return false;
} | 62 virtual bool itemIsLabel(unsigned listIndex) const override { return false;
} |
62 virtual bool itemIsSelected(unsigned listIndex) const override { return list
Index == 0;} | 63 virtual bool itemIsSelected(unsigned listIndex) const override { return list
Index == 0;} |
63 virtual void setTextFromItem(unsigned listIndex) override { } | 64 virtual void setTextFromItem(unsigned listIndex) override { } |
64 virtual bool multiple() const override { return false; } | 65 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; } |
65 | 69 |
66 void setListSize(size_t size) { m_listSize = size; } | 70 void setListSize(size_t size) { m_listSize = size; } |
67 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde
x); } | 71 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde
x); } |
| 72 void setOwnerElement(PassRefPtrWillBeRawPtr<Element> element) { m_ownerEleme
nt = element; } |
68 private: | 73 private: |
69 size_t m_listSize; | 74 size_t m_listSize; |
70 std::set<unsigned> m_displayNoneIndexSet; | 75 std::set<unsigned> m_displayNoneIndexSet; |
| 76 RefPtrWillBePersistent<Element> m_ownerElement; |
71 }; | 77 }; |
72 | 78 |
73 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test { | 79 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test { |
74 public: | 80 public: |
75 ExternalPopupMenuDisplayNoneItemsTest() { } | 81 ExternalPopupMenuDisplayNoneItemsTest() { } |
76 | 82 |
77 protected: | 83 protected: |
78 virtual void SetUp() override | 84 virtual void SetUp() override |
79 { | 85 { |
80 m_popupMenuClient.setListSize(kListSize); | 86 m_popupMenuClient.setListSize(kListSize); |
81 | 87 |
82 // Set the 4th an 5th items to have "display: none" property | 88 // Set the 4th an 5th items to have "display: none" property |
83 m_popupMenuClient.setDisplayNoneIndex(3); | 89 m_popupMenuClient.setDisplayNoneIndex(3); |
84 m_popupMenuClient.setDisplayNoneIndex(4); | 90 m_popupMenuClient.setDisplayNoneIndex(4); |
| 91 |
| 92 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz
e(800, 600)); |
| 93 m_popupMenuClient.setOwnerElement(HTMLSelectElement::create(dummyPageHol
der->document())); |
85 } | 94 } |
86 | 95 |
87 TestPopupMenuClient m_popupMenuClient; | 96 TestPopupMenuClient m_popupMenuClient; |
88 }; | 97 }; |
89 | 98 |
90 TEST_F(ExternalPopupMenuDisplayNoneItemsTest, PopupMenuInfoSizeTest) | 99 TEST_F(ExternalPopupMenuDisplayNoneItemsTest, PopupMenuInfoSizeTest) |
91 { | 100 { |
92 WebPopupMenuInfo info; | 101 WebPopupMenuInfo info; |
93 ExternalPopupMenu::getPopupMenuInfo(info, m_popupMenuClient); | 102 ExternalPopupMenu::getPopupMenuInfo(info, m_popupMenuClient); |
94 EXPECT_EQ(5U, info.items.size()); | 103 EXPECT_EQ(5U, info.items.size()); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 ASSERT_TRUE(menuList->popupIsVisible()); | 266 ASSERT_TRUE(menuList->popupIsVisible()); |
258 | 267 |
259 WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(menuLis
t->popup()); | 268 WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(menuLis
t->popup()); |
260 WebVector<int> indices; | 269 WebVector<int> indices; |
261 client->didAcceptIndices(indices); | 270 client->didAcceptIndices(indices); |
262 EXPECT_FALSE(menuList->popupIsVisible()); | 271 EXPECT_FALSE(menuList->popupIsVisible()); |
263 EXPECT_EQ(-1, select->selectedIndex()); | 272 EXPECT_EQ(-1, select->selectedIndex()); |
264 } | 273 } |
265 | 274 |
266 } // namespace | 275 } // namespace |
OLD | NEW |