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

Unified Diff: chrome/browser/ssl/ssl_browser_tests.cc

Issue 2226363002: Track subresources with cert errors separately from mixed content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/ssl_browser_tests.cc
diff --git a/chrome/browser/ssl/ssl_browser_tests.cc b/chrome/browser/ssl/ssl_browser_tests.cc
index 757bae4275290174817fa080218a7ff3030eeafe..22be94e5f4040d84a0035c718aa4f95f7ad25e55 100644
--- a/chrome/browser/ssl/ssl_browser_tests.cc
+++ b/chrome/browser/ssl/ssl_browser_tests.cc
@@ -277,6 +277,13 @@ void CheckSSLStatusesEquals(const content::SSLStatus& one,
EXPECT_TRUE(one_without_cert_id.Equals(two_without_cert_id));
}
+// Sometimes favicons load before tests check the authentication state,
+// and sometimes they load after. This is problematic on tests that load
+// pages with certificate errors, because the page will be marked as
+// having displayed subresources with certificate errors only if the
+// favicon loads before the test checks the authentication
+// state. HungJob and FaviconFilter are used to hang favicon requests to
+// avoid this nondeterminism.
class HungJob : public net::URLRequestJob {
public:
HungJob(net::URLRequest* request, net::NetworkDelegate* network_delegate)
@@ -325,9 +332,13 @@ class SSLUITest
net::EmbeddedTestServer::CERT_MISMATCHED_NAME);
https_server_mismatched_.AddDefaultHandlers(base::FilePath(kDocRoot));
- // TODO(estark): once http://crbug.com/634171 is fixed and certificate
- // errors for subresources don't generate DISPLAYED_INSECURE_CONTENT remove
- // these filters.
+ // Sometimes favicons load before tests check the authentication
+ // state, and sometimes they load after. This is problematic on
+ // tests that load pages with certificate errors, because the page
+ // will be marked as having displayed subresources with certificate
+ // errors only if the favicon loads before the test checks the
+ // authentication state. To avoid this non-determinism, add an
+ // interceptor to hang all favicon requests.
jam 2016/08/11 19:53:20 nit: did you mean to have nearly the same comment
estark 2016/08/12 04:56:02 Done.
std::unique_ptr<net::URLRequestInterceptor> interceptor(new FaviconFilter);
net::URLRequestFilter::GetInstance()->AddHostnameInterceptor(
"https", "127.0.0.1", std::move(interceptor));
@@ -2312,6 +2323,14 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorkerWithUserException) {
CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::NONE);
+ ChromeSecurityStateModelClient* client =
+ ChromeSecurityStateModelClient::FromWebContents(tab);
+ ASSERT_TRUE(client);
+ EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE,
+ client->GetSecurityInfo().mixed_content_status);
+ EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE,
+ client->GetSecurityInfo().content_with_cert_errors_status);
+
// Navigate to safe page that has Worker loading unsafe content.
// Expect content to load but be marked as auth broken due to running insecure
// content.
@@ -2321,8 +2340,12 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorkerWithUserException) {
ui_test_utils::NavigateToURL(
browser(), https_server_.GetURL(page_with_unsafe_worker_path));
CheckWorkerLoadResult(tab, true); // Worker loads insecure content
- CheckAuthenticationBrokenState(tab, CertError::NONE,
- AuthState::RAN_INSECURE_CONTENT);
+ CheckAuthenticationBrokenState(tab, CertError::NONE, AuthState::NONE);
+
+ EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE,
+ client->GetSecurityInfo().mixed_content_status);
+ EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_RAN,
+ client->GetSecurityInfo().content_with_cert_errors_status);
}
// Visits a page with unsafe content and makes sure that if a user exception to
@@ -2331,9 +2354,16 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) {
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_NO_FATAL_FAILURE(SetUpUnsafeContentsWithUserException(
"/ssl/page_with_unsafe_contents.html"));
- CheckAuthenticationBrokenState(
- tab, CertError::NONE,
- AuthState::RAN_INSECURE_CONTENT | AuthState::DISPLAYED_INSECURE_CONTENT);
+ CheckAuthenticationBrokenState(tab, CertError::NONE, AuthState::NONE);
+
+ ChromeSecurityStateModelClient* client =
+ ChromeSecurityStateModelClient::FromWebContents(tab);
+ ASSERT_TRUE(client);
+ EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE,
+ client->GetSecurityInfo().mixed_content_status);
+ EXPECT_EQ(
+ security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN,
+ client->GetSecurityInfo().content_with_cert_errors_status);
int img_width;
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
@@ -2349,8 +2379,7 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) {
EXPECT_TRUE(js_result);
// Test that active subresources with the same certificate errors as
- // the main resources don't cause mixed content UI downgrades. (Such
- // errors would be confusing and duplicative.)
+ // the main resources also get noted in |content_with_cert_errors_status|.
std::string replacement_path;
GetFilePathWithHostAndPortReplacement(
"/ssl/page_with_unsafe_contents.html",
@@ -2361,11 +2390,14 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) {
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab, "window.domAutomationController.send(IsFooSet());", &js_result));
EXPECT_TRUE(js_result);
- // TODO(estark): once http://crbug.com/634171 is fixed and certificate errors
- // for subresources don't generate DISPLAYED_INSECURE_CONTENT switch this back
- // to AuthState::NONE.
CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID,
- AuthState::DISPLAYED_INSECURE_CONTENT);
+ AuthState::NONE);
+
+ EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE,
+ client->GetSecurityInfo().mixed_content_status);
+ EXPECT_EQ(
+ security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN,
+ client->GetSecurityInfo().content_with_cert_errors_status);
}
// Like the test above, but only displaying inactive content (an image).
@@ -2373,7 +2405,15 @@ IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeImageWithUserException) {
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_NO_FATAL_FAILURE(
SetUpUnsafeContentsWithUserException("/ssl/page_with_unsafe_image.html"));
- CheckAuthenticatedState(tab, AuthState::DISPLAYED_INSECURE_CONTENT);
+ CheckAuthenticatedState(tab, AuthState::NONE);
+
+ ChromeSecurityStateModelClient* client =
+ ChromeSecurityStateModelClient::FromWebContents(tab);
+ ASSERT_TRUE(client);
+ EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_NONE,
+ client->GetSecurityInfo().mixed_content_status);
+ EXPECT_EQ(security_state::SecurityStateModel::CONTENT_STATUS_DISPLAYED,
+ client->GetSecurityInfo().content_with_cert_errors_status);
int img_width;
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
« no previous file with comments | « no previous file | content/browser/site_per_process_browsertest.cc » ('j') | content/public/browser/web_contents.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698