Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/errorpage_browsertest.cc

Issue 961443002: Three way experiment for "Show saved copy" button. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: histograms fix Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_COPY);
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
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->AppendSwitchASCII(switches::kShowSavedCopy,
303 switches::kEnableShowSavedCopyPrimary);
303 } 304 }
304 305
305 // Navigates the active tab to a mock url created for the file at |file_path|. 306 // Navigates the active tab to a mock url created for the file at |file_path|.
306 void NavigateToFileURL(const base::FilePath::StringType& file_path) { 307 void NavigateToFileURL(const base::FilePath::StringType& file_path) {
307 ui_test_utils::NavigateToURL( 308 ui_test_utils::NavigateToURL(
308 browser(), 309 browser(),
309 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path))); 310 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(file_path)));
310 } 311 }
311 312
312 // Navigates to the given URL and waits for |num_navigations| to occur, and 313 // 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
351 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD); 352 NavigateHistory(num_navigations, HISTORY_NAVIGATE_FORWARD);
352 } 353 }
353 354
354 // Confirms that the javascript variable indicating whether or not we have 355 // 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 356 // 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. 357 // stale load button is or isn't there based on the same expectation.
357 testing::AssertionResult ProbeStaleCopyValue(bool expected) { 358 testing::AssertionResult ProbeStaleCopyValue(bool expected) {
358 const char* js_cache_probe = 359 const char* js_cache_probe =
359 "try {\n" 360 "try {\n"
360 " domAutomationController.send(\n" 361 " domAutomationController.send(\n"
361 " loadTimeData.valueExists('staleLoadButton') ? 'yes' : 'no');\n" 362 " loadTimeData.valueExists('showSavedCopyButton') ?"
363 " 'yes' : 'no');\n"
362 "} catch (e) {\n" 364 "} catch (e) {\n"
363 " domAutomationController.send(e.message);\n" 365 " domAutomationController.send(e.message);\n"
364 "}\n"; 366 "}\n";
365 367
366 std::string result; 368 std::string result;
367 bool ret = 369 bool ret =
368 content::ExecuteScriptAndExtractString( 370 content::ExecuteScriptAndExtractString(
369 browser()->tab_strip_model()->GetActiveWebContents(), 371 browser()->tab_strip_model()->GetActiveWebContents(),
370 js_cache_probe, 372 js_cache_probe,
371 &result); 373 &result);
372 if (!ret) { 374 if (!ret) {
373 return testing::AssertionFailure() 375 return testing::AssertionFailure()
374 << "Failing return from ExecuteScriptAndExtractString."; 376 << "Failing return from ExecuteScriptAndExtractString.";
375 } 377 }
376 378
377 if ((expected && "yes" == result) || (!expected && "no" == result)) 379 if ((expected && "yes" == result) || (!expected && "no" == result))
378 return testing::AssertionSuccess(); 380 return testing::AssertionSuccess();
379 381
380 return testing::AssertionFailure() << "Cache probe result is " << result; 382 return testing::AssertionFailure() << "Cache probe result is " << result;
381 } 383 }
382 384
383 testing::AssertionResult ReloadStaleCopyFromCache() { 385 testing::AssertionResult ReloadStaleCopyFromCache() {
384 const char* js_reload_script = 386 const char* js_reload_script =
385 "try {\n" 387 "try {\n"
386 " document.getElementById('stale-load-button').click();\n" 388 " document.getElementById('show-saved-copy-button').click();\n"
387 " domAutomationController.send('success');\n" 389 " domAutomationController.send('success');\n"
388 "} catch (e) {\n" 390 "} catch (e) {\n"
389 " domAutomationController.send(e.message);\n" 391 " domAutomationController.send(e.message);\n"
390 "}\n"; 392 "}\n";
391 393
392 std::string result; 394 std::string result;
393 bool ret = content::ExecuteScriptAndExtractString( 395 bool ret = content::ExecuteScriptAndExtractString(
394 browser()->tab_strip_model()->GetActiveWebContents(), 396 browser()->tab_strip_model()->GetActiveWebContents(),
395 js_reload_script, 397 js_reload_script,
396 &result); 398 &result);
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 840
839 // Reload same URL after forcing an error from the the network layer; 841 // Reload same URL after forcing an error from the the network layer;
840 // confirm that the error page is told the cached copy exists. 842 // confirm that the error page is told the cached copy exists.
841 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 843 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
842 browser()->profile()->GetRequestContext(); 844 browser()->profile()->GetRequestContext();
843 BrowserThread::PostTask( 845 BrowserThread::PostTask(
844 BrowserThread::IO, FROM_HERE, 846 BrowserThread::IO, FROM_HERE,
845 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, 847 base::Bind(&InterceptNetworkTransactions, url_request_context_getter,
846 net::ERR_FAILED)); 848 net::ERR_FAILED));
847 849
848 // With no navigation corrections to load, there's only one navigation. 850 // With no navigation corrections to load, there's only one navigation.
849 ui_test_utils::NavigateToURL(browser(), test_url); 851 ui_test_utils::NavigateToURL(browser(), test_url);
850 EXPECT_TRUE(ProbeStaleCopyValue(true)); 852 EXPECT_TRUE(ProbeStaleCopyValue(true));
851 EXPECT_TRUE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); 853 EXPECT_TRUE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
852 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"), 854 EXPECT_NE(base::ASCIIToUTF16("Nocache Test Page"),
853 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 855 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
854 856
855 // Confirm that loading the stale copy from the cache works. 857 // Confirm that loading the stale copy from the cache works.
856 content::TestNavigationObserver same_tab_observer( 858 content::TestNavigationObserver same_tab_observer(
857 browser()->tab_strip_model()->GetActiveWebContents(), 1); 859 browser()->tab_strip_model()->GetActiveWebContents(), 1);
858 ASSERT_TRUE(ReloadStaleCopyFromCache()); 860 ASSERT_TRUE(ReloadStaleCopyFromCache());
859 same_tab_observer.Wait(); 861 same_tab_observer.Wait();
860 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), 862 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"),
861 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 863 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
862 864
865 // Reload the same URL with a post request; confirm the error page is told
866 // that there is no cached copy.
867 ui_test_utils::NavigateToURLWithPost(browser(), test_url);
868 EXPECT_TRUE(ProbeStaleCopyValue(false));
869 EXPECT_FALSE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
870 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
871
863 // Clear the cache and reload the same URL; confirm the error page is told 872 // Clear the cache and reload the same URL; confirm the error page is told
864 // that there is no cached copy. 873 // that there is no cached copy.
865 BrowsingDataRemover* remover = 874 BrowsingDataRemover* remover =
866 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); 875 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile());
867 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 876 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
868 BrowsingDataHelper::UNPROTECTED_WEB); 877 BrowsingDataHelper::UNPROTECTED_WEB);
869 ui_test_utils::NavigateToURL(browser(), test_url); 878 ui_test_utils::NavigateToURL(browser(), test_url);
870 EXPECT_TRUE(ProbeStaleCopyValue(false)); 879 EXPECT_TRUE(ProbeStaleCopyValue(false));
871 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); 880 EXPECT_FALSE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
872 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 881 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
873 } 882 }
874 883
875 class ErrorPageAutoReloadTest : public InProcessBrowserTest { 884 class ErrorPageAutoReloadTest : public InProcessBrowserTest {
876 public: 885 public:
877 void SetUpCommandLine(base::CommandLine* command_line) override { 886 void SetUpCommandLine(base::CommandLine* command_line) override {
878 command_line->AppendSwitch(switches::kEnableOfflineAutoReload); 887 command_line->AppendSwitch(switches::kEnableOfflineAutoReload);
879 } 888 }
880 889
881 void InstallInterceptor(const GURL& url, int requests_to_fail) { 890 void InstallInterceptor(const GURL& url, int requests_to_fail) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 // confirm that the error page is told the cached copy exists. 1049 // confirm that the error page is told the cached copy exists.
1041 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 1050 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
1042 browser()->profile()->GetRequestContext(); 1051 browser()->profile()->GetRequestContext();
1043 BrowserThread::PostTask( 1052 BrowserThread::PostTask(
1044 BrowserThread::IO, FROM_HERE, 1053 BrowserThread::IO, FROM_HERE,
1045 base::Bind(&InterceptNetworkTransactions, url_request_context_getter, 1054 base::Bind(&InterceptNetworkTransactions, url_request_context_getter,
1046 net::ERR_CONNECTION_FAILED)); 1055 net::ERR_CONNECTION_FAILED));
1047 1056
1048 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 1057 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
1049 browser(), test_url, 2); 1058 browser(), test_url, 2);
1050 EXPECT_TRUE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); 1059 EXPECT_TRUE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
1051 EXPECT_TRUE(ProbeStaleCopyValue(true)); 1060 EXPECT_TRUE(ProbeStaleCopyValue(true));
1052 1061
1053 // Confirm that loading the stale copy from the cache works. 1062 // Confirm that loading the stale copy from the cache works.
1054 content::TestNavigationObserver same_tab_observer( 1063 content::TestNavigationObserver same_tab_observer(
1055 browser()->tab_strip_model()->GetActiveWebContents(), 1); 1064 browser()->tab_strip_model()->GetActiveWebContents(), 1);
1056 ASSERT_TRUE(ReloadStaleCopyFromCache()); 1065 ASSERT_TRUE(ReloadStaleCopyFromCache());
1057 same_tab_observer.Wait(); 1066 same_tab_observer.Wait();
1058 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"), 1067 EXPECT_EQ(base::ASCIIToUTF16("Nocache Test Page"),
1059 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 1068 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
1060 1069
1061 // Clear the cache and reload the same URL; confirm the error page is told 1070 // Clear the cache and reload the same URL; confirm the error page is told
1062 // that there is no cached copy. 1071 // that there is no cached copy.
1063 BrowsingDataRemover* remover = 1072 BrowsingDataRemover* remover =
1064 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); 1073 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile());
1065 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 1074 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1066 BrowsingDataHelper::UNPROTECTED_WEB); 1075 BrowsingDataHelper::UNPROTECTED_WEB);
1067 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 1076 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
1068 browser(), test_url, 2); 1077 browser(), test_url, 2);
1069 EXPECT_TRUE(ProbeStaleCopyValue(false)); 1078 EXPECT_TRUE(ProbeStaleCopyValue(false));
1070 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); 1079 EXPECT_FALSE(IsDisplayingText(browser(), GetShowSavedButtonLabel()));
1071 } 1080 }
1072 1081
1073 // A test fixture that simulates failing requests for an IDN domain name. 1082 // A test fixture that simulates failing requests for an IDN domain name.
1074 class ErrorPageForIDNTest : public InProcessBrowserTest { 1083 class ErrorPageForIDNTest : public InProcessBrowserTest {
1075 public: 1084 public:
1076 // Target hostname in different forms. 1085 // Target hostname in different forms.
1077 static const char kHostname[]; 1086 static const char kHostname[];
1078 static const char kHostnameJSUnicode[]; 1087 static const char kHostnameJSUnicode[];
1079 1088
1080 // InProcessBrowserTest: 1089 // InProcessBrowserTest:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 ui_test_utils::NavigateToURL( 1126 ui_test_utils::NavigateToURL(
1118 browser(), 1127 browser(),
1119 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 1128 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
1120 kHostname)); 1129 kHostname));
1121 1130
1122 ToggleHelpBox(browser()); 1131 ToggleHelpBox(browser());
1123 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); 1132 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
1124 } 1133 }
1125 1134
1126 } // namespace 1135 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698