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

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

Issue 25414005: Clear session-only data when all browser windows are closed. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 2 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/background/background_mode_manager.h"
12 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/content_settings/cookie_settings.h" 15 #include "chrome/browser/content_settings/cookie_settings.h"
14 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 16 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
15 #include "chrome/browser/infobars/infobar_service.h" 17 #include "chrome/browser/infobars/infobar_service.h"
18 #include "chrome/browser/lifetime/application_lifetime.h"
16 #include "chrome/browser/prefs/session_startup_pref.h" 19 #include "chrome/browser/prefs/session_startup_pref.h"
17 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_impl.h" 21 #include "chrome/browser/profiles/profile_impl.h"
19 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/sessions/session_backend.h" 23 #include "chrome/browser/sessions/session_backend.h"
21 #include "chrome/browser/sessions/session_service_factory.h" 24 #include "chrome/browser/sessions/session_service_factory.h"
25 #include "chrome/browser/sessions/session_service_test_helper.h"
22 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_commands.h" 27 #include "chrome/browser/ui/browser_commands.h"
24 #include "chrome/browser/ui/browser_iterator.h" 28 #include "chrome/browser/ui/browser_iterator.h"
25 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/startup/startup_browser_creator.h" 30 #include "chrome/browser/ui/startup/startup_browser_creator.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 31 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/common/chrome_switches.h" 32 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/content_settings.h" 33 #include "chrome/common/content_settings.h"
30 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
32 #include "chrome/test/base/in_process_browser_test.h" 36 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/ui_test_utils.h" 37 #include "chrome/test/base/ui_test_utils.h"
34 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/url_constants.h" 39 #include "content/public/common/url_constants.h"
36 #include "content/public/test/browser_test_utils.h" 40 #include "content/public/test/browser_test_utils.h"
37 #include "net/base/net_util.h" 41 #include "net/base/net_util.h"
38 #include "net/base/upload_bytes_element_reader.h" 42 #include "net/base/upload_bytes_element_reader.h"
39 #include "net/base/upload_data_stream.h" 43 #include "net/base/upload_data_stream.h"
40 #include "net/url_request/url_request.h" 44 #include "net/url_request/url_request.h"
41 #include "net/url_request/url_request_filter.h" 45 #include "net/url_request/url_request_filter.h"
42 #include "net/url_request/url_request_test_job.h" 46 #include "net/url_request/url_request_test_job.h"
43 47
48 #if defined(OS_MACOSX)
49 #include "base/mac/scoped_nsautorelease_pool.h"
50 #endif
51
44 namespace { 52 namespace {
45 53
46 Browser* FindOneOtherBrowserForProfile(Profile* profile, 54 Browser* FindOneOtherBrowserForProfile(Profile* profile,
47 Browser* not_this_browser) { 55 Browser* not_this_browser) {
48 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 56 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
49 if (*it != not_this_browser && it->profile() == profile) 57 if (*it != not_this_browser && it->profile() == profile)
50 return *it; 58 return *it;
51 } 59 }
52 return NULL; 60 return NULL;
53 } 61 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 std::string(bytes_reader->bytes(), bytes_reader->length()); 98 std::string(bytes_reader->bytes(), bytes_reader->length());
91 } 99 }
92 } 100 }
93 } 101 }
94 return new net::URLRequestTestJob( 102 return new net::URLRequestTestJob(
95 request, network_delegate, net::URLRequestTestJob::test_headers(), 103 request, network_delegate, net::URLRequestTestJob::test_headers(),
96 "<html><head><title>PASS</title></head><body>Data posted</body></html>", 104 "<html><head><title>PASS</title></head><body>Data posted</body></html>",
97 true); 105 true);
98 } 106 }
99 107
108 class FakeBackgroundModeManager : public BackgroundModeManager {
109 public:
110 FakeBackgroundModeManager()
111 : BackgroundModeManager(
112 CommandLine::ForCurrentProcess(),
113 &g_browser_process->profile_manager()->GetProfileInfoCache()),
114 background_mode_active_(false) {}
115
116 void SetBackgroundModeActive(bool active) {
117 background_mode_active_ = active;
118 }
119
120 virtual bool IsBackgroundModeActive() OVERRIDE {
121 return background_mode_active_;
122 }
123
124 private:
125 bool background_mode_active_;
126
127 };
128
100 } // namespace 129 } // namespace
101 130
102 class BetterSessionRestoreTest : public InProcessBrowserTest { 131 class BetterSessionRestoreTest : public InProcessBrowserTest {
103 public: 132 public:
104 BetterSessionRestoreTest() 133 BetterSessionRestoreTest()
105 : fake_server_address_("http://www.test.com/"), 134 : fake_server_address_("http://www.test.com/"),
106 test_path_("session_restore/"), 135 test_path_("session_restore/"),
107 title_pass_(ASCIIToUTF16("PASS")), 136 title_pass_(ASCIIToUTF16("PASS")),
108 title_storing_(ASCIIToUTF16("STORING")), 137 title_storing_(ASCIIToUTF16("STORING")),
109 title_error_write_failed_(ASCIIToUTF16("ERROR_WRITE_FAILED")), 138 title_error_write_failed_(ASCIIToUTF16("ERROR_WRITE_FAILED")),
(...skipping 21 matching lines...) Expand all
131 net::URLRequestFilter::GetInstance()->AddUrlHandler( 160 net::URLRequestFilter::GetInstance()->AddUrlHandler(
132 GURL(fake_server_address_ + test_path_ + *it), 161 GURL(fake_server_address_ + test_path_ + *it),
133 &URLRequestFaker); 162 &URLRequestFaker);
134 } 163 }
135 net::URLRequestFilter::GetInstance()->AddUrlHandler( 164 net::URLRequestFilter::GetInstance()->AddUrlHandler(
136 GURL(fake_server_address_ + test_path_ + "posted.php"), 165 GURL(fake_server_address_ + test_path_ + "posted.php"),
137 &URLRequestFakerForPostRequests); 166 &URLRequestFakerForPostRequests);
138 } 167 }
139 168
140 protected: 169 protected:
170 virtual void SetUpOnMainThread() OVERRIDE {
171 SessionServiceTestHelper helper(
172 SessionServiceFactory::GetForProfile(browser()->profile()));
173 helper.SetForceBrowserNotAliveWithNoWindows(true);
174 helper.ReleaseService();
175 g_browser_process->set_background_mode_manager_for_test(
176 scoped_ptr<BackgroundModeManager>(new FakeBackgroundModeManager));
177 }
178
141 void StoreDataWithPage(const std::string& filename) { 179 void StoreDataWithPage(const std::string& filename) {
142 StoreDataWithPage(browser(), filename); 180 StoreDataWithPage(browser(), filename);
143 } 181 }
144 182
145 void StoreDataWithPage(Browser* browser, const std::string& filename) { 183 void StoreDataWithPage(Browser* browser, const std::string& filename) {
146 content::WebContents* web_contents = 184 content::WebContents* web_contents =
147 browser->tab_strip_model()->GetActiveWebContents(); 185 browser->tab_strip_model()->GetActiveWebContents();
148 content::TitleWatcher title_watcher(web_contents, title_storing_); 186 content::TitleWatcher title_watcher(web_contents, title_storing_);
149 title_watcher.AlsoWaitForTitle(title_pass_); 187 title_watcher.AlsoWaitForTitle(title_pass_);
150 title_watcher.AlsoWaitForTitle(title_error_write_failed_); 188 title_watcher.AlsoWaitForTitle(title_error_write_failed_);
(...skipping 26 matching lines...) Expand all
177 215
178 void CheckReloadedPageRestored() { 216 void CheckReloadedPageRestored() {
179 CheckTitle(browser(), title_pass_); 217 CheckTitle(browser(), title_pass_);
180 } 218 }
181 219
182 void CheckReloadedPageRestored(Browser* browser) { 220 void CheckReloadedPageRestored(Browser* browser) {
183 CheckTitle(browser, title_pass_); 221 CheckTitle(browser, title_pass_);
184 } 222 }
185 223
186 void CheckReloadedPageNotRestored() { 224 void CheckReloadedPageNotRestored() {
187 CheckTitle(browser(), title_storing_); 225 CheckReloadedPageNotRestored(browser());
226 }
227
228 void CheckReloadedPageNotRestored(Browser* browser) {
229 CheckTitle(browser, title_storing_);
188 } 230 }
189 231
190 void CheckTitle(Browser* browser, const string16& expected_title) { 232 void CheckTitle(Browser* browser, const string16& expected_title) {
191 content::WebContents* web_contents = 233 content::WebContents* web_contents =
192 browser->tab_strip_model()->GetWebContentsAt(0); 234 browser->tab_strip_model()->GetWebContentsAt(0);
193 content::TitleWatcher title_watcher(web_contents, expected_title); 235 content::TitleWatcher title_watcher(web_contents, expected_title);
194 title_watcher.AlsoWaitForTitle(title_pass_); 236 title_watcher.AlsoWaitForTitle(title_pass_);
195 title_watcher.AlsoWaitForTitle(title_storing_); 237 title_watcher.AlsoWaitForTitle(title_storing_);
196 title_watcher.AlsoWaitForTitle(title_error_write_failed_); 238 title_watcher.AlsoWaitForTitle(title_error_write_failed_);
197 title_watcher.AlsoWaitForTitle(title_error_empty_); 239 title_watcher.AlsoWaitForTitle(title_error_empty_);
(...skipping 25 matching lines...) Expand all
223 std::string::npos); 265 std::string::npos);
224 if (password_present) { 266 if (password_present) {
225 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") != 267 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") !=
226 std::string::npos); 268 std::string::npos);
227 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") != 269 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") !=
228 std::string::npos); 270 std::string::npos);
229 } 271 }
230 } 272 }
231 273
232 void CheckFormRestored(bool text_present, bool password_present) { 274 void CheckFormRestored(bool text_present, bool password_present) {
233 CheckReloadedPageRestored(); 275 CheckFormRestored(browser(), text_present, password_present);
276 }
277
278 void CheckFormRestored(
279 Browser* browser, bool text_present, bool password_present) {
280 CheckReloadedPageRestored(browser);
234 if (text_present) { 281 if (text_present) {
235 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") != 282 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") !=
236 std::string::npos); 283 std::string::npos);
237 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") != 284 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") !=
238 std::string::npos); 285 std::string::npos);
239 } else { 286 } else {
240 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") == 287 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") ==
241 std::string::npos); 288 std::string::npos);
242 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") == 289 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") ==
243 std::string::npos); 290 std::string::npos);
244 } 291 }
245 if (password_present) { 292 if (password_present) {
246 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") != 293 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") !=
247 std::string::npos); 294 std::string::npos);
248 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") != 295 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") !=
249 std::string::npos); 296 std::string::npos);
250 } else { 297 } else {
251 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") == 298 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") ==
252 std::string::npos); 299 std::string::npos);
253 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") == 300 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") ==
254 std::string::npos); 301 std::string::npos);
255 } 302 }
256 } 303 }
257 304
305 void CloseBrowserSynchronously(Browser* browser) {
306 content::WindowedNotificationObserver observer(
307 chrome::NOTIFICATION_BROWSER_CLOSED,
308 content::NotificationService::AllSources());
309 browser->window()->Close();
310 #if defined(OS_MACOSX)
311 // BrowserWindowController depends on the auto release pool being recycled
312 // in the message loop to delete itself, which frees the Browser object
313 // which fires this event.
314 AutoreleasePool()->Recycle();
315 #endif
316 observer.Wait();
317 }
318
319 virtual Browser* QuitBrowserAndRestore(Browser* browser) {
320 Profile* profile = browser->profile();
321
322 // Close the browser.
323 chrome::StartKeepAlive();
324 CloseBrowserSynchronously(browser);
325
326 // Create a new window, which should trigger session restore.
327 ui_test_utils::BrowserAddedObserver window_observer;
328 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
329 Browser* new_browser = window_observer.WaitForSingleNewBrowser();
330 chrome::EndKeepAlive();
331
332 return new_browser;
333 }
334
258 std::string fake_server_address() { 335 std::string fake_server_address() {
259 return fake_server_address_; 336 return fake_server_address_;
260 } 337 }
261 338
262 std::string test_path() { 339 std::string test_path() {
263 return test_path_; 340 return test_path_;
264 } 341 }
265 342
343 void EnableBackgroundMode() {
344 static_cast<FakeBackgroundModeManager*>(
345 g_browser_process->background_mode_manager())->
346 SetBackgroundModeActive(true);
347 }
348
349 void DisableBackgroundMode() {
350 static_cast<FakeBackgroundModeManager*>(
351 g_browser_process->background_mode_manager())->
352 SetBackgroundModeActive(false);
353 }
354
266 private: 355 private:
267 const std::string fake_server_address_; 356 const std::string fake_server_address_;
268 const std::string test_path_; 357 const std::string test_path_;
269 const string16 title_pass_; 358 const string16 title_pass_;
270 const string16 title_storing_; 359 const string16 title_storing_;
271 const string16 title_error_write_failed_; 360 const string16 title_error_write_failed_;
272 const string16 title_error_empty_; 361 const string16 title_error_empty_;
273 362
274 DISALLOW_COPY_AND_ASSIGN(BetterSessionRestoreTest); 363 DISALLOW_COPY_AND_ASSIGN(BetterSessionRestoreTest);
275 }; 364 };
276 365
277 class ContinueWhereILeftOffTest : public BetterSessionRestoreTest { 366 class ContinueWhereILeftOffTest : public BetterSessionRestoreTest {
278 public: 367 public:
279 ContinueWhereILeftOffTest() { } 368 ContinueWhereILeftOffTest() { }
280 369
281 virtual void SetUpOnMainThread() OVERRIDE { 370 virtual void SetUpOnMainThread() OVERRIDE {
282 BetterSessionRestoreTest::SetUpOnMainThread(); 371 BetterSessionRestoreTest::SetUpOnMainThread();
283 SessionStartupPref::SetStartupPref( 372 SessionStartupPref::SetStartupPref(
284 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); 373 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST));
285 } 374 }
286 375
376 protected:
377 virtual Browser* QuitBrowserAndRestore(Browser* browser) OVERRIDE {
378 content::WindowedNotificationObserver session_restore_observer(
379 chrome::NOTIFICATION_SESSION_RESTORE_DONE,
380 content::NotificationService::AllSources());
381 Browser* new_browser =
382 BetterSessionRestoreTest::QuitBrowserAndRestore(browser);
383 session_restore_observer.Wait();
384 return new_browser;
385 }
386
287 DISALLOW_COPY_AND_ASSIGN(ContinueWhereILeftOffTest); 387 DISALLOW_COPY_AND_ASSIGN(ContinueWhereILeftOffTest);
288 }; 388 };
289 389
290 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_SessionCookies) { 390 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_SessionCookies) {
291 // Set the startup preference to "continue where I left off" and visit a page 391 // Set the startup preference to "continue where I left off" and visit a page
292 // which stores a session cookie. 392 // which stores a session cookie.
293 StoreDataWithPage("session_cookies.html"); 393 StoreDataWithPage("session_cookies.html");
294 } 394 }
295 395
296 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookies) { 396 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookies) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_PostWithPassword) { 453 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_PostWithPassword) {
354 PostFormWithPage("post_with_password.html", true); 454 PostFormWithPage("post_with_password.html", true);
355 } 455 }
356 456
357 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostWithPassword) { 457 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostWithPassword) {
358 CheckReloadedPageRestored(); 458 CheckReloadedPageRestored();
359 // The form data contained passwords, so it's removed completely. 459 // The form data contained passwords, so it's removed completely.
360 CheckFormRestored(false, false); 460 CheckFormRestored(false, false);
361 } 461 }
362 462
463 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookiesBrowserClose) {
464 // Set the startup preference to "continue where I left off" and visit a page
465 // which stores a session cookie.
466 StoreDataWithPage("session_cookies.html");
467 Browser* new_browser = QuitBrowserAndRestore(browser());
468 // The browsing session will be continued; just wait for the page to reload
469 // and check the stored data.
470 CheckReloadedPageRestored(new_browser);
471 }
472
473 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest,
474 CookiesClearedOnBrowserClose) {
475 StoreDataWithPage("cookies.html");
476 // Normally cookies are restored.
477 Browser* new_browser = QuitBrowserAndRestore(browser());
478 CheckReloadedPageRestored(new_browser);
479 // ... but not if the content setting is set to clear on exit.
480 CookieSettings::Factory::GetForProfile(new_browser->profile())->
481 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY);
482 // ... unless background mode is active.
483 EnableBackgroundMode();
484 new_browser = QuitBrowserAndRestore(new_browser);
485 CheckReloadedPageRestored(new_browser);
486
487 DisableBackgroundMode();
488 new_browser = QuitBrowserAndRestore(new_browser);
489 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
490 CheckReloadedPageRestored(new_browser);
491 #else
492 CheckReloadedPageNotRestored(new_browser);
493 #endif
494 }
495
496 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostBrowserClose) {
497 PostFormWithPage("post.html", false);
498 Browser* new_browser = QuitBrowserAndRestore(browser());
499 CheckFormRestored(new_browser, true, false);
500 }
501
502 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest,
503 PostWithPasswordBrowserClose) {
504 PostFormWithPage("post_with_password.html", true);
505 Browser* new_browser = QuitBrowserAndRestore(browser());
506 CheckReloadedPageRestored(new_browser);
507 // The form data contained passwords, so it's removed completely.
508 CheckFormRestored(new_browser, false, false);
509 }
510
363 class RestartTest : public BetterSessionRestoreTest { 511 class RestartTest : public BetterSessionRestoreTest {
364 public: 512 public:
365 RestartTest() { } 513 RestartTest() { }
366 virtual ~RestartTest() { } 514 virtual ~RestartTest() { }
367 protected: 515 protected:
368 void Restart() { 516 void Restart() {
369 // Simluate restarting the browser, but let the test exit peacefully. 517 // Simluate restarting the browser, but let the test exit peacefully.
370 for (chrome::BrowserIterator it; !it.done(); it.Next()) 518 for (chrome::BrowserIterator it; !it.done(); it.Next())
371 content::BrowserContext::SaveSessionState(it->profile()); 519 content::BrowserContext::SaveSessionState(it->profile());
372 PrefService* pref_service = g_browser_process->local_state(); 520 PrefService* pref_service = g_browser_process->local_state();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 671 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY);
524 } 672 }
525 673
526 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnExit) { 674 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnExit) {
527 content::WebContents* web_contents = 675 content::WebContents* web_contents =
528 browser()->tab_strip_model()->GetActiveWebContents(); 676 browser()->tab_strip_model()->GetActiveWebContents();
529 EXPECT_EQ(std::string(content::kAboutBlankURL), 677 EXPECT_EQ(std::string(content::kAboutBlankURL),
530 web_contents->GetURL().spec()); 678 web_contents->GetURL().spec());
531 StoreDataWithPage("local_storage.html"); 679 StoreDataWithPage("local_storage.html");
532 } 680 }
681
682 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionCookiesBrowserClose) {
683 StoreDataWithPage("session_cookies.html");
684 EnableBackgroundMode();
685 Browser* new_browser = QuitBrowserAndRestore(browser());
686 NavigateAndCheckStoredData(new_browser, "session_cookies.html");
687 DisableBackgroundMode();
688 new_browser = QuitBrowserAndRestore(new_browser);
689 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
690 NavigateAndCheckStoredData(new_browser, "session_cookies.html");
691 #else
692 StoreDataWithPage(new_browser, "session_cookies.html");
693 #endif
694 }
695
696 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnBrowserClose) {
697 StoreDataWithPage("cookies.html");
698
699 // Normally cookies are restored.
700 Browser* new_browser = QuitBrowserAndRestore(browser());
701 NavigateAndCheckStoredData(new_browser, "cookies.html");
702
703 // ... but not if the content setting is set to clear on exit.
704 CookieSettings::Factory::GetForProfile(new_browser->profile())->
705 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY);
706 // ... unless background mode is active.
707 EnableBackgroundMode();
708 new_browser = QuitBrowserAndRestore(new_browser);
709 NavigateAndCheckStoredData(new_browser, "cookies.html");
710 DisableBackgroundMode();
711 new_browser = QuitBrowserAndRestore(new_browser);
712 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
713 NavigateAndCheckStoredData(new_browser, "cookies.html");
714 #else
715 StoreDataWithPage(new_browser, "cookies.html");
716 #endif
717 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698