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

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

Issue 1002803002: Classify navigations without page id in parallel to the existing classifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unit tests Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 607
608 // Back to page A (page_id 1) and commit. 608 // Back to page A (page_id 1) and commit.
609 CommonNavigationParams common_params_A; 609 CommonNavigationParams common_params_A;
610 HistoryNavigationParams history_params_A; 610 HistoryNavigationParams history_params_A;
611 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; 611 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL;
612 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 612 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
613 history_params_A.current_history_list_length = 2; 613 history_params_A.current_history_list_length = 2;
614 history_params_A.current_history_list_offset = 1; 614 history_params_A.current_history_list_offset = 1;
615 history_params_A.pending_history_list_offset = 0; 615 history_params_A.pending_history_list_offset = 0;
616 history_params_A.page_id = 1; 616 history_params_A.page_id = 1;
617 history_params_A.nav_entry_id = 1;
617 history_params_A.page_state = state_A; 618 history_params_A.page_state = state_A;
618 frame()->OnNavigate(common_params_A, StartNavigationParams(), 619 frame()->OnNavigate(common_params_A, StartNavigationParams(),
619 CommitNavigationParams(), history_params_A); 620 CommitNavigationParams(), history_params_A);
620 EXPECT_EQ(1, view()->historyBackListCount()); 621 EXPECT_EQ(1, view()->historyBackListCount());
621 EXPECT_EQ(2, view()->historyBackListCount() + 622 EXPECT_EQ(2, view()->historyBackListCount() +
622 view()->historyForwardListCount() + 1); 623 view()->historyForwardListCount() + 1);
623 ProcessPendingMessages(); 624 ProcessPendingMessages();
624 625
625 // Respond to a swap out request. 626 // Respond to a swap out request.
626 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, true, 627 view()->GetMainRenderFrame()->OnSwapOut(kProxyRoutingId, true,
(...skipping 11 matching lines...) Expand all
638 // Ensure the old page gets reloaded, not swappedout://. 639 // Ensure the old page gets reloaded, not swappedout://.
639 CommonNavigationParams common_params; 640 CommonNavigationParams common_params;
640 HistoryNavigationParams history_params; 641 HistoryNavigationParams history_params;
641 common_params.url = GURL("data:text/html,<div>Page A</div>"); 642 common_params.url = GURL("data:text/html,<div>Page A</div>");
642 common_params.navigation_type = FrameMsg_Navigate_Type::RELOAD; 643 common_params.navigation_type = FrameMsg_Navigate_Type::RELOAD;
643 common_params.transition = ui::PAGE_TRANSITION_RELOAD; 644 common_params.transition = ui::PAGE_TRANSITION_RELOAD;
644 history_params.current_history_list_length = 2; 645 history_params.current_history_list_length = 2;
645 history_params.current_history_list_offset = 0; 646 history_params.current_history_list_offset = 0;
646 history_params.pending_history_list_offset = 0; 647 history_params.pending_history_list_offset = 0;
647 history_params.page_id = 1; 648 history_params.page_id = 1;
649 history_params.nav_entry_id = 1;
648 history_params.page_state = state_A; 650 history_params.page_state = state_A;
649 frame()->OnNavigate(common_params, StartNavigationParams(), 651 frame()->OnNavigate(common_params, StartNavigationParams(),
650 CommitNavigationParams(), history_params); 652 CommitNavigationParams(), history_params);
651 ProcessPendingMessages(); 653 ProcessPendingMessages();
652 654
653 // Verify page A committed, not swappedout://. 655 // Verify page A committed, not swappedout://.
654 const IPC::Message* frame_navigate_msg = 656 const IPC::Message* frame_navigate_msg =
655 render_thread_->sink().GetUniqueMessageMatching( 657 render_thread_->sink().GetUniqueMessageMatching(
656 FrameHostMsg_DidCommitProvisionalLoad::ID); 658 FrameHostMsg_DidCommitProvisionalLoad::ID);
657 EXPECT_TRUE(frame_navigate_msg); 659 EXPECT_TRUE(frame_navigate_msg);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 EXPECT_EQ(page_id_C, page_id); 814 EXPECT_EQ(page_id_C, page_id);
813 EXPECT_NE(state_A, state); 815 EXPECT_NE(state_A, state);
814 EXPECT_NE(state_B, state); 816 EXPECT_NE(state_B, state);
815 EXPECT_EQ(state_C, state); 817 EXPECT_EQ(state_C, state);
816 } 818 }
817 819
818 // Test that stale back/forward navigations arriving from the browser are 820 // Test that stale back/forward navigations arriving from the browser are
819 // ignored. See http://crbug.com/86758. 821 // ignored. See http://crbug.com/86758.
820 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) { 822 TEST_F(RenderViewImplTest, StaleNavigationsIgnored) {
821 // Load page A. 823 // Load page A.
822 LoadHTML("<div>Page A</div>"); 824 LoadHTML("<div id=pagename>Page A</div>");
823 EXPECT_EQ(1, view()->history_list_length_); 825 EXPECT_EQ(1, view()->history_list_length_);
824 EXPECT_EQ(0, view()->history_list_offset_); 826 EXPECT_EQ(0, view()->history_list_offset_);
825 827
826 // Load page B, which will trigger an UpdateState message for page A. 828 // Load page B, which will trigger an UpdateState message for page A.
827 LoadHTML("<div>Page B</div>"); 829 LoadHTML("<div id=pagename>Page B</div>");
828 EXPECT_EQ(2, view()->history_list_length_); 830 EXPECT_EQ(2, view()->history_list_length_);
829 EXPECT_EQ(1, view()->history_list_offset_); 831 EXPECT_EQ(1, view()->history_list_offset_);
830 832
831 // Check for a valid UpdateState message for page A. 833 // Check for a valid UpdateState message for page A.
832 ProcessPendingMessages(); 834 ProcessPendingMessages();
833 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching( 835 const IPC::Message* msg_A = render_thread_->sink().GetUniqueMessageMatching(
834 ViewHostMsg_UpdateState::ID); 836 ViewHostMsg_UpdateState::ID);
835 ASSERT_TRUE(msg_A); 837 ASSERT_TRUE(msg_A);
836 ViewHostMsg_UpdateState::Param param; 838 ViewHostMsg_UpdateState::Param param;
837 ViewHostMsg_UpdateState::Read(msg_A, &param); 839 ViewHostMsg_UpdateState::Read(msg_A, &param);
838 int page_id_A = get<0>(param); 840 int page_id_A = get<0>(param);
839 PageState state_A = get<1>(param); 841 PageState state_A = get<1>(param);
840 EXPECT_EQ(1, page_id_A); 842 EXPECT_EQ(1, page_id_A);
841 render_thread_->sink().ClearMessages(); 843 render_thread_->sink().ClearMessages();
842 844
843 // Back to page A (page_id 1) and commit. 845 // Back to page A (nav_entry_id 1) and commit.
844 CommonNavigationParams common_params_A; 846 CommonNavigationParams common_params_A;
845 HistoryNavigationParams history_params_A; 847 HistoryNavigationParams history_params_A;
846 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL; 848 common_params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL;
847 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 849 common_params_A.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
848 history_params_A.current_history_list_length = 2; 850 history_params_A.current_history_list_length = 2;
849 history_params_A.current_history_list_offset = 1; 851 history_params_A.current_history_list_offset = 1;
850 history_params_A.pending_history_list_offset = 0; 852 history_params_A.pending_history_list_offset = 0;
851 history_params_A.page_id = 1; 853 history_params_A.page_id = 1;
854 history_params_A.nav_entry_id = 1;
852 history_params_A.page_state = state_A; 855 history_params_A.page_state = state_A;
853 frame()->OnNavigate(common_params_A, StartNavigationParams(), 856 frame()->OnNavigate(common_params_A, StartNavigationParams(),
854 CommitNavigationParams(), history_params_A); 857 CommitNavigationParams(), history_params_A);
855 ProcessPendingMessages(); 858 ProcessPendingMessages();
856 859
857 // A new navigation commits, clearing the forward history. 860 // A new navigation commits, clearing the forward history.
858 LoadHTML("<div>Page C</div>"); 861 LoadHTML("<div id=pagename>Page C</div>");
859 EXPECT_EQ(2, view()->history_list_length_); 862 EXPECT_EQ(2, view()->history_list_length_);
860 EXPECT_EQ(1, view()->history_list_offset_); 863 EXPECT_EQ(1, view()->history_list_offset_);
861 EXPECT_EQ(3, view()->page_id_); // page C is now page id 3 864 EXPECT_EQ(3, view()->page_id_); // page C is now page id 3
865 int was_page_c = -1;
866 base::string16 check_page_c =
867 base::ASCIIToUTF16(
868 "Number(document.getElementById('pagename').innerHTML == 'Page C')");
869 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c));
870 EXPECT_EQ(1, was_page_c);
862 871
863 // The browser then sends a stale navigation to B, which should be ignored. 872 // The browser then sends a stale navigation to B, which should be ignored.
864 CommonNavigationParams common_params_B; 873 CommonNavigationParams common_params_B;
865 HistoryNavigationParams history_params_B; 874 HistoryNavigationParams history_params_B;
866 common_params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL; 875 common_params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL;
867 common_params_B.transition = ui::PAGE_TRANSITION_FORWARD_BACK; 876 common_params_B.transition = ui::PAGE_TRANSITION_FORWARD_BACK;
868 history_params_B.current_history_list_length = 2; 877 history_params_B.current_history_list_length = 2;
869 history_params_B.current_history_list_offset = 0; 878 history_params_B.current_history_list_offset = 0;
870 history_params_B.pending_history_list_offset = 1; 879 history_params_B.pending_history_list_offset = 1;
871 history_params_B.page_id = 2; 880 history_params_B.page_id = 2;
881 history_params_B.nav_entry_id = 2;
872 history_params_B.page_state = 882 history_params_B.page_state =
873 state_A; // Doesn't matter, just has to be present. 883 state_A; // Doesn't matter, just has to be present.
874 frame()->OnNavigate(common_params_B, StartNavigationParams(), 884 frame()->OnNavigate(common_params_B, StartNavigationParams(),
875 CommitNavigationParams(), history_params_B); 885 CommitNavigationParams(), history_params_B);
876 886
877 // State should be unchanged. 887 // State should be unchanged.
878 EXPECT_EQ(2, view()->history_list_length_); 888 EXPECT_EQ(2, view()->history_list_length_);
879 EXPECT_EQ(1, view()->history_list_offset_); 889 EXPECT_EQ(1, view()->history_list_offset_);
880 EXPECT_EQ(3, view()->page_id_); // page C, not page B 890 EXPECT_EQ(3, view()->page_id_); // page C, not page B
891 was_page_c = -1;
892 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c));
893 EXPECT_EQ(1, was_page_c);
881 894
882 // Check for a valid DidDropNavigation message. 895 // Check for a valid DidDropNavigation message.
883 ProcessPendingMessages(); 896 ProcessPendingMessages();
884 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( 897 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching(
885 FrameHostMsg_DidDropNavigation::ID); 898 FrameHostMsg_DidDropNavigation::ID);
886 ASSERT_TRUE(msg); 899 ASSERT_TRUE(msg);
887 render_thread_->sink().ClearMessages(); 900 render_thread_->sink().ClearMessages();
888 } 901 }
889 902
890 // Test that our IME backend sends a notification message when the input focus 903 // Test that our IME backend sends a notification message when the input focus
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 frame()->OnNavigate(CommonNavigationParams(), StartNavigationParams(), 2322 frame()->OnNavigate(CommonNavigationParams(), StartNavigationParams(),
2310 CommitNavigationParams(), history_params); 2323 CommitNavigationParams(), history_params);
2311 2324
2312 // The history list in RenderView should have been updated. 2325 // The history list in RenderView should have been updated.
2313 EXPECT_EQ(1, view()->historyBackListCount()); 2326 EXPECT_EQ(1, view()->historyBackListCount());
2314 EXPECT_EQ(2, view()->historyBackListCount() + 2327 EXPECT_EQ(2, view()->historyBackListCount() +
2315 view()->historyForwardListCount() + 1); 2328 view()->historyForwardListCount() + 1);
2316 } 2329 }
2317 2330
2318 } // namespace content 2331 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698