OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "content/common/view_messages.h" | 6 #include "content/common/view_messages.h" |
7 #include "content/public/test/render_view_test.h" | 7 #include "content/public/test/render_view_test.h" |
8 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/WebKit/public/web/WebView.h" | 10 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 EXPECT_TRUE(SimulateElementClick(kSelectID)); | 138 EXPECT_TRUE(SimulateElementClick(kSelectID)); |
139 | 139 |
140 // Select something, it causes the select to be removed from the page. | 140 // Select something, it causes the select to be removed from the page. |
141 view()->OnSelectPopupMenuItem(0); | 141 view()->OnSelectPopupMenuItem(0); |
142 | 142 |
143 // Just to check the soundness of the test, call SimulateElementClick again. | 143 // Just to check the soundness of the test, call SimulateElementClick again. |
144 // It should return false as the select has been removed. | 144 // It should return false as the select has been removed. |
145 EXPECT_FALSE(SimulateElementClick(kSelectID)); | 145 EXPECT_FALSE(SimulateElementClick(kSelectID)); |
146 } | 146 } |
147 | 147 |
148 class ExternalPopupMenuDisplayNoneTest : public RenderViewTest { | |
149 public: | |
150 ExternalPopupMenuDisplayNoneTest() {} | |
151 RenderViewImpl* view() { | |
152 return static_cast<RenderViewImpl*>(view_); | |
153 } | |
154 | |
155 virtual void SetUp() { | |
156 | |
157 RenderViewTest::SetUp(); | |
158 // We need to set this explictly as RenderMain is not run. | |
159 blink::WebView::setUseExternalPopupMenus(true); | |
160 | |
161 std::string html = "<select id='mySelect'>" | |
162 " <option value='zero'>zero</option>" | |
163 " <optgroup label='hide' style='display: none'>" | |
164 " <option value='one'>one</option>" | |
165 " </optgroup>" | |
166 " <option value='two'>two</option>" | |
167 " <option value='three'>three</option>" | |
168 " <option value='four'>four</option>" | |
169 " <option value='five'>five</option>" | |
170 "</select>"; | |
171 // Load the test page. | |
172 LoadHTML(html.c_str()); | |
173 | |
174 // Set a minimum size and give focus so simulated events work. | |
175 view()->webwidget()->resize(blink::WebSize(500, 500)); | |
176 view()->webwidget()->setFocus(true); | |
177 } | |
178 | |
179 std::string GetSelectedValue() { | |
180 base::string16 script(base::ASCIIToUTF16(kSelectID)); | |
181 script.append(base::ASCIIToUTF16(".value")); | |
keishi
2014/08/06 03:10:55
Maybe if you used selectedIndex, you won't need to
spartha
2014/08/06 05:29:32
Since we are skipping an item because of "display:
keishi
2014/08/06 06:43:27
I'm not sure.
After calling "view()->OnSelectPopup
spartha
2014/08/06 11:09:40
Done.
| |
182 std::string value; | |
183 ExecuteJavaScriptAndReturnStringValue(script, value); | |
184 return value; | |
185 } | |
186 }; | |
187 | |
188 TEST_F(ExternalPopupMenuDisplayNoneTest, SelectItem) { | |
189 // Click the text field once to show the popup. | |
190 EXPECT_TRUE(SimulateElementClick(kSelectID)); | |
191 | |
192 // Select index 1 item. This should select item with value 'two'. | |
193 view()->OnSelectPopupMenuItem(1); | |
194 | |
195 EXPECT_EQ("two",GetSelectedValue()); | |
196 } | |
197 | |
148 } // namespace content | 198 } // namespace content |
OLD | NEW |