Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: content/renderer/render_view_browsertest.cc

Issue 8230034: Split most of RenderViewTest and associated classes into content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac build breaks. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/basictypes.h" 5 #include "base/basictypes.h"
6 6
7 #include "base/shared_memory.h" 7 #include "base/shared_memory.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/test/base/render_view_test.h"
11 #include "content/common/native_web_keyboard_event.h" 10 #include "content/common/native_web_keyboard_event.h"
12 #include "content/common/view_messages.h" 11 #include "content/common/view_messages.h"
13 #include "content/renderer/render_view_impl.h" 12 #include "content/renderer/render_view_impl.h"
13 #include "content/test/render_view_test.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
19 #include "ui/base/keycodes/keyboard_codes.h" 19 #include "ui/base/keycodes/keyboard_codes.h"
20 #include "ui/base/range/range.h" 20 #include "ui/base/range/range.h"
21 #include "ui/gfx/codec/jpeg_codec.h" 21 #include "ui/gfx/codec/jpeg_codec.h"
22 #include "webkit/glue/web_io_operators.h" 22 #include "webkit/glue/web_io_operators.h"
23 23
24 using WebKit::WebFrame; 24 using WebKit::WebFrame;
25 using WebKit::WebString; 25 using WebKit::WebString;
26 using WebKit::WebTextDirection; 26 using WebKit::WebTextDirection;
27 using WebKit::WebURLError; 27 using WebKit::WebURLError;
28 28
29 class RenderViewImplTest : public RenderViewTest { 29 class RenderViewImplTest : public content::RenderViewTest {
30 public: 30 public:
31 RenderViewImpl* view() { 31 RenderViewImpl* view() {
32 return static_cast<RenderViewImpl*>(view_); 32 return static_cast<RenderViewImpl*>(view_);
33 } 33 }
34 }; 34 };
35 35
36 // Test that we get form state change notifications when input fields change. 36 // Test that we get form state change notifications when input fields change.
37 TEST_F(RenderViewImplTest, OnNavStateChanged) { 37 TEST_F(RenderViewImplTest, OnNavStateChanged) {
38 // Don't want any delay for form state sync changes. This will still post a 38 // Don't want any delay for form state sync changes. This will still post a
39 // message so updates will get coalesced, but as soon as we spin the message 39 // message so updates will get coalesced, but as soon as we spin the message
40 // loop, it will generate an update. 40 // loop, it will generate an update.
41 view()->set_send_content_state_immediately(true); 41 view()->set_send_content_state_immediately(true);
42 42
43 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>"); 43 LoadHTML("<input type=\"text\" id=\"elt_text\"></input>");
44 44
45 // We should NOT have gotten a form state change notification yet. 45 // We should NOT have gotten a form state change notification yet.
46 EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( 46 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
47 ViewHostMsg_UpdateState::ID)); 47 ViewHostMsg_UpdateState::ID));
48 render_thread_.sink().ClearMessages(); 48 render_thread_->sink().ClearMessages();
49 49
50 // Change the value of the input. We should have gotten an update state 50 // Change the value of the input. We should have gotten an update state
51 // notification. We need to spin the message loop to catch this update. 51 // notification. We need to spin the message loop to catch this update.
52 ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); 52 ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';");
53 ProcessPendingMessages(); 53 ProcessPendingMessages();
54 EXPECT_TRUE(render_thread_.sink().GetUniqueMessageMatching( 54 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching(
55 ViewHostMsg_UpdateState::ID)); 55 ViewHostMsg_UpdateState::ID));
56 } 56 }
57 57
58 // Test that we get the correct UpdateState message when we go back twice 58 // Test that we get the correct UpdateState message when we go back twice
59 // quickly without committing. Regression test for http://crbug.com/58082. 59 // quickly without committing. Regression test for http://crbug.com/58082.
60 TEST_F(RenderViewImplTest, LastCommittedUpdateState) { 60 TEST_F(RenderViewImplTest, LastCommittedUpdateState) {
61 // Load page A. 61 // Load page A.
62 LoadHTML("<div>Page A</div>"); 62 LoadHTML("<div>Page A</div>");
63 63
64 // Load page B, which will trigger an UpdateState message for page A. 64 // Load page B, which will trigger an UpdateState message for page A.
65 LoadHTML("<div>Page B</div>"); 65 LoadHTML("<div>Page B</div>");
66 66
67 // Check for a valid UpdateState message for page A. 67 // Check for a valid UpdateState message for page A.
68 const IPC::Message* msg_A = render_thread_.sink().GetUniqueMessageMatching( 68 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching(
69 ViewHostMsg_UpdateState::ID); 69 ViewHostMsg_UpdateState::ID);
70 ASSERT_TRUE(msg_A); 70 ASSERT_TRUE(msg_A);
71 int page_id_A; 71 int page_id_A;
72 std::string state_A; 72 std::string state_A;
73 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); 73 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A);
74 EXPECT_EQ(1, page_id_A); 74 EXPECT_EQ(1, page_id_A);
75 render_thread_.sink().ClearMessages(); 75 render_thread_->sink().ClearMessages();
76 76
77 // Load page C, which will trigger an UpdateState message for page B. 77 // Load page C, which will trigger an UpdateState message for page B.
78 LoadHTML("<div>Page C</div>"); 78 LoadHTML("<div>Page C</div>");
79 79
80 // Check for a valid UpdateState for page B. 80 // Check for a valid UpdateState for page B.
81 const IPC::Message* msg_B = render_thread_.sink().GetUniqueMessageMatching( 81 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching(
82 ViewHostMsg_UpdateState::ID); 82 ViewHostMsg_UpdateState::ID);
83 ASSERT_TRUE(msg_B); 83 ASSERT_TRUE(msg_B);
84 int page_id_B; 84 int page_id_B;
85 std::string state_B; 85 std::string state_B;
86 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); 86 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B);
87 EXPECT_EQ(2, page_id_B); 87 EXPECT_EQ(2, page_id_B);
88 EXPECT_NE(state_A, state_B); 88 EXPECT_NE(state_A, state_B);
89 render_thread_.sink().ClearMessages(); 89 render_thread_->sink().ClearMessages();
90 90
91 // Load page D, which will trigger an UpdateState message for page C. 91 // Load page D, which will trigger an UpdateState message for page C.
92 LoadHTML("<div>Page D</div>"); 92 LoadHTML("<div>Page D</div>");
93 93
94 // Check for a valid UpdateState for page C. 94 // Check for a valid UpdateState for page C.
95 const IPC::Message* msg_C = render_thread_.sink().GetUniqueMessageMatching( 95 const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching(
96 ViewHostMsg_UpdateState::ID); 96 ViewHostMsg_UpdateState::ID);
97 ASSERT_TRUE(msg_C); 97 ASSERT_TRUE(msg_C);
98 int page_id_C; 98 int page_id_C;
99 std::string state_C; 99 std::string state_C;
100 ViewHostMsg_UpdateState::Read(msg_C, &page_id_C, &state_C); 100 ViewHostMsg_UpdateState::Read(msg_C, &page_id_C, &state_C);
101 EXPECT_EQ(3, page_id_C); 101 EXPECT_EQ(3, page_id_C);
102 EXPECT_NE(state_B, state_C); 102 EXPECT_NE(state_B, state_C);
103 render_thread_.sink().ClearMessages(); 103 render_thread_->sink().ClearMessages();
104 104
105 // Go back to C and commit, preparing for our real test. 105 // Go back to C and commit, preparing for our real test.
106 ViewMsg_Navigate_Params params_C; 106 ViewMsg_Navigate_Params params_C;
107 params_C.navigation_type = ViewMsg_Navigate_Type::NORMAL; 107 params_C.navigation_type = ViewMsg_Navigate_Type::NORMAL;
108 params_C.transition = content::PAGE_TRANSITION_FORWARD_BACK; 108 params_C.transition = content::PAGE_TRANSITION_FORWARD_BACK;
109 params_C.current_history_list_length = 4; 109 params_C.current_history_list_length = 4;
110 params_C.current_history_list_offset = 3; 110 params_C.current_history_list_offset = 3;
111 params_C.pending_history_list_offset = 2; 111 params_C.pending_history_list_offset = 2;
112 params_C.page_id = 3; 112 params_C.page_id = 3;
113 params_C.state = state_C; 113 params_C.state = state_C;
114 view()->OnNavigate(params_C); 114 view()->OnNavigate(params_C);
115 ProcessPendingMessages(); 115 ProcessPendingMessages();
116 render_thread_.sink().ClearMessages(); 116 render_thread_->sink().ClearMessages();
117 117
118 // Go back twice quickly, such that page B does not have a chance to commit. 118 // Go back twice quickly, such that page B does not have a chance to commit.
119 // This leads to two changes to the back/forward list but only one change to 119 // This leads to two changes to the back/forward list but only one change to
120 // the RenderView's page ID. 120 // the RenderView's page ID.
121 121
122 // Back to page B (page_id 2), without committing. 122 // Back to page B (page_id 2), without committing.
123 ViewMsg_Navigate_Params params_B; 123 ViewMsg_Navigate_Params params_B;
124 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; 124 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL;
125 params_B.transition = content::PAGE_TRANSITION_FORWARD_BACK; 125 params_B.transition = content::PAGE_TRANSITION_FORWARD_BACK;
126 params_B.current_history_list_length = 4; 126 params_B.current_history_list_length = 4;
(...skipping 10 matching lines...) Expand all
137 params_B.current_history_list_length = 4; 137 params_B.current_history_list_length = 4;
138 params_B.current_history_list_offset = 2; 138 params_B.current_history_list_offset = 2;
139 params_B.pending_history_list_offset = 0; 139 params_B.pending_history_list_offset = 0;
140 params.page_id = 1; 140 params.page_id = 1;
141 params.state = state_A; 141 params.state = state_A;
142 view()->OnNavigate(params); 142 view()->OnNavigate(params);
143 ProcessPendingMessages(); 143 ProcessPendingMessages();
144 144
145 // Now ensure that the UpdateState message we receive is consistent 145 // Now ensure that the UpdateState message we receive is consistent
146 // and represents page C in both page_id and state. 146 // and represents page C in both page_id and state.
147 const IPC::Message* msg = render_thread_.sink().GetUniqueMessageMatching( 147 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching(
148 ViewHostMsg_UpdateState::ID); 148 ViewHostMsg_UpdateState::ID);
149 ASSERT_TRUE(msg); 149 ASSERT_TRUE(msg);
150 int page_id; 150 int page_id;
151 std::string state; 151 std::string state;
152 ViewHostMsg_UpdateState::Read(msg, &page_id, &state); 152 ViewHostMsg_UpdateState::Read(msg, &page_id, &state);
153 EXPECT_EQ(page_id_C, page_id); 153 EXPECT_EQ(page_id_C, page_id);
154 EXPECT_NE(state_A, state); 154 EXPECT_NE(state_A, state);
155 EXPECT_NE(state_B, state); 155 EXPECT_NE(state_B, state);
156 EXPECT_EQ(state_C, state); 156 EXPECT_EQ(state_C, state);
157 } 157 }
158 158
159 // Test that the history_page_ids_ list can reveal when a stale back/forward 159 // Test that the history_page_ids_ list can reveal when a stale back/forward
160 // navigation arrives from the browser and can be ignored. See 160 // navigation arrives from the browser and can be ignored. See
161 // http://crbug.com/86758. 161 // http://crbug.com/86758.
162 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { 162 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) {
163 // Load page A. 163 // Load page A.
164 LoadHTML("<div>Page A</div>"); 164 LoadHTML("<div>Page A</div>");
165 EXPECT_EQ(1, view()->history_list_length_); 165 EXPECT_EQ(1, view()->history_list_length_);
166 EXPECT_EQ(0, view()->history_list_offset_); 166 EXPECT_EQ(0, view()->history_list_offset_);
167 EXPECT_EQ(1, view()->history_page_ids_[0]); 167 EXPECT_EQ(1, view()->history_page_ids_[0]);
168 168
169 // Load page B, which will trigger an UpdateState message for page A. 169 // Load page B, which will trigger an UpdateState message for page A.
170 LoadHTML("<div>Page B</div>"); 170 LoadHTML("<div>Page B</div>");
171 EXPECT_EQ(2, view()->history_list_length_); 171 EXPECT_EQ(2, view()->history_list_length_);
172 EXPECT_EQ(1, view()->history_list_offset_); 172 EXPECT_EQ(1, view()->history_list_offset_);
173 EXPECT_EQ(2, view()->history_page_ids_[1]); 173 EXPECT_EQ(2, view()->history_page_ids_[1]);
174 174
175 // Check for a valid UpdateState message for page A. 175 // Check for a valid UpdateState message for page A.
176 const IPC::Message* msg_A = render_thread_.sink().GetUniqueMessageMatching( 176 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching(
177 ViewHostMsg_UpdateState::ID); 177 ViewHostMsg_UpdateState::ID);
178 ASSERT_TRUE(msg_A); 178 ASSERT_TRUE(msg_A);
179 int page_id_A; 179 int page_id_A;
180 std::string state_A; 180 std::string state_A;
181 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); 181 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A);
182 EXPECT_EQ(1, page_id_A); 182 EXPECT_EQ(1, page_id_A);
183 render_thread_.sink().ClearMessages(); 183 render_thread_->sink().ClearMessages();
184 184
185 // Back to page A (page_id 1) and commit. 185 // Back to page A (page_id 1) and commit.
186 ViewMsg_Navigate_Params params_A; 186 ViewMsg_Navigate_Params params_A;
187 params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL; 187 params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL;
188 params_A.transition = content::PAGE_TRANSITION_FORWARD_BACK; 188 params_A.transition = content::PAGE_TRANSITION_FORWARD_BACK;
189 params_A.current_history_list_length = 2; 189 params_A.current_history_list_length = 2;
190 params_A.current_history_list_offset = 1; 190 params_A.current_history_list_offset = 1;
191 params_A.pending_history_list_offset = 0; 191 params_A.pending_history_list_offset = 0;
192 params_A.page_id = 1; 192 params_A.page_id = 1;
193 params_A.state = state_A; 193 params_A.state = state_A;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 EXPECT_EQ(0, view()->history_list_offset_); 230 EXPECT_EQ(0, view()->history_list_offset_);
231 EXPECT_EQ(1, view()->history_page_ids_[0]); 231 EXPECT_EQ(1, view()->history_page_ids_[0]);
232 232
233 // Load page B, which will trigger an UpdateState message for page A. 233 // Load page B, which will trigger an UpdateState message for page A.
234 LoadHTML("<div>Page B</div>"); 234 LoadHTML("<div>Page B</div>");
235 EXPECT_EQ(2, view()->history_list_length_); 235 EXPECT_EQ(2, view()->history_list_length_);
236 EXPECT_EQ(1, view()->history_list_offset_); 236 EXPECT_EQ(1, view()->history_list_offset_);
237 EXPECT_EQ(2, view()->history_page_ids_[1]); 237 EXPECT_EQ(2, view()->history_page_ids_[1]);
238 238
239 // Check for a valid UpdateState message for page A. 239 // Check for a valid UpdateState message for page A.
240 const IPC::Message* msg_A = render_thread_.sink().GetUniqueMessageMatching( 240 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching(
241 ViewHostMsg_UpdateState::ID); 241 ViewHostMsg_UpdateState::ID);
242 ASSERT_TRUE(msg_A); 242 ASSERT_TRUE(msg_A);
243 int page_id_A; 243 int page_id_A;
244 std::string state_A; 244 std::string state_A;
245 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); 245 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A);
246 EXPECT_EQ(1, page_id_A); 246 EXPECT_EQ(1, page_id_A);
247 render_thread_.sink().ClearMessages(); 247 render_thread_->sink().ClearMessages();
248 248
249 // Load page C, which will trigger an UpdateState message for page B. 249 // Load page C, which will trigger an UpdateState message for page B.
250 LoadHTML("<div>Page C</div>"); 250 LoadHTML("<div>Page C</div>");
251 EXPECT_EQ(3, view()->history_list_length_); 251 EXPECT_EQ(3, view()->history_list_length_);
252 EXPECT_EQ(2, view()->history_list_offset_); 252 EXPECT_EQ(2, view()->history_list_offset_);
253 EXPECT_EQ(3, view()->history_page_ids_[2]); 253 EXPECT_EQ(3, view()->history_page_ids_[2]);
254 254
255 // Check for a valid UpdateState message for page B. 255 // Check for a valid UpdateState message for page B.
256 const IPC::Message* msg_B = render_thread_.sink().GetUniqueMessageMatching( 256 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching(
257 ViewHostMsg_UpdateState::ID); 257 ViewHostMsg_UpdateState::ID);
258 ASSERT_TRUE(msg_B); 258 ASSERT_TRUE(msg_B);
259 int page_id_B; 259 int page_id_B;
260 std::string state_B; 260 std::string state_B;
261 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); 261 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B);
262 EXPECT_EQ(2, page_id_B); 262 EXPECT_EQ(2, page_id_B);
263 render_thread_.sink().ClearMessages(); 263 render_thread_->sink().ClearMessages();
264 264
265 // Suppose the browser has limited the number of NavigationEntries to 2. 265 // Suppose the browser has limited the number of NavigationEntries to 2.
266 // It has now dropped the first entry, but the renderer isn't notified. 266 // It has now dropped the first entry, but the renderer isn't notified.
267 // Ensure that going back to page B (page_id 2) at offset 0 is successful. 267 // Ensure that going back to page B (page_id 2) at offset 0 is successful.
268 ViewMsg_Navigate_Params params_B; 268 ViewMsg_Navigate_Params params_B;
269 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; 269 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL;
270 params_B.transition = content::PAGE_TRANSITION_FORWARD_BACK; 270 params_B.transition = content::PAGE_TRANSITION_FORWARD_BACK;
271 params_B.current_history_list_length = 2; 271 params_B.current_history_list_length = 2;
272 params_B.current_history_list_offset = 1; 272 params_B.current_history_list_offset = 1;
273 params_B.pending_history_list_offset = 0; 273 params_B.pending_history_list_offset = 0;
(...skipping 16 matching lines...) Expand all
290 // Load an HTML page consisting of two input fields. 290 // Load an HTML page consisting of two input fields.
291 view()->set_send_content_state_immediately(true); 291 view()->set_send_content_state_immediately(true);
292 LoadHTML("<html>" 292 LoadHTML("<html>"
293 "<head>" 293 "<head>"
294 "</head>" 294 "</head>"
295 "<body>" 295 "<body>"
296 "<input id=\"test1\" type=\"text\"></input>" 296 "<input id=\"test1\" type=\"text\"></input>"
297 "<input id=\"test2\" type=\"password\"></input>" 297 "<input id=\"test2\" type=\"password\"></input>"
298 "</body>" 298 "</body>"
299 "</html>"); 299 "</html>");
300 render_thread_.sink().ClearMessages(); 300 render_thread_->sink().ClearMessages();
301 301
302 const int kRepeatCount = 10; 302 const int kRepeatCount = 10;
303 for (int i = 0; i < kRepeatCount; i++) { 303 for (int i = 0; i < kRepeatCount; i++) {
304 // Move the input focus to the first <input> element, where we should 304 // Move the input focus to the first <input> element, where we should
305 // activate IMEs. 305 // activate IMEs.
306 ExecuteJavaScript("document.getElementById('test1').focus();"); 306 ExecuteJavaScript("document.getElementById('test1').focus();");
307 ProcessPendingMessages(); 307 ProcessPendingMessages();
308 render_thread_.sink().ClearMessages(); 308 render_thread_->sink().ClearMessages();
309 309
310 // Update the IME status and verify if our IME backend sends an IPC message 310 // Update the IME status and verify if our IME backend sends an IPC message
311 // to activate IMEs. 311 // to activate IMEs.
312 view()->UpdateInputMethod(); 312 view()->UpdateInputMethod();
313 const IPC::Message* msg = render_thread_.sink().GetMessageAt(0); 313 const IPC::Message* msg = render_thread_->sink().GetMessageAt(0);
314 EXPECT_TRUE(msg != NULL); 314 EXPECT_TRUE(msg != NULL);
315 EXPECT_EQ(ViewHostMsg_ImeUpdateTextInputState::ID, msg->type()); 315 EXPECT_EQ(ViewHostMsg_ImeUpdateTextInputState::ID, msg->type());
316 ViewHostMsg_ImeUpdateTextInputState::Param params; 316 ViewHostMsg_ImeUpdateTextInputState::Param params;
317 ViewHostMsg_ImeUpdateTextInputState::Read(msg, &params); 317 ViewHostMsg_ImeUpdateTextInputState::Read(msg, &params);
318 EXPECT_EQ(params.a, ui::TEXT_INPUT_TYPE_TEXT); 318 EXPECT_EQ(params.a, ui::TEXT_INPUT_TYPE_TEXT);
319 EXPECT_EQ(params.b, true); 319 EXPECT_EQ(params.b, true);
320 EXPECT_TRUE(params.c.x() > 0 && params.c.y() > 0); 320 EXPECT_TRUE(params.c.x() > 0 && params.c.y() > 0);
321 321
322 // Move the input focus to the second <input> element, where we should 322 // Move the input focus to the second <input> element, where we should
323 // de-activate IMEs. 323 // de-activate IMEs.
324 ExecuteJavaScript("document.getElementById('test2').focus();"); 324 ExecuteJavaScript("document.getElementById('test2').focus();");
325 ProcessPendingMessages(); 325 ProcessPendingMessages();
326 render_thread_.sink().ClearMessages(); 326 render_thread_->sink().ClearMessages();
327 327
328 // Update the IME status and verify if our IME backend sends an IPC message 328 // Update the IME status and verify if our IME backend sends an IPC message
329 // to de-activate IMEs. 329 // to de-activate IMEs.
330 view()->UpdateInputMethod(); 330 view()->UpdateInputMethod();
331 msg = render_thread_.sink().GetMessageAt(0); 331 msg = render_thread_->sink().GetMessageAt(0);
332 EXPECT_TRUE(msg != NULL); 332 EXPECT_TRUE(msg != NULL);
333 EXPECT_EQ(ViewHostMsg_ImeUpdateTextInputState::ID, msg->type()); 333 EXPECT_EQ(ViewHostMsg_ImeUpdateTextInputState::ID, msg->type());
334 ViewHostMsg_ImeUpdateTextInputState::Read(msg, &params); 334 ViewHostMsg_ImeUpdateTextInputState::Read(msg, &params);
335 EXPECT_EQ(params.a, ui::TEXT_INPUT_TYPE_PASSWORD); 335 EXPECT_EQ(params.a, ui::TEXT_INPUT_TYPE_PASSWORD);
336 } 336 }
337 } 337 }
338 338
339 // Test that our IME backend can compose CJK words. 339 // Test that our IME backend can compose CJK words.
340 // Our IME front-end sends many platform-independent messages to the IME backend 340 // Our IME front-end sends many platform-independent messages to the IME backend
341 // while it composes CJK words. This test sends the minimal messages captured 341 // while it composes CJK words. This test sends the minimal messages captured
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 string16(), 454 string16(),
455 std::vector<WebKit::WebCompositionUnderline>(), 455 std::vector<WebKit::WebCompositionUnderline>(),
456 0, 0); 456 0, 0);
457 break; 457 break;
458 } 458 }
459 459
460 // Update the status of our IME back-end. 460 // Update the status of our IME back-end.
461 // TODO(hbono): we should verify messages to be sent from the back-end. 461 // TODO(hbono): we should verify messages to be sent from the back-end.
462 view()->UpdateInputMethod(); 462 view()->UpdateInputMethod();
463 ProcessPendingMessages(); 463 ProcessPendingMessages();
464 render_thread_.sink().ClearMessages(); 464 render_thread_->sink().ClearMessages();
465 465
466 if (ime_message->result) { 466 if (ime_message->result) {
467 // Retrieve the content of this page and compare it with the expected 467 // Retrieve the content of this page and compare it with the expected
468 // result. 468 // result.
469 const int kMaxOutputCharacters = 128; 469 const int kMaxOutputCharacters = 128;
470 std::wstring output = UTF16ToWideHack( 470 std::wstring output = UTF16ToWideHack(
471 GetMainFrame()->contentAsText(kMaxOutputCharacters)); 471 GetMainFrame()->contentAsText(kMaxOutputCharacters));
472 EXPECT_EQ(output, ime_message->result); 472 EXPECT_EQ(output, ime_message->result);
473 } 473 }
474 } 474 }
475 } 475 }
476 476
477 // Test that the RenderView::OnSetTextDirection() function can change the text 477 // Test that the RenderView::OnSetTextDirection() function can change the text
478 // direction of the selected input element. 478 // direction of the selected input element.
479 TEST_F(RenderViewImplTest, OnSetTextDirection) { 479 TEST_F(RenderViewImplTest, OnSetTextDirection) {
480 // Load an HTML page consisting of a <textarea> element and a <div> element. 480 // Load an HTML page consisting of a <textarea> element and a <div> element.
481 // This test changes the text direction of the <textarea> element, and 481 // This test changes the text direction of the <textarea> element, and
482 // writes the values of its 'dir' attribute and its 'direction' property to 482 // writes the values of its 'dir' attribute and its 'direction' property to
483 // verify that the text direction is changed. 483 // verify that the text direction is changed.
484 view()->set_send_content_state_immediately(true); 484 view()->set_send_content_state_immediately(true);
485 LoadHTML("<html>" 485 LoadHTML("<html>"
486 "<head>" 486 "<head>"
487 "</head>" 487 "</head>"
488 "<body>" 488 "<body>"
489 "<textarea id=\"test\"></textarea>" 489 "<textarea id=\"test\"></textarea>"
490 "<div id=\"result\" contenteditable=\"true\"></div>" 490 "<div id=\"result\" contenteditable=\"true\"></div>"
491 "</body>" 491 "</body>"
492 "</html>"); 492 "</html>");
493 render_thread_.sink().ClearMessages(); 493 render_thread_->sink().ClearMessages();
494 494
495 static const struct { 495 static const struct {
496 WebTextDirection direction; 496 WebTextDirection direction;
497 const wchar_t* expected_result; 497 const wchar_t* expected_result;
498 } kTextDirection[] = { 498 } kTextDirection[] = {
499 { WebKit::WebTextDirectionRightToLeft, L"\x000A" L"rtl,rtl" }, 499 { WebKit::WebTextDirectionRightToLeft, L"\x000A" L"rtl,rtl" },
500 { WebKit::WebTextDirectionLeftToRight, L"\x000A" L"ltr,ltr" }, 500 { WebKit::WebTextDirectionLeftToRight, L"\x000A" L"ltr,ltr" },
501 }; 501 };
502 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) { 502 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) {
503 // Set the text direction of the <textarea> element. 503 // Set the text direction of the <textarea> element.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 "</input>" 558 "</input>"
559 "<div id='keydown' contenteditable='true'>" 559 "<div id='keydown' contenteditable='true'>"
560 "</div>" 560 "</div>"
561 "<div id='keypress' contenteditable='true'>" 561 "<div id='keypress' contenteditable='true'>"
562 "</div>" 562 "</div>"
563 "<div id='keyup' contenteditable='true'>" 563 "<div id='keyup' contenteditable='true'>"
564 "</div>" 564 "</div>"
565 "</body>" 565 "</body>"
566 "</html>"); 566 "</html>");
567 ExecuteJavaScript("document.getElementById('test').focus();"); 567 ExecuteJavaScript("document.getElementById('test').focus();");
568 render_thread_.sink().ClearMessages(); 568 render_thread_->sink().ClearMessages();
569 569
570 static const MockKeyboard::Layout kLayouts[] = { 570 static const MockKeyboard::Layout kLayouts[] = {
571 #if defined(OS_WIN) 571 #if defined(OS_WIN)
572 // Since we ignore the mock keyboard layout on Linux and instead just use 572 // Since we ignore the mock keyboard layout on Linux and instead just use
573 // the screen's keyboard layout, these trivially pass. They are commented 573 // the screen's keyboard layout, these trivially pass. They are commented
574 // out to avoid the illusion that they work. 574 // out to avoid the illusion that they work.
575 MockKeyboard::LAYOUT_ARABIC, 575 MockKeyboard::LAYOUT_ARABIC,
576 MockKeyboard::LAYOUT_CANADIAN_FRENCH, 576 MockKeyboard::LAYOUT_CANADIAN_FRENCH,
577 MockKeyboard::LAYOUT_FRENCH, 577 MockKeyboard::LAYOUT_FRENCH,
578 MockKeyboard::LAYOUT_HEBREW, 578 MockKeyboard::LAYOUT_HEBREW,
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 LoadHTML("<html>" 819 LoadHTML("<html>"
820 "<head>" 820 "<head>"
821 "<title></title>" 821 "<title></title>"
822 "</head>" 822 "</head>"
823 "<body>" 823 "<body>"
824 "<div id='test' contenteditable='true'>" 824 "<div id='test' contenteditable='true'>"
825 "</div>" 825 "</div>"
826 "</body>" 826 "</body>"
827 "</html>"); 827 "</html>");
828 ExecuteJavaScript("document.getElementById('test').focus();"); 828 ExecuteJavaScript("document.getElementById('test').focus();");
829 render_thread_.sink().ClearMessages(); 829 render_thread_->sink().ClearMessages();
830 830
831 // For each key code, we send three keyboard events. 831 // For each key code, we send three keyboard events.
832 // * Pressing only the key; 832 // * Pressing only the key;
833 // * Pressing the key and a left-shift key, and; 833 // * Pressing the key and a left-shift key, and;
834 // * Pressing the key and a right-alt (AltGr) key. 834 // * Pressing the key and a right-alt (AltGr) key.
835 static const MockKeyboard::Modifiers kModifiers[] = { 835 static const MockKeyboard::Modifiers kModifiers[] = {
836 MockKeyboard::NONE, 836 MockKeyboard::NONE,
837 MockKeyboard::LEFT_SHIFT, 837 MockKeyboard::LEFT_SHIFT,
838 #if defined(OS_WIN) 838 #if defined(OS_WIN)
839 MockKeyboard::RIGHT_ALT, 839 MockKeyboard::RIGHT_ALT,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 expected_page_id_2 = view()->page_id_; 1078 expected_page_id_2 = view()->page_id_;
1079 EXPECT_GT(expected_page_id_2, expected_page_id); 1079 EXPECT_GT(expected_page_id_2, expected_page_id);
1080 view()->OnSetHistoryLengthAndPrune(2, -1); 1080 view()->OnSetHistoryLengthAndPrune(2, -1);
1081 EXPECT_EQ(4, view()->history_list_length_); 1081 EXPECT_EQ(4, view()->history_list_length_);
1082 EXPECT_EQ(3, view()->history_list_offset_); 1082 EXPECT_EQ(3, view()->history_list_offset_);
1083 EXPECT_EQ(-1, view()->history_page_ids_[0]); 1083 EXPECT_EQ(-1, view()->history_page_ids_[0]);
1084 EXPECT_EQ(-1, view()->history_page_ids_[1]); 1084 EXPECT_EQ(-1, view()->history_page_ids_[1]);
1085 EXPECT_EQ(expected_page_id, view()->history_page_ids_[2]); 1085 EXPECT_EQ(expected_page_id, view()->history_page_ids_[2]);
1086 EXPECT_EQ(expected_page_id_2, view()->history_page_ids_[3]); 1086 EXPECT_EQ(expected_page_id_2, view()->history_page_ids_[3]);
1087 } 1087 }
OLDNEW
« no previous file with comments | « content/renderer/external_popup_menu_unittest.cc ('k') | content/renderer/render_view_browsertest_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698