Chromium Code Reviews| 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/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/browser/render_frame_host.h" | 29 #include "content/public/browser/render_frame_host.h" |
| 30 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
| 31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 32 #include "content/public/browser/web_contents_observer.h" | 32 #include "content/public/browser/web_contents_observer.h" |
| 33 #include "content/public/test/browser_test_utils.h" | 33 #include "content/public/test/browser_test_utils.h" |
| 34 #include "content/public/test/test_navigation_observer.h" | 34 #include "content/public/test/test_navigation_observer.h" |
| 35 #include "content/test/net/url_request_failed_job.h" | 35 #include "content/test/net/url_request_failed_job.h" |
| 36 #include "content/test/net/url_request_mock_http_job.h" | 36 #include "content/test/net/url_request_mock_http_job.h" |
| 37 #include "grit/generated_resources.h" | |
| 37 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
| 38 #include "net/base/net_util.h" | 39 #include "net/base/net_util.h" |
| 39 #include "net/http/failing_http_transaction_factory.h" | 40 #include "net/http/failing_http_transaction_factory.h" |
| 40 #include "net/http/http_cache.h" | 41 #include "net/http/http_cache.h" |
| 41 #include "net/test/spawned_test_server/spawned_test_server.h" | 42 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 42 #include "net/url_request/url_request_context.h" | 43 #include "net/url_request/url_request_context.h" |
| 43 #include "net/url_request/url_request_context_getter.h" | 44 #include "net/url_request/url_request_context_getter.h" |
| 44 #include "net/url_request/url_request_filter.h" | 45 #include "net/url_request/url_request_filter.h" |
| 45 #include "net/url_request/url_request_job.h" | 46 #include "net/url_request/url_request_job.h" |
| 46 #include "net/url_request/url_request_job_factory.h" | 47 #include "net/url_request/url_request_job_factory.h" |
| 47 #include "net/url_request/url_request_test_job.h" | 48 #include "net/url_request/url_request_test_job.h" |
| 48 #include "net/url_request/url_request_test_util.h" | 49 #include "net/url_request/url_request_test_util.h" |
| 50 #include "ui/base/l10n/l10n_util.h" | |
| 49 | 51 |
| 50 using content::BrowserThread; | 52 using content::BrowserThread; |
| 51 using content::NavigationController; | 53 using content::NavigationController; |
| 52 using content::URLRequestFailedJob; | 54 using content::URLRequestFailedJob; |
| 53 using net::URLRequestJobFactory; | 55 using net::URLRequestJobFactory; |
| 54 using net::URLRequestTestJob; | 56 using net::URLRequestTestJob; |
| 55 | 57 |
| 56 namespace { | 58 namespace { |
| 57 | 59 |
| 58 // Returns true if |text| is displayed on the page |browser| is currently | 60 // Returns true if |text| is displayed on the page |browser| is currently |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 | 244 |
| 243 void GoBackAndWaitForNavigations(int num_navigations) { | 245 void GoBackAndWaitForNavigations(int num_navigations) { |
| 244 NavigateHistory(num_navigations, HISTORY_NAVIGATE_BACK); | 246 NavigateHistory(num_navigations, HISTORY_NAVIGATE_BACK); |
| 245 } | 247 } |
| 246 | 248 |
| 247 void GoForwardAndWaitForNavigations(int num_navigations) { | 249 void GoForwardAndWaitForNavigations(int num_navigations) { |
| 248 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); | 250 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); |
| 249 } | 251 } |
| 250 | 252 |
| 251 // Confirms that the javascript variable indicating whether or not we have | 253 // Confirms that the javascript variable indicating whether or not we have |
| 252 // a stale copy in the cache has been set to |expected|. | 254 // a stale copy in the cache has been set to |expected|, and that the |
| 253 bool ProbeStaleCopyValue(bool expected) { | 255 // stale load button is or isn't there based on the same expectation. |
| 256 testing::AssertionResult ProbeStaleCopyValue(bool expected) { | |
| 254 const char* js_cache_probe = | 257 const char* js_cache_probe = |
| 255 "try {\n" | 258 "try {\n" |
| 256 " domAutomationController.send(\n" | 259 " domAutomationController.send(\n" |
| 257 " templateData.staleCopyInCache ? 'yes' : 'no');\n" | 260 " 'staleLoadButton' in templateData ? 'yes' : 'no');\n" |
| 258 "} catch (e) {\n" | 261 "} catch (e) {\n" |
| 259 " domAutomationController.send(e.message);\n" | 262 " domAutomationController.send(e.message);\n" |
| 260 "}\n"; | 263 "}\n"; |
| 261 | 264 |
| 262 std::string result; | 265 std::string result; |
| 263 bool ret = | 266 bool ret = |
| 264 content::ExecuteScriptAndExtractString( | 267 content::ExecuteScriptAndExtractString( |
| 265 browser()->tab_strip_model()->GetActiveWebContents(), | 268 browser()->tab_strip_model()->GetActiveWebContents(), |
| 266 js_cache_probe, | 269 js_cache_probe, |
| 267 &result); | 270 &result); |
| 268 EXPECT_TRUE(ret); | 271 if (!ret) { |
| 269 if (!ret) | 272 return testing::AssertionFailure() |
| 270 return false; | 273 << "Failing return from ExecuteScriptAndExtractString."; |
| 271 EXPECT_EQ(expected ? "yes" : "no", result); | 274 } |
| 272 return ((expected ? "yes" : "no") == result); | 275 |
| 276 if ((expected && "yes" == result) || (!expected && "no" == result)) | |
| 277 return testing::AssertionSuccess(); | |
| 278 | |
| 279 return testing::AssertionFailure() << "Result is " << result; | |
|
mmenke
2014/04/15 16:02:25
nit: "Cache probe result is..." maybe?
Randy Smith (Not in Mondays)
2014/04/15 18:27:29
Done.
| |
| 273 } | 280 } |
| 274 | 281 |
| 275 testing::AssertionResult ReloadStaleCopyFromCache() { | 282 testing::AssertionResult ReloadStaleCopyFromCache() { |
| 276 const char* js_reload_script = | 283 const char* js_reload_script = |
| 277 "try {\n" | 284 "try {\n" |
| 278 " errorCacheLoad.reloadStaleInstance();\n" | 285 " document.getElementById('stale-load-button').click();\n" |
| 279 " domAutomationController.send('success');\n" | 286 " domAutomationController.send('success');\n" |
| 280 "} catch (e) {\n" | 287 "} catch (e) {\n" |
| 281 " domAutomationController.send(e.message);\n" | 288 " domAutomationController.send(e.message);\n" |
| 282 "}\n"; | 289 "}\n"; |
| 283 | 290 |
| 284 std::string result; | 291 std::string result; |
| 285 bool ret = content::ExecuteScriptAndExtractString( | 292 bool ret = content::ExecuteScriptAndExtractString( |
| 286 browser()->tab_strip_model()->GetActiveWebContents(), | 293 browser()->tab_strip_model()->GetActiveWebContents(), |
| 287 js_reload_script, | 294 js_reload_script, |
| 288 &result); | 295 &result); |
| 289 EXPECT_TRUE(ret); | 296 EXPECT_TRUE(ret); |
| 290 if (!ret) | 297 if (!ret) |
| 291 return testing::AssertionFailure(); | 298 return testing::AssertionFailure(); |
| 292 return ("success" == result ? testing::AssertionSuccess() : | 299 return ("success" == result ? testing::AssertionSuccess() : |
| 293 (testing::AssertionFailure() << "Exception message is " << result)); | 300 (testing::AssertionFailure() << "Exception message is " << result)); |
| 294 } | 301 } |
| 295 | 302 |
| 303 std::string LoadStaleButtonLabel() { | |
|
mmenke
2014/04/15 16:02:25
Suggest either making this static, or putting in a
Randy Smith (Not in Mondays)
2014/04/15 18:27:29
Done.
| |
| 304 return l10n_util::GetStringUTF8(IDS_ERRORPAGES_BUTTON_LOAD_STALE); | |
| 305 } | |
| 306 | |
| 296 protected: | 307 protected: |
| 297 static void EnableMocks(const GURL& search_url) { | 308 static void EnableMocks(const GURL& search_url) { |
| 298 chrome_browser_net::SetUrlRequestMocksEnabled(true); | 309 chrome_browser_net::SetUrlRequestMocksEnabled(true); |
| 299 | 310 |
| 300 // Add a mock for the search engine the error page will use. | 311 // Add a mock for the search engine the error page will use. |
| 301 base::FilePath root_http; | 312 base::FilePath root_http; |
| 302 PathService::Get(chrome::DIR_TEST_DATA, &root_http); | 313 PathService::Get(chrome::DIR_TEST_DATA, &root_http); |
| 303 content::URLRequestMockHTTPJob::AddHostnameToFileHandler( | 314 content::URLRequestMockHTTPJob::AddHostnameToFileHandler( |
| 304 search_url.host(), root_http.AppendASCII("title3.html")); | 315 search_url.host(), root_http.AppendASCII("title3.html")); |
| 305 } | 316 } |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 browser()->profile()->GetRequestContext(); | 685 browser()->profile()->GetRequestContext(); |
| 675 BrowserThread::PostTask( | 686 BrowserThread::PostTask( |
| 676 BrowserThread::IO, FROM_HERE, | 687 BrowserThread::IO, FROM_HERE, |
| 677 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, | 688 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, |
| 678 net::ERR_FAILED)); | 689 net::ERR_FAILED)); |
| 679 | 690 |
| 680 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 691 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 681 // With no navigation corrections to load, there's only one navigation. | 692 // With no navigation corrections to load, there's only one navigation. |
| 682 browser(), test_url, 1); | 693 browser(), test_url, 1); |
| 683 EXPECT_TRUE(ProbeStaleCopyValue(true)); | 694 EXPECT_TRUE(ProbeStaleCopyValue(true)); |
| 695 EXPECT_TRUE(IsDisplayingText(browser(), LoadStaleButtonLabel())); | |
| 684 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"), | 696 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"), |
| 685 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 697 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 686 | 698 |
| 687 // Confirm that loading the stale copy from the cache works. | 699 // Confirm that loading the stale copy from the cache works. |
| 688 content::TestNavigationObserver same_tab_observer( | 700 content::TestNavigationObserver same_tab_observer( |
| 689 browser()->tab_strip_model()->GetActiveWebContents(), 1); | 701 browser()->tab_strip_model()->GetActiveWebContents(), 1); |
| 690 ASSERT_TRUE(ReloadStaleCopyFromCache()); | 702 ASSERT_TRUE(ReloadStaleCopyFromCache()); |
| 691 same_tab_observer.Wait(); | 703 same_tab_observer.Wait(); |
| 692 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), | 704 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), |
| 693 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 705 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 694 | 706 |
| 695 // Clear the cache and reload the same URL; confirm the error page is told | 707 // Clear the cache and reload the same URL; confirm the error page is told |
| 696 // that there is no cached copy. | 708 // that there is no cached copy. |
| 697 BrowsingDataRemover* remover = | 709 BrowsingDataRemover* remover = |
| 698 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); | 710 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); |
| 699 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, | 711 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
| 700 BrowsingDataHelper::UNPROTECTED_WEB); | 712 BrowsingDataHelper::UNPROTECTED_WEB); |
| 701 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 713 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 702 browser(), test_url, 1); | 714 browser(), test_url, 1); |
| 703 EXPECT_TRUE(ProbeStaleCopyValue(false)); | 715 EXPECT_TRUE(ProbeStaleCopyValue(false)); |
| 716 EXPECT_FALSE(IsDisplayingText(browser(), LoadStaleButtonLabel())); | |
| 704 } | 717 } |
| 705 | 718 |
| 706 class ErrorPageAutoReloadTest : public InProcessBrowserTest { | 719 class ErrorPageAutoReloadTest : public InProcessBrowserTest { |
| 707 public: | 720 public: |
| 708 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 721 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 709 command_line->AppendSwitch(switches::kEnableOfflineAutoReload); | 722 command_line->AppendSwitch(switches::kEnableOfflineAutoReload); |
| 710 } | 723 } |
| 711 | 724 |
| 712 void InstallProtocolHandler(const GURL& url, int requests_to_fail) { | 725 void InstallProtocolHandler(const GURL& url, int requests_to_fail) { |
| 713 protocol_handler_ = new FailFirstNRequestsProtocolHandler( | 726 protocol_handler_ = new FailFirstNRequestsProtocolHandler( |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 855 // confirm that the error page is told the cached copy exists. | 868 // confirm that the error page is told the cached copy exists. |
| 856 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = | 869 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = |
| 857 browser()->profile()->GetRequestContext(); | 870 browser()->profile()->GetRequestContext(); |
| 858 BrowserThread::PostTask( | 871 BrowserThread::PostTask( |
| 859 BrowserThread::IO, FROM_HERE, | 872 BrowserThread::IO, FROM_HERE, |
| 860 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, | 873 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, |
| 861 net::ERR_CONNECTION_FAILED)); | 874 net::ERR_CONNECTION_FAILED)); |
| 862 | 875 |
| 863 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 876 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 864 browser(), test_url, 2); | 877 browser(), test_url, 2); |
| 865 ProbeStaleCopyValue(true); | 878 EXPECT_TRUE(IsDisplayingText(browser(), LoadStaleButtonLabel())); |
| 879 EXPECT_TRUE(ProbeStaleCopyValue(true)); | |
| 866 | 880 |
| 867 // Confirm that loading the stale copy from the cache works. | 881 // Confirm that loading the stale copy from the cache works. |
| 868 content::TestNavigationObserver same_tab_observer( | 882 content::TestNavigationObserver same_tab_observer( |
| 869 browser()->tab_strip_model()->GetActiveWebContents(), 1); | 883 browser()->tab_strip_model()->GetActiveWebContents(), 1); |
| 870 ASSERT_TRUE(ReloadStaleCopyFromCache()); | 884 ASSERT_TRUE(ReloadStaleCopyFromCache()); |
| 871 same_tab_observer.Wait(); | 885 same_tab_observer.Wait(); |
| 872 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), | 886 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), |
| 873 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 887 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 874 | 888 |
| 875 // Clear the cache and reload the same URL; confirm the error page is told | 889 // Clear the cache and reload the same URL; confirm the error page is told |
| 876 // that there is no cached copy. | 890 // that there is no cached copy. |
| 877 BrowsingDataRemover* remover = | 891 BrowsingDataRemover* remover = |
| 878 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); | 892 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); |
| 879 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, | 893 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
| 880 BrowsingDataHelper::UNPROTECTED_WEB); | 894 BrowsingDataHelper::UNPROTECTED_WEB); |
| 881 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 895 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 882 browser(), test_url, 2); | 896 browser(), test_url, 2); |
| 883 ProbeStaleCopyValue(false); | 897 EXPECT_TRUE(ProbeStaleCopyValue(false)); |
| 898 EXPECT_FALSE(IsDisplayingText(browser(), LoadStaleButtonLabel())); | |
| 884 } | 899 } |
| 885 | 900 |
| 886 // A test fixture that simulates failing requests for an IDN domain name. | 901 // A test fixture that simulates failing requests for an IDN domain name. |
| 887 class ErrorPageForIDNTest : public InProcessBrowserTest { | 902 class ErrorPageForIDNTest : public InProcessBrowserTest { |
| 888 public: | 903 public: |
| 889 // Target hostname in different forms. | 904 // Target hostname in different forms. |
| 890 static const char kHostname[]; | 905 static const char kHostname[]; |
| 891 static const char kHostnameJSUnicode[]; | 906 static const char kHostnameJSUnicode[]; |
| 892 | 907 |
| 893 // InProcessBrowserTest: | 908 // InProcessBrowserTest: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 931 browser(), | 946 browser(), |
| 932 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 947 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
| 933 kHostname), | 948 kHostname), |
| 934 1); | 949 1); |
| 935 | 950 |
| 936 ToggleHelpBox(browser()); | 951 ToggleHelpBox(browser()); |
| 937 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); | 952 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
| 938 } | 953 } |
| 939 | 954 |
| 940 } // namespace | 955 } // namespace |
| OLD | NEW |