| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="UTF-8"> |
| <title>Test for Telemetry Generation</title> |
| <script src="/js-test-resources/js-test.js"></script> |
| <script src="resources/util.js"></script> |
| </head> |
| <body> |
| <script> |
| description("Tests that telemetry for prevalent resources 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.totalPrevalentResources", "0"); |
| shouldBe("testResult.totalPrevalentResourcesWithUserInteraction", "0"); |
| shouldBe("testResult.top3SubframeUnderTopFrameOrigins", "0"); |
| setUpSufficientStatisticsAndContinue(); |
| } |
| |
| function checkSufficientTelemetry(result) { |
| testResult = result; |
| shouldBe("testResult.totalPrevalentResources", "4"); |
| shouldBe("testResult.totalPrevalentResourcesWithUserInteraction", "1"); |
| shouldBe("testResult.top3SubframeUnderTopFrameOrigins", "4"); |
| setEnableFeature(false, finishJSTest); |
| } |
| |
| if (window.testRunner) { |
| setEnableFeature(true, function() { |
| testRunner.setStatisticsNotifyPagesWhenTelemetryWasCaptured(true); |
| setUpInsufficientStatisticsAndContinue(); |
| }); |
| } |
| </script> |
| </body> |
| </html> |