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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 void GoForwardAndWaitForNavigations(int num_navigations) { | 247 void GoForwardAndWaitForNavigations(int num_navigations) { |
248 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); | 248 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); |
249 } | 249 } |
250 | 250 |
251 // Confirms that the javascript variable indicating whether or not we have | 251 // Confirms that the javascript variable indicating whether or not we have |
252 // a stale copy in the cache has been set to |expected|. | 252 // a stale copy in the cache has been set to |expected|. |
253 bool ProbeStaleCopyValue(bool expected) { | 253 bool ProbeStaleCopyValue(bool expected) { |
254 const char* js_cache_probe = | 254 const char* js_cache_probe = |
255 "try {\n" | 255 "try {\n" |
256 " domAutomationController.send(\n" | 256 " domAutomationController.send(\n" |
257 " templateData.staleCopyInCache ? 'yes' : 'no');\n" | 257 " 'staleCopyInCache' in templateData ? 'yes' : 'no');\n" |
258 "} catch (e) {\n" | 258 "} catch (e) {\n" |
259 " domAutomationController.send(e.message);\n" | 259 " domAutomationController.send(e.message);\n" |
260 "}\n"; | 260 "}\n"; |
261 | 261 |
262 std::string result; | 262 std::string result; |
263 bool ret = | 263 bool ret = |
264 content::ExecuteScriptAndExtractString( | 264 content::ExecuteScriptAndExtractString( |
265 browser()->tab_strip_model()->GetActiveWebContents(), | 265 browser()->tab_strip_model()->GetActiveWebContents(), |
266 js_cache_probe, | 266 js_cache_probe, |
267 &result); | 267 &result); |
268 EXPECT_TRUE(ret); | 268 EXPECT_TRUE(ret); |
269 if (!ret) | 269 if (!ret) |
270 return false; | 270 return false; |
271 EXPECT_EQ(expected ? "yes" : "no", result); | 271 EXPECT_EQ(expected ? "yes" : "no", result); |
272 return ((expected ? "yes" : "no") == result); | 272 return ((expected ? "yes" : "no") == result); |
273 } | 273 } |
274 | 274 |
275 testing::AssertionResult ReloadStaleCopyFromCache() { | 275 testing::AssertionResult ReloadStaleCopyFromCache() { |
mmenke
2014/04/11 19:42:32
Now that we have a button, should "click" it with
Randy Smith (Not in Mondays)
2014/04/14 22:02:13
Done.
| |
276 const char* js_reload_script = | 276 const char* js_reload_script = |
277 "try {\n" | 277 "try {\n" |
278 " errorCacheLoad.reloadStaleInstance();\n" | 278 " errorCacheLoad.reloadStaleInstance();\n" |
279 " domAutomationController.send('success');\n" | 279 " domAutomationController.send('success');\n" |
280 "} catch (e) {\n" | 280 "} catch (e) {\n" |
281 " domAutomationController.send(e.message);\n" | 281 " domAutomationController.send(e.message);\n" |
282 "}\n"; | 282 "}\n"; |
283 | 283 |
284 std::string result; | 284 std::string result; |
285 bool ret = content::ExecuteScriptAndExtractString( | 285 bool ret = content::ExecuteScriptAndExtractString( |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = | 673 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = |
674 browser()->profile()->GetRequestContext(); | 674 browser()->profile()->GetRequestContext(); |
675 BrowserThread::PostTask( | 675 BrowserThread::PostTask( |
676 BrowserThread::IO, FROM_HERE, | 676 BrowserThread::IO, FROM_HERE, |
677 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, | 677 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, |
678 net::ERR_FAILED)); | 678 net::ERR_FAILED)); |
679 | 679 |
680 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 680 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
681 // With no navigation corrections to load, there's only one navigation. | 681 // With no navigation corrections to load, there's only one navigation. |
682 browser(), test_url, 1); | 682 browser(), test_url, 1); |
683 EXPECT_TRUE(ProbeStaleCopyValue(true)); | 683 EXPECT_TRUE(ProbeStaleCopyValue(true)); |
mmenke
2014/04/11 19:42:32
Suggest also checking the button's visibility. Sh
Randy Smith (Not in Mondays)
2014/04/14 22:02:13
Done.
| |
684 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"), | 684 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"), |
685 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 685 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
686 | 686 |
687 // Confirm that loading the stale copy from the cache works. | 687 // Confirm that loading the stale copy from the cache works. |
688 content::TestNavigationObserver same_tab_observer( | 688 content::TestNavigationObserver same_tab_observer( |
689 browser()->tab_strip_model()->GetActiveWebContents(), 1); | 689 browser()->tab_strip_model()->GetActiveWebContents(), 1); |
690 ASSERT_TRUE(ReloadStaleCopyFromCache()); | 690 ASSERT_TRUE(ReloadStaleCopyFromCache()); |
691 same_tab_observer.Wait(); | 691 same_tab_observer.Wait(); |
692 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), | 692 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), |
693 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 693 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 873 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
874 | 874 |
875 // Clear the cache and reload the same URL; confirm the error page is told | 875 // Clear the cache and reload the same URL; confirm the error page is told |
876 // that there is no cached copy. | 876 // that there is no cached copy. |
877 BrowsingDataRemover* remover = | 877 BrowsingDataRemover* remover = |
878 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); | 878 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); |
879 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, | 879 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
880 BrowsingDataHelper::UNPROTECTED_WEB); | 880 BrowsingDataHelper::UNPROTECTED_WEB); |
881 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 881 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
882 browser(), test_url, 2); | 882 browser(), test_url, 2); |
883 ProbeStaleCopyValue(false); | 883 ProbeStaleCopyValue(false); |
mmenke
2014/04/11 19:42:32
Should also check that the button's hidden.
Randy Smith (Not in Mondays)
2014/04/14 22:02:13
Done.
| |
884 } | 884 } |
885 | 885 |
886 // A test fixture that simulates failing requests for an IDN domain name. | 886 // A test fixture that simulates failing requests for an IDN domain name. |
887 class ErrorPageForIDNTest : public InProcessBrowserTest { | 887 class ErrorPageForIDNTest : public InProcessBrowserTest { |
888 public: | 888 public: |
889 // Target hostname in different forms. | 889 // Target hostname in different forms. |
890 static const char kHostname[]; | 890 static const char kHostname[]; |
891 static const char kHostnameJSUnicode[]; | 891 static const char kHostnameJSUnicode[]; |
892 | 892 |
893 // InProcessBrowserTest: | 893 // InProcessBrowserTest: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
931 browser(), | 931 browser(), |
932 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, | 932 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, |
933 kHostname), | 933 kHostname), |
934 1); | 934 1); |
935 | 935 |
936 ToggleHelpBox(browser()); | 936 ToggleHelpBox(browser()); |
937 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); | 937 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); |
938 } | 938 } |
939 | 939 |
940 } // namespace | 940 } // namespace |
OLD | NEW |