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 "web/ExternalPopupMenu.h" | 5 #include "web/ExternalPopupMenu.h" |
6 | 6 |
7 #include "core/HTMLNames.h" | 7 #include "core/HTMLNames.h" |
8 #include "core/dom/NodeComputedStyle.h" | 8 #include "core/dom/NodeComputedStyle.h" |
9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
10 #include "core/frame/VisualViewport.h" | 10 #include "core/frame/VisualViewport.h" |
11 #include "core/html/HTMLSelectElement.h" | 11 #include "core/html/HTMLSelectElement.h" |
12 #include "core/layout/LayoutMenuList.h" | 12 #include "core/layout/LayoutMenuList.h" |
13 #include "core/page/Page.h" | 13 #include "core/page/Page.h" |
14 #include "core/testing/DummyPageHolder.h" | 14 #include "core/testing/DummyPageHolder.h" |
15 #include "platform/PopupMenu.h" | 15 #include "platform/PopupMenu.h" |
16 #include "platform/testing/URLTestHelpers.h" | 16 #include "platform/testing/URLTestHelpers.h" |
17 #include "platform/testing/UnitTestHelpers.h" | |
17 #include "public/platform/Platform.h" | 18 #include "public/platform/Platform.h" |
18 #include "public/platform/WebURLLoaderMockFactory.h" | 19 #include "public/platform/WebURLLoaderMockFactory.h" |
19 #include "public/web/WebCache.h" | 20 #include "public/web/WebCache.h" |
20 #include "public/web/WebExternalPopupMenu.h" | 21 #include "public/web/WebExternalPopupMenu.h" |
21 #include "public/web/WebPopupMenuInfo.h" | 22 #include "public/web/WebPopupMenuInfo.h" |
22 #include "public/web/WebSettings.h" | 23 #include "public/web/WebSettings.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "web/WebLocalFrameImpl.h" | 25 #include "web/WebLocalFrameImpl.h" |
25 #include "web/tests/FrameTestHelpers.h" | 26 #include "web/tests/FrameTestHelpers.h" |
26 #include <memory> | 27 #include <memory> |
27 | 28 |
28 namespace blink { | 29 namespace blink { |
29 | 30 |
30 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test { | 31 class ExternalPopupMenuDisplayNoneItemsTest : public ::testing::Test { |
31 public: | 32 public: |
32 ExternalPopupMenuDisplayNoneItemsTest() {} | 33 ExternalPopupMenuDisplayNoneItemsTest() {} |
33 | 34 |
34 protected: | 35 protected: |
35 void SetUp() override { | 36 void SetUp() override { |
36 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 37 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
37 HTMLSelectElement* element = | 38 HTMLSelectElement* element = |
38 HTMLSelectElement::create(m_dummyPageHolder->document()); | 39 HTMLSelectElement::create(m_dummyPageHolder->document()); |
39 // Set the 4th an 5th items to have "display: none" property | 40 // Set the 4th an 5th items to have "display: none" property |
40 element->setInnerHTML( | 41 element->setInnerHTML( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 public: | 91 public: |
91 WebRect shownBounds() const { return m_shownBounds; } | 92 WebRect shownBounds() const { return m_shownBounds; } |
92 | 93 |
93 private: | 94 private: |
94 WebRect m_shownBounds; | 95 WebRect m_shownBounds; |
95 }; | 96 }; |
96 WebRect m_shownBounds; | 97 WebRect m_shownBounds; |
97 MockWebExternalPopupMenu m_mockWebExternalPopupMenu; | 98 MockWebExternalPopupMenu m_mockWebExternalPopupMenu; |
98 }; | 99 }; |
99 | 100 |
100 class ExternalPopupMenuTest : public testing::Test { | 101 class ExternalPopupMenuTest : public ::testing::Test { |
101 public: | 102 public: |
102 ExternalPopupMenuTest() : m_baseURL("http://www.test.com") {} | 103 ExternalPopupMenuTest() : m_baseURL("http://www.test.com") {} |
103 | 104 |
104 protected: | 105 protected: |
105 void SetUp() override { | 106 void SetUp() override { |
106 m_helper.initialize(false, &m_webFrameClient, &m_webViewClient); | 107 m_helper.initialize(false, &m_webFrameClient, &m_webViewClient); |
107 webView()->setUseExternalPopupMenus(true); | 108 webView()->setUseExternalPopupMenus(true); |
108 } | 109 } |
109 void TearDown() override { | 110 void TearDown() override { |
110 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 111 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
111 WebCache::clear(); | 112 WebCache::clear(); |
112 } | 113 } |
113 | 114 |
114 void registerMockedURLLoad(const std::string& fileName) { | 115 void registerMockedURLLoad(const std::string& fileName) { |
115 URLTestHelpers::registerMockedURLLoad( | 116 URLTestHelpers::registerMockedURLLoadFromBase( |
116 URLTestHelpers::toKURL(m_baseURL + fileName), | 117 WebString::fromUTF8(m_baseURL.c_str()), |
kinuko
2017/01/26 09:32:41
fromUTF8 can directly take std::string
Takashi Toyoshima
2017/01/26 10:57:57
Done.
| |
117 WebString::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/"), | 118 testing::webTestDataPath("popup"), |
119 WebString::fromUTF8(fileName.c_str()), | |
118 WebString::fromUTF8("text/html")); | 120 WebString::fromUTF8("text/html")); |
119 } | 121 } |
120 | 122 |
121 void loadFrame(const std::string& fileName) { | 123 void loadFrame(const std::string& fileName) { |
122 FrameTestHelpers::loadFrame(mainFrame(), m_baseURL + fileName); | 124 FrameTestHelpers::loadFrame(mainFrame(), m_baseURL + fileName); |
123 webView()->resize(WebSize(800, 600)); | 125 webView()->resize(WebSize(800, 600)); |
124 webView()->updateAllLifecyclePhases(); | 126 webView()->updateAllLifecyclePhases(); |
125 } | 127 } |
126 | 128 |
127 WebViewImpl* webView() const { return m_helper.webView(); } | 129 WebViewImpl* webView() const { return m_helper.webView(); } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 | 230 |
229 WebExternalPopupMenuClient* client = | 231 WebExternalPopupMenuClient* client = |
230 static_cast<ExternalPopupMenu*>(select->popup()); | 232 static_cast<ExternalPopupMenu*>(select->popup()); |
231 WebVector<int> indices; | 233 WebVector<int> indices; |
232 client->didAcceptIndices(indices); | 234 client->didAcceptIndices(indices); |
233 EXPECT_FALSE(select->popupIsVisible()); | 235 EXPECT_FALSE(select->popupIsVisible()); |
234 EXPECT_EQ(-1, select->selectedIndex()); | 236 EXPECT_EQ(-1, select->selectedIndex()); |
235 } | 237 } |
236 | 238 |
237 } // namespace blink | 239 } // namespace blink |
OLD | NEW |