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

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 2214393003: Change network error titles to just the hostname (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused title string Created 4 years, 4 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 }; 364 };
365 365
366 // Verifies that the given url |spec| can be opened. This assumes that |spec| 366 // Verifies that the given url |spec| can be opened. This assumes that |spec|
367 // points at empty.html in the test data dir. 367 // points at empty.html in the test data dir.
368 void CheckCanOpenURL(Browser* browser, const char* spec) { 368 void CheckCanOpenURL(Browser* browser, const char* spec) {
369 GURL url(spec); 369 GURL url(spec);
370 ui_test_utils::NavigateToURL(browser, url); 370 ui_test_utils::NavigateToURL(browser, url);
371 content::WebContents* contents = 371 content::WebContents* contents =
372 browser->tab_strip_model()->GetActiveWebContents(); 372 browser->tab_strip_model()->GetActiveWebContents();
373 EXPECT_EQ(url, contents->GetURL()); 373 EXPECT_EQ(url, contents->GetURL());
374 base::string16 spec16 = base::UTF8ToUTF16(url.spec()); 374
375 base::string16 title = 375 base::string16 title;
376 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_BLOCKED, spec16); 376 if (url.has_host())
377 title = base::UTF8ToUTF16(url.host());
378 else
379 // Local file paths show the filename as the title.
380 title = base::UTF8ToUTF16(url.ExtractFileName());
377 EXPECT_NE(title, contents->GetTitle()); 381 EXPECT_NE(title, contents->GetTitle());
378 } 382 }
379 383
380 // Verifies that access to the given url |spec| is blocked. 384 // Verifies that access to the given url |spec| is blocked.
381 void CheckURLIsBlocked(Browser* browser, const char* spec) { 385 void CheckURLIsBlocked(Browser* browser, const char* spec) {
382 GURL url(spec); 386 GURL url(spec);
383 ui_test_utils::NavigateToURL(browser, url); 387 ui_test_utils::NavigateToURL(browser, url);
384 content::WebContents* contents = 388 content::WebContents* contents =
385 browser->tab_strip_model()->GetActiveWebContents(); 389 browser->tab_strip_model()->GetActiveWebContents();
386 EXPECT_EQ(url, contents->GetURL()); 390 EXPECT_EQ(url, contents->GetURL());
387 base::string16 spec16 = base::UTF8ToUTF16(url.spec()); 391
388 base::string16 title = 392 base::string16 title;
389 l10n_util::GetStringFUTF16(IDS_ERRORPAGES_TITLE_BLOCKED, spec16); 393 if (url.has_host())
394 title = base::UTF8ToUTF16(url.host());
395 else
396 // Local file paths show the filename as the title.
397 title = base::UTF8ToUTF16(url.ExtractFileName());
390 EXPECT_EQ(title, contents->GetTitle()); 398 EXPECT_EQ(title, contents->GetTitle());
391 399
392 // Verify that the expected error page is being displayed. 400 // Verify that the expected error page is being displayed.
393 bool result = false; 401 bool result = false;
394 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 402 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
395 contents, 403 contents,
396 "var textContent = document.body.textContent;" 404 "var textContent = document.body.textContent;"
397 "var hasError = textContent.indexOf('ERR_BLOCKED_BY_ADMINISTRATOR') >= 0;" 405 "var hasError = textContent.indexOf('ERR_BLOCKED_BY_ADMINISTRATOR') >= 0;"
398 "domAutomationController.send(hasError);", 406 "domAutomationController.send(hasError);",
399 &result)); 407 &result));
(...skipping 2146 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 #define MAYBE_FileURLBlacklist FileURLBlacklist 2554 #define MAYBE_FileURLBlacklist FileURLBlacklist
2547 #endif 2555 #endif
2548 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_FileURLBlacklist) { 2556 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_FileURLBlacklist) {
2549 // Check that FileURLs can be blacklisted and DisabledSchemes works together 2557 // Check that FileURLs can be blacklisted and DisabledSchemes works together
2550 // with URLblacklisting and URLwhitelisting. 2558 // with URLblacklisting and URLwhitelisting.
2551 2559
2552 base::FilePath test_path; 2560 base::FilePath test_path;
2553 PathService::Get(chrome::DIR_TEST_DATA, &test_path); 2561 PathService::Get(chrome::DIR_TEST_DATA, &test_path);
2554 const std::string base_path = "file://" + test_path.AsUTF8Unsafe() +"/"; 2562 const std::string base_path = "file://" + test_path.AsUTF8Unsafe() +"/";
2555 const std::string folder_path = base_path + "apptest/"; 2563 const std::string folder_path = base_path + "apptest/";
2556 const std::string file_path1 = base_path + "title1.html"; 2564 const std::string file_path1 = base_path + "title2.html";
2557 const std::string file_path2 = folder_path + "basic.html"; 2565 const std::string file_path2 = folder_path + "basic.html";
2558 2566
2559 CheckCanOpenURL(browser(), file_path1.c_str()); 2567 CheckCanOpenURL(browser(), file_path1.c_str());
2560 CheckCanOpenURL(browser(), file_path2.c_str()); 2568 CheckCanOpenURL(browser(), file_path2.c_str());
2561 2569
2562 // Set a blacklist for all the files. 2570 // Set a blacklist for all the files.
2563 base::ListValue blacklist; 2571 base::ListValue blacklist;
2564 blacklist.AppendString("file://*"); 2572 blacklist.AppendString("file://*");
2565 PolicyMap policies; 2573 PolicyMap policies;
2566 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 2574 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after
4123 4131
4124 SetEmptyPolicy(); 4132 SetEmptyPolicy();
4125 // Policy not set. 4133 // Policy not set.
4126 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); 4134 CheckSystemTimezoneAutomaticDetectionPolicyUnset();
4127 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); 4135 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false));
4128 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); 4136 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests());
4129 } 4137 }
4130 #endif // defined(OS_CHROMEOS) 4138 #endif // defined(OS_CHROMEOS)
4131 4139
4132 } // namespace policy 4140 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698