| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/prefs/session_startup_pref.h" | 9 #include "chrome/browser/prefs/session_startup_pref.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_tabstrip.h" | 11 #include "chrome/browser/ui/browser_tabstrip.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
| 17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 18 #include "webkit/dom_storage/dom_storage_area.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // The tests server is started separately for each test function (including PRE_ | 22 // The tests server is started separately for each test function (including PRE_ |
| 22 // functions). We need a test server which always uses the same port, so that | 23 // functions). We need a test server which always uses the same port, so that |
| 23 // the pages can be accessed with the same URLs after restoring the browser | 24 // the pages can be accessed with the same URLs after restoring the browser |
| 24 // session. | 25 // session. |
| 25 class FixedPortTestServer : public net::LocalTestServer { | 26 class FixedPortTestServer : public net::LocalTestServer { |
| 26 public: | 27 public: |
| 27 explicit FixedPortTestServer(uint16 port) | 28 explicit FixedPortTestServer(uint16 port) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 46 title_storing_(ASCIIToUTF16("STORING")), | 47 title_storing_(ASCIIToUTF16("STORING")), |
| 47 title_error_write_failed_(ASCIIToUTF16("ERROR_WRITE_FAILED")), | 48 title_error_write_failed_(ASCIIToUTF16("ERROR_WRITE_FAILED")), |
| 48 title_error_empty_(ASCIIToUTF16("ERROR_EMPTY")) { | 49 title_error_empty_(ASCIIToUTF16("ERROR_EMPTY")) { |
| 49 CHECK(test_server_.Start()); | 50 CHECK(test_server_.Start()); |
| 50 } | 51 } |
| 51 protected: | 52 protected: |
| 52 void StoreDataWithPage(const std::string& filename) { | 53 void StoreDataWithPage(const std::string& filename) { |
| 53 GURL url = test_server_.GetURL("files/session_restore/" + filename); | 54 GURL url = test_server_.GetURL("files/session_restore/" + filename); |
| 54 content::WebContents* web_contents = | 55 content::WebContents* web_contents = |
| 55 chrome::GetActiveWebContents(browser()); | 56 chrome::GetActiveWebContents(browser()); |
| 56 string16 expected_title(title_storing_); | |
| 57 content::TitleWatcher title_watcher(web_contents, title_storing_); | 57 content::TitleWatcher title_watcher(web_contents, title_storing_); |
| 58 title_watcher.AlsoWaitForTitle(title_pass_); | 58 title_watcher.AlsoWaitForTitle(title_pass_); |
| 59 title_watcher.AlsoWaitForTitle(title_error_write_failed_); | 59 title_watcher.AlsoWaitForTitle(title_error_write_failed_); |
| 60 title_watcher.AlsoWaitForTitle(title_error_empty_); | 60 title_watcher.AlsoWaitForTitle(title_error_empty_); |
| 61 ui_test_utils::NavigateToURL(browser(), url); | 61 ui_test_utils::NavigateToURL(browser(), url); |
| 62 string16 final_title = title_watcher.WaitAndGetTitle(); | 62 string16 final_title = title_watcher.WaitAndGetTitle(); |
| 63 EXPECT_EQ(title_storing_, final_title); | 63 EXPECT_EQ(title_storing_, final_title); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void CheckReloadedPage() { | 66 void CheckReloadedPage() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 93 SessionStartupPref::SetStartupPref( | 93 SessionStartupPref::SetStartupPref( |
| 94 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); | 94 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); |
| 95 StoreDataWithPage("session_cookies.html"); | 95 StoreDataWithPage("session_cookies.html"); |
| 96 } | 96 } |
| 97 | 97 |
| 98 IN_PROC_BROWSER_TEST_F(BetterSessionRestoreTest, SessionCookies) { | 98 IN_PROC_BROWSER_TEST_F(BetterSessionRestoreTest, SessionCookies) { |
| 99 // The browsing session will be continued; just wait for the page to reload | 99 // The browsing session will be continued; just wait for the page to reload |
| 100 // and check the stored data. | 100 // and check the stored data. |
| 101 CheckReloadedPage(); | 101 CheckReloadedPage(); |
| 102 } | 102 } |
| 103 |
| 104 IN_PROC_BROWSER_TEST_F(BetterSessionRestoreTest, PRE_SessionStorage) { |
| 105 // Write the data on disk less lazily. |
| 106 dom_storage::DomStorageArea::DisableCommitDelayForTesting(); |
| 107 SessionStartupPref::SetStartupPref( |
| 108 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); |
| 109 StoreDataWithPage("session_storage.html"); |
| 110 } |
| 111 |
| 112 IN_PROC_BROWSER_TEST_F(BetterSessionRestoreTest, SessionStorage) { |
| 113 CheckReloadedPage(); |
| 114 } |
| OLD | NEW |