78f7f1391c621de866e1bd23b01bda332d0d9f37
[WebKit-https.git] / LayoutTests / http / tests / resourceLoadStatistics / classify-as-prevalent-based-on-subresource-unique-redirects-to-database.html
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4     <meta charset="UTF-8">
5     <title>Tests for Classification Based on Subresource Unique Redirects To</title>
6     <script src="/js-test-resources/js-test.js"></script>
7 </head>
8 <body>
9 <script>
10     const hostUnderTest = "127.0.0.1:8000";
11     const statisticsUrl = "http://" + hostUnderTest + "/temp";
12     const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
13     const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
14     const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
15     const topFrameOrigin4 = "http://127.0.0.5:8000/temp";
16
17     function completeTest() {
18         if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
19             testFailed("Host did not get classified as prevalent resource.");
20         if (testRunner.isStatisticsVeryPrevalentResource(statisticsUrl))
21             testFailed("Host got classified as very prevalent resource.");
22         else
23             testPassed("Host classified as prevalent resource.");
24
25         internals.setResourceLoadStatisticsEnabled(false);
26         testRunner.statisticsResetToConsistentState(function() {
27             testRunner.notifyDone();
28         });
29     }
30
31     function runTestRunnerTest() {
32         testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
33  
34         testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
35             if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
36                 testFailed("Host did not get set as non-prevalent resource.");
37
38             testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin1);
39             testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin2);
40             testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin3);
41             testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin4);
42
43             testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
44
45             testRunner.statisticsProcessStatisticsAndDataRecords();
46         });
47     }
48
49     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
50         testRunner.setUseITPDatabase(true);
51         testRunner.waitUntilDone();
52         internals.setResourceLoadStatisticsEnabled(true);
53         runTestRunnerTest();
54     }
55 </script>
56 </body>
57 </html>