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

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

Issue 18500005: Fix SessionStorage confusion between RenderViewHostImpl and NavigationController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: code review Created 7 years, 5 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 EXPECT_EQ(url1_, 1066 EXPECT_EQ(url1_,
1067 new_browser->tab_strip_model()->GetWebContentsAt(0)->GetURL()); 1067 new_browser->tab_strip_model()->GetWebContentsAt(0)->GetURL());
1068 EXPECT_EQ(url2_, 1068 EXPECT_EQ(url2_,
1069 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); 1069 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL());
1070 } 1070 }
1071 1071
1072 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, SessionStorage) { 1072 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, SessionStorage) {
1073 ui_test_utils::NavigateToURL(browser(), url1_); 1073 ui_test_utils::NavigateToURL(browser(), url1_);
1074 content::NavigationController* controller = 1074 content::NavigationController* controller =
1075 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); 1075 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
1076 ASSERT_TRUE(controller->GetDefaultSessionStorageNamespace()); 1076 ASSERT_TRUE(controller->GetSessionStorageNamespace());
1077 std::string session_storage_persistent_id = 1077 std::string session_storage_persistent_id =
1078 controller->GetDefaultSessionStorageNamespace()->persistent_id(); 1078 controller->GetSessionStorageNamespace()->persistent_id();
1079 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); 1079 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
1080 ASSERT_EQ(1u, active_browser_list_->size()); 1080 ASSERT_EQ(1u, active_browser_list_->size());
1081 ASSERT_EQ(url1_, 1081 ASSERT_EQ(url1_,
1082 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL()); 1082 new_browser->tab_strip_model()->GetActiveWebContents()->GetURL());
1083 content::NavigationController* new_controller = 1083 content::NavigationController* new_controller =
1084 &new_browser->tab_strip_model()->GetActiveWebContents()->GetController(); 1084 &new_browser->tab_strip_model()->GetActiveWebContents()->GetController();
1085 ASSERT_TRUE(new_controller->GetDefaultSessionStorageNamespace()); 1085 ASSERT_TRUE(new_controller->GetSessionStorageNamespace());
1086 std::string restored_session_storage_persistent_id = 1086 std::string restored_session_storage_persistent_id =
1087 new_controller->GetDefaultSessionStorageNamespace()->persistent_id(); 1087 new_controller->GetSessionStorageNamespace()->persistent_id();
1088 EXPECT_EQ(session_storage_persistent_id, 1088 EXPECT_EQ(session_storage_persistent_id,
1089 restored_session_storage_persistent_id); 1089 restored_session_storage_persistent_id);
1090 } 1090 }
1091 1091
1092 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, SessionStorageAfterTabReplace) { 1092 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, SessionStorageAfterTabReplace) {
1093 // Simulate what prerendering does: create a new WebContents with the same 1093 // Simulate what prerendering does: create a new WebContents with the same
1094 // SessionStorageNamespace as an existing tab, then replace the tab with it. 1094 // SessionStorageNamespace as an existing tab, then replace the tab with it.
1095 { 1095 {
1096 content::NavigationController* controller = 1096 content::NavigationController* controller =
1097 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); 1097 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
1098 ASSERT_TRUE(controller->GetDefaultSessionStorageNamespace()); 1098 ASSERT_TRUE(controller->GetSessionStorageNamespace());
1099 1099
1100 content::SessionStorageNamespaceMap session_storage_namespace_map;
1101 session_storage_namespace_map[std::string()] =
1102 controller->GetDefaultSessionStorageNamespace();
1103 scoped_ptr<content::WebContents> web_contents( 1100 scoped_ptr<content::WebContents> web_contents(
1104 content::WebContents::CreateWithSessionStorage( 1101 content::WebContents::CreateWithSessionStorage(
1105 content::WebContents::CreateParams(browser()->profile()), 1102 content::WebContents::CreateParams(browser()->profile()),
1106 session_storage_namespace_map)); 1103 controller->GetSessionStorageNamespace()));
1107 1104
1108 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 1105 TabStripModel* tab_strip_model = browser()->tab_strip_model();
1109 scoped_ptr<content::WebContents> old_web_contents( 1106 scoped_ptr<content::WebContents> old_web_contents(
1110 tab_strip_model->ReplaceWebContentsAt( 1107 tab_strip_model->ReplaceWebContentsAt(
1111 tab_strip_model->active_index(), web_contents.release())); 1108 tab_strip_model->active_index(), web_contents.release()));
1112 // Navigate with the new tab. 1109 // Navigate with the new tab.
1113 ui_test_utils::NavigateToURL(browser(), url2_); 1110 ui_test_utils::NavigateToURL(browser(), url2_);
1114 // old_web_contents goes out of scope. 1111 // old_web_contents goes out of scope.
1115 } 1112 }
1116 1113
1117 // Check that the sessionStorage data is going to be persisted. 1114 // Check that the sessionStorage data is going to be persisted.
1118 content::NavigationController* controller = 1115 content::NavigationController* controller =
1119 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); 1116 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
1120 EXPECT_TRUE( 1117 EXPECT_TRUE(
1121 controller->GetDefaultSessionStorageNamespace()->should_persist()); 1118 controller->GetSessionStorageNamespace()->should_persist());
1122 1119
1123 // Quit and restore. Check that no extra tabs were created. 1120 // Quit and restore. Check that no extra tabs were created.
1124 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); 1121 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
1125 ASSERT_EQ(1u, active_browser_list_->size()); 1122 ASSERT_EQ(1u, active_browser_list_->size());
1126 EXPECT_EQ(1, new_browser->tab_strip_model()->count()); 1123 EXPECT_EQ(1, new_browser->tab_strip_model()->count());
1127 } 1124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698