| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| 11 #include "content/public/browser/native_web_keyboard_event.h" | 11 #include "content/public/browser/native_web_keyboard_event.h" |
| 12 #include "content/public/browser/web_ui_controller_factory.h" | 12 #include "content/public/browser/web_ui_controller_factory.h" |
| 13 #include "content/public/common/bindings_policy.h" | 13 #include "content/public/common/bindings_policy.h" |
| 14 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
| 15 #include "content/public/renderer/document_state.h" | 15 #include "content/public/renderer/document_state.h" |
| 16 #include "content/public/renderer/history_item_serialization.h" |
| 16 #include "content/public/renderer/navigation_state.h" | 17 #include "content/public/renderer/navigation_state.h" |
| 17 #include "content/public/test/render_view_test.h" | 18 #include "content/public/test/render_view_test.h" |
| 18 #include "content/renderer/render_view_impl.h" | 19 #include "content/renderer/render_view_impl.h" |
| 19 #include "content/shell/common/shell_content_client.h" | 20 #include "content/shell/common/shell_content_client.h" |
| 20 #include "content/shell/shell_content_browser_client.h" | 21 #include "content/shell/shell_content_browser_client.h" |
| 21 #include "content/test/mock_keyboard.h" | 22 #include "content/test/mock_keyboard.h" |
| 22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" | 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" |
| 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" | 26 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" |
| 26 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 27 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
| 27 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" | 28 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLError.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
| 31 #include "ui/base/keycodes/keyboard_codes.h" | 32 #include "ui/base/keycodes/keyboard_codes.h" |
| 32 #include "ui/base/range/range.h" | 33 #include "ui/base/range/range.h" |
| 33 #include "ui/gfx/codec/jpeg_codec.h" | 34 #include "ui/gfx/codec/jpeg_codec.h" |
| 34 #include "webkit/glue/glue_serialize.h" | |
| 35 #include "webkit/glue/web_io_operators.h" | 35 #include "webkit/glue/web_io_operators.h" |
| 36 | 36 |
| 37 #if defined(OS_LINUX) && !defined(USE_AURA) | 37 #if defined(OS_LINUX) && !defined(USE_AURA) |
| 38 #include "ui/base/gtk/event_synthesis_gtk.h" | 38 #include "ui/base/gtk/event_synthesis_gtk.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 #if defined(USE_AURA) | 41 #if defined(USE_AURA) |
| 42 #include "ui/base/events/event.h" | 42 #include "ui/base/events/event.h" |
| 43 #endif | 43 #endif |
| 44 | 44 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 const IPC::Message* frame_navigate_msg = | 294 const IPC::Message* frame_navigate_msg = |
| 295 render_thread_->sink().GetUniqueMessageMatching( | 295 render_thread_->sink().GetUniqueMessageMatching( |
| 296 ViewHostMsg_FrameNavigate::ID); | 296 ViewHostMsg_FrameNavigate::ID); |
| 297 EXPECT_TRUE(frame_navigate_msg); | 297 EXPECT_TRUE(frame_navigate_msg); |
| 298 | 298 |
| 299 ViewHostMsg_FrameNavigate::Param host_nav_params; | 299 ViewHostMsg_FrameNavigate::Param host_nav_params; |
| 300 ViewHostMsg_FrameNavigate::Read(frame_navigate_msg, &host_nav_params); | 300 ViewHostMsg_FrameNavigate::Read(frame_navigate_msg, &host_nav_params); |
| 301 EXPECT_TRUE(host_nav_params.a.is_post); | 301 EXPECT_TRUE(host_nav_params.a.is_post); |
| 302 | 302 |
| 303 // Check post data sent to browser matches | 303 // Check post data sent to browser matches |
| 304 EXPECT_FALSE(host_nav_params.a.content_state.empty()); | 304 EXPECT_TRUE(host_nav_params.a.page_state.IsValid()); |
| 305 const WebKit::WebHistoryItem item = webkit_glue::HistoryItemFromString( | 305 const WebKit::WebHistoryItem item = PageStateToHistoryItem( |
| 306 host_nav_params.a.content_state); | 306 host_nav_params.a.page_state); |
| 307 WebKit::WebHTTPBody body = item.httpBody(); | 307 WebKit::WebHTTPBody body = item.httpBody(); |
| 308 WebKit::WebHTTPBody::Element element; | 308 WebKit::WebHTTPBody::Element element; |
| 309 bool successful = body.elementAt(0, element); | 309 bool successful = body.elementAt(0, element); |
| 310 EXPECT_TRUE(successful); | 310 EXPECT_TRUE(successful); |
| 311 EXPECT_EQ(WebKit::WebHTTPBody::Element::TypeData, element.type); | 311 EXPECT_EQ(WebKit::WebHTTPBody::Element::TypeData, element.type); |
| 312 EXPECT_EQ(length, element.data.size()); | 312 EXPECT_EQ(length, element.data.size()); |
| 313 EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length)); | 313 EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length)); |
| 314 } | 314 } |
| 315 | 315 |
| 316 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { | 316 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 480 |
| 481 // Load page B, which will trigger an UpdateState message for page A. | 481 // Load page B, which will trigger an UpdateState message for page A. |
| 482 LoadHTML("<div>Page B</div>"); | 482 LoadHTML("<div>Page B</div>"); |
| 483 | 483 |
| 484 // Check for a valid UpdateState message for page A. | 484 // Check for a valid UpdateState message for page A. |
| 485 ProcessPendingMessages(); | 485 ProcessPendingMessages(); |
| 486 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 486 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
| 487 ViewHostMsg_UpdateState::ID); | 487 ViewHostMsg_UpdateState::ID); |
| 488 ASSERT_TRUE(msg_A); | 488 ASSERT_TRUE(msg_A); |
| 489 int page_id_A; | 489 int page_id_A; |
| 490 std::string state_A; | 490 PageState state_A; |
| 491 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); | 491 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); |
| 492 EXPECT_EQ(1, page_id_A); | 492 EXPECT_EQ(1, page_id_A); |
| 493 render_thread_->sink().ClearMessages(); | 493 render_thread_->sink().ClearMessages(); |
| 494 | 494 |
| 495 // Back to page A (page_id 1) and commit. | 495 // Back to page A (page_id 1) and commit. |
| 496 ViewMsg_Navigate_Params params_A; | 496 ViewMsg_Navigate_Params params_A; |
| 497 params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 497 params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 498 params_A.transition = PAGE_TRANSITION_FORWARD_BACK; | 498 params_A.transition = PAGE_TRANSITION_FORWARD_BACK; |
| 499 params_A.current_history_list_length = 2; | 499 params_A.current_history_list_length = 2; |
| 500 params_A.current_history_list_offset = 1; | 500 params_A.current_history_list_offset = 1; |
| 501 params_A.pending_history_list_offset = 0; | 501 params_A.pending_history_list_offset = 0; |
| 502 params_A.page_id = 1; | 502 params_A.page_id = 1; |
| 503 params_A.state = state_A; | 503 params_A.page_state = state_A; |
| 504 view()->OnNavigate(params_A); | 504 view()->OnNavigate(params_A); |
| 505 ProcessPendingMessages(); | 505 ProcessPendingMessages(); |
| 506 | 506 |
| 507 // Respond to a swap out request. | 507 // Respond to a swap out request. |
| 508 ViewMsg_SwapOut_Params params; | 508 ViewMsg_SwapOut_Params params; |
| 509 params.closing_process_id = 10; | 509 params.closing_process_id = 10; |
| 510 params.closing_route_id = 11; | 510 params.closing_route_id = 11; |
| 511 params.new_render_process_host_id = 12; | 511 params.new_render_process_host_id = 12; |
| 512 params.new_request_id = 13; | 512 params.new_request_id = 13; |
| 513 view()->OnSwapOut(params); | 513 view()->OnSwapOut(params); |
| 514 | 514 |
| 515 // Check for a OnSwapOutACK. | 515 // Check for a OnSwapOutACK. |
| 516 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 516 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
| 517 ViewHostMsg_SwapOut_ACK::ID); | 517 ViewHostMsg_SwapOut_ACK::ID); |
| 518 ASSERT_TRUE(msg); | 518 ASSERT_TRUE(msg); |
| 519 render_thread_->sink().ClearMessages(); | 519 render_thread_->sink().ClearMessages(); |
| 520 | 520 |
| 521 // It is possible to get a reload request at this point, containing the | 521 // It is possible to get a reload request at this point, containing the |
| 522 // params.state of the initial page (e.g., if the new page fails the | 522 // params.page_state of the initial page (e.g., if the new page fails the |
| 523 // provisional load in the renderer process, after we unload the old page). | 523 // provisional load in the renderer process, after we unload the old page). |
| 524 // Ensure the old page gets reloaded, not swappedout://. | 524 // Ensure the old page gets reloaded, not swappedout://. |
| 525 ViewMsg_Navigate_Params nav_params; | 525 ViewMsg_Navigate_Params nav_params; |
| 526 nav_params.url = GURL("data:text/html,<div>Page A</div>"); | 526 nav_params.url = GURL("data:text/html,<div>Page A</div>"); |
| 527 nav_params.navigation_type = ViewMsg_Navigate_Type::RELOAD; | 527 nav_params.navigation_type = ViewMsg_Navigate_Type::RELOAD; |
| 528 nav_params.transition = PAGE_TRANSITION_RELOAD; | 528 nav_params.transition = PAGE_TRANSITION_RELOAD; |
| 529 nav_params.current_history_list_length = 2; | 529 nav_params.current_history_list_length = 2; |
| 530 nav_params.current_history_list_offset = 0; | 530 nav_params.current_history_list_offset = 0; |
| 531 nav_params.pending_history_list_offset = 0; | 531 nav_params.pending_history_list_offset = 0; |
| 532 nav_params.page_id = 1; | 532 nav_params.page_id = 1; |
| 533 nav_params.state = state_A; | 533 nav_params.page_state = state_A; |
| 534 view()->OnNavigate(nav_params); | 534 view()->OnNavigate(nav_params); |
| 535 ProcessPendingMessages(); | 535 ProcessPendingMessages(); |
| 536 | 536 |
| 537 // Verify page A committed, not swappedout://. | 537 // Verify page A committed, not swappedout://. |
| 538 const IPC::Message* frame_navigate_msg = | 538 const IPC::Message* frame_navigate_msg = |
| 539 render_thread_->sink().GetUniqueMessageMatching( | 539 render_thread_->sink().GetUniqueMessageMatching( |
| 540 ViewHostMsg_FrameNavigate::ID); | 540 ViewHostMsg_FrameNavigate::ID); |
| 541 EXPECT_TRUE(frame_navigate_msg); | 541 EXPECT_TRUE(frame_navigate_msg); |
| 542 | 542 |
| 543 // Read URL out of the parent trait of the params object. | 543 // Read URL out of the parent trait of the params object. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 556 | 556 |
| 557 // Load page B, which will trigger an UpdateState message for page A. | 557 // Load page B, which will trigger an UpdateState message for page A. |
| 558 LoadHTML("<div>Page B</div>"); | 558 LoadHTML("<div>Page B</div>"); |
| 559 | 559 |
| 560 // Check for a valid UpdateState message for page A. | 560 // Check for a valid UpdateState message for page A. |
| 561 ProcessPendingMessages(); | 561 ProcessPendingMessages(); |
| 562 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 562 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
| 563 ViewHostMsg_UpdateState::ID); | 563 ViewHostMsg_UpdateState::ID); |
| 564 ASSERT_TRUE(msg_A); | 564 ASSERT_TRUE(msg_A); |
| 565 int page_id_A; | 565 int page_id_A; |
| 566 std::string state_A; | 566 PageState state_A; |
| 567 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); | 567 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); |
| 568 EXPECT_EQ(1, page_id_A); | 568 EXPECT_EQ(1, page_id_A); |
| 569 render_thread_->sink().ClearMessages(); | 569 render_thread_->sink().ClearMessages(); |
| 570 | 570 |
| 571 // Load page C, which will trigger an UpdateState message for page B. | 571 // Load page C, which will trigger an UpdateState message for page B. |
| 572 LoadHTML("<div>Page C</div>"); | 572 LoadHTML("<div>Page C</div>"); |
| 573 | 573 |
| 574 // Check for a valid UpdateState for page B. | 574 // Check for a valid UpdateState for page B. |
| 575 ProcessPendingMessages(); | 575 ProcessPendingMessages(); |
| 576 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( | 576 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( |
| 577 ViewHostMsg_UpdateState::ID); | 577 ViewHostMsg_UpdateState::ID); |
| 578 ASSERT_TRUE(msg_B); | 578 ASSERT_TRUE(msg_B); |
| 579 int page_id_B; | 579 int page_id_B; |
| 580 std::string state_B; | 580 PageState state_B; |
| 581 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); | 581 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); |
| 582 EXPECT_EQ(2, page_id_B); | 582 EXPECT_EQ(2, page_id_B); |
| 583 EXPECT_NE(state_A, state_B); | 583 EXPECT_NE(state_A, state_B); |
| 584 render_thread_->sink().ClearMessages(); | 584 render_thread_->sink().ClearMessages(); |
| 585 | 585 |
| 586 // Load page D, which will trigger an UpdateState message for page C. | 586 // Load page D, which will trigger an UpdateState message for page C. |
| 587 LoadHTML("<div>Page D</div>"); | 587 LoadHTML("<div>Page D</div>"); |
| 588 | 588 |
| 589 // Check for a valid UpdateState for page C. | 589 // Check for a valid UpdateState for page C. |
| 590 ProcessPendingMessages(); | 590 ProcessPendingMessages(); |
| 591 const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching( | 591 const IPC::Message* msg_C = render_thread_->sink().GetUniqueMessageMatching( |
| 592 ViewHostMsg_UpdateState::ID); | 592 ViewHostMsg_UpdateState::ID); |
| 593 ASSERT_TRUE(msg_C); | 593 ASSERT_TRUE(msg_C); |
| 594 int page_id_C; | 594 int page_id_C; |
| 595 std::string state_C; | 595 PageState state_C; |
| 596 ViewHostMsg_UpdateState::Read(msg_C, &page_id_C, &state_C); | 596 ViewHostMsg_UpdateState::Read(msg_C, &page_id_C, &state_C); |
| 597 EXPECT_EQ(3, page_id_C); | 597 EXPECT_EQ(3, page_id_C); |
| 598 EXPECT_NE(state_B, state_C); | 598 EXPECT_NE(state_B, state_C); |
| 599 render_thread_->sink().ClearMessages(); | 599 render_thread_->sink().ClearMessages(); |
| 600 | 600 |
| 601 // Go back to C and commit, preparing for our real test. | 601 // Go back to C and commit, preparing for our real test. |
| 602 ViewMsg_Navigate_Params params_C; | 602 ViewMsg_Navigate_Params params_C; |
| 603 params_C.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 603 params_C.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 604 params_C.transition = PAGE_TRANSITION_FORWARD_BACK; | 604 params_C.transition = PAGE_TRANSITION_FORWARD_BACK; |
| 605 params_C.current_history_list_length = 4; | 605 params_C.current_history_list_length = 4; |
| 606 params_C.current_history_list_offset = 3; | 606 params_C.current_history_list_offset = 3; |
| 607 params_C.pending_history_list_offset = 2; | 607 params_C.pending_history_list_offset = 2; |
| 608 params_C.page_id = 3; | 608 params_C.page_id = 3; |
| 609 params_C.state = state_C; | 609 params_C.page_state = state_C; |
| 610 view()->OnNavigate(params_C); | 610 view()->OnNavigate(params_C); |
| 611 ProcessPendingMessages(); | 611 ProcessPendingMessages(); |
| 612 render_thread_->sink().ClearMessages(); | 612 render_thread_->sink().ClearMessages(); |
| 613 | 613 |
| 614 // Go back twice quickly, such that page B does not have a chance to commit. | 614 // Go back twice quickly, such that page B does not have a chance to commit. |
| 615 // This leads to two changes to the back/forward list but only one change to | 615 // This leads to two changes to the back/forward list but only one change to |
| 616 // the RenderView's page ID. | 616 // the RenderView's page ID. |
| 617 | 617 |
| 618 // Back to page B (page_id 2), without committing. | 618 // Back to page B (page_id 2), without committing. |
| 619 ViewMsg_Navigate_Params params_B; | 619 ViewMsg_Navigate_Params params_B; |
| 620 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 620 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 621 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; | 621 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; |
| 622 params_B.current_history_list_length = 4; | 622 params_B.current_history_list_length = 4; |
| 623 params_B.current_history_list_offset = 2; | 623 params_B.current_history_list_offset = 2; |
| 624 params_B.pending_history_list_offset = 1; | 624 params_B.pending_history_list_offset = 1; |
| 625 params_B.page_id = 2; | 625 params_B.page_id = 2; |
| 626 params_B.state = state_B; | 626 params_B.page_state = state_B; |
| 627 view()->OnNavigate(params_B); | 627 view()->OnNavigate(params_B); |
| 628 | 628 |
| 629 // Back to page A (page_id 1) and commit. | 629 // Back to page A (page_id 1) and commit. |
| 630 ViewMsg_Navigate_Params params; | 630 ViewMsg_Navigate_Params params; |
| 631 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 631 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 632 params.transition = PAGE_TRANSITION_FORWARD_BACK; | 632 params.transition = PAGE_TRANSITION_FORWARD_BACK; |
| 633 params_B.current_history_list_length = 4; | 633 params_B.current_history_list_length = 4; |
| 634 params_B.current_history_list_offset = 2; | 634 params_B.current_history_list_offset = 2; |
| 635 params_B.pending_history_list_offset = 0; | 635 params_B.pending_history_list_offset = 0; |
| 636 params.page_id = 1; | 636 params.page_id = 1; |
| 637 params.state = state_A; | 637 params.page_state = state_A; |
| 638 view()->OnNavigate(params); | 638 view()->OnNavigate(params); |
| 639 ProcessPendingMessages(); | 639 ProcessPendingMessages(); |
| 640 | 640 |
| 641 // Now ensure that the UpdateState message we receive is consistent | 641 // Now ensure that the UpdateState message we receive is consistent |
| 642 // and represents page C in both page_id and state. | 642 // and represents page C in both page_id and state. |
| 643 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 643 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
| 644 ViewHostMsg_UpdateState::ID); | 644 ViewHostMsg_UpdateState::ID); |
| 645 ASSERT_TRUE(msg); | 645 ASSERT_TRUE(msg); |
| 646 int page_id; | 646 int page_id; |
| 647 std::string state; | 647 PageState state; |
| 648 ViewHostMsg_UpdateState::Read(msg, &page_id, &state); | 648 ViewHostMsg_UpdateState::Read(msg, &page_id, &state); |
| 649 EXPECT_EQ(page_id_C, page_id); | 649 EXPECT_EQ(page_id_C, page_id); |
| 650 EXPECT_NE(state_A, state); | 650 EXPECT_NE(state_A, state); |
| 651 EXPECT_NE(state_B, state); | 651 EXPECT_NE(state_B, state); |
| 652 EXPECT_EQ(state_C, state); | 652 EXPECT_EQ(state_C, state); |
| 653 } | 653 } |
| 654 | 654 |
| 655 // Test that the history_page_ids_ list can reveal when a stale back/forward | 655 // Test that the history_page_ids_ list can reveal when a stale back/forward |
| 656 // navigation arrives from the browser and can be ignored. See | 656 // navigation arrives from the browser and can be ignored. See |
| 657 // http://crbug.com/86758. | 657 // http://crbug.com/86758. |
| 658 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { | 658 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { |
| 659 // Load page A. | 659 // Load page A. |
| 660 LoadHTML("<div>Page A</div>"); | 660 LoadHTML("<div>Page A</div>"); |
| 661 EXPECT_EQ(1, view()->history_list_length_); | 661 EXPECT_EQ(1, view()->history_list_length_); |
| 662 EXPECT_EQ(0, view()->history_list_offset_); | 662 EXPECT_EQ(0, view()->history_list_offset_); |
| 663 EXPECT_EQ(1, view()->history_page_ids_[0]); | 663 EXPECT_EQ(1, view()->history_page_ids_[0]); |
| 664 | 664 |
| 665 // Load page B, which will trigger an UpdateState message for page A. | 665 // Load page B, which will trigger an UpdateState message for page A. |
| 666 LoadHTML("<div>Page B</div>"); | 666 LoadHTML("<div>Page B</div>"); |
| 667 EXPECT_EQ(2, view()->history_list_length_); | 667 EXPECT_EQ(2, view()->history_list_length_); |
| 668 EXPECT_EQ(1, view()->history_list_offset_); | 668 EXPECT_EQ(1, view()->history_list_offset_); |
| 669 EXPECT_EQ(2, view()->history_page_ids_[1]); | 669 EXPECT_EQ(2, view()->history_page_ids_[1]); |
| 670 | 670 |
| 671 // Check for a valid UpdateState message for page A. | 671 // Check for a valid UpdateState message for page A. |
| 672 ProcessPendingMessages(); | 672 ProcessPendingMessages(); |
| 673 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 673 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
| 674 ViewHostMsg_UpdateState::ID); | 674 ViewHostMsg_UpdateState::ID); |
| 675 ASSERT_TRUE(msg_A); | 675 ASSERT_TRUE(msg_A); |
| 676 int page_id_A; | 676 int page_id_A; |
| 677 std::string state_A; | 677 PageState state_A; |
| 678 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); | 678 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); |
| 679 EXPECT_EQ(1, page_id_A); | 679 EXPECT_EQ(1, page_id_A); |
| 680 render_thread_->sink().ClearMessages(); | 680 render_thread_->sink().ClearMessages(); |
| 681 | 681 |
| 682 // Back to page A (page_id 1) and commit. | 682 // Back to page A (page_id 1) and commit. |
| 683 ViewMsg_Navigate_Params params_A; | 683 ViewMsg_Navigate_Params params_A; |
| 684 params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 684 params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 685 params_A.transition = PAGE_TRANSITION_FORWARD_BACK; | 685 params_A.transition = PAGE_TRANSITION_FORWARD_BACK; |
| 686 params_A.current_history_list_length = 2; | 686 params_A.current_history_list_length = 2; |
| 687 params_A.current_history_list_offset = 1; | 687 params_A.current_history_list_offset = 1; |
| 688 params_A.pending_history_list_offset = 0; | 688 params_A.pending_history_list_offset = 0; |
| 689 params_A.page_id = 1; | 689 params_A.page_id = 1; |
| 690 params_A.state = state_A; | 690 params_A.page_state = state_A; |
| 691 view()->OnNavigate(params_A); | 691 view()->OnNavigate(params_A); |
| 692 ProcessPendingMessages(); | 692 ProcessPendingMessages(); |
| 693 | 693 |
| 694 // A new navigation commits, clearing the forward history. | 694 // A new navigation commits, clearing the forward history. |
| 695 LoadHTML("<div>Page C</div>"); | 695 LoadHTML("<div>Page C</div>"); |
| 696 EXPECT_EQ(2, view()->history_list_length_); | 696 EXPECT_EQ(2, view()->history_list_length_); |
| 697 EXPECT_EQ(1, view()->history_list_offset_); | 697 EXPECT_EQ(1, view()->history_list_offset_); |
| 698 EXPECT_EQ(3, view()->history_page_ids_[1]); | 698 EXPECT_EQ(3, view()->history_page_ids_[1]); |
| 699 | 699 |
| 700 // The browser then sends a stale navigation to B, which should be ignored. | 700 // The browser then sends a stale navigation to B, which should be ignored. |
| 701 ViewMsg_Navigate_Params params_B; | 701 ViewMsg_Navigate_Params params_B; |
| 702 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 702 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 703 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; | 703 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; |
| 704 params_B.current_history_list_length = 2; | 704 params_B.current_history_list_length = 2; |
| 705 params_B.current_history_list_offset = 0; | 705 params_B.current_history_list_offset = 0; |
| 706 params_B.pending_history_list_offset = 1; | 706 params_B.pending_history_list_offset = 1; |
| 707 params_B.page_id = 2; | 707 params_B.page_id = 2; |
| 708 params_B.state = state_A; // Doesn't matter, just has to be present. | 708 params_B.page_state = state_A; // Doesn't matter, just has to be present. |
| 709 view()->OnNavigate(params_B); | 709 view()->OnNavigate(params_B); |
| 710 | 710 |
| 711 // State should be unchanged. | 711 // State should be unchanged. |
| 712 EXPECT_EQ(2, view()->history_list_length_); | 712 EXPECT_EQ(2, view()->history_list_length_); |
| 713 EXPECT_EQ(1, view()->history_list_offset_); | 713 EXPECT_EQ(1, view()->history_list_offset_); |
| 714 EXPECT_EQ(3, view()->history_page_ids_[1]); | 714 EXPECT_EQ(3, view()->history_page_ids_[1]); |
| 715 } | 715 } |
| 716 | 716 |
| 717 // Test that we do not ignore navigations after the entry limit is reached, | 717 // Test that we do not ignore navigations after the entry limit is reached, |
| 718 // in which case the browser starts dropping entries from the front. In this | 718 // in which case the browser starts dropping entries from the front. In this |
| (...skipping 13 matching lines...) Expand all Loading... |
| 732 EXPECT_EQ(2, view()->history_list_length_); | 732 EXPECT_EQ(2, view()->history_list_length_); |
| 733 EXPECT_EQ(1, view()->history_list_offset_); | 733 EXPECT_EQ(1, view()->history_list_offset_); |
| 734 EXPECT_EQ(2, view()->history_page_ids_[1]); | 734 EXPECT_EQ(2, view()->history_page_ids_[1]); |
| 735 | 735 |
| 736 // Check for a valid UpdateState message for page A. | 736 // Check for a valid UpdateState message for page A. |
| 737 ProcessPendingMessages(); | 737 ProcessPendingMessages(); |
| 738 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 738 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
| 739 ViewHostMsg_UpdateState::ID); | 739 ViewHostMsg_UpdateState::ID); |
| 740 ASSERT_TRUE(msg_A); | 740 ASSERT_TRUE(msg_A); |
| 741 int page_id_A; | 741 int page_id_A; |
| 742 std::string state_A; | 742 PageState state_A; |
| 743 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); | 743 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); |
| 744 EXPECT_EQ(1, page_id_A); | 744 EXPECT_EQ(1, page_id_A); |
| 745 render_thread_->sink().ClearMessages(); | 745 render_thread_->sink().ClearMessages(); |
| 746 | 746 |
| 747 // Load page C, which will trigger an UpdateState message for page B. | 747 // Load page C, which will trigger an UpdateState message for page B. |
| 748 LoadHTML("<div>Page C</div>"); | 748 LoadHTML("<div>Page C</div>"); |
| 749 EXPECT_EQ(3, view()->history_list_length_); | 749 EXPECT_EQ(3, view()->history_list_length_); |
| 750 EXPECT_EQ(2, view()->history_list_offset_); | 750 EXPECT_EQ(2, view()->history_list_offset_); |
| 751 EXPECT_EQ(3, view()->history_page_ids_[2]); | 751 EXPECT_EQ(3, view()->history_page_ids_[2]); |
| 752 | 752 |
| 753 // Check for a valid UpdateState message for page B. | 753 // Check for a valid UpdateState message for page B. |
| 754 ProcessPendingMessages(); | 754 ProcessPendingMessages(); |
| 755 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( | 755 const IPC::Message* msg_B = render_thread_->sink().GetUniqueMessageMatching( |
| 756 ViewHostMsg_UpdateState::ID); | 756 ViewHostMsg_UpdateState::ID); |
| 757 ASSERT_TRUE(msg_B); | 757 ASSERT_TRUE(msg_B); |
| 758 int page_id_B; | 758 int page_id_B; |
| 759 std::string state_B; | 759 PageState state_B; |
| 760 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); | 760 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); |
| 761 EXPECT_EQ(2, page_id_B); | 761 EXPECT_EQ(2, page_id_B); |
| 762 render_thread_->sink().ClearMessages(); | 762 render_thread_->sink().ClearMessages(); |
| 763 | 763 |
| 764 // Suppose the browser has limited the number of NavigationEntries to 2. | 764 // Suppose the browser has limited the number of NavigationEntries to 2. |
| 765 // It has now dropped the first entry, but the renderer isn't notified. | 765 // It has now dropped the first entry, but the renderer isn't notified. |
| 766 // Ensure that going back to page B (page_id 2) at offset 0 is successful. | 766 // Ensure that going back to page B (page_id 2) at offset 0 is successful. |
| 767 ViewMsg_Navigate_Params params_B; | 767 ViewMsg_Navigate_Params params_B; |
| 768 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 768 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 769 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; | 769 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; |
| 770 params_B.current_history_list_length = 2; | 770 params_B.current_history_list_length = 2; |
| 771 params_B.current_history_list_offset = 1; | 771 params_B.current_history_list_offset = 1; |
| 772 params_B.pending_history_list_offset = 0; | 772 params_B.pending_history_list_offset = 0; |
| 773 params_B.page_id = 2; | 773 params_B.page_id = 2; |
| 774 params_B.state = state_B; | 774 params_B.page_state = state_B; |
| 775 view()->OnNavigate(params_B); | 775 view()->OnNavigate(params_B); |
| 776 ProcessPendingMessages(); | 776 ProcessPendingMessages(); |
| 777 | 777 |
| 778 EXPECT_EQ(2, view()->history_list_length_); | 778 EXPECT_EQ(2, view()->history_list_length_); |
| 779 EXPECT_EQ(0, view()->history_list_offset_); | 779 EXPECT_EQ(0, view()->history_list_offset_); |
| 780 EXPECT_EQ(2, view()->history_page_ids_[0]); | 780 EXPECT_EQ(2, view()->history_page_ids_[0]); |
| 781 } | 781 } |
| 782 | 782 |
| 783 // Test that our IME backend sends a notification message when the input focus | 783 // Test that our IME backend sends a notification message when the input focus |
| 784 // changes. | 784 // changes. |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 | 1849 |
| 1850 // Copy the document content to std::wstring and compare with the | 1850 // Copy the document content to std::wstring and compare with the |
| 1851 // expected result. | 1851 // expected result. |
| 1852 const int kMaxOutputCharacters = 256; | 1852 const int kMaxOutputCharacters = 256; |
| 1853 std::wstring output = UTF16ToWideHack( | 1853 std::wstring output = UTF16ToWideHack( |
| 1854 GetMainFrame()->contentAsText(kMaxOutputCharacters)); | 1854 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
| 1855 EXPECT_EQ(output, L"hello \n\nworld"); | 1855 EXPECT_EQ(output, L"hello \n\nworld"); |
| 1856 } | 1856 } |
| 1857 | 1857 |
| 1858 } // namespace content | 1858 } // namespace content |
| OLD | NEW |