blob: 1a19949457e2c768a407da1500253cbab2cbffdc [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="/js-test-resources/js-test.js"></script>
<script src="resources/util.js"></script>
<script>description("Tests that merged statistic overwrites old statistic");</script>
</head>
<body onload="setTimeout('setUpAndRun()', 0)">
<script>
jsTestIsAsync = true;
const url = "http://127.0.0.1:8000";
const sampleTopFrameURL1 = "http://topFrameDomain1:8000";
const sampleTopFrameURL2 = "http://topFrameDomain2:8000";
const olderTimestamp = Math.round((new Date()).getTime() / 1000);
const newerTimestamp = olderTimestamp + 10;
const mostRecentUIToTriggerFirstPartyInteractionCount = newerTimestamp + 90000;
function insertSecondStatistic() {
// set url1 as prevalent so it is in the statistics store
// set url2 having UI so it is in the statistics store
testRunner.setStatisticsPrevalentResource(sampleTopFrameURL1, true, function() {
testRunner.setStatisticsHasHadUserInteraction(sampleTopFrameURL2, true, function () {
testRunner.setStatisticsMergeStatistic(url, sampleTopFrameURL1, sampleTopFrameURL2, newerTimestamp, true, mostRecentUIToTriggerFirstPartyInteractionCount, true, true, true, 1, function() {
if (testRunner.isStatisticsPrevalentResource(url))
testPassed("Host overwrote old prevalent resource value.");
else
testFailed("Host not set as prevalent resource.");
if (testRunner.isStatisticsVeryPrevalentResource(url))
testPassed("Host overwrote old very prevalent resource value.");
else
testFailed("Host not set as very prevalent resource.");
if (testRunner.isStatisticsHasHadUserInteraction(url))
testPassed("Host overwrote old user interaction value.");
else
testFailed("Host not logged for user interaction.");
if (testRunner.isStatisticsGrandfathered(url))
testPassed("Host overwrote old grandfathered value.");
else
testFailed("Host not set as grandfathered.");
if (testRunner.isStatisticsRegisteredAsSubFrameUnder(url, sampleTopFrameURL1))
testPassed("Host set as subframe under top frame1.");
else
testFailed("Host not set as subframe under top frame1.");
if (testRunner.isStatisticsRegisteredAsSubFrameUnder(url, sampleTopFrameURL2))
testPassed("Host set as subframe under top frame2.");
else
testFailed("Host not set as subframe under top frame2.");
testRunner.statisticsResetToConsistentState(function() {
finishJSTest();
});
});
});
});
}
function runTestRunnerTest() {
testRunner.setStatisticsMergeStatistic(url, "", "", olderTimestamp, false, 0, false, false, false, 0, function() {
if (testRunner.isStatisticsPrevalentResource(url))
testFailed("Host got set as prevalent resource.");
if (testRunner.isStatisticsVeryPrevalentResource(url))
testFailed("Host got set as prevalent resource.");
if (testRunner.isStatisticsHasHadUserInteraction(url))
testFailed("Host got logged for user interaction.");
if (testRunner.isStatisticsGrandfathered(url))
testFailed("Host got set as grandfathered.");
insertSecondStatistic();
});
}
function setUpAndRun() {
if (window.testRunner) {
testRunner.setUseITPDatabase(true);
setEnableFeature(true, function () {
runTestRunnerTest();
});
} else {
testFailed("no testRunner");
testRunner.statisticsResetToConsistentState(function() {
finishJSTest();
});
}
}
</script>
</body>
</html>