| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="UTF-8"> |
| <title>Test for Advanced 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 advanced telemetry for prevalent resources in the SQLite Database is calculated correctly."); |
| jsTestIsAsync = true; |
| |
| const topFrameUrl = "http://127.0.0.5:8000/temp"; |
| const topResourceUrl = "http://127.0.0.6:8000/temp"; |
| const toUniqueRedirectUrl = "http://127.0.0.7:8000/temp"; |
| |
| 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 url1 = "http://127.0.1.1:8000/temp"; |
| const url2 = "http://127.0.1.2:8000/temp"; |
| const url3 = "http://127.0.1.3:8000/temp"; |
| const url4 = "http://127.0.1.4:8000/temp"; |
| const url5 = "http://127.0.1.5:8000/temp"; |
| |
| const twoDaysOld = Math.round((new Date()).getTime() / 1000) - 180000; |
| |
| function checkClassificationAndContinue() { |
| if (!testRunner.isStatisticsPrevalentResource(url1)) { |
| testFailed("Host 1 did not get classified as prevalent resource."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsPrevalentResource(url2)) { |
| testFailed("Host 2 did not get classified as prevalent resource."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsPrevalentResource(url3)) { |
| testFailed("Host 3 did not get classified as prevalent resource."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsPrevalentResource(url4)) { |
| testFailed("Host 4 did not get classified as prevalent resource."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsPrevalentResource(url5)) { |
| testFailed("Host 5 did not get classified as prevalent resource."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsHasHadUserInteraction(url1)) { |
| testFailed("Host 1 did not get classified as having user interaction."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsHasHadUserInteraction(url2)) { |
| testFailed("Host 2 did not get classified as having user interaction."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsRegisteredAsSubFrameUnder(url1, topFrameUrl)) { |
| testFailed("Host 1 did not get set as subframe."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsRegisteredAsSubresourceUnder(url1, topResourceUrl)) { |
| testFailed("Host 1 did not get set as subresource."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsRegisteredAsSubFrameUnder(url2, topFrameUrl)) { |
| testFailed("Host 2 did not get set as subframe."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsRegisteredAsSubFrameUnder(url3, topFrameUrl)) { |
| testFailed("Host 3 did not get set as subframe."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsRegisteredAsSubresourceUnder(url3, topResourceUrl)) { |
| testFailed("Host 3 did not get set as subresource."); |
| setEnableFeature(false, finishJSTest); |
| } else if (!testRunner.isStatisticsRegisteredAsSubFrameUnder(url4, topFrameUrl)) { |
| testFailed("Host 4 did not get set as subframe."); |
| setEnableFeature(false, finishJSTest); |
| } else { |
| testPassed("Hosts classified correctly."); |
| 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 setUpStatisticsAndContinue() { |
| // merge statistic arguments: hostName, topFrameDomain, lastSeen, hadUserInteraction, mostRecentUserInteraction, isGrandfathered, isPrevalent, isVeryPrevalent, dataRecordsRemoved |
| makeUrlPrevalent(url1); |
| testRunner.setStatisticsSubframeUnderTopFrameOrigin(url1, topFrameUrl); |
| testRunner.setStatisticsSubresourceUnderTopFrameOrigin(url1, topResourceUrl); |
| testRunner.setStatisticsSubresourceUniqueRedirectTo(url1, toUniqueRedirectUrl); |
| |
| makeUrlPrevalent(url2); |
| testRunner.setStatisticsSubframeUnderTopFrameOrigin(url2, topFrameUrl); |
| testRunner.setStatisticsSubresourceUniqueRedirectTo(url2, toUniqueRedirectUrl); |
| |
| makeUrlPrevalent(url3); |
| testRunner.setStatisticsSubframeUnderTopFrameOrigin(url3, topFrameUrl); |
| testRunner.setStatisticsSubresourceUnderTopFrameOrigin(url3, topResourceUrl); |
| testRunner.setStatisticsSubresourceUniqueRedirectTo(url3, toUniqueRedirectUrl); |
| |
| makeUrlPrevalent(url4); |
| testRunner.setStatisticsSubframeUnderTopFrameOrigin(url4, topFrameUrl); |
| testRunner.setStatisticsSubresourceUnderTopFrameOrigin(url4, topResourceUrl); |
| |
| makeUrlPrevalent(url5); |
| |
| // set URLs 1 and 2 to have user interaction. UI for url 2 will be set to be 2 days old. |
| testRunner.setStatisticsHasHadUserInteraction(url1, true, function() { |
| testRunner.setStatisticsMergeStatistic(url2, topFrameUrl, "", twoDaysOld, true, twoDaysOld, false, true, false, 0, function() { |
| testRunner.installStatisticsDidScanDataRecordsCallback(checkClassificationAndContinue); |
| testRunner.installStatisticsDidRunTelemetryCallback(checkTelemetry); |
| testRunner.statisticsProcessStatisticsAndDataRecords(); |
| }); |
| }); |
| } |
| |
| function runTelemetryAndContinue() { |
| testRunner.statisticsSubmitTelemetry(); |
| } |
| |
| var testResult; |
| function checkTelemetry(result) { |
| testResult = result; |
| shouldBe("testResult.numberOfPrevalentResources", "5"); |
| shouldBe("testResult.numberOfPrevalentResourcesWithUserInteraction", "2"); |
| shouldBe("testResult.numberOfPrevalentResourcesWithoutUserInteraction", "3"); |
| shouldBe("testResult.topPrevalentResourceWithUserInteractionDaysSinceUserInteraction", "0"); |
| shouldBe("testResult.medianDaysSinceUserInteractionPrevalentResourceWithUserInteraction", "1"); |
| shouldBe("testResult.top3NumberOfPrevalentResourcesWithUI", "2"); |
| shouldBe("testResult.top3MedianSubFrameWithoutUI", "5"); |
| shouldBe("testResult.top3MedianSubResourceWithoutUI", "5"); |
| shouldBe("testResult.top3MedianUniqueRedirectsWithoutUI", "4"); |
| shouldBe("testResult.top3MedianDataRecordsRemovedWithoutUI", "0"); |
| setEnableFeature(false, finishJSTest); |
| } |
| |
| if (window.testRunner) { |
| setEnableFeature(true, function() { |
| testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true); |
| testRunner.setStatisticsNotifyPagesWhenTelemetryWasCaptured(true); |
| setUpStatisticsAndContinue(); |
| }); |
| } |
| </script> |
| </body> |
| </html> |