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" | 10 #include "chrome/test/base/render_view_test.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 params_B.page_id = 2; | 201 params_B.page_id = 2; |
202 params_B.state = state_A; // Doesn't matter, just has to be present. | 202 params_B.state = state_A; // Doesn't matter, just has to be present. |
203 view_->OnNavigate(params_B); | 203 view_->OnNavigate(params_B); |
204 | 204 |
205 // State should be unchanged. | 205 // State should be unchanged. |
206 EXPECT_EQ(2, view_->history_list_length_); | 206 EXPECT_EQ(2, view_->history_list_length_); |
207 EXPECT_EQ(1, view_->history_list_offset_); | 207 EXPECT_EQ(1, view_->history_list_offset_); |
208 EXPECT_EQ(3, view_->history_page_ids_[1]); | 208 EXPECT_EQ(3, view_->history_page_ids_[1]); |
209 } | 209 } |
210 | 210 |
| 211 // Test that we do not ignore navigations after the entry limit is reached, |
| 212 // in which case the browser starts dropping entries from the front. In this |
| 213 // case, we'll see a page_id mismatch but the RenderView's id will be older, |
| 214 // not newer, than params.page_id. Use this as a cue that we should update the |
| 215 // state and not treat it like a navigation to a cropped forward history item. |
| 216 // See http://crbug.com/89798. |
| 217 TEST_F(RenderViewTest, DontIgnoreBackAfterNavEntryLimit) { |
| 218 // Load page A. |
| 219 LoadHTML("<div>Page A</div>"); |
| 220 EXPECT_EQ(1, view_->history_list_length_); |
| 221 EXPECT_EQ(0, view_->history_list_offset_); |
| 222 EXPECT_EQ(1, view_->history_page_ids_[0]); |
| 223 |
| 224 // Load page B, which will trigger an UpdateState message for page A. |
| 225 LoadHTML("<div>Page B</div>"); |
| 226 EXPECT_EQ(2, view_->history_list_length_); |
| 227 EXPECT_EQ(1, view_->history_list_offset_); |
| 228 EXPECT_EQ(2, view_->history_page_ids_[1]); |
| 229 |
| 230 // Check for a valid UpdateState message for page A. |
| 231 const IPC::Message* msg_A = render_thread_.sink().GetUniqueMessageMatching( |
| 232 ViewHostMsg_UpdateState::ID); |
| 233 ASSERT_TRUE(msg_A); |
| 234 int page_id_A; |
| 235 std::string state_A; |
| 236 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); |
| 237 EXPECT_EQ(1, page_id_A); |
| 238 render_thread_.sink().ClearMessages(); |
| 239 |
| 240 // Load page C, which will trigger an UpdateState message for page B. |
| 241 LoadHTML("<div>Page C</div>"); |
| 242 EXPECT_EQ(3, view_->history_list_length_); |
| 243 EXPECT_EQ(2, view_->history_list_offset_); |
| 244 EXPECT_EQ(3, view_->history_page_ids_[2]); |
| 245 |
| 246 // Check for a valid UpdateState message for page B. |
| 247 const IPC::Message* msg_B = render_thread_.sink().GetUniqueMessageMatching( |
| 248 ViewHostMsg_UpdateState::ID); |
| 249 ASSERT_TRUE(msg_B); |
| 250 int page_id_B; |
| 251 std::string state_B; |
| 252 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); |
| 253 EXPECT_EQ(2, page_id_B); |
| 254 render_thread_.sink().ClearMessages(); |
| 255 |
| 256 // Suppose the browser has limited the number of NavigationEntries to 2. |
| 257 // It has now dropped the first entry, but the renderer isn't notified. |
| 258 // Ensure that going back to page B (page_id 2) at offset 0 is successful. |
| 259 ViewMsg_Navigate_Params params_B; |
| 260 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 261 params_B.transition = PageTransition::FORWARD_BACK; |
| 262 params_B.current_history_list_length = 2; |
| 263 params_B.current_history_list_offset = 1; |
| 264 params_B.pending_history_list_offset = 0; |
| 265 params_B.page_id = 2; |
| 266 params_B.state = state_B; |
| 267 view_->OnNavigate(params_B); |
| 268 ProcessPendingMessages(); |
| 269 |
| 270 EXPECT_EQ(2, view_->history_list_length_); |
| 271 EXPECT_EQ(0, view_->history_list_offset_); |
| 272 EXPECT_EQ(2, view_->history_page_ids_[0]); |
| 273 } |
| 274 |
211 // Test that our IME backend sends a notification message when the input focus | 275 // Test that our IME backend sends a notification message when the input focus |
212 // changes. | 276 // changes. |
213 TEST_F(RenderViewTest, OnImeStateChanged) { | 277 TEST_F(RenderViewTest, OnImeStateChanged) { |
214 // Enable our IME backend code. | 278 // Enable our IME backend code. |
215 view_->OnSetInputMethodActive(true); | 279 view_->OnSetInputMethodActive(true); |
216 | 280 |
217 // Load an HTML page consisting of two input fields. | 281 // Load an HTML page consisting of two input fields. |
218 view_->set_send_content_state_immediately(true); | 282 view_->set_send_content_state_immediately(true); |
219 LoadHTML("<html>" | 283 LoadHTML("<html>" |
220 "<head>" | 284 "<head>" |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 // Frame should stay in view-source mode. | 907 // Frame should stay in view-source mode. |
844 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); | 908 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); |
845 } | 909 } |
846 | 910 |
847 // Regression test for http://crbug.com/41562 | 911 // Regression test for http://crbug.com/41562 |
848 TEST_F(RenderViewTest, UpdateTargetURLWithInvalidURL) { | 912 TEST_F(RenderViewTest, UpdateTargetURLWithInvalidURL) { |
849 const GURL invalid_gurl("http://"); | 913 const GURL invalid_gurl("http://"); |
850 view_->setMouseOverURL(WebKit::WebURL(invalid_gurl)); | 914 view_->setMouseOverURL(WebKit::WebURL(invalid_gurl)); |
851 EXPECT_EQ(invalid_gurl, view_->target_url_); | 915 EXPECT_EQ(invalid_gurl, view_->target_url_); |
852 } | 916 } |
OLD | NEW |