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" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/files/file_util.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/infobar_service.h" 188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/lifetime/application_lifetime.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/prefs/session_startup_pref.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile_impl.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/sessions/session_backend.h" 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/sessions/session_service_factory.h" 258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/sessions/session_service_test_helper.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_iterator.h" 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_window.h" 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/startup/startup_browser_creator.h" 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h" 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/pref_names.h" 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/url_constants.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/content_settings/core/common/content_settings.h" 38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/infobars/core/confirm_infobar_delegate.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/"), 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) title_pass_(base::ASCIIToUTF16("PASS")), 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) title_storing_(base::ASCIIToUTF16("STORING")), 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) title_error_write_failed_(base::ASCIIToUTF16("ERROR_WRITE_FAILED")), 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) title_error_empty_(base::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. 319a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) chrome::IncrementKeepAliveCount(); 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(); 332a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) chrome::DecrementKeepAliveCount(); 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) 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Test that leaving a popup open will not prevent session restore. 4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SessionCookiesBrowserCloseWithPopupOpen) { 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set the startup preference to "continue where I left off" and visit a page 4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // which stores a session cookie. 4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StoreDataWithPage("session_cookies.html"); 4825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser* popup = new Browser(Browser::CreateParams( 4835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser::TYPE_POPUP, 4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) browser()->profile(), 4855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_NATIVE)); 4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) popup->window()->Show(); 4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 4895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The browsing session will be continued; just wait for the page to reload 4905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // and check the stored data. 4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CheckReloadedPageRestored(new_browser); 4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 4948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CookiesClearedOnBrowserClose) { 4958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage("cookies.html"); 4968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Normally cookies are restored. 4971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 4988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(new_browser); 4998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // ... but not if the content setting is set to clear on exit. 5008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CookieSettings::Factory::GetForProfile(new_browser->profile())-> 5018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 5028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // ... unless background mode is active. 5038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EnableBackgroundMode(); 5041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 5058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(new_browser); 5068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 5078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DisableBackgroundMode(); 5081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 5098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (browser_defaults::kBrowserAliveWithNoWindows) 5108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(new_browser); 5118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) else 5128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageNotRestored(new_browser); 5138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 5148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 5158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostBrowserClose) { 5168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PostFormWithPage("post.html", false); 5171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 5188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckFormRestored(new_browser, true, false); 5198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 5208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 5218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 5228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PostWithPasswordBrowserClose) { 5238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PostFormWithPage("post_with_password.html", true); 5241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 5251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageRestored(new_browser); 5261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The form data contained passwords, so it's removed completely. 5271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckFormRestored(new_browser, false, false); 5281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that session cookies are cleared on a wrench menu quit. 5311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 5321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SessionCookiesCloseAllBrowsers) { 5331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Set the startup preference to "continue where I left off" and visit a page 5341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // which stores a session cookie. 5351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage("session_cookies.html"); 5361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 5371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The browsing session will be continued; just wait for the page to reload 5381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // and check the stored data. 5391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageRestored(new_browser); 5401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that cookies are cleared on a wrench menu quit only if cookies are set 5431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// to current session only, regardless of whether background mode is enabled. 5441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 5451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CookiesClearedOnCloseAllBrowsers) { 5461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage("cookies.html"); 5471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Normally cookies are restored. 5481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 5491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageRestored(new_browser); 5501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // ... but not if the content setting is set to clear on exit. 5511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CookieSettings::Factory::GetForProfile(new_browser->profile())-> 5521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 5531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // ... even if background mode is active. 5541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EnableBackgroundMode(); 5551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 5561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageNotRestored(new_browser); 5571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DisableBackgroundMode(); 5591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 5601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckReloadedPageNotRestored(new_browser); 5611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that form data is restored after wrench menu quit. 5641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostCloseAllBrowsers) { 5651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PostFormWithPage("post.html", false); 5661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 5671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CheckFormRestored(new_browser, true, false); 5681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 5691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 5701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that form data with a password field is cleared after wrench menu quit. 5711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, 5721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PostWithPasswordCloseAllBrowsers) { 5731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PostFormWithPage("post_with_password.html", true); 5741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 5758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckReloadedPageRestored(new_browser); 5768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // The form data contained passwords, so it's removed completely. 5778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CheckFormRestored(new_browser, false, false); 5788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 5798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class RestartTest : public BetterSessionRestoreTest { 5812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RestartTest() { } 5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~RestartTest() { } 5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Restart() { 5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Simluate restarting the browser, but let the test exit peacefully. 5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (chrome::BrowserIterator it; !it.done(); it.Next()) 5882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::BrowserContext::SaveSessionState(it->profile()); 5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PrefService* pref_service = g_browser_process->local_state(); 5902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_service->SetBoolean(prefs::kWasRestarted, true); 5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 5920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (pref_service->HasPrefPath(prefs::kRelaunchMode)) 5930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) pref_service->ClearPref(prefs::kRelaunchMode); 5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(RestartTest); 5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_SessionCookies) { 6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_cookies.html"); 6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, SessionCookies) { 6072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_SessionStorage) { 6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_storage.html"); 6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, SessionStorage) { 6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_LocalStorageClearedOnExit) { 6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("local_storage.html"); 6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, LocalStorageClearedOnExit) { 6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_CookiesClearedOnExit) { 6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("cookies.html"); 6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, CookiesClearedOnExit) { 6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckReloadedPageRestored(); 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_Post) { 6422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PostFormWithPage("post.html", false); 6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, Post) { 6472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckFormRestored(true, false); 6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PRE_PostWithPassword) { 6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PostFormWithPage("post_with_password.html", true); 6522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Restart(); 6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(RestartTest, PostWithPassword) { 6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The form data contained passwords, so it's removed completely. 6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CheckFormRestored(false, false); 6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// These tests ensure that the Better Session Restore features are not triggered 6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// when they shouldn't be. 6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NoSessionRestoreTest : public BetterSessionRestoreTest { 6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NoSessionRestoreTest() { } 6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUpOnMainThread() OVERRIDE { 6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BetterSessionRestoreTest::SetUpOnMainThread(); 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SessionStartupPref::SetStartupPref( 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->profile(), SessionStartupPref(SessionStartupPref::DEFAULT)); 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(NoSessionRestoreTest); 6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_SessionCookies) { 6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_cookies.html"); 6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionCookies) { 6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 683f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_EQ(std::string(url::kAboutBlankURL), web_contents->GetURL().spec()); 6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // When we navigate to the page again, it doens't see the data previously 6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // stored. 6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_cookies.html"); 6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_SessionStorage) { 6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_storage.html"); 6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionStorage) { 6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 696f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_EQ(std::string(url::kAboutBlankURL), web_contents->GetURL().spec()); 6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("session_storage.html"); 6982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, 7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PRE_PRE_LocalStorageClearedOnExit) { 7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("local_storage.html"); 7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_LocalStorageClearedOnExit) { 7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Normally localStorage is persisted. 7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 709f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_EQ(std::string(url::kAboutBlankURL), web_contents->GetURL().spec()); 7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCheckStoredData("local_storage.html"); 7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ... but not if it's set to clear on exit. 7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 7132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 7142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, LocalStorageClearedOnExit) { 7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 7182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 719f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_EQ(std::string(url::kAboutBlankURL), web_contents->GetURL().spec()); 7202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("local_storage.html"); 7212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_PRE_CookiesClearedOnExit) { 7242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("cookies.html"); 7252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_CookiesClearedOnExit) { 7282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Normally cookies are restored. 7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 731f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_EQ(std::string(url::kAboutBlankURL), web_contents->GetURL().spec()); 7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigateAndCheckStoredData("cookies.html"); 7332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ... but not if the content setting is set to clear on exit. 7342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CookieSettings::Factory::GetForProfile(browser()->profile())-> 7352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 7362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnExit) { 7392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = 7402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(); 741f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_EQ(std::string(url::kAboutBlankURL), web_contents->GetURL().spec()); 7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StoreDataWithPage("local_storage.html"); 7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 7458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionCookiesBrowserClose) { 7468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage("session_cookies.html"); 7478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EnableBackgroundMode(); 7481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 7498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "session_cookies.html"); 7508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DisableBackgroundMode(); 7511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 7528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (browser_defaults::kBrowserAliveWithNoWindows) 7538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "session_cookies.html"); 7548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) else 7558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage(new_browser, "session_cookies.html"); 7568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 7578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Tests that session cookies are not cleared when only a popup window is open. 7595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, 7605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SessionCookiesBrowserCloseWithPopupOpen) { 7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StoreDataWithPage("session_cookies.html"); 7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser* popup = new Browser(Browser::CreateParams( 7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser::TYPE_POPUP, 7645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) browser()->profile(), 7655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_NATIVE)); 7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) popup->window()->Show(); 7675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 7685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NavigateAndCheckStoredData(new_browser, "session_cookies.html"); 7695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Tests that session cookies are cleared if the last window to close is a 7725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// popup. 7735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, 7745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SessionCookiesBrowserClosePopupLast) { 7755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StoreDataWithPage("session_cookies.html"); 7765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser* popup = new Browser(Browser::CreateParams( 7775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser::TYPE_POPUP, 7785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) browser()->profile(), 7795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::HOST_DESKTOP_TYPE_NATIVE)); 7805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) popup->window()->Show(); 7815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CloseBrowserSynchronously(browser(), false); 7825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(popup, false); 7835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (browser_defaults::kBrowserAliveWithNoWindows) 7845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NavigateAndCheckStoredData(new_browser, "session_cookies.html"); 7855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) else 7865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StoreDataWithPage(new_browser, "session_cookies.html"); 7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnBrowserClose) { 7908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage("cookies.html"); 7918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 7928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Normally cookies are restored. 7931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), false); 7948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "cookies.html"); 7958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 7968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // ... but not if the content setting is set to clear on exit. 7978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CookieSettings::Factory::GetForProfile(new_browser->profile())-> 7988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 7998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // ... unless background mode is active. 8008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) EnableBackgroundMode(); 8011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 8028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "cookies.html"); 8038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DisableBackgroundMode(); 8041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, false); 8058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (browser_defaults::kBrowserAliveWithNoWindows) 8068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) NavigateAndCheckStoredData(new_browser, "cookies.html"); 8078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) else 8088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) StoreDataWithPage(new_browser, "cookies.html"); 8098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 8101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that session cookies are cleared on a wrench menu quit. 8121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionCookiesCloseAllBrowsers) { 8131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage("session_cookies.html"); 8141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EnableBackgroundMode(); 8151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 8161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage(new_browser, "session_cookies.html"); 8171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DisableBackgroundMode(); 8181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 8191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage(new_browser, "session_cookies.html"); 8201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 8211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Check that cookies are cleared on a wrench menu quit only if cookies are set 8231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// to current session only, regardless of whether background mode is enabled. 8241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnCloseAllBrowsers) { 8251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage("cookies.html"); 8261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Normally cookies are restored. 8281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* new_browser = QuitBrowserAndRestore(browser(), true); 8291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NavigateAndCheckStoredData(new_browser, "cookies.html"); 8301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 8311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // ... but not if the content setting is set to clear on exit. 8321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CookieSettings::Factory::GetForProfile(new_browser->profile())-> 8331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); 8341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // ... even if background mode is active. 8351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EnableBackgroundMode(); 8361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 8371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage(new_browser, "cookies.html"); 8381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DisableBackgroundMode(); 8391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) new_browser = QuitBrowserAndRestore(new_browser, true); 8401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) StoreDataWithPage(new_browser, "cookies.html"); 8411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 842