| <!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 sampleTopFrameURL = "http://topFrameDomain:8000"; |
| const olderTimestamp = Math.round((new Date()).getTime() / 1000); |
| const newerTimestamp = olderTimestamp + 10; |
| const mostRecentUIToTriggerFirstPartyInteractionCount = newerTimestamp + 90000; |
| |
| function insertSecondStatistic() { |
| |
| // set this resource as prevalent so it is in the statistics store |
| testRunner.setStatisticsPrevalentResource(sampleTopFrameURL, true, function() { |
| |
| testRunner.setStatisticsMergeStatistic(url, sampleTopFrameURL, "", newerTimestamp, false, 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 did not overwrite 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, sampleTopFrameURL)) |
| testPassed("Host set as subframe under top frame."); |
| else |
| testFailed("Host not set as subframe under top frame."); |
| |
| 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> |