blob: 470f192e7e315576703f4932c624ed095220b8bd [file] [edit]
<!DOCTYPE html>
<html>
<body>
<script src="/js-test-resources/js-test.js"></script>
<script src="resources/util.js"></script>
<script>
description("Tests that we grant User Interaction credit for handled keypresses.");
jsTestIsAsync = true;
const statisticsUrl = "http://127.0.0.1:8000/temp";
function completeTestWhenKeyDownIsReceived() {
if (testInput.value != "a") {
setTimeout(completeTestWhenKeyDownIsReceived, 100);
return;
}
shouldBeEqualToString("testInput.value", "a");
if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
testFailed("Origin did not get user interaction credit.");
else
testPassed("Origin was granted user interaction.");
setTimeout(function() {
testFrame.src = "about:blank";
setTimeout(function() {
setEnableFeature(false, finishJSTest);
}, 0);
}, 0);
}
onload = function() {
const testFrame = document.getElementById("testFrame");
if (window.testRunner && window.internals) {
setEnableFeature(true, function() {
testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
testFailed("Host did not get set as prevalent resource.");
testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, false, async function() {
if (testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
testFailed("Host did not get cleared of user interaction.");
testInput = document.getElementById("testInput");
testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
await testRunner.statisticsProcessStatisticsAndDataRecords();
debug("Simulate user typing letter 'a' into the field.");
testInput.focus();
if (window.eventSender)
eventSender.keyDown("a");
completeTestWhenKeyDownIsReceived();
});
});
});
}
}
</script>
<iframe id="testFrame" src="resources/onclick.html"></iframe>
<input id="testInput" type="text">
</body>
</html>