blob: 414a8b3e09f2b7364b1775e43df7e04eae7f9419 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<script src="/js-test-resources/js-test.js"></script>
<script src="/js-test-resources/ui-helper.js"></script>
<script>
description("Tests that user interaction is not reported repeatedly within a short period of time.");
jsTestIsAsync = true;
const topFrameOrigin = "http://127.0.0.1:8000";
const subFrameOrigin = "http://localhost:8000";
function activateElement(elementId, callback) {
var element = document.getElementById(elementId);
var centerX = element.offsetLeft + element.offsetWidth / 2;
var centerY = element.offsetTop + element.offsetHeight / 2;
UIHelper.activateAt(centerX, centerY).then(
function() {
callback();
},
function() {
testFailed("Promise rejected.");
finishJSTest();
}
);
}
function firstInteraction() {
shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
activateElement("testElement", secondInteraction);
}
function secondInteraction() {
shouldBeTrue("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
if (testRunner)
testRunner.setStatisticsHasHadUserInteraction(topFrameOrigin, false);
shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
activateElement("testElement", finishTest);
}
function finishTest() {
shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
finishJSTest();
}
onload = function() {
if (internals)
internals.setResourceLoadStatisticsEnabled(true);
shouldBe("document.location.origin", "topFrameOrigin");
firstInteraction();
};
</script>
<div id="testElement">This is the test element</div>
</body>
</html>