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

Side by Side Diff: chrome/browser/sessions/session_service_unittest.cc

Issue 14985014: Introduce content::PageState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comments to the top of page_state.h Created 7 years, 7 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 | Annotate | Revision Log
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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/defaults.h" 16 #include "chrome/browser/defaults.h"
17 #include "chrome/browser/sessions/session_backend.h" 17 #include "chrome/browser/sessions/session_backend.h"
18 #include "chrome/browser/sessions/session_service.h" 18 #include "chrome/browser/sessions/session_service.h"
19 #include "chrome/browser/sessions/session_service_test_helper.h" 19 #include "chrome/browser/sessions/session_service_test_helper.h"
20 #include "chrome/browser/sessions/session_types.h" 20 #include "chrome/browser/sessions/session_types.h"
21 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/test/base/browser_with_test_window_test.h" 23 #include "chrome/test/base/browser_with_test_window_test.h"
24 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
25 #include "components/sessions/serialized_navigation_entry_test_helper.h" 25 #include "components/sessions/serialized_navigation_entry_test_helper.h"
26 #include "content/public/browser/navigation_entry.h" 26 #include "content/public/browser/navigation_entry.h"
27 #include "content/public/browser/notification_observer.h" 27 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_registrar.h" 28 #include "content/public/browser/notification_registrar.h"
29 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
30 #include "content/public/common/page_state.h"
30 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
31 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" 32 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h"
32 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h" 33 #include "third_party/WebKit/Source/Platform/chromium/public/WebHTTPBody.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
34 #include "webkit/glue/glue_serialize.h"
35 35
36 using content::NavigationEntry; 36 using content::NavigationEntry;
37 using sessions::SerializedNavigationEntry; 37 using sessions::SerializedNavigationEntry;
38 using sessions::SerializedNavigationEntryTestHelper; 38 using sessions::SerializedNavigationEntryTestHelper;
39 39
40 class SessionServiceTest : public BrowserWithTestWindowTest, 40 class SessionServiceTest : public BrowserWithTestWindowTest,
41 public content::NotificationObserver { 41 public content::NotificationObserver {
42 public: 42 public:
43 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0) {} 43 SessionServiceTest() : window_bounds(0, 1, 2, 3), sync_save_count_(0) {}
44 44
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 ScopedVector<SessionWindow> windows; 774 ScopedVector<SessionWindow> windows;
775 ReadWindows(&(windows.get()), NULL); 775 ReadWindows(&(windows.get()), NULL);
776 ASSERT_EQ(1U, windows.size()); 776 ASSERT_EQ(1U, windows.size());
777 EXPECT_EQ(ui::SHOW_STATE_NORMAL, windows[0]->show_state); 777 EXPECT_EQ(ui::SHOW_STATE_NORMAL, windows[0]->show_state);
778 } 778 }
779 779
780 TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) { 780 TEST_F(SessionServiceTest, KeepPostDataWithoutPasswords) {
781 SessionID tab_id; 781 SessionID tab_id;
782 ASSERT_NE(window_id.id(), tab_id.id()); 782 ASSERT_NE(window_id.id(), tab_id.id());
783 783
784 // Create a content state representing a HTTP body without posted passwords. 784 // Create a page state representing a HTTP body without posted passwords.
785 WebKit::WebHTTPBody http_body; 785 content::PageState page_state =
786 http_body.initialize(); 786 content::PageState::CreateForTesting(GURL(), false, "data", NULL);
787 const char char_data[] = "data";
788 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1));
789 WebKit::WebHistoryItem history_item;
790 history_item.initialize();
791 history_item.setHTTPBody(http_body);
792 std::string content_state = webkit_glue::HistoryItemToString(history_item);
793 787
794 // Create a TabNavigation containing content_state and representing a POST 788 // Create a TabNavigation containing page_state and representing a POST
795 // request. 789 // request.
796 SerializedNavigationEntry nav1 = 790 SerializedNavigationEntry nav1 =
797 SerializedNavigationEntryTestHelper::CreateNavigation( 791 SerializedNavigationEntryTestHelper::CreateNavigation(
798 "http://google.com", "title"); 792 "http://google.com", "title");
799 SerializedNavigationEntryTestHelper::SetContentState(content_state, &nav1); 793 SerializedNavigationEntryTestHelper::SetPageState(page_state, &nav1);
800 SerializedNavigationEntryTestHelper::SetHasPostData(true, &nav1); 794 SerializedNavigationEntryTestHelper::SetHasPostData(true, &nav1);
801 795
802 // Create a TabNavigation containing content_state and representing a normal 796 // Create a TabNavigation containing page_state and representing a normal
803 // request. 797 // request.
804 SerializedNavigationEntry nav2 = 798 SerializedNavigationEntry nav2 =
805 SerializedNavigationEntryTestHelper::CreateNavigation( 799 SerializedNavigationEntryTestHelper::CreateNavigation(
806 "http://google.com/nopost", "title"); 800 "http://google.com/nopost", "title");
807 SerializedNavigationEntryTestHelper::SetContentState(content_state, &nav2); 801 SerializedNavigationEntryTestHelper::SetPageState(page_state, &nav2);
808 nav2.set_index(1); 802 nav2.set_index(1);
809 803
810 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 804 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
811 UpdateNavigation(window_id, tab_id, nav1, true); 805 UpdateNavigation(window_id, tab_id, nav1, true);
812 UpdateNavigation(window_id, tab_id, nav2, true); 806 UpdateNavigation(window_id, tab_id, nav2, true);
813 807
814 ScopedVector<SessionWindow> windows; 808 ScopedVector<SessionWindow> windows;
815 ReadWindows(&(windows.get()), NULL); 809 ReadWindows(&(windows.get()), NULL);
816 810
817 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2); 811 helper_.AssertSingleWindowWithSingleTab(windows.get(), 2);
818 812
819 // Expected: the content state of both navigations was saved and restored. 813 // Expected: the page state of both navigations was saved and restored.
820 ASSERT_EQ(2u, windows[0]->tabs[0]->navigations.size()); 814 ASSERT_EQ(2u, windows[0]->tabs[0]->navigations.size());
821 helper_.AssertNavigationEquals(nav1, windows[0]->tabs[0]->navigations[0]); 815 helper_.AssertNavigationEquals(nav1, windows[0]->tabs[0]->navigations[0]);
822 helper_.AssertNavigationEquals(nav2, windows[0]->tabs[0]->navigations[1]); 816 helper_.AssertNavigationEquals(nav2, windows[0]->tabs[0]->navigations[1]);
823 } 817 }
824 818
825 TEST_F(SessionServiceTest, RemovePostDataWithPasswords) { 819 TEST_F(SessionServiceTest, RemovePostDataWithPasswords) {
826 SessionID tab_id; 820 SessionID tab_id;
827 ASSERT_NE(window_id.id(), tab_id.id()); 821 ASSERT_NE(window_id.id(), tab_id.id());
828 822
829 // Create a content state representing a HTTP body with posted passwords. 823 // Create a page state representing a HTTP body with posted passwords.
830 WebKit::WebHTTPBody http_body; 824 content::PageState page_state =
831 http_body.initialize(); 825 content::PageState::CreateForTesting(GURL(), true, "data", NULL);
832 const char char_data[] = "data";
833 http_body.appendData(WebKit::WebData(char_data, sizeof(char_data)-1));
834 http_body.setContainsPasswordData(true);
835 WebKit::WebHistoryItem history_item;
836 history_item.initialize();
837 history_item.setHTTPBody(http_body);
838 std::string content_state = webkit_glue::HistoryItemToString(history_item);
839 826
840 // Create a TabNavigation containing content_state and representing a POST 827 // Create a TabNavigation containing page_state and representing a POST
841 // request with passwords. 828 // request with passwords.
842 SerializedNavigationEntry nav1 = 829 SerializedNavigationEntry nav1 =
843 SerializedNavigationEntryTestHelper::CreateNavigation( 830 SerializedNavigationEntryTestHelper::CreateNavigation(
844 "http://google.com", "title"); 831 "http://google.com", "title");
845 SerializedNavigationEntryTestHelper::SetContentState(content_state, &nav1); 832 SerializedNavigationEntryTestHelper::SetPageState(page_state, &nav1);
846 SerializedNavigationEntryTestHelper::SetHasPostData(true, &nav1); 833 SerializedNavigationEntryTestHelper::SetHasPostData(true, &nav1);
847 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); 834 helper_.PrepareTabInWindow(window_id, tab_id, 0, true);
848 UpdateNavigation(window_id, tab_id, nav1, true); 835 UpdateNavigation(window_id, tab_id, nav1, true);
849 836
850 ScopedVector<SessionWindow> windows; 837 ScopedVector<SessionWindow> windows;
851 ReadWindows(&(windows.get()), NULL); 838 ReadWindows(&(windows.get()), NULL);
852 839
853 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); 840 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1);
854 841
855 // Expected: the HTTP body was removed from the content state of the POST 842 // Expected: the HTTP body was removed from the page state of the POST
856 // navigation with passwords. 843 // navigation with passwords.
857 EXPECT_NE(content_state, windows[0]->tabs[0]->navigations[0].content_state()); 844 EXPECT_NE(page_state, windows[0]->tabs[0]->navigations[0].page_state());
858 } 845 }
859 846
860 // This test is only applicable to chromeos. 847 // This test is only applicable to chromeos.
861 #if defined(OS_CHROMEOS) 848 #if defined(OS_CHROMEOS)
862 // Verifies migration of tab/window closed works. 849 // Verifies migration of tab/window closed works.
863 TEST_F(SessionServiceTest, CanOpenV1TabClosed) { 850 TEST_F(SessionServiceTest, CanOpenV1TabClosed) {
864 base::FilePath v1_file_path; 851 base::FilePath v1_file_path;
865 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &v1_file_path)); 852 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &v1_file_path));
866 // v1_session_file contains a tab closed command with the original id. The 853 // v1_session_file contains a tab closed command with the original id. The
867 // file was generated from ClosingTabStaysClosed. If we successfully processed 854 // file was generated from ClosingTabStaysClosed. If we successfully processed
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 service()->ScheduleCommand( 979 service()->ScheduleCommand(
993 service()->CreateSetActiveWindowCommand(window_id)); 980 service()->CreateSetActiveWindowCommand(window_id));
994 service()->ScheduleCommand( 981 service()->ScheduleCommand(
995 service()->CreateSetActiveWindowCommand(window2_id)); 982 service()->CreateSetActiveWindowCommand(window2_id));
996 983
997 ScopedVector<SessionWindow> windows; 984 ScopedVector<SessionWindow> windows;
998 SessionID::id_type active_window_id = 0; 985 SessionID::id_type active_window_id = 0;
999 ReadWindows(&(windows.get()), &active_window_id); 986 ReadWindows(&(windows.get()), &active_window_id);
1000 EXPECT_EQ(window2_id.id(), active_window_id); 987 EXPECT_EQ(window2_id.id(), active_window_id);
1001 } 988 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698