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

Side by Side Diff: chrome/browser/ssl/chrome_security_state_model_client_browser_tests.cc

Issue 2432933004: Adjust HTTP-bad console messages (Closed)
Patch Set: elawrence comment Created 4 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/ssl/chrome_security_state_model_client.h" 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h"
6 6
7 #include <openssl/ssl.h> 7 #include <openssl/ssl.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 } 1155 }
1156 1156
1157 private: 1157 private:
1158 std::vector<base::string16> console_messages_; 1158 std::vector<base::string16> console_messages_;
1159 base::Closure console_message_callback_; 1159 base::Closure console_message_callback_;
1160 1160
1161 DISALLOW_COPY_AND_ASSIGN(ConsoleWebContentsDelegate); 1161 DISALLOW_COPY_AND_ASSIGN(ConsoleWebContentsDelegate);
1162 }; 1162 };
1163 1163
1164 // Checks that |delegate| has observed exactly one console message for 1164 // Checks that |delegate| has observed exactly one console message for
1165 // HTTP_SHOW_WARNING. This does not check for the exact string (for fear 1165 // HTTP_SHOW_WARNING. To avoid brittleness, this just looks for keywords
1166 // of being too brittle) but rather just a keyword ("not secure"). 1166 // in the string rather than the exact text.
1167 void CheckForOneHttpWarningConsoleMessage( 1167 void CheckForOneHttpWarningConsoleMessage(
1168 ConsoleWebContentsDelegate* delegate) { 1168 ConsoleWebContentsDelegate* delegate) {
1169 const std::vector<base::string16>& messages = delegate->console_messages(); 1169 const std::vector<base::string16>& messages = delegate->console_messages();
1170 ASSERT_EQ(1u, messages.size()); 1170 ASSERT_EQ(1u, messages.size());
1171 EXPECT_NE(base::string16::npos, 1171 EXPECT_NE(base::string16::npos,
1172 messages[0].find(base::ASCIIToUTF16("not secure"))); 1172 messages[0].find(base::ASCIIToUTF16("warning has been added")));
1173 }
1174
1175 // Checks that |delegate| has observed exactly one console message for
1176 // NONE that will be HTTP_SHOW_WARNING in future. To avoid brittleness,
1177 // this just looks for keywords in the string rather than the exact
1178 // text.
1179 void CheckForOneFutureHttpWarningConsoleMessage(
1180 ConsoleWebContentsDelegate* delegate) {
1181 const std::vector<base::string16>& messages = delegate->console_messages();
1182 ASSERT_EQ(1u, messages.size());
1183 EXPECT_NE(base::string16::npos,
1184 messages[0].find(base::ASCIIToUTF16("warning will be added")));
1173 } 1185 }
1174 1186
1175 // Tests that console messages are printed upon a call to 1187 // Tests that console messages are printed upon a call to
1176 // GetSecurityInfo() on an HTTP_SHOW_WARNING page, exactly once per 1188 // GetSecurityInfo() on an HTTP_SHOW_WARNING page, exactly once per
1177 // main-frame navigation. 1189 // main-frame navigation.
1178 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 1190 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch,
1179 ConsoleMessage) { 1191 ConsoleMessage) {
1180 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate( 1192 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1181 Browser::CreateParams(browser()->profile())); 1193 Browser::CreateParams(browser()->profile()));
1182 content::WebContents* original_contents = 1194 content::WebContents* original_contents =
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 contents->OnPasswordInputShownOnHttp(); 1248 contents->OnPasswordInputShownOnHttp();
1237 second_message.Run(); 1249 second_message.Run();
1238 1250
1239 client->GetSecurityInfo(&security_info); 1251 client->GetSecurityInfo(&security_info);
1240 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING, 1252 EXPECT_EQ(security_state::SecurityStateModel::HTTP_SHOW_WARNING,
1241 security_info.security_level); 1253 security_info.security_level);
1242 1254
1243 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate)); 1255 ASSERT_NO_FATAL_FAILURE(CheckForOneHttpWarningConsoleMessage(delegate));
1244 } 1256 }
1245 1257
1258 // Tests that console messages are printed upon a call to
1259 // GetSecurityInfo() on a NONE page that will be marked
1260 // HTTP_SHOW_WARNING in future, exactly once per main-frame navigation.
1261 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTest, ConsoleMessage) {
1262 ASSERT_TRUE(embedded_test_server()->Start());
1263 host_resolver()->AddRule("*", embedded_test_server()->GetURL("/").host());
1264 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1265 Browser::CreateParams(browser()->profile()));
1266 content::WebContents* original_contents =
1267 browser()->tab_strip_model()->GetActiveWebContents();
1268 content::WebContents* contents =
1269 content::WebContents::Create(content::WebContents::CreateParams(
1270 original_contents->GetBrowserContext()));
1271 ASSERT_TRUE(contents);
1272 contents->SetDelegate(delegate);
1273 delegate->tab_strip_model()->AppendWebContents(contents, true);
1274 int index = delegate->tab_strip_model()->GetIndexOfWebContents(contents);
1275 delegate->tab_strip_model()->ActivateTabAt(index, true);
1276 ASSERT_EQ(contents, delegate->tab_strip_model()->GetActiveWebContents());
1277
1278 // Navigate to an HTTP page. Use a non-local hostname so that is it
1279 // not considered secure.
1280 GURL http_url =
1281 GetURLWithNonLocalHostname(embedded_test_server(), "/title1.html");
1282 ui_test_utils::NavigateToURL(delegate, http_url);
1283 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
1284 ASSERT_TRUE(entry);
1285 EXPECT_EQ(http_url, entry->GetURL());
1286 EXPECT_TRUE(delegate->console_messages().empty());
1287
1288 // Trigger the a state that will be marked as HTTP_SHOW_WARNING in future.
1289 base::RunLoop first_message;
1290 delegate->set_console_message_callback(first_message.QuitClosure());
1291 contents->OnPasswordInputShownOnHttp();
1292 first_message.Run();
1293
1294 // Check that the correct state was actually triggered.
1295 ChromeSecurityStateModelClient* client =
1296 ChromeSecurityStateModelClient::FromWebContents(contents);
1297 ASSERT_TRUE(client);
1298 security_state::SecurityStateModel::SecurityInfo security_info;
1299 client->GetSecurityInfo(&security_info);
1300 EXPECT_EQ(security_state::SecurityStateModel::NONE,
1301 security_info.security_level);
1302 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http);
1303
1304 // Check that the expected console message is present.
1305 ASSERT_NO_FATAL_FAILURE(CheckForOneFutureHttpWarningConsoleMessage(delegate));
1306 delegate->ClearConsoleMessages();
1307
1308 // Two subsequent triggers of VisibleSSLStateChanged -- one on the
1309 // same navigation and one on another navigation -- should only result
1310 // in one additional console message.
1311 contents->OnCreditCardInputShownOnHttp();
1312 GURL second_http_url =
1313 GetURLWithNonLocalHostname(embedded_test_server(), "/title2.html");
1314 ui_test_utils::NavigateToURL(delegate, second_http_url);
1315 entry = contents->GetController().GetVisibleEntry();
1316 ASSERT_TRUE(entry);
1317 EXPECT_EQ(second_http_url, entry->GetURL());
1318
1319 base::RunLoop second_message;
1320 delegate->set_console_message_callback(second_message.QuitClosure());
1321 contents->OnPasswordInputShownOnHttp();
1322 second_message.Run();
1323
1324 client->GetSecurityInfo(&security_info);
1325 EXPECT_EQ(security_state::SecurityStateModel::NONE,
1326 security_info.security_level);
1327 EXPECT_TRUE(security_info.displayed_private_user_data_input_on_http);
1328
1329 ASSERT_NO_FATAL_FAILURE(CheckForOneFutureHttpWarningConsoleMessage(delegate));
1330 }
1331
1246 // Tests that additional HTTP_SHOW_WARNING console messages are not 1332 // Tests that additional HTTP_SHOW_WARNING console messages are not
1247 // printed after subframe navigations. 1333 // printed after subframe navigations.
1248 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch, 1334 IN_PROC_BROWSER_TEST_F(ChromeSecurityStateModelClientTestWithPasswordCcSwitch,
1249 ConsoleMessageNotPrintedForFrameNavigation) { 1335 ConsoleMessageNotPrintedForFrameNavigation) {
1250 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate( 1336 ConsoleWebContentsDelegate* delegate = new ConsoleWebContentsDelegate(
1251 Browser::CreateParams(browser()->profile())); 1337 Browser::CreateParams(browser()->profile()));
1252 content::WebContents* original_contents = 1338 content::WebContents* original_contents =
1253 browser()->tab_strip_model()->GetActiveWebContents(); 1339 browser()->tab_strip_model()->GetActiveWebContents();
1254 content::WebContents* contents = 1340 content::WebContents* contents =
1255 content::WebContents::Create(content::WebContents::CreateParams( 1341 content::WebContents::Create(content::WebContents::CreateParams(
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 ChromeSecurityStateModelClient* model_client = 2042 ChromeSecurityStateModelClient* model_client =
1957 ChromeSecurityStateModelClient::FromWebContents(web_contents); 2043 ChromeSecurityStateModelClient::FromWebContents(web_contents);
1958 ASSERT_TRUE(model_client); 2044 ASSERT_TRUE(model_client);
1959 SecurityStateModel::SecurityInfo security_info; 2045 SecurityStateModel::SecurityInfo security_info;
1960 model_client->GetSecurityInfo(&security_info); 2046 model_client->GetSecurityInfo(&security_info);
1961 EXPECT_EQ(SecurityStateModel::SECURE, security_info.security_level); 2047 EXPECT_EQ(SecurityStateModel::SECURE, security_info.security_level);
1962 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); 2048 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses);
1963 } 2049 }
1964 2050
1965 } // namespace 2051 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698