| 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/layout/LayoutMenuList.h" | 13 #include "core/layout/LayoutMenuList.h" |
| 14 #include "core/page/Page.h" | 14 #include "core/page/Page.h" |
| 15 #include "core/testing/DummyPageHolder.h" | 15 #include "core/testing/DummyPageHolder.h" |
| 16 #include "platform/PopupMenu.h" | 16 #include "platform/PopupMenu.h" |
| 17 #include "platform/testing/URLTestHelpers.h" | 17 #include "platform/testing/URLTestHelpers.h" |
| 18 #include "public/platform/Platform.h" | 18 #include "public/platform/Platform.h" |
| 19 #include "public/platform/WebUnitTestSupport.h" | 19 #include "public/platform/WebUnitTestSupport.h" |
| 20 #include "public/web/WebExternalPopupMenu.h" | 20 #include "public/web/WebExternalPopupMenu.h" |
| 21 #include "public/web/WebPopupMenuInfo.h" | 21 #include "public/web/WebPopupMenuInfo.h" |
| 22 #include "public/web/WebSettings.h" | 22 #include "public/web/WebSettings.h" |
| 23 #include "web/WebLocalFrameImpl.h" | 23 #include "web/WebLocalFrameImpl.h" |
| 24 #include "web/tests/FrameTestHelpers.h" | 24 #include "web/tests/FrameTestHelpers.h" |
| 25 #include <gtest/gtest.h> | 25 #include <gtest/gtest.h> |
| 26 | 26 |
| 27 using namespace blink; | 27 namespace blink { |
| 28 | |
| 29 namespace { | |
| 30 | 28 |
| 31 const size_t kListSize = 7; | 29 const size_t kListSize = 7; |
| 32 | 30 |
| 33 class TestPopupMenuClient : public PopupMenuClient { | 31 class TestPopupMenuClient : public PopupMenuClient { |
| 34 public: | 32 public: |
| 35 TestPopupMenuClient() : m_listSize(0) { } | 33 TestPopupMenuClient() : m_listSize(0) { } |
| 36 virtual ~TestPopupMenuClient() { } | 34 ~TestPopupMenuClient() override { } |
| 37 | 35 |
| 38 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) overri
de { } | 36 void valueChanged(unsigned listIndex, bool fireEvents = true) override { } |
| 39 virtual void selectionChanged(unsigned listIndex, bool fireEvents = true) ov
erride { } | 37 void selectionChanged(unsigned listIndex, bool fireEvents = true) override {
} |
| 40 virtual void selectionCleared() override { } | 38 void selectionCleared() override { } |
| 41 | 39 |
| 42 virtual String itemText(unsigned listIndex) const override { return emptyStr
ing(); } | 40 String itemText(unsigned listIndex) const override { return emptyString(); } |
| 43 virtual String itemToolTip(unsigned listIndex) const override { return empty
String(); } | 41 String itemToolTip(unsigned listIndex) const override { return emptyString()
; } |
| 44 virtual String itemAccessibilityText(unsigned listIndex) const override { re
turn emptyString(); } | 42 String itemAccessibilityText(unsigned listIndex) const override { return emp
tyString(); } |
| 45 virtual bool itemIsEnabled(unsigned listIndex) const override { return true;
} | 43 bool itemIsEnabled(unsigned listIndex) const override { return true; } |
| 46 virtual PopupMenuStyle itemStyle(unsigned listIndex) const override | 44 PopupMenuStyle itemStyle(unsigned listIndex) const override |
| 47 { | 45 { |
| 48 FontDescription fontDescription; | 46 FontDescription fontDescription; |
| 49 fontDescription.setComputedSize(12.0); | 47 fontDescription.setComputedSize(12.0); |
| 50 Font font(fontDescription); | 48 Font font(fontDescription); |
| 51 font.update(nullptr); | 49 font.update(nullptr); |
| 52 bool displayNone = m_displayNoneIndexSet.find(listIndex) != m_displayNon
eIndexSet.end(); | 50 bool displayNone = m_displayNoneIndexSet.find(listIndex) != m_displayNon
eIndexSet.end(); |
| 53 return PopupMenuStyle(Color::black, Color::white, font, true, displayNon
e, Length(), TextDirection(), false); | 51 return PopupMenuStyle(Color::black, Color::white, font, true, displayNon
e, Length(), TextDirection(), false); |
| 54 } | 52 } |
| 55 virtual PopupMenuStyle menuStyle() const override { return itemStyle(0); } | 53 PopupMenuStyle menuStyle() const override { return itemStyle(0); } |
| 56 virtual LayoutUnit clientPaddingLeft() const override { return 0; } | 54 LayoutUnit clientPaddingLeft() const override { return 0; } |
| 57 virtual LayoutUnit clientPaddingRight() const override { return 0; } | 55 LayoutUnit clientPaddingRight() const override { return 0; } |
| 58 virtual int listSize() const override { return m_listSize; } | 56 int listSize() const override { return m_listSize; } |
| 59 virtual int selectedIndex() const override { return 0; } | 57 int selectedIndex() const override { return 0; } |
| 60 virtual void popupDidHide() override { } | 58 void popupDidHide() override { } |
| 61 virtual void popupDidCancel() override { } | 59 void popupDidCancel() override { } |
| 62 virtual bool itemIsSeparator(unsigned listIndex) const override { return fal
se;} | 60 bool itemIsSeparator(unsigned listIndex) const override { return false;} |
| 63 virtual bool itemIsLabel(unsigned listIndex) const override { return false;
} | 61 bool itemIsLabel(unsigned listIndex) const override { return false; } |
| 64 virtual bool itemIsSelected(unsigned listIndex) const override { return list
Index == 0;} | 62 bool itemIsSelected(unsigned listIndex) const override { return listIndex ==
0;} |
| 65 virtual void provisionalSelectionChanged(unsigned listIndex) override { } | 63 void provisionalSelectionChanged(unsigned listIndex) override { } |
| 66 virtual bool multiple() const override { return false; } | 64 bool multiple() const override { return false; } |
| 67 virtual IntRect elementRectRelativeToViewport() const override { return IntR
ect(); } | 65 IntRect elementRectRelativeToViewport() const override { return IntRect(); } |
| 68 virtual Element& ownerElement() const override { return *m_ownerElement; } | 66 Element& ownerElement() const override { return *m_ownerElement; } |
| 69 virtual const ComputedStyle* computedStyleForItem(Element& element) const ov
erride { return nullptr; } | 67 const ComputedStyle* computedStyleForItem(Element& element) const override {
return nullptr; } |
| 70 | 68 |
| 71 void setListSize(size_t size) { m_listSize = size; } | 69 void setListSize(size_t size) { m_listSize = size; } |
| 72 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde
x); } | 70 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde
x); } |
| 73 void setOwnerElement(PassRefPtrWillBeRawPtr<Element> element) { m_ownerEleme
nt = element; } | 71 void setOwnerElement(PassRefPtrWillBeRawPtr<Element> element) { m_ownerEleme
nt = element; } |
| 72 |
| 74 private: | 73 private: |
| 75 size_t m_listSize; | 74 size_t m_listSize; |
| 76 std::set<unsigned> m_displayNoneIndexSet; | 75 std::set<unsigned> m_displayNoneIndexSet; |
| 77 RefPtrWillBePersistent<Element> m_ownerElement; | 76 RefPtrWillBePersistent<Element> m_ownerElement; |
| 78 }; | 77 }; |
| 79 | 78 |
| 80 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test { | 79 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test { |
| 81 public: | 80 public: |
| 82 ExternalPopupMenuDisplayNoneItemsTest() { } | 81 ExternalPopupMenuDisplayNoneItemsTest() { } |
| 83 | 82 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 }; | 144 }; |
| 146 WebRect m_shownBounds; | 145 WebRect m_shownBounds; |
| 147 MockWebExternalPopupMenu m_mockWebExternalPopupMenu; | 146 MockWebExternalPopupMenu m_mockWebExternalPopupMenu; |
| 148 }; | 147 }; |
| 149 | 148 |
| 150 class ExternalPopupMenuTest : public testing::Test { | 149 class ExternalPopupMenuTest : public testing::Test { |
| 151 public: | 150 public: |
| 152 ExternalPopupMenuTest() : m_baseURL("http://www.test.com") { } | 151 ExternalPopupMenuTest() : m_baseURL("http://www.test.com") { } |
| 153 | 152 |
| 154 protected: | 153 protected: |
| 155 virtual void SetUp() override | 154 void SetUp() override |
| 156 { | 155 { |
| 157 m_helper.initialize(false, &m_webFrameClient, &m_webViewClient); | 156 m_helper.initialize(false, &m_webFrameClient, &m_webViewClient); |
| 158 webView()->setUseExternalPopupMenus(true); | 157 webView()->setUseExternalPopupMenus(true); |
| 159 } | 158 } |
| 160 virtual void TearDown() override | 159 void TearDown() override |
| 161 { | 160 { |
| 162 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 161 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 163 } | 162 } |
| 164 | 163 |
| 165 void registerMockedURLLoad(const std::string& fileName) | 164 void registerMockedURLLoad(const std::string& fileName) |
| 166 { | 165 { |
| 167 URLTestHelpers::registerMockedURLLoad(URLTestHelpers::toKURL(m_baseURL +
fileName), WebString::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/")
, WebString::fromUTF8("text/html")); | 166 URLTestHelpers::registerMockedURLLoad(URLTestHelpers::toKURL(m_baseURL +
fileName), WebString::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/")
, WebString::fromUTF8("text/html")); |
| 168 } | 167 } |
| 169 | 168 |
| 170 void loadFrame(const std::string& fileName) | 169 void loadFrame(const std::string& fileName) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 menuList->showPopup(); | 260 menuList->showPopup(); |
| 262 ASSERT_TRUE(menuList->popupIsVisible()); | 261 ASSERT_TRUE(menuList->popupIsVisible()); |
| 263 | 262 |
| 264 WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(menuLis
t->popup()); | 263 WebExternalPopupMenuClient* client = static_cast<ExternalPopupMenu*>(menuLis
t->popup()); |
| 265 WebVector<int> indices; | 264 WebVector<int> indices; |
| 266 client->didAcceptIndices(indices); | 265 client->didAcceptIndices(indices); |
| 267 EXPECT_FALSE(menuList->popupIsVisible()); | 266 EXPECT_FALSE(menuList->popupIsVisible()); |
| 268 EXPECT_EQ(-1, select->selectedIndex()); | 267 EXPECT_EQ(-1, select->selectedIndex()); |
| 269 } | 268 } |
| 270 | 269 |
| 271 } // namespace | 270 } // namespace blink |
| OLD | NEW |