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