6095242cad6740417aa9972461898144dc2ce93e
[WebKit-https.git] / LayoutTests / http / tests / resourceLoadStatistics / user-interaction-only-reported-once-within-short-period-of-time-database.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="/js-test-resources/js-test.js"></script>
5 <script src="/js-test-resources/ui-helper.js"></script>
6 <script src="resources/util.js"></script>
7 <script>
8     description("Tests that user interaction is not reported repeatedly within a short period of time.");
9     jsTestIsAsync = true;
10
11     const topFrameOrigin = "http://127.0.0.1:8000";
12     const subFrameOrigin = "http://localhost:8000";
13
14     function activateElement(elementId, callback) {
15         var element = document.getElementById(elementId);
16         var centerX = element.offsetLeft + element.offsetWidth / 2;
17         var centerY = element.offsetTop + element.offsetHeight / 2;
18         UIHelper.activateAt(centerX, centerY).then(
19             function() {
20                 callback();
21             },
22             function() {
23                 testFailed("Promise rejected.");
24                 setEnableFeature(false, finishJSTest);
25             }
26         );
27     }
28
29     function firstInteraction() {
30         shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
31         shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
32         activateElement("testElement", secondInteraction);
33     }
34
35     function secondInteraction() {
36         shouldBeTrue("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
37         shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
38
39         if (testRunner) {
40             testRunner.setStatisticsHasHadUserInteraction(topFrameOrigin, false, function() {
41                 shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
42
43                 activateElement("testElement", finishTest);
44             });
45         }
46     }
47
48     function finishTest() {
49         shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
50         shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
51         setEnableFeature(false, finishJSTest);
52     }
53
54     onload = function() {
55         testRunner.setUseITPDatabase(true);
56         setEnableFeature(true, function() {
57             shouldBe("document.location.origin", "topFrameOrigin");
58
59             firstInteraction();
60         });
61     };
62 </script>
63 <div id="testElement">This is the test element</div>
64 </body>
65 </html>