| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // Check that the search box is populated correctly. | 129 // Check that the search box is populated correctly. |
| 130 bool search_box_populated = false; | 130 bool search_box_populated = false; |
| 131 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 131 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 132 browser->tab_strip_model()->GetActiveWebContents(), | 132 browser->tab_strip_model()->GetActiveWebContents(), |
| 133 "var searchText = document.getElementById('search-box').value;" | 133 "var searchText = document.getElementById('search-box').value;" |
| 134 "domAutomationController.send(searchText == 'search query');", | 134 "domAutomationController.send(searchText == 'search query');", |
| 135 &search_box_populated)); | 135 &search_box_populated)); |
| 136 EXPECT_TRUE(search_box_populated); | 136 EXPECT_TRUE(search_box_populated); |
| 137 } | 137 } |
| 138 | 138 |
| 139 std::string GetLoadStaleButtonLabel() { | 139 std::string GetShowSavedButtonLabel() { |
| 140 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_LOAD_STALE); | 140 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_SHOW_SAVED); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void AddInterceptorForURL( | 143 void AddInterceptorForURL( |
| 144 const GURL& url, | 144 const GURL& url, |
| 145 scoped_ptr<net::URLRequestInterceptor> handler) { | 145 scoped_ptr<net::URLRequestInterceptor> handler) { |
| 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 147 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 147 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
| 148 url, handler.Pass()); | 148 url, handler.Pass()); |
| 149 } | 149 } |
| 150 | 150 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 HISTORY_NAVIGATE_BACK, | 292 HISTORY_NAVIGATE_BACK, |
| 293 HISTORY_NAVIGATE_FORWARD, | 293 HISTORY_NAVIGATE_FORWARD, |
| 294 }; | 294 }; |
| 295 | 295 |
| 296 ErrorPageTest() : link_doctor_interceptor_(NULL) {} | 296 ErrorPageTest() : link_doctor_interceptor_(NULL) {} |
| 297 ~ErrorPageTest() override {} | 297 ~ErrorPageTest() override {} |
| 298 | 298 |
| 299 // Navigates the active tab to a mock url created for the file at |file_path|. | 299 // Navigates the active tab to a mock url created for the file at |file_path|. |
| 300 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests. | 300 // Needed for StaleCacheStatus and StaleCacheStatusFailedCorrections tests. |
| 301 void SetUpCommandLine(base::CommandLine* command_line) override { | 301 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 302 command_line->AppendSwitch(switches::kEnableOfflineLoadStaleCache); | 302 command_line->AppendSwitch(switches::kEnableShowSavedCopyPrimary); |
| 303 } | 303 } |
| 304 | 304 |
| 305 // Navigates the active tab to a mock url created for the file at |file_path|. | 305 // Navigates the active tab to a mock url created for the file at |file_path|. |
| 306 void NavigateToFileURL(const base::FilePath::StringType& file_path) { | 306 void NavigateToFileURL(const base::FilePath::StringType& file_path) { |
| 307 ui_test_utils::NavigateToURL( | 307 ui_test_utils::NavigateToURL( |
| 308 browser(), | 308 browser(), |
| 309 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path))); | 309 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path))); |
| 310 } | 310 } |
| 311 | 311 |
| 312 // Navigates to the given URL and waits for |num_navigations| to occur, and | 312 // Navigates to the given URL and waits for |num_navigations| to occur, and |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); | 351 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); |
| 352 } | 352 } |
| 353 | 353 |
| 354 // Confirms that the javascript variable indicating whether or not we have | 354 // Confirms that the javascript variable indicating whether or not we have |
| 355 // a stale copy in the cache has been set to |expected|, and that the | 355 // a stale copy in the cache has been set to |expected|, and that the |
| 356 // stale load button is or isn't there based on the same expectation. | 356 // stale load button is or isn't there based on the same expectation. |
| 357 testing::AssertionResult ProbeStaleCopyValue(bool expected) { | 357 testing::AssertionResult ProbeStaleCopyValue(bool expected) { |
| 358 const char* js_cache_probe = | 358 const char* js_cache_probe = |
| 359 "try {\n" | 359 "try {\n" |
| 360 " domAutomationController.send(\n" | 360 " domAutomationController.send(\n" |
| 361 " loadTimeData.valueExists('staleLoadButton') ? 'yes' : 'no');\n" | 361 " loadTimeData.valueExists('showSavedCopyButton') ?" |
| 362 " 'yes' : 'no');\n" |
| 362 "} catch (e) {\n" | 363 "} catch (e) {\n" |
| 363 " domAutomationController.send(e.message);\n" | 364 " domAutomationController.send(e.message);\n" |
| 364 "}\n"; | 365 "}\n"; |
| 365 | 366 |
| 366 std::string result; | 367 std::string result; |
| 367 bool ret = | 368 bool ret = |
| 368 content::ExecuteScriptAndExtractString( | 369 content::ExecuteScriptAndExtractString( |
| 369 browser()->tab_strip_model()->GetActiveWebContents(), | 370 browser()->tab_strip_model()->GetActiveWebContents(), |
| 370 js_cache_probe, | 371 js_cache_probe, |
| 371 &result); | 372 &result); |
| 372 if (!ret) { | 373 if (!ret) { |
| 373 return testing::AssertionFailure() | 374 return testing::AssertionFailure() |
| 374 << "Failing return from ExecuteScriptAndExtractString."; | 375 << "Failing return from ExecuteScriptAndExtractString."; |
| 375 } | 376 } |
| 376 | 377 |
| 377 if ((expected && "yes" == result) || (!expected && "no" == result)) | 378 if ((expected && "yes" == result) || (!expected && "no" == result)) |
| 378 return testing::AssertionSuccess(); | 379 return testing::AssertionSuccess(); |
| 379 | 380 |
| 380 return testing::AssertionFailure() << "Cache probe result is " << result; | 381 return testing::AssertionFailure() << "Cache probe result is " << result; |
| 381 } | 382 } |
| 382 | 383 |
| 383 testing::AssertionResult ReloadStaleCopyFromCache() { | 384 testing::AssertionResult ReloadStaleCopyFromCache() { |
| 384 const char* js_reload_script = | 385 const char* js_reload_script = |
| 385 "try {\n" | 386 "try {\n" |
| 386 " document.getElementById('stale-load-button').click();\n" | 387 " document.getElementById('show-saved-copy-button').click();\n" |
| 387 " domAutomationController.send('success');\n" | 388 " domAutomationController.send('success');\n" |
| 388 "} catch (e) {\n" | 389 "} catch (e) {\n" |
| 389 " domAutomationController.send(e.message);\n" | 390 " domAutomationController.send(e.message);\n" |
| 390 "}\n"; | 391 "}\n"; |
| 391 | 392 |
| 392 std::string result; | 393 std::string result; |
| 393 bool ret = content::ExecuteScriptAndExtractString( | 394 bool ret = content::ExecuteScriptAndExtractString( |
| 394 browser()->tab_strip_model()->GetActiveWebContents(), | 395 browser()->tab_strip_model()->GetActiveWebContents(), |
| 395 js_reload_script, | 396 js_reload_script, |
| 396 &result); | 397 &result); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 839 |
| 839 // Reload same URL after forcing an error from the the network layer; | 840 // Reload same URL after forcing an error from the the network layer; |
| 840 // confirm that the error page is told the cached copy exists. | 841 // confirm that the error page is told the cached copy exists. |
| 841 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = | 842 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = |
| 842 browser()->profile()->GetRequestContext(); | 843 browser()->profile()->GetRequestContext(); |
| 843 BrowserThread::PostTask( | 844 BrowserThread::PostTask( |
| 844 BrowserThread::IO, FROM_HERE, | 845 BrowserThread::IO, FROM_HERE, |
| 845 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, | 846 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, |
| 846 net::ERR_FAILED)); | 847 net::ERR_FAILED)); |
| 847 | 848 |
| 848 // With no navigation corrections to load, there's only one navigation. | 849 // With no navigation corrections to load, there's only one navigation. |
| 849 ui_test_utils::NavigateToURL(browser(), test_url); | 850 ui_test_utils::NavigateToURL(browser(), test_url); |
| 850 EXPECT_TRUE(ProbeStaleCopyValue(true)); | 851 EXPECT_TRUE(ProbeStaleCopyValue(true)); |
| 851 EXPECT_TRUE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); | 852 EXPECT_TRUE(IsDisplayingText(browser(), GetShowSavedButtonLabel())); |
| 852 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"), | 853 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"), |
| 853 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 854 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 854 | 855 |
| 855 // Confirm that loading the stale copy from the cache works. | 856 // Confirm that loading the stale copy from the cache works. |
| 856 content::TestNavigationObserver same_tab_observer( | 857 content::TestNavigationObserver same_tab_observer( |
| 857 browser()->tab_strip_model()->GetActiveWebContents(), 1); | 858 browser()->tab_strip_model()->GetActiveWebContents(), 1); |
| 858 ASSERT_TRUE(ReloadStaleCopyFromCache()); | 859 ASSERT_TRUE(ReloadStaleCopyFromCache()); |
| 859 same_tab_observer.Wait(); | 860 same_tab_observer.Wait(); |
| 860 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), | 861 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), |
| 861 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 862 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 862 | 863 |
| 864 // Reload the same URL with a post request; confirm the error page is told |
| 865 // that there is no cached copy. |
| 866 ui_test_utils::NavigateToURLWithPost(browser(), test_url); |
| 867 EXPECT_TRUE(ProbeStaleCopyValue(false)); |
| 868 EXPECT_FALSE(IsDisplayingText(browser(), GetShowSavedButtonLabel())); |
| 869 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); |
| 870 |
| 863 // Clear the cache and reload the same URL; confirm the error page is told | 871 // Clear the cache and reload the same URL; confirm the error page is told |
| 864 // that there is no cached copy. | 872 // that there is no cached copy. |
| 865 BrowsingDataRemover* remover = | 873 BrowsingDataRemover* remover = |
| 866 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); | 874 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); |
| 867 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, | 875 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
| 868 BrowsingDataHelper::UNPROTECTED_WEB); | 876 BrowsingDataHelper::UNPROTECTED_WEB); |
| 869 ui_test_utils::NavigateToURL(browser(), test_url); | 877 ui_test_utils::NavigateToURL(browser(), test_url); |
| 870 EXPECT_TRUE(ProbeStaleCopyValue(false)); | 878 EXPECT_TRUE(ProbeStaleCopyValue(false)); |
| 871 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); | 879 EXPECT_FALSE(IsDisplayingText(browser(), GetShowSavedButtonLabel())); |
| 872 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); | 880 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); |
| 873 } | 881 } |
| 874 | 882 |
| 875 class ErrorPageAutoReloadTest : public InProcessBrowserTest { | 883 class ErrorPageAutoReloadTest : public InProcessBrowserTest { |
| 876 public: | 884 public: |
| 877 void SetUpCommandLine(base::CommandLine* command_line) override { | 885 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 878 command_line->AppendSwitch(switches::kEnableOfflineAutoReload); | 886 command_line->AppendSwitch(switches::kEnableOfflineAutoReload); |
| 879 } | 887 } |
| 880 | 888 |
| 881 void InstallInterceptor(const GURL& url, int requests_to_fail) { | 889 void InstallInterceptor(const GURL& url, int requests_to_fail) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 // confirm that the error page is told the cached copy exists. | 1048 // confirm that the error page is told the cached copy exists. |
| 1041 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = | 1049 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = |
| 1042 browser()->profile()->GetRequestContext(); | 1050 browser()->profile()->GetRequestContext(); |
| 1043 BrowserThread::PostTask( | 1051 BrowserThread::PostTask( |
| 1044 BrowserThread::IO, FROM_HERE, | 1052 BrowserThread::IO, FROM_HERE, |
| 1045 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, | 1053 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, |
| 1046 net::ERR_CONNECTION_FAILED)); | 1054 net::ERR_CONNECTION_FAILED)); |
| 1047 | 1055 |
| 1048 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 1056 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 1049 browser(), test_url, 2); | 1057 browser(), test_url, 2); |
| 1050 EXPECT_TRUE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); | 1058 EXPECT_TRUE(IsDisplayingText(browser(), GetShowSavedButtonLabel())); |
| 1051 EXPECT_TRUE(ProbeStaleCopyValue(true)); | 1059 EXPECT_TRUE(ProbeStaleCopyValue(true)); |
| 1052 | 1060 |
| 1053 // Confirm that loading the stale copy from the cache works. | 1061 // Confirm that loading the stale copy from the cache works. |
| 1054 content::TestNavigationObserver same_tab_observer( | 1062 content::TestNavigationObserver same_tab_observer( |
| 1055 browser()->tab_strip_model()->GetActiveWebContents(), 1); | 1063 browser()->tab_strip_model()->GetActiveWebContents(), 1); |
| 1056 ASSERT_TRUE(ReloadStaleCopyFromCache()); | 1064 ASSERT_TRUE(ReloadStaleCopyFromCache()); |
| 1057 same_tab_observer.Wait(); | 1065 same_tab_observer.Wait(); |
| 1058 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), | 1066 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), |
| 1059 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 1067 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 1060 | 1068 |
| 1061 // Clear the cache and reload the same URL; confirm the error page is told | 1069 // Clear the cache and reload the same URL; confirm the error page is told |
| 1062 // that there is no cached copy. | 1070 // that there is no cached copy. |
| 1063 BrowsingDataRemover* remover = | 1071 BrowsingDataRemover* remover = |
| 1064 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); | 1072 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); |
| 1065 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, | 1073 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
| 1066 BrowsingDataHelper::UNPROTECTED_WEB); | 1074 BrowsingDataHelper::UNPROTECTED_WEB); |
| 1067 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 1075 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 1068 browser(), test_url, 2); | 1076 browser(), test_url, 2); |
| 1069 EXPECT_TRUE(ProbeStaleCopyValue(false)); | 1077 EXPECT_TRUE(ProbeStaleCopyValue(false)); |
| 1070 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); | 1078 EXPECT_FALSE(IsDisplayingText(browser(), GetShowSavedButtonLabel())); |
| 1071 } | 1079 } |
| 1072 | 1080 |
| 1073 // A test fixture that simulates failing requests for an IDN domain name. | 1081 // A test fixture that simulates failing requests for an IDN domain name. |
| 1074 class ErrorPageForIDNTest : public InProcessBrowserTest { | 1082 class ErrorPageForIDNTest : public InProcessBrowserTest { |
| 1075 public: | 1083 public: |
| 1076 // Target hostname in different forms. | 1084 // Target hostname in different forms. |
| 1077 static const char kHostname[]; | 1085 static const char kHostname[]; |
| 1078 static const char kHostnameJSUnicode[]; | 1086 static const char kHostnameJSUnicode[]; |
| 1079 | 1087 |
| 1080 // InProcessBrowserTest: | 1088 // InProcessBrowserTest: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 ui_test_utils::NavigateToURL( | 1125 ui_test_utils::NavigateToURL( |
| 1118 browser(), | 1126 browser(), |
| 1119 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 1127 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
| 1120 kHostname)); | 1128 kHostname)); |
| 1121 | 1129 |
| 1122 ToggleHelpBox(browser()); | 1130 ToggleHelpBox(browser()); |
| 1123 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); | 1131 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
| 1124 } | 1132 } |
| 1125 | 1133 |
| 1126 } // namespace | 1134 } // namespace |
| OLD | NEW |