| 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/common/frame_messages.h" | 7 #include "content/common/frame_messages.h" |
| 8 #include "content/public/test/render_view_test.h" | 8 #include "content/public/test/render_view_test.h" |
| 9 #include "content/renderer/render_frame_impl.h" | 9 #include "content/renderer/render_frame_impl.h" |
| 10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 " function selectChanged(select) {" | 51 " function selectChanged(select) {" |
| 52 " select.parentNode.removeChild(select);" | 52 " select.parentNode.removeChild(select);" |
| 53 " }" | 53 " }" |
| 54 "</script>"; | 54 "</script>"; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Load the test page. | 57 // Load the test page. |
| 58 LoadHTML(html.c_str()); | 58 LoadHTML(html.c_str()); |
| 59 | 59 |
| 60 // Set a minimum size and give focus so simulated events work. | 60 // Set a minimum size and give focus so simulated events work. |
| 61 view()->GetWidget()->webwidget()->resize(blink::WebSize(500, 500)); | 61 view()->webwidget()->resize(blink::WebSize(500, 500)); |
| 62 view()->GetWidget()->webwidget()->setFocus(true); | 62 view()->webwidget()->setFocus(true); |
| 63 } | 63 } |
| 64 | 64 |
| 65 int GetSelectedIndex() { | 65 int GetSelectedIndex() { |
| 66 base::string16 script(base::ASCIIToUTF16(kSelectID)); | 66 base::string16 script(base::ASCIIToUTF16(kSelectID)); |
| 67 script.append(base::ASCIIToUTF16(".selectedIndex")); | 67 script.append(base::ASCIIToUTF16(".selectedIndex")); |
| 68 int selected_index = -1; | 68 int selected_index = -1; |
| 69 ExecuteJavaScriptAndReturnIntValue(script, &selected_index); | 69 ExecuteJavaScriptAndReturnIntValue(script, &selected_index); |
| 70 return selected_index; | 70 return selected_index; |
| 71 } | 71 } |
| 72 | 72 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 " </optgroup>" | 167 " </optgroup>" |
| 168 " <option value='two'>two</option>" | 168 " <option value='two'>two</option>" |
| 169 " <option value='three'>three</option>" | 169 " <option value='three'>three</option>" |
| 170 " <option value='four'>four</option>" | 170 " <option value='four'>four</option>" |
| 171 " <option value='five'>five</option>" | 171 " <option value='five'>five</option>" |
| 172 "</select>"; | 172 "</select>"; |
| 173 // Load the test page. | 173 // Load the test page. |
| 174 LoadHTML(html.c_str()); | 174 LoadHTML(html.c_str()); |
| 175 | 175 |
| 176 // Set a minimum size and give focus so simulated events work. | 176 // Set a minimum size and give focus so simulated events work. |
| 177 view()->GetWidget()->webwidget()->resize(blink::WebSize(500, 500)); | 177 view()->webwidget()->resize(blink::WebSize(500, 500)); |
| 178 view()->GetWidget()->webwidget()->setFocus(true); | 178 view()->webwidget()->setFocus(true); |
| 179 } | 179 } |
| 180 | 180 |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 TEST_F(ExternalPopupMenuDisplayNoneTest, SelectItem) { | 183 TEST_F(ExternalPopupMenuDisplayNoneTest, SelectItem) { |
| 184 IPC::TestSink& sink = render_thread_->sink(); | 184 IPC::TestSink& sink = render_thread_->sink(); |
| 185 | 185 |
| 186 // Click the text field once to show the popup. | 186 // Click the text field once to show the popup. |
| 187 EXPECT_TRUE(SimulateElementClick(kSelectID)); | 187 EXPECT_TRUE(SimulateElementClick(kSelectID)); |
| 188 | 188 |
| 189 // Read the message sent to browser to show the popup menu. | 189 // Read the message sent to browser to show the popup menu. |
| 190 const IPC::Message* message = | 190 const IPC::Message* message = |
| 191 sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID); | 191 sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID); |
| 192 ASSERT_TRUE(message != NULL); | 192 ASSERT_TRUE(message != NULL); |
| 193 base::Tuple<FrameHostMsg_ShowPopup_Params> param; | 193 base::Tuple<FrameHostMsg_ShowPopup_Params> param; |
| 194 FrameHostMsg_ShowPopup::Read(message, ¶m); | 194 FrameHostMsg_ShowPopup::Read(message, ¶m); |
| 195 // Number of items should match item count minus the number | 195 // Number of items should match item count minus the number |
| 196 // of "display: none" items. | 196 // of "display: none" items. |
| 197 ASSERT_EQ(5U, base::get<0>(param).popup_items.size()); | 197 ASSERT_EQ(5U, base::get<0>(param).popup_items.size()); |
| 198 | 198 |
| 199 // Select index 1 item. This should select item with index 2, | 199 // Select index 1 item. This should select item with index 2, |
| 200 // skipping the item with 'display: none' | 200 // skipping the item with 'display: none' |
| 201 frame()->OnSelectPopupMenuItem(1); | 201 frame()->OnSelectPopupMenuItem(1); |
| 202 | 202 |
| 203 EXPECT_EQ(2, GetSelectedIndex()); | 203 EXPECT_EQ(2, GetSelectedIndex()); |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace content | 206 } // namespace content |
| OLD | NEW |