| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="UTF-8"> |
| <title>Test for Resource Load Statistics Pruning</title> |
| <script src="/js-test-resources/js-test.js"></script> |
| </head> |
| <body> |
| <script> |
| description("Tests that statistics are pruned in the right order."); |
| jsTestIsAsync = true; |
| |
| const olderTimestamp = Math.round((new Date()).getTime() / 1000); |
| const newerTimestamp = olderTimestamp + 10; |
| const newestTimestamp = newerTimestamp + 10; |
| |
| const urlsToBePruned = [ |
| { url: "http://127.0.0.1:8000/temp", prevalent: false }, |
| { url: "http://127.0.0.2:8000/temp", prevalent: false }, |
| { url: "http://127.0.0.3:8000/temp", prevalent: true }, |
| { url: "http://127.0.0.4:8000/temp", prevalent: true }, |
| { url: "http://127.0.0.5:8000/temp", prevalent: false }, |
| { url: "http://127.0.0.6:8000/temp", prevalent: false }, |
| { url: "http://127.0.0.7:8000/temp", prevalent: true }, |
| { url: "http://127.0.0.8:8000/temp", prevalent: true } |
| ]; |
| |
| function checkIfPrevalentAccordingToInitialExpectation(begin, end) { |
| var failed = false; |
| for (var i = begin; i < end; ++i) { |
| if (testRunner.isStatisticsPrevalentResource(urlsToBePruned[i].url) !== urlsToBePruned[i].prevalent) { |
| testFailed("checkIfPrevalentAccordingToInitialExpectation: Test iteration " + currentTest + " failed. " + urlsToBePruned[i].url + (urlsToBePruned[i].prevalent ? " wasn't " : " was ") + "prevalent"); |
| failed = true; |
| } |
| } |
| if (failed) |
| finishJSTest(); |
| } |
| |
| function checkIfPrevalent(begin, end, expected) { |
| var failed = false; |
| for (var i = begin; i < end; ++i) { |
| if (testRunner.isStatisticsPrevalentResource(urlsToBePruned[i].url) !== expected) { |
| testFailed("checkIfPrevalent: Test iteration " + currentTest + " failed. " + urlsToBePruned[i].url + (expected ? " wasn't " : " was ") + "prevalent"); |
| failed = true; |
| } |
| } |
| if (failed) |
| finishJSTest(); |
| } |
| |
| function initializeStatistics() { |
| testRunner.installStatisticsDidScanDataRecordsCallback(checkStatisticsAfterPruning); |
| |
| // Non-prevalent without user interaction to be pruned first. |
| testRunner.setStatisticsLastSeen(urlsToBePruned[0].url, olderTimestamp); |
| testRunner.setStatisticsLastSeen(urlsToBePruned[1].url, newerTimestamp); |
| |
| // Prevalent without user interaction to be pruned second. |
| testRunner.setStatisticsPrevalentResource(urlsToBePruned[2].url, true); |
| testRunner.setStatisticsLastSeen(urlsToBePruned[2].url, olderTimestamp); |
| testRunner.setStatisticsPrevalentResource(urlsToBePruned[3].url, true); |
| testRunner.setStatisticsLastSeen(urlsToBePruned[3].url, newerTimestamp); |
| |
| // Non-prevalent with user interaction to be pruned third. |
| testRunner.setStatisticsHasHadUserInteraction(urlsToBePruned[4].url, true); |
| testRunner.setStatisticsLastSeen(urlsToBePruned[4].url, olderTimestamp); |
| testRunner.setStatisticsHasHadUserInteraction(urlsToBePruned[5].url, true); |
| testRunner.setStatisticsLastSeen(urlsToBePruned[5].url, newerTimestamp); |
| |
| // Prevalent with user interaction to be pruned last. |
| testRunner.setStatisticsPrevalentResource(urlsToBePruned[6].url, true); |
| testRunner.setStatisticsHasHadUserInteraction(urlsToBePruned[6].url, true); |
| testRunner.setStatisticsLastSeen(urlsToBePruned[6].url, olderTimestamp); |
| testRunner.setStatisticsPrevalentResource(urlsToBePruned[7].url, true); |
| testRunner.setStatisticsHasHadUserInteraction(urlsToBePruned[7].url, true); |
| testRunner.setStatisticsLastSeen(urlsToBePruned[7].url, newerTimestamp); |
| |
| checkIfPrevalentAccordingToInitialExpectation(0, urlsToBePruned.length); |
| } |
| |
| var currentTest; |
| function checkStatisticsAfterPruning() { |
| // Pruned entries should not be prevalent. |
| checkIfPrevalent(0, currentTest, false); |
| // Non-pruned entries should keep their expected status. |
| checkIfPrevalentAccordingToInitialExpectation(currentTest, urlsToBePruned.length); |
| testPassed("Test iteration " + currentTest + " passed."); |
| if (currentTest < urlsToBePruned.length) { |
| ++currentTest; |
| runTest(); |
| } else { |
| finishJSTest(); |
| } |
| } |
| |
| function runTest() { |
| initializeStatistics(); |
| |
| var fillerUrl = "http://127.0." + currentTest + ".1:8000/temp"; |
| testRunner.setStatisticsPrevalentResource(fillerUrl, true); |
| testRunner.setStatisticsHasHadUserInteraction(fillerUrl, true); |
| testRunner.setStatisticsLastSeen(fillerUrl, newestTimestamp); |
| testRunner.statisticsProcessStatisticsAndDataRecords(); |
| } |
| |
| if (window.testRunner) { |
| testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false); |
| testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0); |
| testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true); |
| testRunner.setStatisticsMaxStatisticsEntries(urlsToBePruned.length); |
| testRunner.setStatisticsPruneEntriesDownTo(urlsToBePruned.length); |
| |
| currentTest = 1; |
| runTest(); |
| } |
| </script> |
| </body> |
| </html> |