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 <tuple> |
| 6 |
5 #include "base/macros.h" | 7 #include "base/macros.h" |
6 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
7 #include "content/common/frame_messages.h" | 9 #include "content/common/frame_messages.h" |
8 #include "content/public/test/render_view_test.h" | 10 #include "content/public/test/render_view_test.h" |
9 #include "content/renderer/render_frame_impl.h" | 11 #include "content/renderer/render_frame_impl.h" |
10 #include "content/renderer/render_view_impl.h" | 12 #include "content/renderer/render_view_impl.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/WebKit/public/platform/WebSize.h" | 14 #include "third_party/WebKit/public/platform/WebSize.h" |
13 #include "third_party/WebKit/public/web/WebView.h" | 15 #include "third_party/WebKit/public/web/WebView.h" |
14 | 16 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 TEST_F(ExternalPopupMenuTest, NormalCase) { | 82 TEST_F(ExternalPopupMenuTest, NormalCase) { |
81 IPC::TestSink& sink = render_thread_->sink(); | 83 IPC::TestSink& sink = render_thread_->sink(); |
82 | 84 |
83 // Click the text field once. | 85 // Click the text field once. |
84 EXPECT_TRUE(SimulateElementClick(kSelectID)); | 86 EXPECT_TRUE(SimulateElementClick(kSelectID)); |
85 | 87 |
86 // We should have sent a message to the browser to show the popup menu. | 88 // We should have sent a message to the browser to show the popup menu. |
87 const IPC::Message* message = | 89 const IPC::Message* message = |
88 sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID); | 90 sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID); |
89 ASSERT_TRUE(message != NULL); | 91 ASSERT_TRUE(message != NULL); |
90 base::Tuple<FrameHostMsg_ShowPopup_Params> param; | 92 std::tuple<FrameHostMsg_ShowPopup_Params> param; |
91 FrameHostMsg_ShowPopup::Read(message, ¶m); | 93 FrameHostMsg_ShowPopup::Read(message, ¶m); |
92 ASSERT_EQ(3U, base::get<0>(param).popup_items.size()); | 94 ASSERT_EQ(3U, std::get<0>(param).popup_items.size()); |
93 EXPECT_EQ(1, base::get<0>(param).selected_item); | 95 EXPECT_EQ(1, std::get<0>(param).selected_item); |
94 | 96 |
95 // Simulate the user canceling the popup; the index should not have changed. | 97 // Simulate the user canceling the popup; the index should not have changed. |
96 frame()->OnSelectPopupMenuItem(-1); | 98 frame()->OnSelectPopupMenuItem(-1); |
97 EXPECT_EQ(1, GetSelectedIndex()); | 99 EXPECT_EQ(1, GetSelectedIndex()); |
98 | 100 |
99 // Show the pop-up again and this time make a selection. | 101 // Show the pop-up again and this time make a selection. |
100 EXPECT_TRUE(SimulateElementClick(kSelectID)); | 102 EXPECT_TRUE(SimulateElementClick(kSelectID)); |
101 frame()->OnSelectPopupMenuItem(0); | 103 frame()->OnSelectPopupMenuItem(0); |
102 EXPECT_EQ(0, GetSelectedIndex()); | 104 EXPECT_EQ(0, GetSelectedIndex()); |
103 | 105 |
104 // Show the pop-up again and make another selection. | 106 // Show the pop-up again and make another selection. |
105 sink.ClearMessages(); | 107 sink.ClearMessages(); |
106 EXPECT_TRUE(SimulateElementClick(kSelectID)); | 108 EXPECT_TRUE(SimulateElementClick(kSelectID)); |
107 message = sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID); | 109 message = sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID); |
108 ASSERT_TRUE(message != NULL); | 110 ASSERT_TRUE(message != NULL); |
109 FrameHostMsg_ShowPopup::Read(message, ¶m); | 111 FrameHostMsg_ShowPopup::Read(message, ¶m); |
110 ASSERT_EQ(3U, base::get<0>(param).popup_items.size()); | 112 ASSERT_EQ(3U, std::get<0>(param).popup_items.size()); |
111 EXPECT_EQ(0, base::get<0>(param).selected_item); | 113 EXPECT_EQ(0, std::get<0>(param).selected_item); |
112 } | 114 } |
113 | 115 |
114 // Page shows popup, then navigates away while popup showing, then select. | 116 // Page shows popup, then navigates away while popup showing, then select. |
115 TEST_F(ExternalPopupMenuTest, ShowPopupThenNavigate) { | 117 TEST_F(ExternalPopupMenuTest, ShowPopupThenNavigate) { |
116 // Click the text field once. | 118 // Click the text field once. |
117 EXPECT_TRUE(SimulateElementClick(kSelectID)); | 119 EXPECT_TRUE(SimulateElementClick(kSelectID)); |
118 | 120 |
119 // Now we navigate to another pager. | 121 // Now we navigate to another pager. |
120 LoadHTML("<blink>Awesome page!</blink>"); | 122 LoadHTML("<blink>Awesome page!</blink>"); |
121 | 123 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 TEST_F(ExternalPopupMenuDisplayNoneTest, SelectItem) { | 185 TEST_F(ExternalPopupMenuDisplayNoneTest, SelectItem) { |
184 IPC::TestSink& sink = render_thread_->sink(); | 186 IPC::TestSink& sink = render_thread_->sink(); |
185 | 187 |
186 // Click the text field once to show the popup. | 188 // Click the text field once to show the popup. |
187 EXPECT_TRUE(SimulateElementClick(kSelectID)); | 189 EXPECT_TRUE(SimulateElementClick(kSelectID)); |
188 | 190 |
189 // Read the message sent to browser to show the popup menu. | 191 // Read the message sent to browser to show the popup menu. |
190 const IPC::Message* message = | 192 const IPC::Message* message = |
191 sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID); | 193 sink.GetUniqueMessageMatching(FrameHostMsg_ShowPopup::ID); |
192 ASSERT_TRUE(message != NULL); | 194 ASSERT_TRUE(message != NULL); |
193 base::Tuple<FrameHostMsg_ShowPopup_Params> param; | 195 std::tuple<FrameHostMsg_ShowPopup_Params> param; |
194 FrameHostMsg_ShowPopup::Read(message, ¶m); | 196 FrameHostMsg_ShowPopup::Read(message, ¶m); |
195 // Number of items should match item count minus the number | 197 // Number of items should match item count minus the number |
196 // of "display: none" items. | 198 // of "display: none" items. |
197 ASSERT_EQ(5U, base::get<0>(param).popup_items.size()); | 199 ASSERT_EQ(5U, std::get<0>(param).popup_items.size()); |
198 | 200 |
199 // Select index 1 item. This should select item with index 2, | 201 // Select index 1 item. This should select item with index 2, |
200 // skipping the item with 'display: none' | 202 // skipping the item with 'display: none' |
201 frame()->OnSelectPopupMenuItem(1); | 203 frame()->OnSelectPopupMenuItem(1); |
202 | 204 |
203 EXPECT_EQ(2, GetSelectedIndex()); | 205 EXPECT_EQ(2, GetSelectedIndex()); |
204 } | 206 } |
205 | 207 |
206 } // namespace content | 208 } // namespace content |
OLD | NEW |