33d7812c5fb5206b28759afda4c3c32e20979336
[WebKit-https.git] / LayoutTests / inspector / page / overrideSetting-ICECandidateFilteringEnabled.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script>
6
7 if (window.internals)
8     window.internals.setICECandidateFiltering(true);
9
10 function createDataChannel() {
11     let receivedCandidate = false;
12
13     let pc = new RTCPeerConnection();
14     pc.createDataChannel("sendDataChannel");
15     pc.onicecandidate = (event) => {
16         if (event.candidate) {
17             receivedCandidate = true;
18             return;
19         }
20
21         if (receivedCandidate) {
22             pc.createOffer().then((offer) => {
23                 TestPage.dispatchEventToFrontend("DataChannel", {success: true});
24             });
25         } else
26             TestPage.dispatchEventToFrontend("DataChannel", {success: false});
27
28         delete pc.onicecandidate;
29     };
30     pc.createOffer().then((offer) => {
31         pc.setLocalDescription(offer);
32     });
33 }
34
35 function test()
36 {
37     let suite = InspectorTest.createAsyncSuite("Page.overrideSetting");
38
39     suite.addTestCase({
40         name: "Page.overrideSetting.ICECandidateFilteringEnabled",
41         description: "Test that changing whether ice candidate filtering is enabled has an effect.",
42         async test() {
43             let [defaultResult] = await Promise.all([
44                 InspectorTest.awaitEvent("DataChannel"),
45                 InspectorTest.evaluateInPage(`createDataChannel()`),
46             ]);
47             InspectorTest.expectFalse(defaultResult.data.success, "Should not be able to establish a connection when filtering ice candidates.");
48
49             InspectorTest.log("Overriding ICECandidateFilteringEnabled to false...");
50             await PageAgent.overrideSetting(PageAgent.Setting.ICECandidateFilteringEnabled, false);
51
52             let [overriddenResult] = await Promise.all([
53                 InspectorTest.awaitEvent("DataChannel"),
54                 InspectorTest.evaluateInPage(`createDataChannel()`),
55             ])
56             InspectorTest.expectFalse(defaultResult.data.success, "Should be able to establish a connection when filtering ice candidates.");
57
58             InspectorTest.log("Removing ICECandidateFilteringEnabled override...");
59             await PageAgent.overrideSetting(PageAgent.Setting.ICECandidateFilteringEnabled);
60
61             let [originalResult] = await Promise.all([
62                 InspectorTest.awaitEvent("DataChannel"),
63                 InspectorTest.evaluateInPage(`createDataChannel()`),
64             ])
65             InspectorTest.expectFalse(defaultResult.data.success, "Should not be able to establish a connection when filtering ice candidates.");
66         },
67     });
68
69     suite.runTestCasesAndFinish();
70 }
71
72 </script>
73 </head>
74 <body onload="runTest()">
75     <p>Tests for the Page.overrideSetting command.</p>
76 </body>
77 </html>