better_session_restore_browsertest.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/file_util.h" 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/lazy_instance.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/path_service.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/background/background_mode_manager.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/browser_process.h" 148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/chrome_notification_types.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/content_settings/cookie_settings.h" 168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/defaults.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/infobars/confirm_infobar_delegate.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/infobars/infobar_service.h" 198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/lifetime/application_lifetime.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/prefs/session_startup_pref.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile_impl.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h" 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/sessions/session_backend.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/sessions/session_service_factory.h" 268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/sessions/session_service_test_helper.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_iterator.h" 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_window.h" 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/startup/startup_browser_creator.h" 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/content_settings.h" 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/pref_names.h" 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/url_constants.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h" 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/common/url_constants.h" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/browser_test_utils.h" 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_util.h" 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/upload_bytes_element_reader.h" 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/upload_data_stream.h" 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request.h" 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_filter.h" 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_test_job.h" 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#if defined(OS_MACOSX) 508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/mac/scoped_nsautorelease_pool.h" 518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif 528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// We need to serve the test files so that PRE_Test and Test can access the same 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// page using the same URL. In addition, perceived security origin of the page 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// needs to stay the same, so e.g., redirecting the URL requests doesn't 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// work. (If we used a test server, the PRE_Test and Test would have separate 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// instances running on separate ports.) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::LazyInstance<std::map<std::string, std::string> > g_file_contents = 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LAZY_INSTANCE_INITIALIZER; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)net::URLRequestJob* URLRequestFaker( 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::URLRequest* request, 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::NetworkDelegate* network_delegate, 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& scheme) { 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return new net::URLRequestTestJob( 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) request, network_delegate, net::URLRequestTestJob::test_headers(), 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_file_contents.Get()[request->url().path()], true); 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::LazyInstance<std::string> g_last_upload_bytes = LAZY_INSTANCE_INITIALIZER; 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)net::URLRequestJob* URLRequestFakerForPostRequests( 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) net::URLRequest* request, 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) net::NetworkDelegate* network_delegate, 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& scheme) { 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Read the uploaded data and store it to g_last_upload_bytes. 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const net::UploadDataStream* upload_data = request->get_upload(); 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_last_upload_bytes.Get().clear(); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (upload_data) { 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ScopedVector<net::UploadElementReader>& readers = 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) upload_data->element_readers(); 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (size_t i = 0; i < readers.size(); ++i) { 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const net::UploadBytesElementReader* bytes_reader = 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) readers[i]->AsBytesReader(); 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (bytes_reader) { 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_last_upload_bytes.Get() += 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string(bytes_reader->bytes(), bytes_reader->length()); 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return new net::URLRequestTestJob( 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) request, network_delegate, net::URLRequestTestJob::test_headers(), 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "<html><head><title>PASS</title></head><body>Data posted</body></html>", 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) true); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class FakeBackgroundModeManager : public BackgroundModeManager { 1018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public: 1028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) FakeBackgroundModeManager() 1038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) : BackgroundModeManager( 1048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CommandLine::ForCurrentProcess(), 1058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) &g_browser_process->profile_manager()->GetProfileInfoCache()), 1068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) background_mode_active_(false) {} 1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void SetBackgroundModeActive(bool active) { 1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) background_mode_active_ = active; 1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual bool IsBackgroundModeActive() OVERRIDE { 1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return background_mode_active_; 1148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) private: 1178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) bool background_mode_active_; 1188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}; 1208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BetterSessionRestoreTest : public InProcessBrowserTest { 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BetterSessionRestoreTest() 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : fake_server_address_("http://www.test.com/"), 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) test_path_("session_restore/"), 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) title_pass_(ASCIIToUTF16("PASS")), 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title_storing_(ASCIIToUTF16("STORING")), 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title_error_write_failed_(ASCIIToUTF16("ERROR_WRITE_FAILED")), 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) title_error_empty_(ASCIIToUTF16("ERROR_EMPTY")) { 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set up the URL request filtering. 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<std::string> test_files; 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_files.push_back("common.js"); 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) test_files.push_back("cookies.html"); 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_files.push_back("local_storage.html"); 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) test_files.push_back("post.html"); 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) test_files.push_back("post_with_password.html"); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_files.push_back("session_cookies.html"); 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_files.push_back("session_storage.html"); 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath test_file_dir; 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &test_file_dir)); 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_file_dir = 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test_file_dir.AppendASCII("chrome/test/data").AppendASCII(test_path_); 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (std::vector<std::string>::const_iterator it = test_files.begin(); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) it != test_files.end(); ++it) { 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path = test_file_dir.AppendASCII(*it); 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string contents; 15058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) CHECK(base::ReadFileToString(path, &contents)); 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_file_contents.Get()["/" + test_path_ + *it] = contents; 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::URLRequestFilter::GetInstance()->AddUrlHandler( 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL(fake_server_address_ + test_path_ + *it), 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &URLRequestFaker); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) net::URLRequestFilter::GetInstance()->AddUrlHandler( 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GURL(fake_server_address_ + test_path_ + "posted.php"), 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) &URLRequestFakerForPostRequests); 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 1628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void SetUpOnMainThread() OVERRIDE { 1638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SessionServiceTestHelper helper( 1648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SessionServiceFactory::GetForProfile(browser()->profile())); 1658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) helper.SetForceBrowserNotAliveWithNoWindows(true); 1668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) helper.ReleaseService(); 1678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) g_browser_process->set_background_mode_manager_for_test( 1688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) scoped_ptr<BackgroundModeManager>(new FakeBackgroundModeManager)); 1698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StoreDataWithPage(const std::string& filename) { 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage(browser(), filename); 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void StoreDataWithPage(Browser* browser, const std::string& filename) { 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WebContents* web_contents = 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->GetActiveWebContents(); 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher(web_contents, title_storing_); 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title_watcher.AlsoWaitForTitle(title_pass_); 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title_watcher.AlsoWaitForTitle(title_error_write_failed_); 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title_watcher.AlsoWaitForTitle(title_error_empty_); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURL( 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser, GURL(fake_server_address_ + test_path_ + filename)); 184a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 final_title = title_watcher.WaitAndGetTitle(); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(title_storing_, final_title); 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NavigateAndCheckStoredData(const std::string& filename) { 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCheckStoredData(browser(), filename); 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NavigateAndCheckStoredData(Browser* browser, 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& filename) { 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Navigate to a page which has previously stored data; check that the 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // stored data can be accessed. 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->GetActiveWebContents(); 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::TitleWatcher title_watcher(web_contents, title_pass_); 1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) title_watcher.AlsoWaitForTitle(title_storing_); 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) title_watcher.AlsoWaitForTitle(title_error_write_failed_); 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) title_watcher.AlsoWaitForTitle(title_error_empty_); 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::NavigateToURL( 2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser, GURL(fake_server_address_ + test_path_ + filename)); 204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 final_title = title_watcher.WaitAndGetTitle(); 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(title_pass_, final_title); 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CheckReloadedPageRestored() { 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckTitle(browser(), title_pass_); 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void CheckReloadedPageRestored(Browser* browser) { 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckTitle(browser, title_pass_); 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CheckReloadedPageNotRestored() { 2178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageNotRestored(browser()); 2188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 2198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void CheckReloadedPageNotRestored(Browser* browser) { 2218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckTitle(browser, title_storing_); 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 224a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void CheckTitle(Browser* browser, const base::string16& expected_title) { 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser->tab_strip_model()->GetWebContentsAt(0); 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::TitleWatcher title_watcher(web_contents, expected_title); 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title_watcher.AlsoWaitForTitle(title_pass_); 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title_watcher.AlsoWaitForTitle(title_storing_); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title_watcher.AlsoWaitForTitle(title_error_write_failed_); 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title_watcher.AlsoWaitForTitle(title_error_empty_); 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // It's possible that the title was already the right one before 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // title_watcher was created. 234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 first_title = web_contents->GetTitle(); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (first_title != title_pass_ && 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) first_title != title_storing_ && 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) first_title != title_error_write_failed_ && 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) first_title != title_error_empty_) { 239a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 final_title = title_watcher.WaitAndGetTitle(); 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title, final_title); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_title, first_title); 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void PostFormWithPage(const std::string& filename, bool password_present) { 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::TitleWatcher title_watcher(web_contents, title_pass_); 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui_test_utils::NavigateToURL( 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser(), GURL(fake_server_address_ + test_path_ + filename)); 252a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 final_title = title_watcher.WaitAndGetTitle(); 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(title_pass_, final_title); 2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") != 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") != 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (password_present) { 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") != 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") != 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void CheckFormRestored(bool text_present, bool password_present) { 2678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckFormRestored(browser(), text_present, password_present); 2688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 2698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void CheckFormRestored( 2718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) Browser* browser, bool text_present, bool password_present) { 2728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(browser); 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (text_present) { 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") != 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") != 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") == 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") == 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (password_present) { 2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") != 2862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") != 2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") == 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") == 2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string::npos); 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void CloseBrowserSynchronously(Browser* browser, bool close_all_windows) { 2988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) content::WindowedNotificationObserver observer( 2998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) chrome::NOTIFICATION_BROWSER_CLOSED, 3008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) content::NotificationService::AllSources()); 3011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (close_all_windows) 3021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome::CloseAllBrowsers(); 3031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) else 3041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser->window()->Close(); 3058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#if defined(OS_MACOSX) 3068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // BrowserWindowController depends on the auto release pool being recycled 3078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // in the message loop to delete itself, which frees the Browser object 3088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // which fires this event. 3098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) AutoreleasePool()->Recycle(); 3108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif 3118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) observer.Wait(); 3128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 3138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual Browser* QuitBrowserAndRestore(Browser* browser, 3151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool close_all_windows) { 3168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) Profile* profile = browser->profile(); 3178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Close the browser. 3198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) chrome::StartKeepAlive(); 3201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CloseBrowserSynchronously(browser, close_all_windows); 3211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SessionServiceTestHelper helper; 3231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) helper.SetService( 3241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SessionServiceFactory::GetForProfileForSessionRestore(profile)); 3251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) helper.SetForceBrowserNotAliveWithNoWindows(true); 3261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) helper.ReleaseService(); 3278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Create a new window, which should trigger session restore. 3298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ui_test_utils::BrowserAddedObserver window_observer; 3308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); 3318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) Browser* new_browser = window_observer.WaitForSingleNewBrowser(); 3328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) chrome::EndKeepAlive(); 3338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return new_browser; 3358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 3368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string fake_server_address() { 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return fake_server_address_; 3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string test_path() { 3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return test_path_; 3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void EnableBackgroundMode() { 3468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static_cast<FakeBackgroundModeManager*>( 3478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) g_browser_process->background_mode_manager())-> 3488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SetBackgroundModeActive(true); 3498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 3508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void DisableBackgroundMode() { 3528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static_cast<FakeBackgroundModeManager*>( 3538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) g_browser_process->background_mode_manager())-> 3548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SetBackgroundModeActive(false); 3558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 3568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string fake_server_address_; 3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string test_path_; 360a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 title_pass_; 361a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 title_storing_; 362a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 title_error_write_failed_; 363a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16 title_error_empty_; 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BetterSessionRestoreTest); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ContinueWhereILeftOffTest : public BetterSessionRestoreTest { 3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ContinueWhereILeftOffTest() { } 3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUpOnMainThread() OVERRIDE { 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BetterSessionRestoreTest::SetUpOnMainThread(); 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SessionStartupPref::SetStartupPref( 3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); 3762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) protected: 3791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual Browser* QuitBrowserAndRestore(Browser* browser, 3801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool close_all_windows) OVERRIDE { 3818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) content::WindowedNotificationObserver session_restore_observer( 3828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) chrome::NOTIFICATION_SESSION_RESTORE_DONE, 3838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) content::NotificationService::AllSources()); 3841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = BetterSessionRestoreTest::QuitBrowserAndRestore( 3851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser, close_all_windows); 3868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) session_restore_observer.Wait(); 3878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return new_browser; 3888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 3898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ContinueWhereILeftOffTest); 3912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 3922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_SessionCookies) { 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set the startup preference to "continue where I left off" and visit a page 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // which stores a session cookie. 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StoreDataWithPage("session_cookies.html"); 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookies) { 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The browsing session will be continued; just wait for the page to reload 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and check the stored data. 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CheckReloadedPageRestored(); 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_SessionStorage) { 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StoreDataWithPage("session_storage.html"); 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionStorage) { 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CheckReloadedPageRestored(); 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRE_PRE_LocalStorageClearedOnExit) { 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StoreDataWithPage("local_storage.html"); 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PRE_LocalStorageClearedOnExit) { 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Normally localStorage is restored. 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CheckReloadedPageRestored(); 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ... but not if it's set to clear on exit. 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, LocalStorageClearedOnExit) { 4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageNotRestored(); 4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PRE_PRE_CookiesClearedOnExit) { 4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("cookies.html"); 4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_CookiesClearedOnExit) { 4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Normally cookies are restored. 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ... but not if the content setting is set to clear on exit. 4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, CookiesClearedOnExit) { 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CheckReloadedPageNotRestored(); 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_Post) { 4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PostFormWithPage("post.html", false); 4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, Post) { 4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckFormRestored(true, false); 4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_PostWithPassword) { 4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PostFormWithPage("post_with_password.html", true); 4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostWithPassword) { 4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The form data contained passwords, so it's removed completely. 4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckFormRestored(false, false); 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookiesBrowserClose) { 4678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Set the startup preference to "continue where I left off" and visit a page 4688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // which stores a session cookie. 4698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage("session_cookies.html"); 4701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 4718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // The browsing session will be continued; just wait for the page to reload 4728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // and check the stored data. 4738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(new_browser); 4748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 4768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 4778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CookiesClearedOnBrowserClose) { 4788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage("cookies.html"); 4798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Normally cookies are restored. 4801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 4818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(new_browser); 4828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // ... but not if the content setting is set to clear on exit. 4838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CookieSettings::Factory::GetForProfile(new_browser->profile())-> 4848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 4858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // ... unless background mode is active. 4868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EnableBackgroundMode(); 4871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 4888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(new_browser); 4898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 4908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DisableBackgroundMode(); 4911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 4928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (browser_defaults::kBrowserAliveWithNoWindows) 4938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(new_browser); 4948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) else 4958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageNotRestored(new_browser); 4968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 4978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 4988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostBrowserClose) { 4998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PostFormWithPage("post.html", false); 5001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 5018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckFormRestored(new_browser, true, false); 5028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 5038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 5048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 5058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PostWithPasswordBrowserClose) { 5068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PostFormWithPage("post_with_password.html", true); 5071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 5081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageRestored(new_browser); 5091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The form data contained passwords, so it's removed completely. 5101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckFormRestored(new_browser, false, false); 5111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that session cookies are cleared on a wrench menu quit. 5141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 5151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SessionCookiesCloseAllBrowsers) { 5161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Set the startup preference to "continue where I left off" and visit a page 5171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // which stores a session cookie. 5181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage("session_cookies.html"); 5191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 5201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The browsing session will be continued; just wait for the page to reload 5211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // and check the stored data. 5221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageRestored(new_browser); 5231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that cookies are cleared on a wrench menu quit only if cookies are set 5261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// to current session only, regardless of whether background mode is enabled. 5271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 5281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CookiesClearedOnCloseAllBrowsers) { 5291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage("cookies.html"); 5301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Normally cookies are restored. 5311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 5321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageRestored(new_browser); 5331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // ... but not if the content setting is set to clear on exit. 5341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CookieSettings::Factory::GetForProfile(new_browser->profile())-> 5351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 5361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // ... even if background mode is active. 5371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EnableBackgroundMode(); 5381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 5391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageNotRestored(new_browser); 5401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DisableBackgroundMode(); 5421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 5431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageNotRestored(new_browser); 5441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that form data is restored after wrench menu quit. 5471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostCloseAllBrowsers) { 5481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PostFormWithPage("post.html", false); 5491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 5501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckFormRestored(new_browser, true, false); 5511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that form data with a password field is cleared after wrench menu quit. 5541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 5551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PostWithPasswordCloseAllBrowsers) { 5561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PostFormWithPage("post_with_password.html", true); 5571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 5588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(new_browser); 5598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // The form data contained passwords, so it's removed completely. 5608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckFormRestored(new_browser, false, false); 5618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 5628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 5632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class RestartTest : public BetterSessionRestoreTest { 5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 5652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RestartTest() { } 5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~RestartTest() { } 5672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Restart() { 5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Simluate restarting the browser, but let the test exit peacefully. 5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (chrome::BrowserIterator it; !it.done(); it.Next()) 5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::BrowserContext::SaveSessionState(it->profile()); 5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PrefService* pref_service = g_browser_process->local_state(); 5732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_service->SetBoolean(prefs::kWasRestarted, true); 5742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 5750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (pref_service->HasPrefPath(prefs::kRelaunchMode)) 5760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) pref_service->ClearPref(prefs::kRelaunchMode); 5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 5812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(RestartTest); 5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_SessionCookies) { 5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_cookies.html"); 5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, SessionCookies) { 5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_SessionStorage) { 5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_storage.html"); 5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, SessionStorage) { 5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_LocalStorageClearedOnExit) { 6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("local_storage.html"); 6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 6062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, LocalStorageClearedOnExit) { 6102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_CookiesClearedOnExit) { 6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("cookies.html"); 6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, CookiesClearedOnExit) { 6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_Post) { 6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PostFormWithPage("post.html", false); 6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, Post) { 6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckFormRestored(true, false); 6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_PostWithPassword) { 6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PostFormWithPage("post_with_password.html", true); 6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PostWithPassword) { 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The form data contained passwords, so it's removed completely. 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckFormRestored(false, false); 6412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// These tests ensure that the Better Session Restore features are not triggered 6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// when they shouldn't be. 6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NoSessionRestoreTest : public BetterSessionRestoreTest { 6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 6472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NoSessionRestoreTest() { } 6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUpOnMainThread() OVERRIDE { 6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BetterSessionRestoreTest::SetUpOnMainThread(); 6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SessionStartupPref::SetStartupPref( 6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->profile(), SessionStartupPref(SessionStartupPref::DEFAULT)); 6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(NoSessionRestoreTest); 6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_SessionCookies) { 6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_cookies.html"); 6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionCookies) { 6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 66690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(std::string(content::kAboutBlankURL), 66790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) web_contents->GetURL().spec()); 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // When we navigate to the page again, it doens't see the data previously 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // stored. 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_cookies.html"); 6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_SessionStorage) { 6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_storage.html"); 6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionStorage) { 6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 68090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(std::string(content::kAboutBlankURL), 68190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) web_contents->GetURL().spec()); 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_storage.html"); 6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, 6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PRE_PRE_LocalStorageClearedOnExit) { 6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("local_storage.html"); 6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_LocalStorageClearedOnExit) { 6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Normally localStorage is persisted. 6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 69490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(std::string(content::kAboutBlankURL), 69590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) web_contents->GetURL().spec()); 6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCheckStoredData("local_storage.html"); 6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ... but not if it's set to clear on exit. 6982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, LocalStorageClearedOnExit) { 7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 70590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(std::string(content::kAboutBlankURL), 70690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) web_contents->GetURL().spec()); 7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("local_storage.html"); 7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_PRE_CookiesClearedOnExit) { 7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("cookies.html"); 7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_CookiesClearedOnExit) { 7152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Normally cookies are restored. 7162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 71890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(std::string(content::kAboutBlankURL), 71990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) web_contents->GetURL().spec()); 7202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCheckStoredData("cookies.html"); 7212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ... but not if the content setting is set to clear on exit. 7222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 7232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 7242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnExit) { 7272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 7282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 72990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(std::string(content::kAboutBlankURL), 73090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) web_contents->GetURL().spec()); 7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("local_storage.html"); 7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 7348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionCookiesBrowserClose) { 7358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage("session_cookies.html"); 7368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EnableBackgroundMode(); 7371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 7388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "session_cookies.html"); 7398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DisableBackgroundMode(); 7401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 7418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (browser_defaults::kBrowserAliveWithNoWindows) 7428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "session_cookies.html"); 7438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) else 7448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage(new_browser, "session_cookies.html"); 7458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 7468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 7478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnBrowserClose) { 7488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage("cookies.html"); 7498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 7508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Normally cookies are restored. 7511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 7528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "cookies.html"); 7538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 7548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // ... but not if the content setting is set to clear on exit. 7558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CookieSettings::Factory::GetForProfile(new_browser->profile())-> 7568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 7578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // ... unless background mode is active. 7588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EnableBackgroundMode(); 7591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 7608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "cookies.html"); 7618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DisableBackgroundMode(); 7621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 7638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (browser_defaults::kBrowserAliveWithNoWindows) 7648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "cookies.html"); 7658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) else 7668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage(new_browser, "cookies.html"); 7678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 7681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that session cookies are cleared on a wrench menu quit. 7701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionCookiesCloseAllBrowsers) { 7711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage("session_cookies.html"); 7721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EnableBackgroundMode(); 7731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 7741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage(new_browser, "session_cookies.html"); 7751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DisableBackgroundMode(); 7761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 7771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage(new_browser, "session_cookies.html"); 7781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 7791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that cookies are cleared on a wrench menu quit only if cookies are set 7811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// to current session only, regardless of whether background mode is enabled. 7821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnCloseAllBrowsers) { 7831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage("cookies.html"); 7841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Normally cookies are restored. 7861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 7871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NavigateAndCheckStoredData(new_browser, "cookies.html"); 7881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 7891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // ... but not if the content setting is set to clear on exit. 7901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CookieSettings::Factory::GetForProfile(new_browser->profile())-> 7911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 7921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // ... even if background mode is active. 7931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EnableBackgroundMode(); 7941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 7951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage(new_browser, "cookies.html"); 7961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DisableBackgroundMode(); 7971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 7981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage(new_browser, "cookies.html"); 7991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 800