blob: 97b5579fa0b11d2cbac70055636b9afbcc4761ce [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test for Basic Telemetry Generation</title>
<script src="/js-test-resources/js-test.js"></script>
<script src="resources/util.js"></script>
</head>
<body>
<script>
testRunner.setUseITPDatabase(true);
description("Tests that basic telemetry for prevalent resources in the SQLite Database is calculated correctly.");
jsTestIsAsync = true;
const topFrameUrl1 = "http://127.0.0.1:8000/temp";
const topFrameUrl2 = "http://127.0.0.2:8000/temp";
const topFrameUrl3 = "http://127.0.0.3:8000/temp";
const topFrameUrl4 = "http://127.0.0.4:8000/temp";
const prevalentResourceUrl1 = "http://127.0.1.1:8000/temp";
const prevalentResourceUrl2 = "http://127.0.1.2:8000/temp";
const prevalentResourceUrl3 = "http://127.0.1.3:8000/temp";
const prevalentResourceUrl4 = "http://127.0.1.4:8000/temp";
function checkInsufficientClassificationAndContinue() {
if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl1)) {
testFailed("Host 1 did not get classified as prevalent resource.");
setEnableFeature(false, finishJSTest);
} else if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl2)) {
testFailed("Host 2 did not get classified as prevalent resource.");
setEnableFeature(false, finishJSTest);
} else {
testPassed("Hosts classified as prevalent resources.");
runTelemetryAndContinue();
}
}
function checkSufficientClassificationAndContinue() {
if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl1)) {
testFailed("Host 1 did not get classified as prevalent resource.");
setEnableFeature(false, finishJSTest);
} else if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl2)) {
testFailed("Host 2 did not get classified as prevalent resource.");
setEnableFeature(false, finishJSTest);
} else if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl3)) {
testFailed("Host 3 did not get classified as prevalent resource.");
setEnableFeature(false, finishJSTest);
} else if (!testRunner.isStatisticsPrevalentResource(prevalentResourceUrl4)) {
testFailed("Host 4 did not get classified as prevalent resource.");
setEnableFeature(false, finishJSTest);
} else {
testPassed("Hosts classified as prevalent resources.");
runTelemetryAndContinue();
}
}
function makeUrlPrevalent(prevalentResourceUrl) {
testRunner.setStatisticsSubframeUnderTopFrameOrigin(prevalentResourceUrl, topFrameUrl1);
testRunner.setStatisticsSubframeUnderTopFrameOrigin(prevalentResourceUrl, topFrameUrl2);
testRunner.setStatisticsSubframeUnderTopFrameOrigin(prevalentResourceUrl, topFrameUrl3);
testRunner.setStatisticsSubframeUnderTopFrameOrigin(prevalentResourceUrl, topFrameUrl4);
testRunner.setStatisticsSubresourceUniqueRedirectTo(prevalentResourceUrl, topFrameUrl1);
testRunner.setStatisticsSubresourceUniqueRedirectTo(prevalentResourceUrl, topFrameUrl2);
testRunner.setStatisticsSubresourceUniqueRedirectTo(prevalentResourceUrl, topFrameUrl3);
testRunner.setStatisticsSubresourceUniqueRedirectTo(prevalentResourceUrl, topFrameUrl4);
testRunner.setStatisticsSubresourceUnderTopFrameOrigin(prevalentResourceUrl, topFrameUrl1);
testRunner.setStatisticsSubresourceUnderTopFrameOrigin(prevalentResourceUrl, topFrameUrl2);
testRunner.setStatisticsSubresourceUnderTopFrameOrigin(prevalentResourceUrl, topFrameUrl3);
testRunner.setStatisticsSubresourceUnderTopFrameOrigin(prevalentResourceUrl, topFrameUrl4);
}
function setUpInsufficientStatisticsAndContinue() {
makeUrlPrevalent(prevalentResourceUrl1);
makeUrlPrevalent(prevalentResourceUrl2);
testRunner.installStatisticsDidScanDataRecordsCallback(checkInsufficientClassificationAndContinue);
testRunner.installStatisticsDidRunTelemetryCallback(checkInsufficientTelemetry);
testRunner.statisticsProcessStatisticsAndDataRecords();
}
function setUpSufficientStatisticsAndContinue() {
makeUrlPrevalent(prevalentResourceUrl3);
makeUrlPrevalent(prevalentResourceUrl4);
testRunner.setStatisticsHasHadUserInteraction(prevalentResourceUrl4, true, function() {
testRunner.installStatisticsDidScanDataRecordsCallback(checkSufficientClassificationAndContinue);
testRunner.installStatisticsDidRunTelemetryCallback(checkSufficientTelemetry);
testRunner.statisticsProcessStatisticsAndDataRecords();
});
}
function runTelemetryAndContinue() {
testRunner.statisticsSubmitTelemetry();
}
var testResult;
function checkInsufficientTelemetry(result) {
testResult = result;
shouldBe("testResult.numberOfPrevalentResources", "0");
shouldBe("testResult.numberOfPrevalentResourcesWithUserInteraction", "0");
shouldBe("testResult.numberOfPrevalentResourcesWithoutUserInteraction", "0");
shouldBe("testResult.topPrevalentResourceWithUserInteractionDaysSinceUserInteraction", "0");
shouldBe("testResult.medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction", "0");
shouldBe("testResult.top3NumberOfPrevalentResourcesWithUI", "0");
shouldBe("testResult.top3MedianSubFrameWithoutUI", "0");
shouldBe("testResult.top3MedianSubResourceWithoutUI", "0");
shouldBe("testResult.top3MedianUniqueRedirectsWithoutUI", "0");
shouldBe("testResult.top3MedianDataRecordsRemovedWithoutUI", "0");
setUpSufficientStatisticsAndContinue();
}
function checkSufficientTelemetry(result) {
testResult = result;
shouldBe("testResult.numberOfPrevalentResources", "4");
shouldBe("testResult.numberOfPrevalentResourcesWithUserInteraction", "1");
shouldBe("testResult.numberOfPrevalentResourcesWithoutUserInteraction", "3");
shouldBe("testResult.topPrevalentResourceWithUserInteractionDaysSinceUserInteraction", "0");
shouldBe("testResult.medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction", "0");
shouldBe("testResult.top3NumberOfPrevalentResourcesWithUI", "0");
shouldBe("testResult.top3MedianSubFrameWithoutUI", "4");
shouldBe("testResult.top3MedianSubResourceWithoutUI", "4");
shouldBe("testResult.top3MedianUniqueRedirectsWithoutUI", "4");
shouldBe("testResult.top3MedianDataRecordsRemovedWithoutUI", "0");
setEnableFeature(false, finishJSTest);
}
if (window.testRunner) {
setEnableFeature(true, function() {
testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
testRunner.setStatisticsNotifyPagesWhenTelemetryWasCaptured(true);
setUpInsufficientStatisticsAndContinue();
});
}
</script>
</body>
</html>