Add stability to tests for web API statistics
[WebKit-https.git] / LayoutTests / http / tests / webAPIStatistics / canvas-read-and-write-data-collection.html
1 <!DOCTYPE html><!-- webkit-test-runner [ internal:WebAPIStatisticsEnabled=true ] -->
2 <head>
3     <meta charset="UTF-8">
4     <title>Test for canvas read and write data collection in resource load statistics</title>
5 </head>
6 <script>
7     internals.setResourceLoadStatisticsEnabled(false);
8 </script>
9 <body>
10 <p> Tests for canvas read and write data collection in ResourceLoadStatistics plist by rendering and reading text on the canvas and dumping the entire resource load statistics map. </p>
11 <script>
12     const hostUnderTest = "127.0.0.1:8000";
13     const statisticsUrl = "http://" + hostUnderTest + "/temp";
14
15     function completeTest() {  
16         testRunner.statisticsResetToConsistentState(function() {
17             testRunner.notifyDone();
18         });
19     }
20
21     function runTestRunnerTest() {
22         testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
23
24         testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
25     
26         var canvas = document.createElement('canvas');
27         var context = canvas.getContext('2d');
28         context.fillText('suspicious invisible text', 2, 15);
29         canvas.toDataURL();
30         testRunner.statisticsNotifyObserver();
31     }
32
33     if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
34         testRunner.dumpAsText();
35         testRunner.dumpResourceLoadStatistics();
36         testRunner.waitUntilDone();
37         internals.setResourceLoadStatisticsEnabled(true);
38         testRunner.setWebAPIStatisticsEnabled(true);
39         runTestRunnerTest();
40     }
41 </script>
42 </body>
43 </html>