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 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 324 |
325 // Change the value of the input. We should have gotten an update state | 325 // Change the value of the input. We should have gotten an update state |
326 // notification. We need to spin the message loop to catch this update. | 326 // notification. We need to spin the message loop to catch this update. |
327 ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); | 327 ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); |
328 ProcessPendingMessages(); | 328 ProcessPendingMessages(); |
329 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( | 329 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( |
330 ViewHostMsg_UpdateState::ID)); | 330 ViewHostMsg_UpdateState::ID)); |
331 } | 331 } |
332 | 332 |
333 TEST_F(RenderViewImplTest, OnNavigationHttpPost) { | 333 TEST_F(RenderViewImplTest, OnNavigationHttpPost) { |
334 ViewMsg_Navigate_Params nav_params; | 334 FrameMsg_Navigate_Params nav_params; |
335 | 335 |
336 // An http url will trigger a resource load so cannot be used here. | 336 // An http url will trigger a resource load so cannot be used here. |
337 nav_params.url = GURL("data:text/html,<div>Page</div>"); | 337 nav_params.url = GURL("data:text/html,<div>Page</div>"); |
338 nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 338 nav_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
339 nav_params.transition = PAGE_TRANSITION_TYPED; | 339 nav_params.transition = PAGE_TRANSITION_TYPED; |
340 nav_params.page_id = -1; | 340 nav_params.page_id = -1; |
341 nav_params.is_post = true; | 341 nav_params.is_post = true; |
342 | 342 |
343 // Set up post data. | 343 // Set up post data. |
344 const unsigned char* raw_data = reinterpret_cast<const unsigned char*>( | 344 const unsigned char* raw_data = reinterpret_cast<const unsigned char*>( |
345 "post \0\ndata"); | 345 "post \0\ndata"); |
346 const unsigned int length = 11; | 346 const unsigned int length = 11; |
347 const std::vector<unsigned char> post_data(raw_data, raw_data + length); | 347 const std::vector<unsigned char> post_data(raw_data, raw_data + length); |
348 nav_params.browser_initiated_post_data = post_data; | 348 nav_params.browser_initiated_post_data = post_data; |
349 | 349 |
350 view()->OnNavigate(nav_params); | 350 frame()->OnNavigate(nav_params); |
351 ProcessPendingMessages(); | 351 ProcessPendingMessages(); |
352 | 352 |
353 const IPC::Message* frame_navigate_msg = | 353 const IPC::Message* frame_navigate_msg = |
354 render_thread_->sink().GetUniqueMessageMatching( | 354 render_thread_->sink().GetUniqueMessageMatching( |
355 FrameHostMsg_DidCommitProvisionalLoad::ID); | 355 FrameHostMsg_DidCommitProvisionalLoad::ID); |
356 EXPECT_TRUE(frame_navigate_msg); | 356 EXPECT_TRUE(frame_navigate_msg); |
357 | 357 |
358 FrameHostMsg_DidCommitProvisionalLoad::Param host_nav_params; | 358 FrameHostMsg_DidCommitProvisionalLoad::Param host_nav_params; |
359 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg, | 359 FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg, |
360 &host_nav_params); | 360 &host_nav_params); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 // It is possible to get another swap out request. Ensure that we send | 529 // It is possible to get another swap out request. Ensure that we send |
530 // an ACK, even if we don't have to do anything else. | 530 // an ACK, even if we don't have to do anything else. |
531 render_thread_->sink().ClearMessages(); | 531 render_thread_->sink().ClearMessages(); |
532 view()->OnSwapOut(); | 532 view()->OnSwapOut(); |
533 const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching( | 533 const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching( |
534 ViewHostMsg_SwapOut_ACK::ID); | 534 ViewHostMsg_SwapOut_ACK::ID); |
535 ASSERT_TRUE(msg2); | 535 ASSERT_TRUE(msg2); |
536 | 536 |
537 // If we navigate back to this RenderView, ensure we don't send a state | 537 // If we navigate back to this RenderView, ensure we don't send a state |
538 // update for the swapped out URL. (http://crbug.com/72235) | 538 // update for the swapped out URL. (http://crbug.com/72235) |
539 ViewMsg_Navigate_Params nav_params; | 539 FrameMsg_Navigate_Params nav_params; |
540 nav_params.url = GURL("data:text/html,<div>Page B</div>"); | 540 nav_params.url = GURL("data:text/html,<div>Page B</div>"); |
541 nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 541 nav_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
542 nav_params.transition = PAGE_TRANSITION_TYPED; | 542 nav_params.transition = PAGE_TRANSITION_TYPED; |
543 nav_params.current_history_list_length = 1; | 543 nav_params.current_history_list_length = 1; |
544 nav_params.current_history_list_offset = 0; | 544 nav_params.current_history_list_offset = 0; |
545 nav_params.pending_history_list_offset = 1; | 545 nav_params.pending_history_list_offset = 1; |
546 nav_params.page_id = -1; | 546 nav_params.page_id = -1; |
547 view()->OnNavigate(nav_params); | 547 frame()->OnNavigate(nav_params); |
548 ProcessPendingMessages(); | 548 ProcessPendingMessages(); |
549 const IPC::Message* msg3 = render_thread_->sink().GetUniqueMessageMatching( | 549 const IPC::Message* msg3 = render_thread_->sink().GetUniqueMessageMatching( |
550 ViewHostMsg_UpdateState::ID); | 550 ViewHostMsg_UpdateState::ID); |
551 EXPECT_FALSE(msg3); | 551 EXPECT_FALSE(msg3); |
552 } | 552 } |
553 | 553 |
554 // Ensure the RenderViewImpl reloads the previous page if a reload request | 554 // Ensure the RenderViewImpl reloads the previous page if a reload request |
555 // arrives while it is showing swappedout://. http://crbug.com/143155. | 555 // arrives while it is showing swappedout://. http://crbug.com/143155. |
556 TEST_F(RenderViewImplTest, ReloadWhileSwappedOut) { | 556 TEST_F(RenderViewImplTest, ReloadWhileSwappedOut) { |
557 // Load page A. | 557 // Load page A. |
558 LoadHTML("<div>Page A</div>"); | 558 LoadHTML("<div>Page A</div>"); |
559 | 559 |
560 // Load page B, which will trigger an UpdateState message for page A. | 560 // Load page B, which will trigger an UpdateState message for page A. |
561 LoadHTML("<div>Page B</div>"); | 561 LoadHTML("<div>Page B</div>"); |
562 | 562 |
563 // Check for a valid UpdateState message for page A. | 563 // Check for a valid UpdateState message for page A. |
564 ProcessPendingMessages(); | 564 ProcessPendingMessages(); |
565 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 565 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
566 ViewHostMsg_UpdateState::ID); | 566 ViewHostMsg_UpdateState::ID); |
567 ASSERT_TRUE(msg_A); | 567 ASSERT_TRUE(msg_A); |
568 int page_id_A; | 568 int page_id_A; |
569 PageState state_A; | 569 PageState state_A; |
570 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); | 570 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); |
571 EXPECT_EQ(1, page_id_A); | 571 EXPECT_EQ(1, page_id_A); |
572 render_thread_->sink().ClearMessages(); | 572 render_thread_->sink().ClearMessages(); |
573 | 573 |
574 // Back to page A (page_id 1) and commit. | 574 // Back to page A (page_id 1) and commit. |
575 ViewMsg_Navigate_Params params_A; | 575 FrameMsg_Navigate_Params params_A; |
576 params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 576 params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
577 params_A.transition = PAGE_TRANSITION_FORWARD_BACK; | 577 params_A.transition = PAGE_TRANSITION_FORWARD_BACK; |
578 params_A.current_history_list_length = 2; | 578 params_A.current_history_list_length = 2; |
579 params_A.current_history_list_offset = 1; | 579 params_A.current_history_list_offset = 1; |
580 params_A.pending_history_list_offset = 0; | 580 params_A.pending_history_list_offset = 0; |
581 params_A.page_id = 1; | 581 params_A.page_id = 1; |
582 params_A.page_state = state_A; | 582 params_A.page_state = state_A; |
583 view()->OnNavigate(params_A); | 583 frame()->OnNavigate(params_A); |
584 ProcessPendingMessages(); | 584 ProcessPendingMessages(); |
585 | 585 |
586 // Respond to a swap out request. | 586 // Respond to a swap out request. |
587 view()->OnSwapOut(); | 587 view()->OnSwapOut(); |
588 | 588 |
589 // Check for a OnSwapOutACK. | 589 // Check for a OnSwapOutACK. |
590 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 590 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
591 ViewHostMsg_SwapOut_ACK::ID); | 591 ViewHostMsg_SwapOut_ACK::ID); |
592 ASSERT_TRUE(msg); | 592 ASSERT_TRUE(msg); |
593 render_thread_->sink().ClearMessages(); | 593 render_thread_->sink().ClearMessages(); |
594 | 594 |
595 // It is possible to get a reload request at this point, containing the | 595 // It is possible to get a reload request at this point, containing the |
596 // params.page_state of the initial page (e.g., if the new page fails the | 596 // params.page_state of the initial page (e.g., if the new page fails the |
597 // provisional load in the renderer process, after we unload the old page). | 597 // provisional load in the renderer process, after we unload the old page). |
598 // Ensure the old page gets reloaded, not swappedout://. | 598 // Ensure the old page gets reloaded, not swappedout://. |
599 ViewMsg_Navigate_Params nav_params; | 599 FrameMsg_Navigate_Params nav_params; |
600 nav_params.url = GURL("data:text/html,<div>Page A</div>"); | 600 nav_params.url = GURL("data:text/html,<div>Page A</div>"); |
601 nav_params.navigation_type = ViewMsg_Navigate_Type::RELOAD; | 601 nav_params.navigation_type = FrameMsg_Navigate_Type::RELOAD; |
602 nav_params.transition = PAGE_TRANSITION_RELOAD; | 602 nav_params.transition = PAGE_TRANSITION_RELOAD; |
603 nav_params.current_history_list_length = 2; | 603 nav_params.current_history_list_length = 2; |
604 nav_params.current_history_list_offset = 0; | 604 nav_params.current_history_list_offset = 0; |
605 nav_params.pending_history_list_offset = 0; | 605 nav_params.pending_history_list_offset = 0; |
606 nav_params.page_id = 1; | 606 nav_params.page_id = 1; |
607 nav_params.page_state = state_A; | 607 nav_params.page_state = state_A; |
608 view()->OnNavigate(nav_params); | 608 frame()->OnNavigate(nav_params); |
609 ProcessPendingMessages(); | 609 ProcessPendingMessages(); |
610 | 610 |
611 // Verify page A committed, not swappedout://. | 611 // Verify page A committed, not swappedout://. |
612 const IPC::Message* frame_navigate_msg = | 612 const IPC::Message* frame_navigate_msg = |
613 render_thread_->sink().GetUniqueMessageMatching( | 613 render_thread_->sink().GetUniqueMessageMatching( |
614 FrameHostMsg_DidCommitProvisionalLoad::ID); | 614 FrameHostMsg_DidCommitProvisionalLoad::ID); |
615 EXPECT_TRUE(frame_navigate_msg); | 615 EXPECT_TRUE(frame_navigate_msg); |
616 | 616 |
617 // Read URL out of the parent trait of the params object. | 617 // Read URL out of the parent trait of the params object. |
618 FrameHostMsg_DidCommitProvisionalLoad::Param commit_params; | 618 FrameHostMsg_DidCommitProvisionalLoad::Param commit_params; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 ViewHostMsg_UpdateState::ID); | 667 ViewHostMsg_UpdateState::ID); |
668 ASSERT_TRUE(msg_C); | 668 ASSERT_TRUE(msg_C); |
669 int page_id_C; | 669 int page_id_C; |
670 PageState state_C; | 670 PageState state_C; |
671 ViewHostMsg_UpdateState::Read(msg_C, &page_id_C, &state_C); | 671 ViewHostMsg_UpdateState::Read(msg_C, &page_id_C, &state_C); |
672 EXPECT_EQ(3, page_id_C); | 672 EXPECT_EQ(3, page_id_C); |
673 EXPECT_NE(state_B, state_C); | 673 EXPECT_NE(state_B, state_C); |
674 render_thread_->sink().ClearMessages(); | 674 render_thread_->sink().ClearMessages(); |
675 | 675 |
676 // Go back to C and commit, preparing for our real test. | 676 // Go back to C and commit, preparing for our real test. |
677 ViewMsg_Navigate_Params params_C; | 677 FrameMsg_Navigate_Params params_C; |
678 params_C.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 678 params_C.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
679 params_C.transition = PAGE_TRANSITION_FORWARD_BACK; | 679 params_C.transition = PAGE_TRANSITION_FORWARD_BACK; |
680 params_C.current_history_list_length = 4; | 680 params_C.current_history_list_length = 4; |
681 params_C.current_history_list_offset = 3; | 681 params_C.current_history_list_offset = 3; |
682 params_C.pending_history_list_offset = 2; | 682 params_C.pending_history_list_offset = 2; |
683 params_C.page_id = 3; | 683 params_C.page_id = 3; |
684 params_C.page_state = state_C; | 684 params_C.page_state = state_C; |
685 view()->OnNavigate(params_C); | 685 frame()->OnNavigate(params_C); |
686 ProcessPendingMessages(); | 686 ProcessPendingMessages(); |
687 render_thread_->sink().ClearMessages(); | 687 render_thread_->sink().ClearMessages(); |
688 | 688 |
689 // Go back twice quickly, such that page B does not have a chance to commit. | 689 // Go back twice quickly, such that page B does not have a chance to commit. |
690 // This leads to two changes to the back/forward list but only one change to | 690 // This leads to two changes to the back/forward list but only one change to |
691 // the RenderView's page ID. | 691 // the RenderView's page ID. |
692 | 692 |
693 // Back to page B (page_id 2), without committing. | 693 // Back to page B (page_id 2), without committing. |
694 ViewMsg_Navigate_Params params_B; | 694 FrameMsg_Navigate_Params params_B; |
695 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 695 params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
696 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; | 696 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; |
697 params_B.current_history_list_length = 4; | 697 params_B.current_history_list_length = 4; |
698 params_B.current_history_list_offset = 2; | 698 params_B.current_history_list_offset = 2; |
699 params_B.pending_history_list_offset = 1; | 699 params_B.pending_history_list_offset = 1; |
700 params_B.page_id = 2; | 700 params_B.page_id = 2; |
701 params_B.page_state = state_B; | 701 params_B.page_state = state_B; |
702 view()->OnNavigate(params_B); | 702 frame()->OnNavigate(params_B); |
703 | 703 |
704 // Back to page A (page_id 1) and commit. | 704 // Back to page A (page_id 1) and commit. |
705 ViewMsg_Navigate_Params params; | 705 FrameMsg_Navigate_Params params; |
706 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 706 params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
707 params.transition = PAGE_TRANSITION_FORWARD_BACK; | 707 params.transition = PAGE_TRANSITION_FORWARD_BACK; |
708 params_B.current_history_list_length = 4; | 708 params_B.current_history_list_length = 4; |
709 params_B.current_history_list_offset = 2; | 709 params_B.current_history_list_offset = 2; |
710 params_B.pending_history_list_offset = 0; | 710 params_B.pending_history_list_offset = 0; |
711 params.page_id = 1; | 711 params.page_id = 1; |
712 params.page_state = state_A; | 712 params.page_state = state_A; |
713 view()->OnNavigate(params); | 713 frame()->OnNavigate(params); |
714 ProcessPendingMessages(); | 714 ProcessPendingMessages(); |
715 | 715 |
716 // Now ensure that the UpdateState message we receive is consistent | 716 // Now ensure that the UpdateState message we receive is consistent |
717 // and represents page C in both page_id and state. | 717 // and represents page C in both page_id and state. |
718 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 718 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
719 ViewHostMsg_UpdateState::ID); | 719 ViewHostMsg_UpdateState::ID); |
720 ASSERT_TRUE(msg); | 720 ASSERT_TRUE(msg); |
721 int page_id; | 721 int page_id; |
722 PageState state; | 722 PageState state; |
723 ViewHostMsg_UpdateState::Read(msg, &page_id, &state); | 723 ViewHostMsg_UpdateState::Read(msg, &page_id, &state); |
(...skipping 24 matching lines...) Expand all Loading... |
748 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( | 748 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( |
749 ViewHostMsg_UpdateState::ID); | 749 ViewHostMsg_UpdateState::ID); |
750 ASSERT_TRUE(msg_A); | 750 ASSERT_TRUE(msg_A); |
751 int page_id_A; | 751 int page_id_A; |
752 PageState state_A; | 752 PageState state_A; |
753 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); | 753 ViewHostMsg_UpdateState::Read(msg_A, &page_id_A, &state_A); |
754 EXPECT_EQ(1, page_id_A); | 754 EXPECT_EQ(1, page_id_A); |
755 render_thread_->sink().ClearMessages(); | 755 render_thread_->sink().ClearMessages(); |
756 | 756 |
757 // Back to page A (page_id 1) and commit. | 757 // Back to page A (page_id 1) and commit. |
758 ViewMsg_Navigate_Params params_A; | 758 FrameMsg_Navigate_Params params_A; |
759 params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 759 params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
760 params_A.transition = PAGE_TRANSITION_FORWARD_BACK; | 760 params_A.transition = PAGE_TRANSITION_FORWARD_BACK; |
761 params_A.current_history_list_length = 2; | 761 params_A.current_history_list_length = 2; |
762 params_A.current_history_list_offset = 1; | 762 params_A.current_history_list_offset = 1; |
763 params_A.pending_history_list_offset = 0; | 763 params_A.pending_history_list_offset = 0; |
764 params_A.page_id = 1; | 764 params_A.page_id = 1; |
765 params_A.page_state = state_A; | 765 params_A.page_state = state_A; |
766 view()->OnNavigate(params_A); | 766 frame()->OnNavigate(params_A); |
767 ProcessPendingMessages(); | 767 ProcessPendingMessages(); |
768 | 768 |
769 // A new navigation commits, clearing the forward history. | 769 // A new navigation commits, clearing the forward history. |
770 LoadHTML("<div>Page C</div>"); | 770 LoadHTML("<div>Page C</div>"); |
771 EXPECT_EQ(2, view()->history_list_length_); | 771 EXPECT_EQ(2, view()->history_list_length_); |
772 EXPECT_EQ(1, view()->history_list_offset_); | 772 EXPECT_EQ(1, view()->history_list_offset_); |
773 EXPECT_EQ(3, view()->history_page_ids_[1]); | 773 EXPECT_EQ(3, view()->history_page_ids_[1]); |
774 | 774 |
775 // The browser then sends a stale navigation to B, which should be ignored. | 775 // The browser then sends a stale navigation to B, which should be ignored. |
776 ViewMsg_Navigate_Params params_B; | 776 FrameMsg_Navigate_Params params_B; |
777 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 777 params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
778 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; | 778 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; |
779 params_B.current_history_list_length = 2; | 779 params_B.current_history_list_length = 2; |
780 params_B.current_history_list_offset = 0; | 780 params_B.current_history_list_offset = 0; |
781 params_B.pending_history_list_offset = 1; | 781 params_B.pending_history_list_offset = 1; |
782 params_B.page_id = 2; | 782 params_B.page_id = 2; |
783 params_B.page_state = state_A; // Doesn't matter, just has to be present. | 783 params_B.page_state = state_A; // Doesn't matter, just has to be present. |
784 view()->OnNavigate(params_B); | 784 frame()->OnNavigate(params_B); |
785 | 785 |
786 // State should be unchanged. | 786 // State should be unchanged. |
787 EXPECT_EQ(2, view()->history_list_length_); | 787 EXPECT_EQ(2, view()->history_list_length_); |
788 EXPECT_EQ(1, view()->history_list_offset_); | 788 EXPECT_EQ(1, view()->history_list_offset_); |
789 EXPECT_EQ(3, view()->history_page_ids_[1]); | 789 EXPECT_EQ(3, view()->history_page_ids_[1]); |
790 } | 790 } |
791 | 791 |
792 // Test that we do not ignore navigations after the entry limit is reached, | 792 // Test that we do not ignore navigations after the entry limit is reached, |
793 // in which case the browser starts dropping entries from the front. In this | 793 // in which case the browser starts dropping entries from the front. In this |
794 // case, we'll see a page_id mismatch but the RenderView's id will be older, | 794 // case, we'll see a page_id mismatch but the RenderView's id will be older, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 ASSERT_TRUE(msg_B); | 832 ASSERT_TRUE(msg_B); |
833 int page_id_B; | 833 int page_id_B; |
834 PageState state_B; | 834 PageState state_B; |
835 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); | 835 ViewHostMsg_UpdateState::Read(msg_B, &page_id_B, &state_B); |
836 EXPECT_EQ(2, page_id_B); | 836 EXPECT_EQ(2, page_id_B); |
837 render_thread_->sink().ClearMessages(); | 837 render_thread_->sink().ClearMessages(); |
838 | 838 |
839 // Suppose the browser has limited the number of NavigationEntries to 2. | 839 // Suppose the browser has limited the number of NavigationEntries to 2. |
840 // It has now dropped the first entry, but the renderer isn't notified. | 840 // It has now dropped the first entry, but the renderer isn't notified. |
841 // Ensure that going back to page B (page_id 2) at offset 0 is successful. | 841 // Ensure that going back to page B (page_id 2) at offset 0 is successful. |
842 ViewMsg_Navigate_Params params_B; | 842 FrameMsg_Navigate_Params params_B; |
843 params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 843 params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
844 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; | 844 params_B.transition = PAGE_TRANSITION_FORWARD_BACK; |
845 params_B.current_history_list_length = 2; | 845 params_B.current_history_list_length = 2; |
846 params_B.current_history_list_offset = 1; | 846 params_B.current_history_list_offset = 1; |
847 params_B.pending_history_list_offset = 0; | 847 params_B.pending_history_list_offset = 0; |
848 params_B.page_id = 2; | 848 params_B.page_id = 2; |
849 params_B.page_state = state_B; | 849 params_B.page_state = state_B; |
850 view()->OnNavigate(params_B); | 850 frame()->OnNavigate(params_B); |
851 ProcessPendingMessages(); | 851 ProcessPendingMessages(); |
852 | 852 |
853 EXPECT_EQ(2, view()->history_list_length_); | 853 EXPECT_EQ(2, view()->history_list_length_); |
854 EXPECT_EQ(0, view()->history_list_offset_); | 854 EXPECT_EQ(0, view()->history_list_offset_); |
855 EXPECT_EQ(2, view()->history_page_ids_[0]); | 855 EXPECT_EQ(2, view()->history_page_ids_[0]); |
856 } | 856 } |
857 | 857 |
858 // Test that our IME backend sends a notification message when the input focus | 858 // Test that our IME backend sends a notification message when the input focus |
859 // changes. | 859 // changes. |
860 TEST_F(RenderViewImplTest, OnImeTypeChanged) { | 860 TEST_F(RenderViewImplTest, OnImeTypeChanged) { |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 TEST_F(RenderViewImplTest, DISABLED_DidFailProvisionalLoadWithErrorForError) { | 1551 TEST_F(RenderViewImplTest, DISABLED_DidFailProvisionalLoadWithErrorForError) { |
1552 GetMainFrame()->enableViewSourceMode(true); | 1552 GetMainFrame()->enableViewSourceMode(true); |
1553 WebURLError error; | 1553 WebURLError error; |
1554 error.domain = WebString::fromUTF8(net::kErrorDomain); | 1554 error.domain = WebString::fromUTF8(net::kErrorDomain); |
1555 error.reason = net::ERR_FILE_NOT_FOUND; | 1555 error.reason = net::ERR_FILE_NOT_FOUND; |
1556 error.unreachableURL = GURL("http://foo"); | 1556 error.unreachableURL = GURL("http://foo"); |
1557 WebFrame* web_frame = GetMainFrame(); | 1557 WebFrame* web_frame = GetMainFrame(); |
1558 | 1558 |
1559 // Start a load that will reach provisional state synchronously, | 1559 // Start a load that will reach provisional state synchronously, |
1560 // but won't complete synchronously. | 1560 // but won't complete synchronously. |
1561 ViewMsg_Navigate_Params params; | 1561 FrameMsg_Navigate_Params params; |
1562 params.page_id = -1; | 1562 params.page_id = -1; |
1563 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 1563 params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
1564 params.url = GURL("data:text/html,test data"); | 1564 params.url = GURL("data:text/html,test data"); |
1565 view()->OnNavigate(params); | 1565 frame()->OnNavigate(params); |
1566 | 1566 |
1567 // An error occurred. | 1567 // An error occurred. |
1568 view()->main_render_frame()->didFailProvisionalLoad(web_frame, error); | 1568 view()->main_render_frame()->didFailProvisionalLoad(web_frame, error); |
1569 // Frame should exit view-source mode. | 1569 // Frame should exit view-source mode. |
1570 EXPECT_FALSE(web_frame->isViewSourceModeEnabled()); | 1570 EXPECT_FALSE(web_frame->isViewSourceModeEnabled()); |
1571 } | 1571 } |
1572 | 1572 |
1573 TEST_F(RenderViewImplTest, DidFailProvisionalLoadWithErrorForCancellation) { | 1573 TEST_F(RenderViewImplTest, DidFailProvisionalLoadWithErrorForCancellation) { |
1574 GetMainFrame()->enableViewSourceMode(true); | 1574 GetMainFrame()->enableViewSourceMode(true); |
1575 WebURLError error; | 1575 WebURLError error; |
1576 error.domain = WebString::fromUTF8(net::kErrorDomain); | 1576 error.domain = WebString::fromUTF8(net::kErrorDomain); |
1577 error.reason = net::ERR_ABORTED; | 1577 error.reason = net::ERR_ABORTED; |
1578 error.unreachableURL = GURL("http://foo"); | 1578 error.unreachableURL = GURL("http://foo"); |
1579 WebFrame* web_frame = GetMainFrame(); | 1579 WebFrame* web_frame = GetMainFrame(); |
1580 | 1580 |
1581 // Start a load that will reach provisional state synchronously, | 1581 // Start a load that will reach provisional state synchronously, |
1582 // but won't complete synchronously. | 1582 // but won't complete synchronously. |
1583 ViewMsg_Navigate_Params params; | 1583 FrameMsg_Navigate_Params params; |
1584 params.page_id = -1; | 1584 params.page_id = -1; |
1585 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 1585 params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
1586 params.url = GURL("data:text/html,test data"); | 1586 params.url = GURL("data:text/html,test data"); |
1587 view()->OnNavigate(params); | 1587 frame()->OnNavigate(params); |
1588 | 1588 |
1589 // A cancellation occurred. | 1589 // A cancellation occurred. |
1590 view()->main_render_frame()->didFailProvisionalLoad(web_frame, error); | 1590 view()->main_render_frame()->didFailProvisionalLoad(web_frame, error); |
1591 // Frame should stay in view-source mode. | 1591 // Frame should stay in view-source mode. |
1592 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); | 1592 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); |
1593 } | 1593 } |
1594 | 1594 |
1595 // Regression test for http://crbug.com/41562 | 1595 // Regression test for http://crbug.com/41562 |
1596 TEST_F(RenderViewImplTest, UpdateTargetURLWithInvalidURL) { | 1596 TEST_F(RenderViewImplTest, UpdateTargetURLWithInvalidURL) { |
1597 const GURL invalid_gurl("http://"); | 1597 const GURL invalid_gurl("http://"); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1906 } | 1906 } |
1907 view()->OnImeConfirmComposition( | 1907 view()->OnImeConfirmComposition( |
1908 empty_string, gfx::Range::InvalidRange(), false); | 1908 empty_string, gfx::Range::InvalidRange(), false); |
1909 } | 1909 } |
1910 #endif | 1910 #endif |
1911 | 1911 |
1912 TEST_F(RenderViewImplTest, ZoomLimit) { | 1912 TEST_F(RenderViewImplTest, ZoomLimit) { |
1913 const double kMinZoomLevel = ZoomFactorToZoomLevel(kMinimumZoomFactor); | 1913 const double kMinZoomLevel = ZoomFactorToZoomLevel(kMinimumZoomFactor); |
1914 const double kMaxZoomLevel = ZoomFactorToZoomLevel(kMaximumZoomFactor); | 1914 const double kMaxZoomLevel = ZoomFactorToZoomLevel(kMaximumZoomFactor); |
1915 | 1915 |
1916 ViewMsg_Navigate_Params params; | 1916 FrameMsg_Navigate_Params params; |
1917 params.page_id = -1; | 1917 params.page_id = -1; |
1918 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 1918 params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
1919 | 1919 |
1920 // Verifies navigation to a URL with preset zoom level indeed sets the level. | 1920 // Verifies navigation to a URL with preset zoom level indeed sets the level. |
1921 // Regression test for http://crbug.com/139559, where the level was not | 1921 // Regression test for http://crbug.com/139559, where the level was not |
1922 // properly set when it is out of the default zoom limits of WebView. | 1922 // properly set when it is out of the default zoom limits of WebView. |
1923 params.url = GURL("data:text/html,min_zoomlimit_test"); | 1923 params.url = GURL("data:text/html,min_zoomlimit_test"); |
1924 view()->OnSetZoomLevelForLoadingURL(params.url, kMinZoomLevel); | 1924 view()->OnSetZoomLevelForLoadingURL(params.url, kMinZoomLevel); |
1925 view()->OnNavigate(params); | 1925 frame()->OnNavigate(params); |
1926 ProcessPendingMessages(); | 1926 ProcessPendingMessages(); |
1927 EXPECT_DOUBLE_EQ(kMinZoomLevel, view()->GetWebView()->zoomLevel()); | 1927 EXPECT_DOUBLE_EQ(kMinZoomLevel, view()->GetWebView()->zoomLevel()); |
1928 | 1928 |
1929 // It should work even when the zoom limit is temporarily changed in the page. | 1929 // It should work even when the zoom limit is temporarily changed in the page. |
1930 view()->GetWebView()->zoomLimitsChanged(ZoomFactorToZoomLevel(1.0), | 1930 view()->GetWebView()->zoomLimitsChanged(ZoomFactorToZoomLevel(1.0), |
1931 ZoomFactorToZoomLevel(1.0)); | 1931 ZoomFactorToZoomLevel(1.0)); |
1932 params.url = GURL("data:text/html,max_zoomlimit_test"); | 1932 params.url = GURL("data:text/html,max_zoomlimit_test"); |
1933 view()->OnSetZoomLevelForLoadingURL(params.url, kMaxZoomLevel); | 1933 view()->OnSetZoomLevelForLoadingURL(params.url, kMaxZoomLevel); |
1934 view()->OnNavigate(params); | 1934 frame()->OnNavigate(params); |
1935 ProcessPendingMessages(); | 1935 ProcessPendingMessages(); |
1936 EXPECT_DOUBLE_EQ(kMaxZoomLevel, view()->GetWebView()->zoomLevel()); | 1936 EXPECT_DOUBLE_EQ(kMaxZoomLevel, view()->GetWebView()->zoomLevel()); |
1937 } | 1937 } |
1938 | 1938 |
1939 TEST_F(RenderViewImplTest, SetEditableSelectionAndComposition) { | 1939 TEST_F(RenderViewImplTest, SetEditableSelectionAndComposition) { |
1940 // Load an HTML page consisting of an input field. | 1940 // Load an HTML page consisting of an input field. |
1941 LoadHTML("<html>" | 1941 LoadHTML("<html>" |
1942 "<head>" | 1942 "<head>" |
1943 "</head>" | 1943 "</head>" |
1944 "<body>" | 1944 "<body>" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1984 EXPECT_EQ(2, info.selectionStart); | 1984 EXPECT_EQ(2, info.selectionStart); |
1985 EXPECT_EQ(2, info.selectionEnd); | 1985 EXPECT_EQ(2, info.selectionEnd); |
1986 } | 1986 } |
1987 | 1987 |
1988 // Test that the navigating specific frames works correctly. | 1988 // Test that the navigating specific frames works correctly. |
1989 TEST_F(RenderViewImplTest, NavigateFrame) { | 1989 TEST_F(RenderViewImplTest, NavigateFrame) { |
1990 // Load page A. | 1990 // Load page A. |
1991 LoadHTML("hello <iframe srcdoc='fail' name='frame'></iframe>"); | 1991 LoadHTML("hello <iframe srcdoc='fail' name='frame'></iframe>"); |
1992 | 1992 |
1993 // Navigate the frame only. | 1993 // Navigate the frame only. |
1994 ViewMsg_Navigate_Params nav_params; | 1994 FrameMsg_Navigate_Params nav_params; |
1995 nav_params.url = GURL("data:text/html,world"); | 1995 nav_params.url = GURL("data:text/html,world"); |
1996 nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 1996 nav_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
1997 nav_params.transition = PAGE_TRANSITION_TYPED; | 1997 nav_params.transition = PAGE_TRANSITION_TYPED; |
1998 nav_params.current_history_list_length = 1; | 1998 nav_params.current_history_list_length = 1; |
1999 nav_params.current_history_list_offset = 0; | 1999 nav_params.current_history_list_offset = 0; |
2000 nav_params.pending_history_list_offset = 1; | 2000 nav_params.pending_history_list_offset = 1; |
2001 nav_params.page_id = -1; | 2001 nav_params.page_id = -1; |
2002 nav_params.frame_to_navigate = "frame"; | 2002 nav_params.frame_to_navigate = "frame"; |
2003 view()->OnNavigate(nav_params); | 2003 frame()->OnNavigate(nav_params); |
2004 ProcessPendingMessages(); | 2004 ProcessPendingMessages(); |
2005 | 2005 |
2006 // Copy the document content to std::wstring and compare with the | 2006 // Copy the document content to std::wstring and compare with the |
2007 // expected result. | 2007 // expected result. |
2008 const int kMaxOutputCharacters = 256; | 2008 const int kMaxOutputCharacters = 256; |
2009 std::wstring output = base::UTF16ToWideHack( | 2009 std::wstring output = base::UTF16ToWideHack( |
2010 GetMainFrame()->contentAsText(kMaxOutputCharacters)); | 2010 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
2011 EXPECT_EQ(output, L"hello \n\nworld"); | 2011 EXPECT_EQ(output, L"hello \n\nworld"); |
2012 } | 2012 } |
2013 | 2013 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2067 public: | 2067 public: |
2068 virtual void SetUp() OVERRIDE { | 2068 virtual void SetUp() OVERRIDE { |
2069 SetRendererClientForTesting(&client_); | 2069 SetRendererClientForTesting(&client_); |
2070 RenderViewTest::SetUp(); | 2070 RenderViewTest::SetUp(); |
2071 } | 2071 } |
2072 | 2072 |
2073 RenderViewImpl* view() { | 2073 RenderViewImpl* view() { |
2074 return static_cast<RenderViewImpl*>(view_); | 2074 return static_cast<RenderViewImpl*>(view_); |
2075 } | 2075 } |
2076 | 2076 |
| 2077 RenderFrameImpl* frame() { |
| 2078 return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame()); |
| 2079 } |
| 2080 |
2077 private: | 2081 private: |
2078 class TestContentRendererClient : public ContentRendererClient { | 2082 class TestContentRendererClient : public ContentRendererClient { |
2079 public: | 2083 public: |
2080 virtual bool ShouldSuppressErrorPage(RenderFrame* render_frame, | 2084 virtual bool ShouldSuppressErrorPage(RenderFrame* render_frame, |
2081 const GURL& url) OVERRIDE { | 2085 const GURL& url) OVERRIDE { |
2082 return url == GURL("http://example.com/suppress"); | 2086 return url == GURL("http://example.com/suppress"); |
2083 } | 2087 } |
2084 | 2088 |
2085 virtual void GetNavigationErrorStrings( | 2089 virtual void GetNavigationErrorStrings( |
2086 content::RenderView* render_view, | 2090 content::RenderView* render_view, |
(...skipping 19 matching lines...) Expand all Loading... |
2106 | 2110 |
2107 TEST_F(SuppressErrorPageTest, MAYBE_Suppresses) { | 2111 TEST_F(SuppressErrorPageTest, MAYBE_Suppresses) { |
2108 WebURLError error; | 2112 WebURLError error; |
2109 error.domain = WebString::fromUTF8(net::kErrorDomain); | 2113 error.domain = WebString::fromUTF8(net::kErrorDomain); |
2110 error.reason = net::ERR_FILE_NOT_FOUND; | 2114 error.reason = net::ERR_FILE_NOT_FOUND; |
2111 error.unreachableURL = GURL("http://example.com/suppress"); | 2115 error.unreachableURL = GURL("http://example.com/suppress"); |
2112 WebFrame* web_frame = GetMainFrame(); | 2116 WebFrame* web_frame = GetMainFrame(); |
2113 | 2117 |
2114 // Start a load that will reach provisional state synchronously, | 2118 // Start a load that will reach provisional state synchronously, |
2115 // but won't complete synchronously. | 2119 // but won't complete synchronously. |
2116 ViewMsg_Navigate_Params params; | 2120 FrameMsg_Navigate_Params params; |
2117 params.page_id = -1; | 2121 params.page_id = -1; |
2118 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 2122 params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
2119 params.url = GURL("data:text/html,test data"); | 2123 params.url = GURL("data:text/html,test data"); |
2120 view()->OnNavigate(params); | 2124 frame()->OnNavigate(params); |
2121 | 2125 |
2122 // An error occurred. | 2126 // An error occurred. |
2123 view()->main_render_frame()->didFailProvisionalLoad(web_frame, error); | 2127 view()->main_render_frame()->didFailProvisionalLoad(web_frame, error); |
2124 const int kMaxOutputCharacters = 22; | 2128 const int kMaxOutputCharacters = 22; |
2125 EXPECT_EQ("", UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters))); | 2129 EXPECT_EQ("", UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters))); |
2126 } | 2130 } |
2127 | 2131 |
2128 #if defined(OS_ANDROID) | 2132 #if defined(OS_ANDROID) |
2129 // Crashing on Android: http://crbug.com/311341 | 2133 // Crashing on Android: http://crbug.com/311341 |
2130 #define MAYBE_DoesNotSuppress DISABLED_DoesNotSuppress | 2134 #define MAYBE_DoesNotSuppress DISABLED_DoesNotSuppress |
2131 #else | 2135 #else |
2132 #define MAYBE_DoesNotSuppress DoesNotSuppress | 2136 #define MAYBE_DoesNotSuppress DoesNotSuppress |
2133 #endif | 2137 #endif |
2134 | 2138 |
2135 TEST_F(SuppressErrorPageTest, MAYBE_DoesNotSuppress) { | 2139 TEST_F(SuppressErrorPageTest, MAYBE_DoesNotSuppress) { |
2136 WebURLError error; | 2140 WebURLError error; |
2137 error.domain = WebString::fromUTF8(net::kErrorDomain); | 2141 error.domain = WebString::fromUTF8(net::kErrorDomain); |
2138 error.reason = net::ERR_FILE_NOT_FOUND; | 2142 error.reason = net::ERR_FILE_NOT_FOUND; |
2139 error.unreachableURL = GURL("http://example.com/dont-suppress"); | 2143 error.unreachableURL = GURL("http://example.com/dont-suppress"); |
2140 WebFrame* web_frame = GetMainFrame(); | 2144 WebFrame* web_frame = GetMainFrame(); |
2141 | 2145 |
2142 // Start a load that will reach provisional state synchronously, | 2146 // Start a load that will reach provisional state synchronously, |
2143 // but won't complete synchronously. | 2147 // but won't complete synchronously. |
2144 ViewMsg_Navigate_Params params; | 2148 FrameMsg_Navigate_Params params; |
2145 params.page_id = -1; | 2149 params.page_id = -1; |
2146 params.navigation_type = ViewMsg_Navigate_Type::NORMAL; | 2150 params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
2147 params.url = GURL("data:text/html,test data"); | 2151 params.url = GURL("data:text/html,test data"); |
2148 view()->OnNavigate(params); | 2152 frame()->OnNavigate(params); |
2149 | 2153 |
2150 // An error occurred. | 2154 // An error occurred. |
2151 view()->main_render_frame()->didFailProvisionalLoad(web_frame, error); | 2155 view()->main_render_frame()->didFailProvisionalLoad(web_frame, error); |
2152 ProcessPendingMessages(); | 2156 ProcessPendingMessages(); |
2153 const int kMaxOutputCharacters = 22; | 2157 const int kMaxOutputCharacters = 22; |
2154 EXPECT_EQ("A suffusion of yellow.", | 2158 EXPECT_EQ("A suffusion of yellow.", |
2155 UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters))); | 2159 UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters))); |
2156 } | 2160 } |
2157 | 2161 |
2158 // Tests if IME API's candidatewindow* events sent from browser are handled | 2162 // Tests if IME API's candidatewindow* events sent from browser are handled |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2240 view()->webview()->clearFocusedElement(); | 2244 view()->webview()->clearFocusedElement(); |
2241 const IPC::Message* msg3 = render_thread_->sink().GetFirstMessageMatching( | 2245 const IPC::Message* msg3 = render_thread_->sink().GetFirstMessageMatching( |
2242 ViewHostMsg_FocusedNodeChanged::ID); | 2246 ViewHostMsg_FocusedNodeChanged::ID); |
2243 EXPECT_TRUE(msg3); | 2247 EXPECT_TRUE(msg3); |
2244 ViewHostMsg_FocusedNodeChanged::Read(msg3, ¶ms); | 2248 ViewHostMsg_FocusedNodeChanged::Read(msg3, ¶ms); |
2245 EXPECT_FALSE(params.a); | 2249 EXPECT_FALSE(params.a); |
2246 render_thread_->sink().ClearMessages(); | 2250 render_thread_->sink().ClearMessages(); |
2247 } | 2251 } |
2248 | 2252 |
2249 } // namespace content | 2253 } // namespace content |
OLD | NEW |