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

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 1181293003: Expand SecurityStyleChanged interfaces to include explanations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments, style tweaks Created 5 years, 6 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 #include "content/public/common/renderer_preferences.h" 85 #include "content/public/common/renderer_preferences.h"
86 #include "content/public/common/url_constants.h" 86 #include "content/public/common/url_constants.h"
87 #include "content/public/test/browser_test_utils.h" 87 #include "content/public/test/browser_test_utils.h"
88 #include "content/public/test/test_navigation_observer.h" 88 #include "content/public/test/test_navigation_observer.h"
89 #include "extensions/browser/extension_registry.h" 89 #include "extensions/browser/extension_registry.h"
90 #include "extensions/browser/extension_system.h" 90 #include "extensions/browser/extension_system.h"
91 #include "extensions/browser/uninstall_reason.h" 91 #include "extensions/browser/uninstall_reason.h"
92 #include "extensions/common/constants.h" 92 #include "extensions/common/constants.h"
93 #include "extensions/common/extension.h" 93 #include "extensions/common/extension.h"
94 #include "extensions/common/extension_set.h" 94 #include "extensions/common/extension_set.h"
95 #include "net/base/net_errors.h"
95 #include "net/dns/mock_host_resolver.h" 96 #include "net/dns/mock_host_resolver.h"
96 #include "net/test/spawned_test_server/spawned_test_server.h" 97 #include "net/test/spawned_test_server/spawned_test_server.h"
97 #include "ui/base/l10n/l10n_util.h" 98 #include "ui/base/l10n/l10n_util.h"
98 #include "ui/base/page_transition_types.h" 99 #include "ui/base/page_transition_types.h"
99 100
100 #if defined(OS_MACOSX) 101 #if defined(OS_MACOSX)
101 #include "base/mac/scoped_nsautorelease_pool.h" 102 #include "base/mac/scoped_nsautorelease_pool.h"
102 #include "chrome/browser/ui/cocoa/run_loop_testing.h" 103 #include "chrome/browser/ui/cocoa/run_loop_testing.h"
103 #endif 104 #endif
104 105
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 const net::HostPortPair& host_port_pair, 335 const net::HostPortPair& host_port_pair,
335 std::string* replacement_path) { 336 std::string* replacement_path) {
336 std::vector<net::SpawnedTestServer::StringPair> replacement_text; 337 std::vector<net::SpawnedTestServer::StringPair> replacement_text;
337 replacement_text.push_back( 338 replacement_text.push_back(
338 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString())); 339 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString()));
339 return net::SpawnedTestServer::GetFilePathWithReplacements( 340 return net::SpawnedTestServer::GetFilePathWithReplacements(
340 original_file_path, replacement_text, replacement_path); 341 original_file_path, replacement_text, replacement_path);
341 } 342 }
342 343
343 // A WebContentsObserver useful for testing the SecurityStyleChanged() 344 // A WebContentsObserver useful for testing the SecurityStyleChanged()
344 // method: it keeps track of the latest security style that was fired. 345 // method: it keeps track of the latest security style and explanation
346 // that was fired.
345 class SecurityStyleTestObserver : public WebContentsObserver { 347 class SecurityStyleTestObserver : public WebContentsObserver {
346 public: 348 public:
347 explicit SecurityStyleTestObserver(content::WebContents* web_contents) 349 explicit SecurityStyleTestObserver(content::WebContents* web_contents)
348 : content::WebContentsObserver(web_contents), 350 : content::WebContentsObserver(web_contents),
349 latest_security_style_(content::SECURITY_STYLE_UNKNOWN) {} 351 latest_security_style_(content::SECURITY_STYLE_UNKNOWN) {}
350 ~SecurityStyleTestObserver() override {} 352 ~SecurityStyleTestObserver() override {}
351 353
352 void SecurityStyleChanged(content::SecurityStyle security_style) override { 354 void SecurityStyleChanged(content::SecurityStyle security_style,
355 const content::SecurityStyleExplanation&
356 security_style_explanation) override {
353 latest_security_style_ = security_style; 357 latest_security_style_ = security_style;
358 latest_security_style_explanation_ = security_style_explanation;
354 } 359 }
355 360
356 content::SecurityStyle latest_security_style() const { 361 content::SecurityStyle latest_security_style() const {
357 return latest_security_style_; 362 return latest_security_style_;
358 } 363 }
359 364
365 const content::SecurityStyleExplanation& latest_security_style_explanation()
Peter Kasting 2015/06/16 06:29:11 Nit: Prefer to break before the function name rath
estark 2015/06/16 15:32:35 Done.
366 const {
367 return latest_security_style_explanation_;
368 }
369
360 private: 370 private:
361 content::SecurityStyle latest_security_style_; 371 content::SecurityStyle latest_security_style_;
372 content::SecurityStyleExplanation latest_security_style_explanation_;
362 373
363 DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver); 374 DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver);
364 }; 375 };
365 376
366 } // namespace 377 } // namespace
367 378
368 class BrowserTest : public ExtensionBrowserTest { 379 class BrowserTest : public ExtensionBrowserTest {
369 protected: 380 protected:
370 // In RTL locales wrap the page title with RTL embedding characters so that it 381 // In RTL locales wrap the page title with RTL embedding characters so that it
371 // matches the value returned by GetWindowTitle(). 382 // matches the value returned by GetWindowTitle().
(...skipping 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2851 // Visit an (otherwise valid) HTTPS page that displays mixed content. 2862 // Visit an (otherwise valid) HTTPS page that displays mixed content.
2852 std::string replacement_path; 2863 std::string replacement_path;
2853 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( 2864 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
2854 "files/ssl/page_displays_insecure_content.html", 2865 "files/ssl/page_displays_insecure_content.html",
2855 test_server()->host_port_pair(), &replacement_path)); 2866 test_server()->host_port_pair(), &replacement_path));
2856 2867
2857 GURL mixed_content_url(https_test_server.GetURL(replacement_path)); 2868 GURL mixed_content_url(https_test_server.GetURL(replacement_path));
2858 ui_test_utils::NavigateToURL(browser(), mixed_content_url); 2869 ui_test_utils::NavigateToURL(browser(), mixed_content_url);
2859 EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style()); 2870 EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style());
2860 2871
2872 const content::SecurityStyleExplanation& mixed_content_explanation =
2873 observer.latest_security_style_explanation();
2874 ASSERT_EQ(1u, mixed_content_explanation.warning_explanations.size());
2875 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT),
2876 mixed_content_explanation.warning_explanations[0].summary);
2877 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_PASSIVE_MIXED_CONTENT_DESCRIPTION),
2878 mixed_content_explanation.warning_explanations[0].description);
2879 EXPECT_EQ(0u, mixed_content_explanation.broken_explanations.size());
2880
2861 // Visit a broken HTTPS url. Other conditions cannot be tested after 2881 // Visit a broken HTTPS url. Other conditions cannot be tested after
2862 // this one because once the interstitial is clicked through, all URLs 2882 // this one because once the interstitial is clicked through, all URLs
2863 // for this host will remain in a broken state. 2883 // for this host will remain in a broken state.
2864 GURL expired_url(https_test_server_expired.GetURL(std::string())); 2884 GURL expired_url(https_test_server_expired.GetURL(std::string()));
2865 ui_test_utils::NavigateToURL(browser(), expired_url); 2885 ui_test_utils::NavigateToURL(browser(), expired_url);
2866 2886
2867 ProceedThroughInterstitial(web_contents); 2887 ProceedThroughInterstitial(web_contents);
2868 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATION_BROKEN, 2888 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATION_BROKEN,
2869 observer.latest_security_style()); 2889 observer.latest_security_style());
2890
2891 const content::SecurityStyleExplanation& expired_explanation =
2892 observer.latest_security_style_explanation();
2893 EXPECT_EQ(0u, expired_explanation.warning_explanations.size());
2894 ASSERT_EQ(1u, expired_explanation.broken_explanations.size());
2895 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_CERTIFICATE_CHAIN_ERROR),
2896 expired_explanation.broken_explanations[0].summary);
2897 base::string16 error_string =
2898 base::UTF8ToUTF16(net::ErrorToString(net::ERR_CERT_DATE_INVALID));
2899 EXPECT_EQ(l10n_util::GetStringFUTF8(
2900 IDS_CERTIFICATE_CHAIN_ERROR_DESCRIPTION_FORMAT, error_string),
2901 expired_explanation.broken_explanations[0].description);
2870 } 2902 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698