ee9091d2b85675b8812b27a1dad8b10acbab4f99
[WebKit-https.git] / LayoutTests / http / tests / resourceLoadStatistics / prevalent-resource-handled-keydown.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="/js-test-resources/js-test.js"></script>
5 <script>
6 description("Tests that we grant User Interaction credit for handled keypresses.");
7 jsTestIsAsync = true;
8
9 const statisticsUrl = "http://127.0.0.1:8000/temp";
10
11 onload = function() {
12     const testFrame = document.getElementById("testFrame");
13
14     if (window.testRunner && window.internals) {
15         internals.setResourceLoadStatisticsEnabled(true);
16         testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
17     }
18
19     testRunner.setStatisticsPrevalentResource(statisticsUrl, true);
20     if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
21         testFailed("Host did not get set as prevalent resource.");
22
23     testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, false);
24     if (testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
25         testFailed("Host did not get cleared of user interaction.");
26
27     testInput = document.getElementById("testInput");
28
29     testRunner.installStatisticsDidModifyDataRecordsCallback(function() {
30         shouldBeEqualToString("testInput.value", "a");
31
32         if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
33             testFailed("Origin did not get user interaction credit.");
34         else
35             testPassed("Origin was granted user interaction.");
36
37         setTimeout(function() {
38             testFrame.src = "about:blank";
39             setTimeout(function() {
40                 testRunner.statisticsResetToConsistentState(function() {
41                     finishJSTest();
42                 });
43             }, 0);
44         }, 0);
45     });
46     testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
47     testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
48     testRunner.statisticsProcessStatisticsAndDataRecords();
49
50     debug("Simulate user typing letter 'a' into the field.");
51     testInput.focus();
52     if (window.eventSender)
53         eventSender.keyDown("a");    
54 }
55 </script>
56 <iframe id="testFrame" src="resources/onclick.html"></iframe>
57 <input id="testInput" type="text"></input>
58 </body>
59 </html>