Web Inspector: Network: add button to show system certificate dialog
[WebKit-https.git] / LayoutTests / http / tests / inspector / network / getSerializedCertificate.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <script src="../resources/inspector-test.js"></script>
6 <script>
7 function createSecureRequest() {
8     let img = document.createElement("img");
9     img.src = "https://localhost:8443/resources/square100.png";
10     document.body.appendChild(img);
11 }
12
13 function createInsecureRequest() {
14     let img = document.createElement("img");
15     img.src = "http://localhost:8000/resources/square100.png";
16     document.body.appendChild(img);
17 }
18
19 function test()
20 {
21     let suite = InspectorTest.createAsyncSuite("Network.getSerializedCertificate");
22
23     suite.addTestCase({
24         name: "Network.getSerializedCertificate.HTTP",
25         description: "Check if an insecure resource is able to serialize its certificate.",
26         test(resolve, reject) {
27             WI.Resource.awaitEvent(WI.Resource.Event.ResponseReceived)
28             .then((event) => InspectorTest.expectException(() => NetworkAgent.getSerializedCertificate(event.target.requestIdentifier)))
29             .then(resolve, reject);
30
31             InspectorTest.evaluateInPage(`createInsecureRequest()`)
32             .catch(reject);
33         }
34     });
35
36     suite.addTestCase({
37         name: "Network.getSerializedCertificate.HTTPS",
38         description: "Check of a secure resource is able to serialize its certificate.",
39         test(resolve, reject) {
40             WI.Resource.awaitEvent(WI.Resource.Event.ResponseReceived)
41             .then((event) => NetworkAgent.getSerializedCertificate(event.target.requestIdentifier))
42             .then(({serializedCertificate}) => {
43                 InspectorTest.expectGreaterThan(serializedCertificate.length, 0, "Request should have serializable certificate.");
44             })
45             .then(resolve, reject);
46
47             InspectorTest.evaluateInPage(`createSecureRequest()`)
48             .catch(reject);
49         }
50     });
51
52     suite.addTestCase({
53         name: "Network.getSerializedCertificate.Invalid",
54         async test() {
55             const invalidRequestIdentifier = "INVALID";
56             await InspectorTest.expectException(() => NetworkAgent.getSerializedCertificate(invalidRequestIdentifier));
57         }
58     });
59
60     suite.runTestCasesAndFinish();
61 }
62 </script>
63 </head>
64 <body onload="runTest()">
65     <p>Tests that the NetworkAgent is able to get a serialized certificate for a given request.</p>
66 </body>
67 </html>