1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/metrics/field_trial.h"
#include "base/prefs/pref_service.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
#include "chrome/browser/net/certificate_error_reporter.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ssl/cert_logger.pb.h"
#include "chrome/browser/ssl/cert_report_helper.h"
#include "chrome/browser/ssl/certificate_error_report.h"
#include "chrome/browser/ssl/certificate_reporting_test_utils.h"
#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
#include "chrome/browser/ssl/ssl_blocking_page.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/variations/variations_associated_data.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/security_style.h"
#include "content/public/common/ssl_status.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/test_renderer_host.h"
#include "net/base/host_port_pair.h"
#include "net/base/net_errors.h"
#include "net/base/test_data_directory.h"
#include "net/cert/cert_status_flags.h"
#include "net/cert/x509_certificate.h"
#include "net/ssl/ssl_info.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "net/url_request/url_request_context.h"
#if defined(USE_NSS_CERTS)
#include "chrome/browser/net/nss_context.h"
#include "net/base/crypto_module.h"
#include "net/cert/nss_cert_database.h"
#endif // defined(USE_NSS_CERTS)
using base::ASCIIToUTF16;
using chrome_browser_interstitials::SecurityInterstitialIDNTest;
using chrome_browser_net::CertificateErrorReporter;
using content::InterstitialPage;
using content::NavigationController;
using content::NavigationEntry;
using content::SSLStatus;
using content::WebContents;
using web_modal::WebContentsModalDialogManager;
const base::FilePath::CharType kDocRoot[] =
FILE_PATH_LITERAL("chrome/test/data");
namespace {
class ProvisionalLoadWaiter : public content::WebContentsObserver {
public:
explicit ProvisionalLoadWaiter(WebContents* tab)
: WebContentsObserver(tab), waiting_(false), seen_(false) {}
void Wait() {
if (seen_)
return;
waiting_ = true;
content::RunMessageLoop();
}
void DidFailProvisionalLoad(
content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
const base::string16& error_description,
bool was_ignored_by_handler) override {
seen_ = true;
if (waiting_)
base::MessageLoopForUI::current()->Quit();
}
private:
bool waiting_;
bool seen_;
};
namespace AuthState {
enum AuthStateFlags {
NONE = 0,
DISPLAYED_INSECURE_CONTENT = 1 << 0,
RAN_INSECURE_CONTENT = 1 << 1,
SHOWING_INTERSTITIAL = 1 << 2,
SHOWING_ERROR = 1 << 3
};
void Check(const NavigationEntry& entry, int expected_authentication_state) {
if (expected_authentication_state == AuthState::SHOWING_ERROR) {
EXPECT_EQ(content::PAGE_TYPE_ERROR, entry.GetPageType());
} else {
EXPECT_EQ(
!!(expected_authentication_state & AuthState::SHOWING_INTERSTITIAL)
? content::PAGE_TYPE_INTERSTITIAL
: content::PAGE_TYPE_NORMAL,
entry.GetPageType());
}
bool displayed_insecure_content =
!!(entry.GetSSL().content_status & SSLStatus::DISPLAYED_INSECURE_CONTENT);
EXPECT_EQ(
!!(expected_authentication_state & AuthState::DISPLAYED_INSECURE_CONTENT),
displayed_insecure_content);
bool ran_insecure_content =
!!(entry.GetSSL().content_status & SSLStatus::RAN_INSECURE_CONTENT);
EXPECT_EQ(!!(expected_authentication_state & AuthState::RAN_INSECURE_CONTENT),
ran_insecure_content);
}
} // namespace AuthState
namespace SecurityStyle {
void Check(const NavigationEntry& entry,
content::SecurityStyle expected_security_style) {
EXPECT_EQ(expected_security_style, entry.GetSSL().security_style);
}
} // namespace SecurityStyle
namespace CertError {
enum CertErrorFlags {
NONE = 0
};
void Check(const NavigationEntry& entry, net::CertStatus error) {
if (error) {
EXPECT_EQ(error, entry.GetSSL().cert_status & error);
net::CertStatus extra_cert_errors =
error ^ (entry.GetSSL().cert_status & net::CERT_STATUS_ALL_ERRORS);
if (extra_cert_errors)
LOG(WARNING) << "Got unexpected cert error: " << extra_cert_errors;
} else {
EXPECT_EQ(0U, entry.GetSSL().cert_status & net::CERT_STATUS_ALL_ERRORS);
}
}
} // namespace CertError
void CheckSecurityState(WebContents* tab,
net::CertStatus error,
content::SecurityStyle expected_security_style,
int expected_authentication_state) {
ASSERT_FALSE(tab->IsCrashed());
NavigationEntry* entry = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
CertError::Check(*entry, error);
SecurityStyle::Check(*entry, expected_security_style);
AuthState::Check(*entry, expected_authentication_state);
}
} // namespace
class SSLUITest
: public CertificateReportingTestUtils::CertificateReportingTest {
public:
SSLUITest()
: https_server_(net::SpawnedTestServer::TYPE_HTTPS,
SSLOptions(SSLOptions::CERT_OK),
base::FilePath(kDocRoot)),
https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS,
SSLOptions(SSLOptions::CERT_EXPIRED),
base::FilePath(kDocRoot)),
https_server_mismatched_(net::SpawnedTestServer::TYPE_HTTPS,
SSLOptions(SSLOptions::CERT_MISMATCHED_NAME),
base::FilePath(kDocRoot)),
wss_server_expired_(net::SpawnedTestServer::TYPE_WSS,
SSLOptions(SSLOptions::CERT_EXPIRED),
net::GetWebSocketTestDataDirectory()) {}
void SetUpCommandLine(base::CommandLine* command_line) override {
// Browser will both run and display insecure content.
command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
// Use process-per-site so that navigating to a same-site page in a
// new tab will use the same process.
command_line->AppendSwitch(switches::kProcessPerSite);
}
void CheckAuthenticatedState(WebContents* tab,
int expected_authentication_state) {
CheckSecurityState(tab,
CertError::NONE,
content::SECURITY_STYLE_AUTHENTICATED,
expected_authentication_state);
}
void CheckUnauthenticatedState(WebContents* tab,
int expected_authentication_state) {
CheckSecurityState(tab,
CertError::NONE,
content::SECURITY_STYLE_UNAUTHENTICATED,
expected_authentication_state);
}
void CheckAuthenticationBrokenState(WebContents* tab,
net::CertStatus error,
int expected_authentication_state) {
CheckSecurityState(tab,
error,
content::SECURITY_STYLE_AUTHENTICATION_BROKEN,
expected_authentication_state);
// CERT_STATUS_UNABLE_TO_CHECK_REVOCATION doesn't lower the security style
// to SECURITY_STYLE_AUTHENTICATION_BROKEN.
ASSERT_NE(net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION, error);
}
void CheckWorkerLoadResult(WebContents* tab, bool expected_load) {
// Workers are async and we don't have notifications for them passing
// messages since they do it between renderer and worker processes.
// So have a polling loop, check every 200ms, timeout at 30s.
const int kTimeoutMS = 200;
base::Time time_to_quit = base::Time::Now() +
base::TimeDelta::FromMilliseconds(30000);
while (base::Time::Now() < time_to_quit) {
bool worker_finished = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(IsWorkerFinished());",
&worker_finished));
if (worker_finished)
break;
// Wait a bit.
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::MessageLoop::QuitClosure(),
base::TimeDelta::FromMilliseconds(kTimeoutMS));
content::RunMessageLoop();
}
bool actually_loaded_content = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(IsContentLoaded());",
&actually_loaded_content));
EXPECT_EQ(expected_load, actually_loaded_content);
}
void ProceedThroughInterstitial(WebContents* tab) {
InterstitialPage* interstitial_page = tab->GetInterstitialPage();
ASSERT_TRUE(interstitial_page);
ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
interstitial_page->Proceed();
observer.Wait();
}
bool IsShowingWebContentsModalDialog() const {
return WebContentsModalDialogManager::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents())->
IsDialogActive();
}
static bool GetFilePathWithHostAndPortReplacement(
const std::string& original_file_path,
const net::HostPortPair& host_port_pair,
std::string* replacement_path) {
std::vector<net::SpawnedTestServer::StringPair> replacement_text;
replacement_text.push_back(
make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString()));
return net::SpawnedTestServer::GetFilePathWithReplacements(
original_file_path, replacement_text, replacement_path);
}
static bool GetTopFramePath(const net::SpawnedTestServer& http_server,
const net::SpawnedTestServer& good_https_server,
const net::SpawnedTestServer& bad_https_server,
std::string* top_frame_path) {
// The "frame_left.html" page contained in the top_frame.html page contains
// <a href>'s to three different servers. This sets up all of the
// replacement text to work with test servers which listen on ephemeral
// ports.
GURL http_url = http_server.GetURL("files/ssl/google.html");
GURL good_https_url = good_https_server.GetURL("files/ssl/google.html");
GURL bad_https_url = bad_https_server.GetURL(
"files/ssl/bad_iframe.html");
std::vector<net::SpawnedTestServer::StringPair> replacement_text_frame_left;
replacement_text_frame_left.push_back(
make_pair("REPLACE_WITH_HTTP_PAGE", http_url.spec()));
replacement_text_frame_left.push_back(
make_pair("REPLACE_WITH_GOOD_HTTPS_PAGE", good_https_url.spec()));
replacement_text_frame_left.push_back(
make_pair("REPLACE_WITH_BAD_HTTPS_PAGE", bad_https_url.spec()));
std::string frame_left_path;
if (!net::SpawnedTestServer::GetFilePathWithReplacements(
"frame_left.html",
replacement_text_frame_left,
&frame_left_path))
return false;
// Substitute the generated frame_left URL into the top_frame page.
std::vector<net::SpawnedTestServer::StringPair> replacement_text_top_frame;
replacement_text_top_frame.push_back(
make_pair("REPLACE_WITH_FRAME_LEFT_PATH", frame_left_path));
return net::SpawnedTestServer::GetFilePathWithReplacements(
"files/ssl/top_frame.html",
replacement_text_top_frame,
top_frame_path);
}
static bool GetPageWithUnsafeWorkerPath(
const net::SpawnedTestServer& https_server,
std::string* page_with_unsafe_worker_path) {
// Get the "imported.js" URL from the expired https server and
// substitute it into the unsafe_worker.js file.
GURL imported_js_url = https_server.GetURL("files/ssl/imported.js");
std::vector<net::SpawnedTestServer::StringPair>
replacement_text_for_unsafe_worker;
replacement_text_for_unsafe_worker.push_back(
make_pair("REPLACE_WITH_IMPORTED_JS_URL", imported_js_url.spec()));
std::string unsafe_worker_path;
if (!net::SpawnedTestServer::GetFilePathWithReplacements(
"unsafe_worker.js",
replacement_text_for_unsafe_worker,
&unsafe_worker_path))
return false;
// Now, substitute this into the page with unsafe worker.
std::vector<net::SpawnedTestServer::StringPair>
replacement_text_for_page_with_unsafe_worker;
replacement_text_for_page_with_unsafe_worker.push_back(
make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path));
return net::SpawnedTestServer::GetFilePathWithReplacements(
"files/ssl/page_with_unsafe_worker.html",
replacement_text_for_page_with_unsafe_worker,
page_with_unsafe_worker_path);
}
// Helper function for testing invalid certificate chain reporting.
void TestBrokenHTTPSReporting(
CertificateReportingTestUtils::OptIn opt_in,
CertificateReportingTestUtils::Proceed proceed,
CertificateReportingTestUtils::ExpectReport expect_report,
Browser* browser) {
base::RunLoop run_loop;
ASSERT_TRUE(https_server_expired_.Start());
ASSERT_NO_FATAL_FAILURE(SetUpMockReporter());
// Opt in to sending reports for invalid certificate chains.
CertificateReportingTestUtils::SetCertReportingOptIn(browser, opt_in);
ui_test_utils::NavigateToURL(browser, https_server_expired_.GetURL("/"));
WebContents* tab = browser->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID,
AuthState::SHOWING_INTERSTITIAL);
scoped_ptr<SSLCertReporter> ssl_cert_reporter =
CertificateReportingTestUtils::SetUpMockSSLCertReporter(&run_loop,
expect_report);
SSLBlockingPage* interstitial_page = static_cast<SSLBlockingPage*>(
tab->GetInterstitialPage()->GetDelegateForTesting());
interstitial_page->SetSSLCertReporterForTesting(ssl_cert_reporter.Pass());
EXPECT_EQ(std::string(), GetLatestHostnameReported());
// Leave the interstitial (either by proceeding or going back)
if (proceed == CertificateReportingTestUtils::SSL_INTERSTITIAL_PROCEED) {
ProceedThroughInterstitial(tab);
} else {
// Click "Take me back"
InterstitialPage* interstitial_page = tab->GetInterstitialPage();
ASSERT_TRUE(interstitial_page);
interstitial_page->DontProceed();
}
if (expect_report == CertificateReportingTestUtils::CERT_REPORT_EXPECTED) {
// Check that the mock reporter received a request to send a report.
run_loop.Run();
EXPECT_EQ(https_server_expired_.GetURL("/").host(),
GetLatestHostnameReported());
} else {
EXPECT_EQ(std::string(), GetLatestHostnameReported());
}
}
net::SpawnedTestServer https_server_;
net::SpawnedTestServer https_server_expired_;
net::SpawnedTestServer https_server_mismatched_;
net::SpawnedTestServer wss_server_expired_;
private:
typedef net::SpawnedTestServer::SSLOptions SSLOptions;
DISALLOW_COPY_AND_ASSIGN(SSLUITest);
};
class SSLUITestBlock : public SSLUITest {
public:
SSLUITestBlock() : SSLUITest() {}
// Browser will neither run nor display insecure content.
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kNoDisplayingInsecureContent);
}
};
class SSLUITestIgnoreCertErrors : public SSLUITest {
public:
SSLUITestIgnoreCertErrors() : SSLUITest() {}
void SetUpCommandLine(base::CommandLine* command_line) override {
// Browser will ignore certificate errors.
command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
}
};
class SSLUITestIgnoreLocalhostCertErrors : public SSLUITest {
public:
SSLUITestIgnoreLocalhostCertErrors() : SSLUITest() {}
void SetUpCommandLine(base::CommandLine* command_line) override {
// Browser will ignore certificate errors on localhost.
command_line->AppendSwitch(switches::kAllowInsecureLocalhost);
}
};
class SSLUITestWithExtendedReporting : public SSLUITest {
public:
SSLUITestWithExtendedReporting() : SSLUITest() {}
};
// Visits a regular page over http.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) {
ASSERT_TRUE(test_server()->Start());
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE);
}
// Visits a page over http which includes broken https resources (status should
// be OK).
// TODO(jcampan): test that bad HTTPS content is blocked (otherwise we'll give
// the secure cookies away!).
IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPWithBrokenHTTPSResource) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_with_unsafe_contents.html",
https_server_expired_.host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(
browser(), test_server()->GetURL(replacement_path));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSWithInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL(replacement_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(tab,
net::CERT_STATUS_DATE_INVALID,
AuthState::DISPLAYED_INSECURE_CONTENT);
}
// http://crbug.com/91745
#if defined(OS_CHROMEOS)
#define MAYBE_TestOKHTTPS DISABLED_TestOKHTTPS
#else
#define MAYBE_TestOKHTTPS TestOKHTTPS
#endif
// Visits a page over OK https:
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestOKHTTPS) {
ASSERT_TRUE(https_server_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL("files/ssl/google.html"));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::NONE);
}
// Visits a page with https error and proceed:
#if defined(OS_LINUX)
// flaky http://crbug.com/396462
#define MAYBE_TestHTTPSExpiredCertAndProceed \
DISABLED_TestHTTPSExpiredCertAndProceed
#else
#define MAYBE_TestHTTPSExpiredCertAndProceed TestHTTPSExpiredCertAndProceed
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestHTTPSExpiredCertAndProceed) {
ASSERT_TRUE(https_server_expired_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
#ifndef NEDBUG
// Flaky on Windows debug (http://crbug.com/280537).
#define MAYBE_TestHTTPSExpiredCertAndDontProceed \
DISABLED_TestHTTPSExpiredCertAndDontProceed
#else
#define MAYBE_TestHTTPSExpiredCertAndDontProceed \
TestHTTPSExpiredCertAndDontProceed
#endif
// Visits a page with https error and don't proceed (and ensure we can still
// navigate at that point):
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestHTTPSExpiredCertAndDontProceed) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
// First navigate to an OK page.
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
NavigationEntry* entry = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
GURL cross_site_url =
https_server_expired_.GetURL("files/ssl/google.html");
// Change the host name from 127.0.0.1 to localhost so it triggers a
// cross-site navigation so we can test http://crbug.com/5800 is gone.
ASSERT_EQ("127.0.0.1", cross_site_url.host());
GURL::Replacements replacements;
replacements.SetHostStr("localhost");
cross_site_url = cross_site_url.ReplaceComponents(replacements);
// Now go to a bad HTTPS page.
ui_test_utils::NavigateToURL(browser(), cross_site_url);
// An interstitial should be showing.
CheckAuthenticationBrokenState(tab,
net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::SHOWING_INTERSTITIAL);
// Simulate user clicking "Take me back".
InterstitialPage* interstitial_page = tab->GetInterstitialPage();
ASSERT_TRUE(interstitial_page);
ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
interstitial_page->DontProceed();
// We should be back to the original good page.
CheckAuthenticatedState(tab, AuthState::NONE);
// Try to navigate to a new page. (to make sure bug 5800 is fixed).
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
CheckUnauthenticatedState(tab, AuthState::NONE);
}
// Test that localhost pages don't show an interstitial.
IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreLocalhostCertErrors,
TestNoInterstitialOnLocalhost) {
ASSERT_TRUE(https_server_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
// Navigate to a localhost page.
GURL url = https_server_.GetURL("files/ssl/page_with_subresource.html");
GURL::Replacements replacements;
std::string new_host("localhost");
replacements.SetHostStr(new_host);
url = url.ReplaceComponents(replacements);
ui_test_utils::NavigateToURL(browser(), url);
// We should see no interstitial, but we should have an error
// (red-crossed-out-https) in the URL bar.
CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::NONE);
// We should see that the script tag in the page loaded and ran (and
// wasn't blocked by the certificate error).
base::string16 title;
base::string16 expected_title = base::ASCIIToUTF16("This script has loaded");
ui_test_utils::GetCurrentTabTitle(browser(), &title);
EXPECT_EQ(title, expected_title);
}
// Visits a page with https error and then goes back using Browser::GoBack.
IN_PROC_BROWSER_TEST_F(SSLUITest,
TestHTTPSExpiredCertAndGoBackViaButton) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
// First navigate to an HTTP page.
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
NavigationEntry* entry = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
// Now go to a bad HTTPS page that shows an interstitial.
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProvisionalLoadWaiter load_failed_observer(tab);
// Simulate user clicking on back button (crbug.com/39248).
chrome::GoBack(browser(), CURRENT_TAB);
// Wait until we hear the load failure, and make sure we haven't swapped out
// the previous page. Prevents regression of http://crbug.com/82667.
// TODO(creis/nick): Move the swapped-out part of this test into content
// and remove IsRenderViewHostSwappedOut from the public API.
load_failed_observer.Wait();
EXPECT_FALSE(content::RenderFrameHostTester::IsRenderFrameHostSwappedOut(
tab->GetMainFrame()));
// We should be back at the original good page.
EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
GetInterstitialPage());
CheckUnauthenticatedState(tab, AuthState::NONE);
}
// Visits a page with https error and then goes back using GoToOffset.
// Disabled because its flaky: http://crbug.com/40932, http://crbug.com/43575.
IN_PROC_BROWSER_TEST_F(SSLUITest,
TestHTTPSExpiredCertAndGoBackViaMenu) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
// First navigate to an HTTP page.
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
NavigationEntry* entry = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry);
// Now go to a bad HTTPS page that shows an interstitial.
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
// Simulate user clicking and holding on back button (crbug.com/37215).
tab->GetController().GoToOffset(-1);
// We should be back at the original good page.
EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
GetInterstitialPage());
CheckUnauthenticatedState(tab, AuthState::NONE);
}
// Visits a page with https error and then goes forward using GoToOffset.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTPSExpiredCertAndGoForward) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
// First navigate to two HTTP pages.
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/google.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
NavigationEntry* entry1 = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry1);
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL("files/ssl/blank_page.html"));
NavigationEntry* entry2 = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry2);
// Now go back so that a page is in the forward history.
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
tab->GetController().GoBack();
observer.Wait();
}
ASSERT_TRUE(tab->GetController().CanGoForward());
NavigationEntry* entry3 = tab->GetController().GetActiveEntry();
ASSERT_TRUE(entry1 == entry3);
// Now go to a bad HTTPS page that shows an interstitial.
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
// Simulate user clicking and holding on forward button.
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
tab->GetController().GoToOffset(1);
observer.Wait();
}
// We should be showing the second good page.
EXPECT_FALSE(browser()->tab_strip_model()->GetActiveWebContents()->
GetInterstitialPage());
CheckUnauthenticatedState(tab, AuthState::NONE);
EXPECT_FALSE(tab->GetController().CanGoForward());
NavigationEntry* entry4 = tab->GetController().GetActiveEntry();
EXPECT_TRUE(entry2 == entry4);
}
// Visit a HTTP page which request WSS connection to a server providing invalid
// certificate. Close the page while WSS connection waits for SSLManager's
// response from UI thread.
// Disabled on Windows because it was flaking on XP Tests (1). crbug.com/165258
#if defined(OS_WIN)
#define MAYBE_TestWSSInvalidCertAndClose DISABLED_TestWSSInvalidCertAndClose
#else
#define MAYBE_TestWSSInvalidCertAndClose TestWSSInvalidCertAndClose
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestWSSInvalidCertAndClose) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(wss_server_expired_.Start());
// Setup page title observer.
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
// Create GURLs to test pages.
std::string master_url_path = base::StringPrintf("%s?%d",
test_server()->GetURL("files/ssl/wss_close.html").spec().c_str(),
wss_server_expired_.host_port_pair().port());
GURL master_url(master_url_path);
std::string slave_url_path = base::StringPrintf("%s?%d",
test_server()->GetURL("files/ssl/wss_close_slave.html").spec().c_str(),
wss_server_expired_.host_port_pair().port());
GURL slave_url(slave_url_path);
// Create tabs and visit pages which keep on creating wss connections.
WebContents* tabs[16];
for (int i = 0; i < 16; ++i) {
tabs[i] = chrome::AddSelectedTabWithURL(browser(), slave_url,
ui::PAGE_TRANSITION_LINK);
}
chrome::SelectNextTab(browser());
// Visit a page which waits for one TLS handshake failure.
// The title will be changed to 'PASS'.
ui_test_utils::NavigateToURL(browser(), master_url);
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(base::LowerCaseEqualsASCII(result, "pass"));
// Close tabs which contains the test page.
for (int i = 0; i < 16; ++i)
chrome::CloseWebContents(browser(), tabs[i], false);
chrome::CloseWebContents(browser(), tab, false);
}
// Visit a HTTPS page and proceeds despite an invalid certificate. The page
// requests WSS connection to the same origin host to check if WSS connection
// share certificates policy with HTTPS correcly.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(wss_server_expired_.Start());
// Setup page title observer.
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
// Visit bad HTTPS page.
GURL::Replacements replacements;
replacements.SetSchemeStr("https");
ui_test_utils::NavigateToURL(
browser(),
wss_server_expired_.GetURL(
"connect_check.html").ReplaceComponents(replacements));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
// Proceed anyway.
ProceedThroughInterstitial(tab);
// Test page run a WebSocket wss connection test. The result will be shown
// as page title.
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(base::LowerCaseEqualsASCII(result, "pass"));
}
#if defined(USE_NSS_CERTS)
class SSLUITestWithClientCert : public SSLUITest {
public:
SSLUITestWithClientCert() : cert_db_(NULL) {}
void SetUpOnMainThread() override {
SSLUITest::SetUpOnMainThread();
base::RunLoop loop;
GetNSSCertDatabaseForProfile(
browser()->profile(),
base::Bind(&SSLUITestWithClientCert::DidGetCertDatabase,
base::Unretained(this),
&loop));
loop.Run();
}
protected:
void DidGetCertDatabase(base::RunLoop* loop, net::NSSCertDatabase* cert_db) {
cert_db_ = cert_db;
loop->Quit();
}
net::NSSCertDatabase* cert_db_;
};
// SSL client certificate tests are only enabled when using NSS for private key
// storage, as only NSS can avoid modifying global machine state when testing.
// See http://crbug.com/51132
// Visit a HTTPS page which requires client cert authentication. The client
// cert will be selected automatically, then a test which uses WebSocket runs.
IN_PROC_BROWSER_TEST_F(SSLUITestWithClientCert, TestWSSClientCert) {
// Import a client cert for test.
scoped_refptr<net::CryptoModule> crypt_module = cert_db_->GetPublicModule();
std::string pkcs12_data;
base::FilePath cert_path = net::GetTestCertsDirectory().Append(
FILE_PATH_LITERAL("websocket_client_cert.p12"));
EXPECT_TRUE(base::ReadFileToString(cert_path, &pkcs12_data));
EXPECT_EQ(net::OK,
cert_db_->ImportFromPKCS12(
crypt_module.get(), pkcs12_data, base::string16(), true, NULL));
// Start WebSocket test server with TLS and client cert authentication.
net::SpawnedTestServer::SSLOptions options(
net::SpawnedTestServer::SSLOptions::CERT_OK);
options.request_client_certificate = true;
base::FilePath ca_path = net::GetTestCertsDirectory().Append(
FILE_PATH_LITERAL("websocket_cacert.pem"));
options.client_authorities.push_back(ca_path);
net::SpawnedTestServer wss_server(net::SpawnedTestServer::TYPE_WSS,
options,
net::GetWebSocketTestDataDirectory());
ASSERT_TRUE(wss_server.Start());
GURL::Replacements replacements;
replacements.SetSchemeStr("https");
GURL url = wss_server.GetURL("connect_check.html").ReplaceComponents(
replacements);
// Setup page title observer.
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
// Add an entry into AutoSelectCertificateForUrls policy for automatic client
// cert selection.
Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
DCHECK(profile);
scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
dict->SetString("ISSUER.CN", "pywebsocket");
profile->GetHostContentSettingsMap()->SetWebsiteSetting(
ContentSettingsPattern::FromURL(url),
ContentSettingsPattern::FromURL(url),
CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
std::string(),
dict.release());
// Visit a HTTPS page which requires client certs.
ui_test_utils::NavigateToURL(browser(), url);
CheckAuthenticatedState(tab, AuthState::NONE);
// Test page runs a WebSocket wss connection test. The result will be shown
// as page title.
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(base::LowerCaseEqualsASCII(result, "pass"));
}
#endif // defined(USE_NSS_CERTS)
// Flaky on CrOS http://crbug.com/92292
#if defined(OS_CHROMEOS)
#define MAYBE_TestHTTPSErrorWithNoNavEntry \
DISABLED_TestHTTPSErrorWithNoNavEntry
#else
#define MAYBE_TestHTTPSErrorWithNoNavEntry TestHTTPSErrorWithNoNavEntry
#endif // defined(OS_CHROMEOS)
// Open a page with a HTTPS error in a tab with no prior navigation (through a
// link with a blank target). This is to test that the lack of navigation entry
// does not cause any problems (it was causing a crasher, see
// http://crbug.com/19941).
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestHTTPSErrorWithNoNavEntry) {
ASSERT_TRUE(https_server_expired_.Start());
GURL url = https_server_expired_.GetURL("files/ssl/google.htm");
WebContents* tab2 = chrome::AddSelectedTabWithURL(
browser(), url, ui::PAGE_TRANSITION_TYPED);
content::WaitForLoadStop(tab2);
// Verify our assumption that there was no prior navigation.
EXPECT_FALSE(chrome::CanGoBack(browser()));
// We should have an interstitial page showing.
ASSERT_TRUE(tab2->GetInterstitialPage());
ASSERT_EQ(SSLBlockingPage::kTypeForTesting, tab2->GetInterstitialPage()
->GetDelegateForTesting()
->GetTypeForTesting());
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestBadHTTPSDownload) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
GURL url_non_dangerous = test_server()->GetURL(std::string());
GURL url_dangerous =
https_server_expired_.GetURL("files/downloads/dangerous/dangerous.exe");
base::ScopedTempDir downloads_directory_;
// Need empty temp dir to avoid having Chrome ask us for a new filename
// when we've downloaded dangerous.exe one hundred times.
ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir());
browser()->profile()->GetPrefs()->SetFilePath(
prefs::kDownloadDefaultDirectory,
downloads_directory_.path());
// Visit a non-dangerous page.
ui_test_utils::NavigateToURL(browser(), url_non_dangerous);
// Now, start a transition to dangerous download.
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::NavigateParams navigate_params(browser(), url_dangerous,
ui::PAGE_TRANSITION_TYPED);
chrome::Navigate(&navigate_params);
observer.Wait();
}
// To exit the browser cleanly (and this test) we need to complete the
// download after completing this test.
content::DownloadTestObserverTerminal dangerous_download_observer(
content::BrowserContext::GetDownloadManager(browser()->profile()),
1,
content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT);
// Proceed through the SSL interstitial. This doesn't use
// |ProceedThroughInterstitial| since no page load will commit.
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(tab != NULL);
ASSERT_TRUE(tab->GetInterstitialPage() != NULL);
ASSERT_EQ(
SSLBlockingPage::kTypeForTesting,
tab->GetInterstitialPage()->GetDelegateForTesting()->GetTypeForTesting());
{
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_DOWNLOAD_INITIATED,
content::NotificationService::AllSources());
tab->GetInterstitialPage()->Proceed();
observer.Wait();
}
// There should still be an interstitial at this point. Press the
// back button on the browser. Note that this doesn't wait for a
// NAV_ENTRY_COMMITTED notification because going back with an
// active interstitial simply hides the interstitial.
ASSERT_TRUE(tab->GetInterstitialPage() != NULL);
ASSERT_EQ(
SSLBlockingPage::kTypeForTesting,
tab->GetInterstitialPage()->GetDelegateForTesting()->GetTypeForTesting());
EXPECT_TRUE(chrome::CanGoBack(browser()));
chrome::GoBack(browser(), CURRENT_TAB);
dangerous_download_observer.WaitForFinished();
}
//
// Insecure content
//
#if defined(OS_WIN)
// http://crbug.com/152940 Flaky on win.
#define MAYBE_TestDisplaysInsecureContent DISABLED_TestDisplaysInsecureContent
#else
#define MAYBE_TestDisplaysInsecureContent TestDisplaysInsecureContent
#endif
// Visits a page that displays insecure content.
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestDisplaysInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
// Load a page that displays insecure content.
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::DISPLAYED_INSECURE_CONTENT);
}
// Test that if the user proceeds and the checkbox is checked, a report
// is sent or not sent depending on the Finch config.
IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
TestBrokenHTTPSProceedReporting) {
CertificateReportingTestUtils::ExpectReport expect_report =
CertificateReportingTestUtils::GetReportExpectedFromFinch();
TestBrokenHTTPSReporting(
CertificateReportingTestUtils::EXTENDED_REPORTING_OPT_IN,
CertificateReportingTestUtils::SSL_INTERSTITIAL_PROCEED, expect_report,
browser());
}
// Test that if the user goes back and the checkbox is checked, a report
// is sent or not sent depending on the Finch config.
IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
TestBrokenHTTPSGoBackReporting) {
CertificateReportingTestUtils::ExpectReport expect_report =
CertificateReportingTestUtils::GetReportExpectedFromFinch();
TestBrokenHTTPSReporting(
CertificateReportingTestUtils::EXTENDED_REPORTING_OPT_IN,
CertificateReportingTestUtils::SSL_INTERSTITIAL_DO_NOT_PROCEED,
expect_report, browser());
}
// User proceeds, checkbox is shown but unchecked. Reports should never
// be sent, regardless of Finch config.
IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
TestBrokenHTTPSProceedReportingWithNoOptIn) {
TestBrokenHTTPSReporting(
CertificateReportingTestUtils::EXTENDED_REPORTING_DO_NOT_OPT_IN,
CertificateReportingTestUtils::SSL_INTERSTITIAL_PROCEED,
CertificateReportingTestUtils::CERT_REPORT_NOT_EXPECTED, browser());
}
// User goes back, checkbox is shown but unchecked. Reports should never
// be sent, regardless of Finch config.
IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
TestBrokenHTTPSGoBackShowYesCheckNoParamYesReportNo) {
TestBrokenHTTPSReporting(
CertificateReportingTestUtils::EXTENDED_REPORTING_DO_NOT_OPT_IN,
CertificateReportingTestUtils::SSL_INTERSTITIAL_DO_NOT_PROCEED,
CertificateReportingTestUtils::CERT_REPORT_NOT_EXPECTED, browser());
}
// User proceeds, checkbox is not shown but checked -> we expect no
// report.
IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
TestBrokenHTTPSProceedShowNoCheckYesReportNo) {
if (base::FieldTrialList::FindFullName(
CertReportHelper::kFinchExperimentName) ==
CertReportHelper::kFinchGroupDontShowDontSend) {
TestBrokenHTTPSReporting(
CertificateReportingTestUtils::EXTENDED_REPORTING_OPT_IN,
CertificateReportingTestUtils::SSL_INTERSTITIAL_PROCEED,
CertificateReportingTestUtils::CERT_REPORT_NOT_EXPECTED, browser());
}
}
// Browser is incognito, user proceeds, checkbox has previously opted in
// -> no report, regardless of Finch config.
IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
TestBrokenHTTPSInIncognitoReportNo) {
TestBrokenHTTPSReporting(
CertificateReportingTestUtils::EXTENDED_REPORTING_OPT_IN,
CertificateReportingTestUtils::SSL_INTERSTITIAL_PROCEED,
CertificateReportingTestUtils::CERT_REPORT_NOT_EXPECTED,
CreateIncognitoBrowser());
}
// Test that reports don't get sent when extended reporting opt-in is
// disabled by policy.
IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
TestBrokenHTTPSNoReportingWhenDisallowed) {
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kSafeBrowsingExtendedReportingOptInAllowed, false);
TestBrokenHTTPSReporting(
CertificateReportingTestUtils::EXTENDED_REPORTING_OPT_IN,
CertificateReportingTestUtils::SSL_INTERSTITIAL_PROCEED,
CertificateReportingTestUtils::CERT_REPORT_NOT_EXPECTED, browser());
}
// Visits a page that runs insecure content and tries to suppress the insecure
// content warnings by randomizing location.hash.
// Based on http://crbug.com/8706
IN_PROC_BROWSER_TEST_F(SSLUITest,
TestRunsInsecuredContentRandomizeHash) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
"files/ssl/page_runs_insecure_content.html"));
CheckAuthenticationBrokenState(
browser()->tab_strip_model()->GetActiveWebContents(),
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
}
// Visits a page with unsafe content and make sure that:
// - frames content is replaced with warning
// - images and scripts are filtered out entirely
IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContents) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_with_unsafe_contents.html",
https_server_expired_.host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
// When the bad content is filtered, the state is expected to be
// authenticated.
CheckAuthenticatedState(tab, AuthState::NONE);
// Because of cross-frame scripting restrictions, we cannot access the iframe
// content. So to know if the frame was loaded, we just check if a popup was
// opened (the iframe content opens one).
// Note: because of bug 1115868, no web contents modal dialog is opened right
// now. Once the bug is fixed, this will do the real check.
EXPECT_FALSE(IsShowingWebContentsModalDialog());
int img_width;
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
tab,
"window.domAutomationController.send(ImageWidth());",
&img_width));
// In order to check that the image was not loaded, we check its width.
// The actual image (Google logo) is 114 pixels wide, we assume the broken
// image is less than 100.
EXPECT_LT(img_width, 100);
bool js_result = false;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(IsFooSet());",
&js_result));
EXPECT_FALSE(js_result);
}
// Visits a page with insecure content loaded by JS (after the initial page
// load).
#if defined(OS_LINUX)
// flaky http://crbug.com/396462
#define MAYBE_TestDisplaysInsecureContentLoadedFromJS \
DISABLED_TestDisplaysInsecureContentLoadedFromJS
#else
#define MAYBE_TestDisplaysInsecureContentLoadedFromJS \
TestDisplaysInsecureContentLoadedFromJS
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest,
MAYBE_TestDisplaysInsecureContentLoadedFromJS) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_with_dynamic_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
replacement_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticatedState(tab, AuthState::NONE);
// Load the insecure image.
bool js_result = false;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"loadBadImage();",
&js_result));
EXPECT_TRUE(js_result);
// We should now have insecure content.
CheckAuthenticatedState(tab, AuthState::DISPLAYED_INSECURE_CONTENT);
}
// Visits two pages from the same origin: one that displays insecure content and
// one that doesn't. The test checks that we do not propagate the insecure
// content state from one to the other.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysInsecureContentTwoTabs) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL("files/ssl/blank_page.html"));
WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
// This tab should be fine.
CheckAuthenticatedState(tab1, AuthState::NONE);
// Create a new tab.
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
GURL url = https_server_.GetURL(replacement_path);
chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
params.disposition = NEW_FOREGROUND_TAB;
params.tabstrip_index = 0;
params.source_contents = tab1;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::Navigate(¶ms);
WebContents* tab2 = params.target_contents;
observer.Wait();
// The new tab has insecure content.
CheckAuthenticatedState(tab2, AuthState::DISPLAYED_INSECURE_CONTENT);
// The original tab should not be contaminated.
CheckAuthenticatedState(tab1, AuthState::NONE);
}
// Visits two pages from the same origin: one that runs insecure content and one
// that doesn't. The test checks that we propagate the insecure content state
// from one to the other.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRunsInsecureContentTwoTabs) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL("files/ssl/blank_page.html"));
WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
// This tab should be fine.
CheckAuthenticatedState(tab1, AuthState::NONE);
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_runs_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
// Create a new tab in the same process. Using a NEW_FOREGROUND_TAB
// disposition won't usually stay in the same process, but this works
// because we are using process-per-site in SetUpCommandLine.
GURL url = https_server_.GetURL(replacement_path);
chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
params.disposition = NEW_FOREGROUND_TAB;
params.source_contents = tab1;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::Navigate(¶ms);
WebContents* tab2 = params.target_contents;
observer.Wait();
// Both tabs should have the same process.
EXPECT_EQ(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost());
// The new tab has insecure content.
CheckAuthenticationBrokenState(
tab2,
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
// Which means the origin for the first tab has also been contaminated with
// insecure content.
CheckAuthenticationBrokenState(
tab1, CertError::NONE, AuthState::RAN_INSECURE_CONTENT);
}
// Visits a page with an image over http. Visits another page over https
// referencing that same image over http (hoping it is coming from the webcore
// memory cache).
IN_PROC_BROWSER_TEST_F(SSLUITest, TestDisplaysCachedInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
// Load original page over HTTP.
const GURL url_http = test_server()->GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_http);
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckUnauthenticatedState(tab, AuthState::NONE);
// Load again but over SSL. It should be marked as displaying insecure
// content (even though the image comes from the WebCore memory cache).
const GURL url_https = https_server_.GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_https);
CheckAuthenticatedState(tab, AuthState::DISPLAYED_INSECURE_CONTENT);
}
// http://crbug.com/84729
#if defined(OS_CHROMEOS)
#define MAYBE_TestRunsCachedInsecureContent \
DISABLED_TestRunsCachedInsecureContent
#else
#define MAYBE_TestRunsCachedInsecureContent TestRunsCachedInsecureContent
#endif // defined(OS_CHROMEOS)
// Visits a page with script over http. Visits another page over https
// referencing that same script over http (hoping it is coming from the webcore
// memory cache).
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestRunsCachedInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_runs_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
// Load original page over HTTP.
const GURL url_http = test_server()->GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_http);
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckUnauthenticatedState(tab, AuthState::NONE);
// Load again but over SSL. It should be marked as displaying insecure
// content (even though the image comes from the WebCore memory cache).
const GURL url_https = https_server_.GetURL(replacement_path);
ui_test_utils::NavigateToURL(browser(), url_https);
CheckAuthenticationBrokenState(
tab,
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
}
// This test ensures the CN invalid status does not 'stick' to a certificate
// (see bug #1044942) and that it depends on the host-name.
// Test if disabled due to flakiness http://crbug.com/368280 .
IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestCNInvalidStickiness) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_mismatched_.Start());
// First we hit the server with hostname, this generates an invalid policy
// error.
ui_test_utils::NavigateToURL(browser(),
https_server_mismatched_.GetURL("files/ssl/google.html"));
// We get an interstitial page as a result.
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(tab,
net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_COMMON_NAME_INVALID, AuthState::NONE);
// Now we try again with the right host name this time.
GURL url(https_server_.GetURL("files/ssl/google.html"));
ui_test_utils::NavigateToURL(browser(), url);
// Security state should be OK.
CheckAuthenticatedState(tab, AuthState::NONE);
// Now try again the broken one to make sure it is still broken.
ui_test_utils::NavigateToURL(browser(),
https_server_mismatched_.GetURL("files/ssl/google.html"));
// Since we OKed the interstitial last time, we get right to the page.
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_COMMON_NAME_INVALID, AuthState::NONE);
}
#if defined(OS_CHROMEOS)
// This test seems to be flaky and hang on chromiumos.
// http://crbug.com/84419
#define MAYBE_TestRefNavigation DISABLED_TestRefNavigation
#else
#define MAYBE_TestRefNavigation TestRefNavigation
#endif
// Test that navigating to a #ref does not change a bad security state.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRefNavigation) {
ASSERT_TRUE(https_server_expired_.Start());
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/page_with_refs.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
// Now navigate to a ref in the page, the security state should not have
// changed.
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/page_with_refs.html#jp"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
// Tests that closing a page that has a unsafe pop-up does not crash the
// browser (bug #1966).
// TODO(jcampan): http://crbug.com/2136 disabled because the popup is not
// opened as it is not initiated by a user gesture.
IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestCloseTabWithUnsafePopup) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_with_unsafe_popup.html",
https_server_expired_.host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL(replacement_path));
WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
// It is probably overkill to add a notification for a popup-opening, let's
// just poll.
for (int i = 0; i < 10; i++) {
if (IsShowingWebContentsModalDialog())
break;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::MessageLoop::QuitClosure(),
base::TimeDelta::FromSeconds(1));
content::RunMessageLoop();
}
ASSERT_TRUE(IsShowingWebContentsModalDialog());
// Let's add another tab to make sure the browser does not exit when we close
// the first tab.
GURL url = test_server()->GetURL("files/ssl/google.html");
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
chrome::AddSelectedTabWithURL(browser(), url, ui::PAGE_TRANSITION_TYPED);
observer.Wait();
// Close the first tab.
chrome::CloseWebContents(browser(), tab1, false);
}
// Visit a page over bad https that is a redirect to a page with good https.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectBadToGoodHTTPS) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
GURL url1 = https_server_expired_.GetURL("server-redirect?");
GURL url2 = https_server_.GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(), GURL(url1.spec() + url2.spec()));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
// We have been redirected to the good page.
CheckAuthenticatedState(tab, AuthState::NONE);
}
// Flaky on Linux. http://crbug.com/368280.
#if defined(OS_LINUX)
#define MAYBE_TestRedirectGoodToBadHTTPS DISABLED_TestRedirectGoodToBadHTTPS
#else
#define MAYBE_TestRedirectGoodToBadHTTPS TestRedirectGoodToBadHTTPS
#endif
// Visit a page over good https that is a redirect to a page with bad https.
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestRedirectGoodToBadHTTPS) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
GURL url1 = https_server_.GetURL("server-redirect?");
GURL url2 = https_server_expired_.GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(), GURL(url1.spec() + url2.spec()));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
// Visit a page over http that is a redirect to a page with good HTTPS.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectHTTPToGoodHTTPS) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
// HTTP redirects to good HTTPS.
GURL http_url = test_server()->GetURL("server-redirect?");
GURL good_https_url =
https_server_.GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(),
GURL(http_url.spec() + good_https_url.spec()));
CheckAuthenticatedState(tab, AuthState::NONE);
}
// Flaky on Linux. http://crbug.com/368280.
#if defined(OS_LINUX)
#define MAYBE_TestRedirectHTTPToBadHTTPS DISABLED_TestRedirectHTTPToBadHTTPS
#else
#define MAYBE_TestRedirectHTTPToBadHTTPS TestRedirectHTTPToBadHTTPS
#endif
// Visit a page over http that is a redirect to a page with bad HTTPS.
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestRedirectHTTPToBadHTTPS) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_expired_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
GURL http_url = test_server()->GetURL("server-redirect?");
GURL bad_https_url =
https_server_expired_.GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(),
GURL(http_url.spec() + bad_https_url.spec()));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
// Visit a page over https that is a redirect to a page with http (to make sure
// we don't keep the secure state).
IN_PROC_BROWSER_TEST_F(SSLUITest, TestRedirectHTTPSToHTTP) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
GURL https_url = https_server_.GetURL("server-redirect?");
GURL http_url = test_server()->GetURL("files/ssl/google.html");
ui_test_utils::NavigateToURL(browser(),
GURL(https_url.spec() + http_url.spec()));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE);
}
// Visits a page to which we could not connect (bad port) over http and https
// and make sure the security style is correct.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestConnectToBadPort) {
ui_test_utils::NavigateToURL(browser(), GURL("http://localhost:17"));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::SHOWING_ERROR);
// Same thing over HTTPS.
ui_test_utils::NavigateToURL(browser(), GURL("https://localhost:17"));
CheckUnauthenticatedState(
browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::SHOWING_ERROR);
}
//
// Frame navigation
//
// From a good HTTPS top frame:
// - navigate to an OK HTTPS frame
// - navigate to a bad HTTPS (expect unsafe content and filtered frame), then
// back
// - navigate to HTTP (expect insecure content), then back
IN_PROC_BROWSER_TEST_F(SSLUITest, TestGoodFrameNavigation) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string top_frame_path;
ASSERT_TRUE(GetTopFramePath(*test_server(),
https_server_,
https_server_expired_,
&top_frame_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(top_frame_path));
CheckAuthenticatedState(tab, AuthState::NONE);
bool success = false;
// Now navigate inside the frame.
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
// We should still be fine.
CheckAuthenticatedState(tab, AuthState::NONE);
// Now let's hit a bad page.
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('badHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
// The security style should still be secure.
CheckAuthenticatedState(tab, AuthState::NONE);
// And the frame should be blocked.
bool is_content_evil = true;
content::RenderFrameHost* content_frame = content::FrameMatchingPredicate(
tab, base::Bind(&content::FrameMatchesName, "contentFrame"));
std::string is_evil_js("window.domAutomationController.send("
"document.getElementById('evilDiv') != null);");
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(content_frame,
is_evil_js,
&is_content_evil));
EXPECT_FALSE(is_content_evil);
// Now go back, our state should still be OK.
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
tab->GetController().GoBack();
observer.Wait();
}
CheckAuthenticatedState(tab, AuthState::NONE);
// Navigate to a page served over HTTP.
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('HTTPLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
// Our state should be unathenticated (in the ran mixed script sense)
CheckAuthenticationBrokenState(
tab,
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
// Go back, our state should be unchanged.
{
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
tab->GetController().GoBack();
observer.Wait();
}
CheckAuthenticationBrokenState(
tab,
CertError::NONE,
AuthState::DISPLAYED_INSECURE_CONTENT | AuthState::RAN_INSECURE_CONTENT);
}
// From a bad HTTPS top frame:
// - navigate to an OK HTTPS frame (expected to be still authentication broken).
IN_PROC_BROWSER_TEST_F(SSLUITest, TestBadFrameNavigation) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string top_frame_path;
ASSERT_TRUE(GetTopFramePath(*test_server(),
https_server_,
https_server_expired_,
&top_frame_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL(top_frame_path));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
// Navigate to a good frame.
bool success = false;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
// We should still be authentication broken.
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
// From an HTTP top frame, navigate to good and bad HTTPS (security state should
// stay unauthenticated).
// Disabled, flakily exceeds test timeout, http://crbug.com/43437.
IN_PROC_BROWSER_TEST_F(SSLUITest, DISABLED_TestUnauthenticatedFrameNavigation) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
std::string top_frame_path;
ASSERT_TRUE(GetTopFramePath(*test_server(),
https_server_,
https_server_expired_,
&top_frame_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
test_server()->GetURL(top_frame_path));
CheckUnauthenticatedState(tab, AuthState::NONE);
// Now navigate inside the frame to a secure HTTPS frame.
{
bool success = false;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('goodHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
// We should still be unauthenticated.
CheckUnauthenticatedState(tab, AuthState::NONE);
// Now navigate to a bad HTTPS frame.
{
bool success = false;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab,
"window.domAutomationController.send(clickLink('badHTTPSLink'));",
&success));
ASSERT_TRUE(success);
observer.Wait();
}
// State should not have changed.
CheckUnauthenticatedState(tab, AuthState::NONE);
// And the frame should have been blocked (see bug #2316).
bool is_content_evil = true;
content::RenderFrameHost* content_frame = content::FrameMatchingPredicate(
tab, base::Bind(&content::FrameMatchesName, "contentFrame"));
std::string is_evil_js("window.domAutomationController.send("
"document.getElementById('evilDiv') != null);");
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(content_frame,
is_evil_js,
&is_content_evil));
EXPECT_FALSE(is_content_evil);
}
IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorkerFiltered) {
ASSERT_TRUE(https_server_.Start());
ASSERT_TRUE(https_server_expired_.Start());
// This page will spawn a Worker which will try to load content from
// BadCertServer.
std::string page_with_unsafe_worker_path;
ASSERT_TRUE(GetPageWithUnsafeWorkerPath(https_server_expired_,
&page_with_unsafe_worker_path));
ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
page_with_unsafe_worker_path));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
// Expect Worker not to load insecure content.
CheckWorkerLoadResult(tab, false);
// The bad content is filtered, expect the state to be authenticated.
CheckAuthenticatedState(tab, AuthState::NONE);
}
// This test, and the related test TestUnsafeContentsWithUserException, verify
// that if unsafe content is loaded but the host of that unsafe content has a
// user exception, the content runs and the security style remains
// authenticated. This is not necessarily the behavior that should exist, but it
// is verification that it does behave that way. See https://crbug.com/477868
// for more inforamtion on this.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsInWorkerWithUserException) {
ASSERT_TRUE(https_server_.Start());
// Note that it is necessary to user https_server_mismatched_ here over the
// other invalid cert servers. This is because the test relies on the two
// servers having different hosts since SSL exceptions are per-host, not per
// origin, and https_server_mismatched_ uses 'localhost' rather than
// '127.0.0.1'.
ASSERT_TRUE(https_server_mismatched_.Start());
// Navigate to an unsafe site. Proceed with interstitial page to indicate
// the user approves the bad certificate.
ui_test_utils::NavigateToURL(
browser(), https_server_mismatched_.GetURL("files/ssl/blank_page.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::NONE);
// 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.
std::string page_with_unsafe_worker_path;
ASSERT_TRUE(GetPageWithUnsafeWorkerPath(https_server_mismatched_,
&page_with_unsafe_worker_path));
ui_test_utils::NavigateToURL(
browser(), https_server_.GetURL(page_with_unsafe_worker_path));
CheckWorkerLoadResult(tab, true); // Worker loads insecure content
CheckAuthenticatedState(tab, CertError::NONE);
}
// Visits a page with unsafe content and makes sure that if a user exception to
// the certificate error is present, the image is loaded and script executes.
//
// See the comment above SSLUITest.TestUnsafeContentsInWorkerWithUserException
// for a discussion about the desired behavior.
IN_PROC_BROWSER_TEST_F(SSLUITest, TestUnsafeContentsWithUserException) {
ASSERT_TRUE(https_server_.Start());
// Note that it is necessary to user https_server_mismatched_ here over the
// other invalid cert servers. This is because the test relies on the two
// servers having different hosts since SSL exceptions are per-host, not per
// origin, and https_server_mismatched_ uses 'localhost' rather than
// '127.0.0.1'.
ASSERT_TRUE(https_server_mismatched_.Start());
// Navigate to an unsafe site. Proceed with interstitial page to indicate
// the user approves the bad certificate.
ui_test_utils::NavigateToURL(
browser(), https_server_mismatched_.GetURL("files/ssl/blank_page.html"));
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::SHOWING_INTERSTITIAL);
ProceedThroughInterstitial(tab);
CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID,
AuthState::NONE);
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_with_unsafe_contents.html",
https_server_mismatched_.host_port_pair(), &replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
// When the bad content is filtered, the state is expected to be
// authenticated.
CheckAuthenticatedState(tab, AuthState::NONE);
int img_width;
EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
tab, "window.domAutomationController.send(ImageWidth());", &img_width));
// In order to check that the image was loaded, we check its width.
// The actual image (Google logo) is 114 pixels wide, so we assume a good
// image is greater than 100.
EXPECT_GT(img_width, 100);
bool js_result = false;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
tab, "window.domAutomationController.send(IsFooSet());", &js_result));
EXPECT_TRUE(js_result);
CheckAuthenticatedState(tab, CertError::NONE);
}
// Test that when the browser blocks displaying insecure content (images), the
// indicator shows a secure page, because the blocking made the otherwise
// unsafe page safe (the notification of this state is handled by other means).
IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockDisplayingInsecureImage) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::NONE);
}
// Test that when the browser blocks displaying insecure content (iframes), the
// indicator shows a secure page, because the blocking made the otherwise
// unsafe page safe (the notification of this state is handled by other means)
IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockDisplayingInsecureIframe) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_displays_insecure_iframe.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::NONE);
}
// Test that when the browser blocks running insecure content, the
// indicator shows a secure page, because the blocking made the otherwise
// unsafe page safe (the notification of this state is handled by other means).
IN_PROC_BROWSER_TEST_F(SSLUITestBlock, TestBlockRunningInsecureContent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(https_server_.Start());
std::string replacement_path;
ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
"files/ssl/page_runs_insecure_content.html",
test_server()->host_port_pair(),
&replacement_path));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL(replacement_path));
CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
AuthState::NONE);
}
// Visit a page and establish a WebSocket connection over bad https with
// --ignore-certificate-errors. The connection should be established without
// interstitial page showing.
IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors, TestWSS) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(wss_server_expired_.Start());
// Setup page title observer.
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
// Visit bad HTTPS page.
GURL::Replacements replacements;
replacements.SetSchemeStr("https");
ui_test_utils::NavigateToURL(
browser(),
wss_server_expired_.GetURL(
"connect_check.html").ReplaceComponents(replacements));
// We shouldn't have an interstitial page showing here.
// Test page run a WebSocket wss connection test. The result will be shown
// as page title.
const base::string16 result = watcher.WaitAndGetTitle();
EXPECT_TRUE(base::LowerCaseEqualsASCII(result, "pass"));
}
// Verifies that the interstitial can proceed, even if JavaScript is disabled.
// http://crbug.com/322948
#if defined(OS_LINUX)
// flaky http://crbug.com/396458
#define MAYBE_TestInterstitialJavaScriptProceeds \
DISABLED_TestInterstitialJavaScriptProceeds
#else
#define MAYBE_TestInterstitialJavaScriptProceeds \
TestInterstitialJavaScriptProceeds
#endif
IN_PROC_BROWSER_TEST_F(SSLUITest, MAYBE_TestInterstitialJavaScriptProceeds) {
browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
ASSERT_TRUE(https_server_expired_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(&tab->GetController()));
InterstitialPage* interstitial_page = tab->GetInterstitialPage();
ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
content::RenderViewHost* interstitial_rvh =
interstitial_page->GetMainFrame()->GetRenderViewHost();
int result = -1;
std::string javascript = base::StringPrintf(
"window.domAutomationController.send(%d);",
SecurityInterstitialPage::CMD_PROCEED);
ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
interstitial_rvh, javascript, &result));
// The above will hang without the fix.
EXPECT_EQ(1, result);
observer.Wait();
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::NONE);
}
// Verifies that the interstitial can go back, even if JavaScript is disabled.
// http://crbug.com/322948
IN_PROC_BROWSER_TEST_F(SSLUITest, TestInterstitialJavaScriptGoesBack) {
browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
ASSERT_TRUE(https_server_expired_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
ui_test_utils::NavigateToURL(browser(),
https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
content::WindowedNotificationObserver observer(
content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
content::NotificationService::AllSources());
InterstitialPage* interstitial_page = tab->GetInterstitialPage();
ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
content::RenderViewHost* interstitial_rvh =
interstitial_page->GetMainFrame()->GetRenderViewHost();
int result = -1;
std::string javascript = base::StringPrintf(
"window.domAutomationController.send(%d);",
SecurityInterstitialPage::CMD_DONT_PROCEED);
ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
interstitial_rvh, javascript, &result));
// The above will hang without the fix.
EXPECT_EQ(0, result);
observer.Wait();
EXPECT_EQ("about:blank", tab->GetVisibleURL().spec());
}
// Verifies that switching tabs, while showing interstitial page, will not
// affect the visibility of the interestitial.
// https://crbug.com/381439
IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNotAffectedByHideShow) {
ASSERT_TRUE(https_server_expired_.Start());
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing());
ui_test_utils::NavigateToURL(
browser(), https_server_expired_.GetURL("files/ssl/google.html"));
CheckAuthenticationBrokenState(
tab, net::CERT_STATUS_DATE_INVALID, AuthState::SHOWING_INTERSTITIAL);
EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing());
AddTabAtIndex(0,
https_server_.GetURL("files/ssl/google.html"),
ui::PAGE_TRANSITION_TYPED);
EXPECT_EQ(2, browser()->tab_strip_model()->count());
EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
EXPECT_EQ(tab, browser()->tab_strip_model()->GetWebContentsAt(1));
EXPECT_FALSE(tab->GetRenderWidgetHostView()->IsShowing());
browser()->tab_strip_model()->ActivateTabAt(1, true);
EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing());
}
// Verifies that if a bad certificate is seen for a host and the user proceeds
// through the interstitial, the decision to proceed is initially remembered.
// However, if this is followed by another visit, and a good certificate
// is seen for the same host, the original exception is forgotten.
IN_PROC_BROWSER_TEST_F(SSLUITest, BadCertFollowedByGoodCert) {
// It is necessary to use |https_server_expired_| rather than
// |https_server_mismatched| because the former shares a host with
// |https_server_| and cert exceptions are per host.
ASSERT_TRUE(https_server_expired_.Start());
ASSERT_TRUE(https_server_.Start());
std::string https_server_expired_host =
https_server_.GetURL("files/ssl/google.html").host();
std::string https_server_host =
https_server_.GetURL("files/ssl/google.html").host();
ASSERT_EQ(https_server_expired_host, https_server_host);
WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
ChromeSSLHostStateDelegate* state =
reinterpret_cast<ChromeSSLHostStateDelegate*>(
profile->GetSSLHostStateDelegate());
ui_test_utils::NavigateToURL(
browser(), https_server_expired_.GetURL("files/ssl/google.html"));
ProceedThroughInterstitial(tab);
EXPECT_TRUE(state->HasAllowException(https_server_host));
ui_test_utils::NavigateToURL(browser(),
https_server_.GetURL("files/ssl/google.html"));
ASSERT_FALSE(tab->GetInterstitialPage());
EXPECT_FALSE(state->HasAllowException(https_server_host));
}
class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest {
protected:
// SecurityInterstitialIDNTest implementation
SecurityInterstitialPage* CreateInterstitial(
content::WebContents* contents,
const GURL& request_url) const override {
net::SSLInfo ssl_info;
ssl_info.cert = new net::X509Certificate(
request_url.host(), "CA", base::Time::Max(), base::Time::Max());
return new SSLBlockingPage(
contents, net::ERR_CERT_CONTAINS_ERRORS, ssl_info, request_url, 0,
base::Time::NowFromSystemTime(), nullptr, base::Callback<void(bool)>());
}
};
IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest, SSLBlockingPageDecodesIDN) {
EXPECT_TRUE(VerifyIDNDecoded());
}
// TODO(jcampan): more tests to do below.
// Visit a page over https that contains a frame with a redirect.
// XMLHttpRequest insecure content in synchronous mode.
// XMLHttpRequest insecure content in asynchronous mode.
// XMLHttpRequest over bad ssl in synchronous mode.
// XMLHttpRequest over OK ssl in synchronous mode.
|