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

Side by Side Diff: content/browser/devtools/protocol/devtools_protocol_browsertest.cc

Issue 2639203003: Add certificate error handling to devtools. (Closed)
Patch Set: Fix tests Created 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <utility> 6 #include <utility>
7 7
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 web_contents->GetController().GetTransientEntry(); 1401 web_contents->GetController().GetTransientEntry();
1402 ASSERT_TRUE(transient_entry); 1402 ASSERT_TRUE(transient_entry);
1403 transient_entry->GetSSL().certificate = expired_cert(); 1403 transient_entry->GetSSL().certificate = expired_cert();
1404 ASSERT_TRUE(transient_entry->GetSSL().certificate); 1404 ASSERT_TRUE(transient_entry->GetSSL().certificate);
1405 1405
1406 std::unique_ptr<base::DictionaryValue> params2(new base::DictionaryValue()); 1406 std::unique_ptr<base::DictionaryValue> params2(new base::DictionaryValue());
1407 SendCommand("Security.showCertificateViewer", std::move(params2), true); 1407 SendCommand("Security.showCertificateViewer", std::move(params2), true);
1408 EXPECT_EQ(transient_entry->GetSSL().certificate, last_shown_certificate()); 1408 EXPECT_EQ(transient_entry->GetSSL().certificate, last_shown_certificate());
1409 } 1409 }
1410 1410
1411 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, CertificateError) {
1412 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
1413 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
1414 https_server.ServeFilesFromSourceDirectory("content/test/data");
1415 ASSERT_TRUE(https_server.Start());
1416 GURL test_url = https_server.GetURL("/devtools/navigation.html");
1417 std::unique_ptr<base::DictionaryValue> params;
1418 std::unique_ptr<base::DictionaryValue> command_params;
1419 int eventID;
1420
1421 shell()->LoadURL(GURL("about:blank"));
1422 WaitForLoadStop(shell()->web_contents());
1423
1424 Attach();
1425 SendCommand("Network.enable", nullptr, true);
1426 SendCommand("Security.enable", nullptr, false);
1427 command_params.reset(new base::DictionaryValue());
1428 command_params->SetBoolean("override", true);
1429 SendCommand("Security.setOverrideCertificateErrors",
1430 std::move(command_params), true);
1431
1432 // Test cancel.
1433 SendCommand("Network.clearBrowserCache", nullptr, true);
1434 SendCommand("Network.clearBrowserCookies", nullptr, true);
1435 TestNavigationObserver cancel_observer(shell()->web_contents(), 1);
1436 shell()->LoadURL(test_url);
1437 params = WaitForNotification("Security.certificateError", false);
1438 EXPECT_TRUE(shell()->web_contents()->GetController().GetPendingEntry());
1439 EXPECT_EQ(
1440 test_url,
1441 shell()->web_contents()->GetController().GetPendingEntry()->GetURL());
1442 EXPECT_TRUE(params->GetInteger("eventID", &eventID));
1443 command_params.reset(new base::DictionaryValue());
1444 command_params->SetInteger("eventID", eventID);
1445 command_params->SetString("action", "cancel");
1446 SendCommand("Security.handleCertificateError", std::move(command_params),
1447 false);
1448 cancel_observer.Wait();
1449 EXPECT_FALSE(shell()->web_contents()->GetController().GetPendingEntry());
1450 EXPECT_EQ(GURL("about:blank"), shell()
1451 ->web_contents()
1452 ->GetController()
1453 .GetLastCommittedEntry()
1454 ->GetURL());
1455
1456 // Test continue.
1457 SendCommand("Network.clearBrowserCache", nullptr, true);
1458 SendCommand("Network.clearBrowserCookies", nullptr, true);
1459 TestNavigationObserver continue_observer(shell()->web_contents(), 1);
1460 shell()->LoadURL(test_url);
1461 params = WaitForNotification("Security.certificateError", false);
1462 EXPECT_TRUE(params->GetInteger("eventID", &eventID));
1463 command_params.reset(new base::DictionaryValue());
1464 command_params->SetInteger("eventID", eventID);
1465 command_params->SetString("action", "continue");
1466 SendCommand("Security.handleCertificateError", std::move(command_params),
1467 false);
1468 WaitForNotification("Network.loadingFinished", true);
1469 continue_observer.Wait();
1470 EXPECT_EQ(test_url, shell()
1471 ->web_contents()
1472 ->GetController()
1473 .GetLastCommittedEntry()
1474 ->GetURL());
1475 }
1476
1477 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, SubresourceWithCertificateError) {
1478 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS);
1479 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
1480 https_server.ServeFilesFromSourceDirectory("content/test/data/devtools");
1481 ASSERT_TRUE(https_server.Start());
1482 GURL test_url = https_server.GetURL("/image.html");
1483 std::unique_ptr<base::DictionaryValue> params;
1484 std::unique_ptr<base::DictionaryValue> command_params;
1485 int eventID;
1486
1487 shell()->LoadURL(GURL("about:blank"));
1488 WaitForLoadStop(shell()->web_contents());
1489
1490 Attach();
1491 SendCommand("Security.enable", nullptr, false);
1492 command_params.reset(new base::DictionaryValue());
1493 command_params->SetBoolean("override", true);
1494 SendCommand("Security.setOverrideCertificateErrors",
1495 std::move(command_params), true);
1496
1497 TestNavigationObserver observer(shell()->web_contents(), 1);
1498 shell()->LoadURL(test_url);
1499
1500 // Expect certificateError event for main frame.
1501 params = WaitForNotification("Security.certificateError", false);
1502 EXPECT_TRUE(params->GetInteger("eventID", &eventID));
1503 command_params.reset(new base::DictionaryValue());
1504 command_params->SetInteger("eventID", eventID);
1505 command_params->SetString("action", "continue");
1506 SendCommand("Security.handleCertificateError", std::move(command_params),
1507 false);
1508
1509 // Expect certificateError event for image.
1510 params = WaitForNotification("Security.certificateError", false);
1511 EXPECT_TRUE(params->GetInteger("eventID", &eventID));
1512 command_params.reset(new base::DictionaryValue());
1513 command_params->SetInteger("eventID", eventID);
1514 command_params->SetString("action", "continue");
1515 SendCommand("Security.handleCertificateError", std::move(command_params),
1516 false);
1517
1518 observer.Wait();
1519 EXPECT_EQ(test_url, shell()
1520 ->web_contents()
1521 ->GetController()
1522 .GetLastCommittedEntry()
1523 ->GetURL());
1524 }
1525
1411 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, TargetDiscovery) { 1526 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, TargetDiscovery) {
1412 std::string temp; 1527 std::string temp;
1413 std::set<std::string> ids; 1528 std::set<std::string> ids;
1414 std::unique_ptr<base::DictionaryValue> command_params; 1529 std::unique_ptr<base::DictionaryValue> command_params;
1415 std::unique_ptr<base::DictionaryValue> params; 1530 std::unique_ptr<base::DictionaryValue> params;
1416 1531
1417 ASSERT_TRUE(embedded_test_server()->Start()); 1532 ASSERT_TRUE(embedded_test_server()->Start());
1418 GURL first_url = embedded_test_server()->GetURL("/devtools/navigation.html"); 1533 GURL first_url = embedded_test_server()->GetURL("/devtools/navigation.html");
1419 NavigateToURLBlockUntilNavigationsComplete(shell(), first_url, 1); 1534 NavigateToURLBlockUntilNavigationsComplete(shell(), first_url, 1);
1420 1535
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 EXPECT_EQ("polyglottal", value); 1756 EXPECT_EQ("polyglottal", value);
1642 found++; 1757 found++;
1643 } else { 1758 } else {
1644 FAIL(); 1759 FAIL();
1645 } 1760 }
1646 } 1761 }
1647 EXPECT_EQ(2u, found); 1762 EXPECT_EQ(2u, found);
1648 } 1763 }
1649 1764
1650 } // namespace content 1765 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698