Source/WebCore:
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Sep 2019 19:16:40 +0000 (19:16 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Sep 2019 19:16:40 +0000 (19:16 +0000)
Enable LayoutTests using ResourceLoadStatistics SQLite backend (195420)
https://bugs.webkit.org/show_bug.cgi?id=195420
<rdar://problem/54213551>

Patch by Kate Cheney <katherine_cheney@apple.com> on 2019-09-26
Reviewed by Brent Fulgham.

Tests: http/tests/resourceLoadStatistics/add-blocking-to-redirect-database.html
       http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database.html
       http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database.html
       http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database.html
       http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database.html
       http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database.html
       http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database.html
       http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database.html
       http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database.html
       http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database.html
       http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database.html
       http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database.html
       http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database.html
       http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database.html
       http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database.html
       http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database.html
       http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database.html
       http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database.html
       http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database.html
       http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database.html
       http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database.html
       http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database.html
       http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database.html
       http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database.html
       http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database.html
       http/tests/resourceLoadStatistics/cookie-deletion-database.html
       http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database.html
       http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database.html
       http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database.html
       http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database.html
       http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database.html
       http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database.html
       http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database.html
       http/tests/resourceLoadStatistics/enable-debug-mode-database.html
       http/tests/resourceLoadStatistics/grandfathering-database.html
       http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database.html
       http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database.html
       http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database.html
       http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
       http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
       http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
       http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
       http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
       http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
       http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database.html
       http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database.html
       http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database.html
       http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database.html
       http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database.html
       http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database.html
       http/tests/resourceLoadStatistics/prune-statistics-database.html
       http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
       http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
       http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
       http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
       http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
       http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
       http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database.html
       http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database.html
       http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database.html
       http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database.html
       http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database.html
       http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-database.html
       http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal-database.html

* platform/sql/SQLiteDatabase.h:
Added WEBCORE_EXPORT prefix to 2 functions needed in the ITP Database
to clear out the database.

Source/WebKit:
Enable LayoutTests using ResourceLoadStatistics SQLite backend (195420)
https://bugs.webkit.org/show_bug.cgi?id=195420
<rdar://problem/54213551>

Patch by Kate Cheney <katherine_cheney@apple.com> on 2019-09-26
Reviewed by Brent Fulgham.

Changed all RELEASE_LOG_ERROR() calls involving domain strings to
RELEASE_LOG_ERROR_IF_ALLOWED() to prevent leaking information about
the domain strings only if sessionID.isAlwaysOnLoggingAllowed().

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::ResourceLoadStatisticsDatabaseStore::ResourceLoadStatisticsDatabaseStore):
Added autovacuuming to the constructor to avoid manually calling
runVacuumCommand(). Changed constructor to take in sessionID so it
can use RELEASE_LOG_ERROR_IF_ALLOWED which requires the sessionID.

(WebKit::ResourceLoadStatisticsDatabaseStore::prepareStatements):
Added 2 statements that were not being prepared.

(WebKit::ResourceLoadStatisticsDatabaseStore::relationshipExists const):
Corrected incorrect capitalization. Added check for nullopt in case
domainID is for a domain not in the database yet.

(WebKit::ResourceLoadStatisticsDatabaseStore::domainID const):
Changed return value to Optional<unsigned>. Some tests were directly
checking for subframes under top frame domains on domains that had
not been inserted yet. Now, domainID() won't crash but will return
a nullopt value which can be checked to know that the tests failed.

(WebKit::ResourceLoadStatisticsDatabaseStore::insertDomainRelationships):
Added a check to assure domainID exists and updated the domainID
interactions to work as Optionals.

(WebKit::ResourceLoadStatisticsDatabaseStore::populateFromMemoryStore):
Moved the prepareStatements() call after the vacuum command in the case
where the database is empty. Otherwise called it before returning.

(WebKit::ResourceLoadStatisticsDatabaseStore::recursivelyFindNonPrevalentDomainsThatRedirectedToThisDomain):
Added a space to the SQL commands to correct the syntax.

(WebKit::ResourceLoadStatisticsDatabaseStore::findNotVeryPrevalentResources):
Corrected a bug in the SQL command for querying
subframeUnderTopFrameDomain. The old query was asking for subresource.

(WebKit::ResourceLoadStatisticsDatabaseStore::reclassifyResources):
Spelling fix.

(WebKit::ResourceLoadStatisticsDatabaseStore::requestStorageAccess):
Changed string concatenation to binding.

(WebKit::ResourceLoadStatisticsDatabaseStore::grandfatherDataForDomains):
The grandfathering.html test was failing because domains were being
"set" to grandfathered in the database before being inserted. This fix
ensures all domains before setting the grandfathering flag.

(WebKit::ResourceLoadStatisticsDatabaseStore::logFrameNavigation):
Multiple tests were failing because the query to insert the relationship
for the source domain relies on the target domain being in the
ObservedDomains table. This patch ensures all domains are added before
performing the query.

(WebKit::ResourceLoadStatisticsDatabaseStore::setUserInteraction):
Added a != SQLITE_OK check to make sure an error is logged if the
statement fails to bind.

(WebKit::ResourceLoadStatisticsDatabaseStore::clearUserInteraction):
Changed string concatenation to binding.

(WebKit::ResourceLoadStatisticsDatabaseStore::hasHadUserInteraction):
The SQL statement was being bound to a value and not being reset. This
patch resets the statement after binding. Additionally, the step()
function was being compared to SQLITE_DONE instead of SQLITE_ROW,
causing an error if the query returned results. The
ASSERT_NOT_REACHED() was causing null searches to crash instead of
returning false (i.e. if a domain is not in the database it should
return that it has no user interaction instead of crashing).

(WebKit::ResourceLoadStatisticsDatabaseStore::setPrevalentResource):
Updated domainID call to act as an Optional.

(WebKit::ResourceLoadStatisticsDatabaseStore::predicateValueForDomain const):
The SQL statement was being bound to a value and not being reset. This
patch resets the statement after binding. SQLITE_DONE changed to
SQLITE_ROW to return non-empty query results. ASSERT_NOT_REACHED()
removed for the same reasons as above.

(WebKit::ResourceLoadStatisticsDatabaseStore::ensureResourceStatisticsForRegistrableDomain):
Fixed the release log statement which was logging the wrong function
name.

(WebKit::ResourceLoadStatisticsDatabaseStore::clearDatabaseContents):
Clears the database and rebuilds the tables on a clear command to
match the functionality in the Memory Store.

(WebKit::ResourceLoadStatisticsDatabaseStore::clear):
Call the clearDatabaseContents function to match the functionality
in the Memory Store.

(WebKit::ResourceLoadStatisticsDatabaseStore::hasUserGrantedStorageAccessThroughPrompt const):
Updated domainID call to act as an Optional.

(WebKit::ResourceLoadStatisticsDatabaseStore::hasHadUnexpiredRecentUserInteraction):
Tests were failing because shouldRemoveAllWebsiteDataFor() was not
checking for expired user interaction. Matched functionality in the
Memory Store.

(WebKit::ResourceLoadStatisticsDatabaseStore::shouldRemoveAllWebsiteDataFor):
Tests were failing because shouldRemoveAllWebsiteDataFor() was not
checking for expired user interaction. Matched functionality in the
Memory Store.

(WebKit::ResourceLoadStatisticsDatabaseStore::registrableDomainsToRemoveWebsiteDataFor):
Spelling fix.

(WebKit::ResourceLoadStatisticsDatabaseStore::pruneStatisticsIfNeeded):
Last seen should be sorted in ascending order because you want to
prune the older statistics first, which will have a lower lastSeen
field (secondsSinceEpoch() will be lower for older values).

(WebKit::ResourceLoadStatisticsDatabaseStore::shouldRemoveAllWebsiteDataFor const): Deleted.
Deleted const specifier because the function needs to clear the
database.

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
Declared new functions. Updated spelling error (registerable -->
registrable). Updated constructor to take sessionID.

* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
ITP database flag now is stored in the NetworkProcess.
* NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::initializeNetworkProcess):
Set the ITP database flag which is now stored in the Network Process.

(WebKit::NetworkProcess::setUseITPDatabase):
* NetworkProcess/NetworkProcess.h:
(WebKit::NetworkProcess::isITPDatabaseEnabled const):
* NetworkProcess/NetworkProcess.messages.in:
Passed the setUseITPDatabase flag to the initialization function
of the statistics store to enable the database backend.

* NetworkProcess/NetworkSession.cpp:
(WebKit::NetworkSession::NetworkSession):
SandboxExtension::consumePermanently was not getting called on the
WebKitTestRunner resourceLoadStatistics path. This was preventing
the database file from opening.

(WebKit::NetworkSession::recreateResourceLoadStatisticStore):
Destroy old WebResourceLoadStatisticsStore and create a new one using
the ITP database.

* NetworkProcess/NetworkSession.h:
* UIProcess/API/C/WKWebsiteDataStoreRef.cpp:
(WKWebsiteDataStoreSetUseITPDatabase):
* UIProcess/API/C/WKWebsiteDataStoreRef.h:
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::setUseITPDatabase):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::setUseITPDatabase):
* UIProcess/WebsiteData/WebsiteDataStore.h:
Passed the setUseITPDatabase flag to the initialization function
of the statistics store to enable the database backend.

Tools:
Enable LayoutTests using ResourceLoadStatistics SQLite backend (195420)
https://bugs.webkit.org/show_bug.cgi?id=195420
<rdar://problem/54213551>

Patch by Kate Cheney <katherine_cheney@apple.com> on 2019-09-26
Reviewed by Brent Fulgham.

Added in logic to send a message from the UIProcess to the Network
Process which will initalize the ITP Database backend to allow for
layout testing.
* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::setUseITPDatabase):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::setUseITPDatabase):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

LayoutTests:
Enable LayoutTests using ResourceLoadStatistics SQLite backend (195420)
https://bugs.webkit.org/show_bug.cgi?id=195420
<rdar://problem/54213551>

Added a flag to all ITP tests to enable the ITP database backend to
allow for testing functionality against the memory store. Tests were
not created for telemetry-generation.html,
log-cross-site-load-with-link-decoration.html, or
website-data-removal-for-site-navigated-to-with-link-decoration.html,
because these rely on functions not yet implemented in the ITP database.
Additionally, added flags to some memory store tests to ensure they
are using the memory store before calling functions not implemented in
the database store yet.

Patch by Kate Cheney <katherine_cheney@apple.com> on 2019-09-26
Reviewed by Brent Fulgham.

* http/tests/resourceLoadStatistics/add-blocking-to-redirect-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/add-blocking-to-redirect-database.html: Added.
* http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database.html: Added.
* http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database.html: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database.html: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database.html: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database.html: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database.html: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database.html: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database.html: Added.
* http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database.html: Added.
* http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database.html: Added.
* http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database.html: Added.
* http/tests/resourceLoadStatistics/cookie-deletion-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/cookie-deletion-database.html: Added.
* http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database.html: Added.
* http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database.html: Added.
* http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database.html: Added.
* http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database.html: Added.
* http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database.html: Added.
* http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database.html: Added.
* http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database.html: Added.
* http/tests/resourceLoadStatistics/enable-debug-mode-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/enable-debug-mode-database.html: Added.
* http/tests/resourceLoadStatistics/grandfathering-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/grandfathering-database.html: Added.
* http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration.html:
* http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database.html: Added.
* http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database.html: Added.
* http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database.html: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
* http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database.html: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database.html: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database.html: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database.html: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database.html: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database.html: Added.
* http/tests/resourceLoadStatistics/prune-statistics-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/prune-statistics-database.html: Added.
* http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
* http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
* http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database.html: Added.
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database.html: Added.
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database.html: Added.
* http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database.html: Added.
* http/tests/resourceLoadStatistics/telemetry-generation.html:
* http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database.html: Added.
* http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-database.html: Added.
* http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal-database-expected.txt: Added.
* http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal-database.html: Added.
* http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration.html:
* platform/ios/TestExpectations:
Added test expectations to skip database tests which do not work in
ios because of reliance on EventSender.keydown() which is not
supported on iOS and also those which use UIHelper.activateAt() which
does not produce a user gesture captured by ITP in iOS.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250393 268f45cc-cd09-0410-ab3c-d52691b4dbfc

157 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/cookie-deletion-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/cookie-deletion-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/enable-debug-mode-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/enable-debug-mode-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/grandfathering-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/grandfathering-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration.html
LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prune-statistics-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/prune-statistics-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/telemetry-generation.html
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal-database-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal-database.html [new file with mode: 0644]
LayoutTests/http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration.html
LayoutTests/platform/ios/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/sql/SQLiteDatabase.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp
Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h
Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcess.messages.in
Source/WebKit/NetworkProcess/NetworkSession.cpp
Source/WebKit/NetworkProcess/NetworkSession.h
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.cpp
Source/WebKit/UIProcess/API/C/WKWebsiteDataStoreRef.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/TestInvocation.cpp

index 7a3f9f2..9343a21 100644 (file)
@@ -1,3 +1,158 @@
+2019-09-26  Kate Cheney  <katherine_cheney@apple.com>
+
+        Enable LayoutTests using ResourceLoadStatistics SQLite backend (195420)
+        https://bugs.webkit.org/show_bug.cgi?id=195420 
+        <rdar://problem/54213551>
+
+        Added a flag to all ITP tests to enable the ITP database backend to 
+        allow for testing functionality against the memory store. Tests were 
+        not created for telemetry-generation.html, 
+        log-cross-site-load-with-link-decoration.html, or 
+        website-data-removal-for-site-navigated-to-with-link-decoration.html, 
+        because these rely on functions not yet implemented in the ITP database.
+        Additionally, added flags to some memory store tests to ensure they
+        are using the memory store before calling functions not implemented in
+        the database store yet.
+
+        Reviewed by Brent Fulgham.
+
+        * http/tests/resourceLoadStatistics/add-blocking-to-redirect-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/add-blocking-to-redirect-database.html: Added.
+        * http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database.html: Added.
+        * http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database.html: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database.html: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database.html: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database.html: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database.html: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database.html: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database.html: Added.
+        * http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database.html: Added.
+        * http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database.html: Added.
+        * http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database.html: Added.
+        * http/tests/resourceLoadStatistics/cookie-deletion-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/cookie-deletion-database.html: Added.
+        * http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database.html: Added.
+        * http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database.html: Added.
+        * http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database.html: Added.
+        * http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database.html: Added.
+        * http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database.html: Added.
+        * http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database.html: Added.
+        * http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database.html: Added.
+        * http/tests/resourceLoadStatistics/enable-debug-mode-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/enable-debug-mode-database.html: Added.
+        * http/tests/resourceLoadStatistics/grandfathering-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/grandfathering-database.html: Added.
+        * http/tests/resourceLoadStatistics/log-cross-site-load-with-link-decoration.html:
+        * http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database.html: Added.
+        * http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database.html: Added.
+        * http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database.html: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
+        * http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database.html: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database.html: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database.html: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database.html: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database.html: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database.html: Added.
+        * http/tests/resourceLoadStatistics/prune-statistics-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/prune-statistics-database.html: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html: Added.
+        * http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database.html: Added.
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database.html: Added.
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database.html: Added.
+        * http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database.html: Added.
+        * http/tests/resourceLoadStatistics/telemetry-generation.html:
+        * http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database.html: Added.
+        * http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/user-interaction-only-reported-once-within-short-period-of-time-database.html: Added.
+        * http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal-database-expected.txt: Added.
+        * http/tests/resourceLoadStatistics/user-interaction-reported-after-website-data-removal-database.html: Added.
+        * http/tests/resourceLoadStatistics/website-data-removal-for-site-navigated-to-with-link-decoration.html:
+        * platform/ios/TestExpectations:
+        Added test expectations to skip database tests which do not work in 
+        ios because of reliance on EventSender.keydown() which is not
+        supported on iOS and also those which use UIHelper.activateAt() which
+        does not produce a user gesture captured by ITP in iOS.
+
 2019-09-26  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS 13] Tapping on a non-editable text selection should toggle callout bar visibility instead of clearing selection
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-database-expected.txt
new file mode 100644 (file)
index 0000000..afef9cd
--- /dev/null
@@ -0,0 +1,63 @@
+Tests that blocking is added mid-flight in redirects.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+  
+
+--------
+Frame: '<!--frame1-->'
+--------
+Should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie: firstPartyCookie=value
+
+--------
+Frame: '<!--frame2-->'
+--------
+Redirect case 1, should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie: firstPartyCookie=value
+
+--------
+Frame: '<!--frame3-->'
+--------
+Should receive no cookies.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--frame4-->'
+--------
+Redirect case 2, should receive no cookie.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--frame5-->'
+--------
+Try to set third-party cookie in blocked mode.
+
+
+--------
+Frame: '<!--frame6-->'
+--------
+After attempted cookie creation, should receive no cookie.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--frame7-->'
+--------
+Redirect case 3, after attempted cookie creation, should receive no cookie.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'partitionedCookie'.
+Client-side document.cookie:
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-database.html b/LayoutTests/http/tests/resourceLoadStatistics/add-blocking-to-redirect-database.html
new file mode 100644 (file)
index 0000000..01d63a5
--- /dev/null
@@ -0,0 +1,104 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Tests that blocking is added mid-flight in redirects.");
+    jsTestIsAsync = true;
+
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const resourcePath = "/resourceLoadStatistics/resources";
+    const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath;
+    const firstPartyCookieName = "firstPartyCookie";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
+    const partitionedCookieName = "partitionedCookie";
+    const subPathToSetPartitionedCookie = "/set-cookie.php?name=" + partitionedCookieName + "&value=value";
+    const returnUrl = "http://" + partitionHost + "/resourceLoadStatistics/add-blocking-to-redirect.html";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + partitionedCookieName;
+    const redirectChainUrl = "http://" + partitionHost + resourcePath + "/redirect.php?redirectTo=" + thirdPartyBaseUrl + subPathToGetCookies;
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                // Set first-party cookie for localhost.
+                document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step2";
+                break;
+            case "#step2":
+                // Check that the cookie gets sent for localhost under 127.0.0.1 since localhost is not prevalent.
+                document.location.hash = "step3";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
+                break;
+            case "#step3":
+                document.location.hash = "step4";
+                // Load an iframe in a redirect chain that starts with 127.0.0.1 and ends with localhost. Expect a cookie for localhost.
+                openIframe(redirectChainUrl + "&message=Redirect case 1, should receive first-party cookie.", runTest);
+                break;
+            case "#step4":
+                // Set localhost as prevalent to put it in the blocking category.
+                document.location.hash = "step5";
+                testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                });
+                break;
+            case "#step5":
+                // Check that no cookie gets sent for localhost under 127.0.0.1 since localhost's cookies are blocked.
+                document.location.hash = "step6";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies +  "&message=Should receive no cookies.", runTest);
+                break;
+            case "#step6":
+                // Load an iframe in a redirect chain that starts with 127.0.0.1 and ends with localhost. Expect no cookie for localhost.
+                document.location.hash = "step7";
+                openIframe(redirectChainUrl + "&message=Redirect case 2, should receive no cookie.", runTest);
+                break;
+            case "#step7":
+                // Try to set cookie for localhost under 127.0.0.1.
+                document.location.hash = "step8";
+                openIframe(thirdPartyBaseUrl + subPathToSetPartitionedCookie + "&message=Try to set third-party cookie in blocked mode.", runTest);
+                break;
+            case "#step8":
+                // Check that no cookie gets sent for localhost under 127.0.0.1 since localhost's cookies are blocked.
+                document.location.hash = "step9";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies +  "&message=After attempted cookie creation, should receive no cookie.", runTest);
+                break;
+            case "#step9":
+                // Load an iframe in a redirect chain that starts with 127.0.0.1 and ends with localhost. Expect no cookie for localhost.
+                document.location.hash = "step10";
+                openIframe(redirectChainUrl + "&message=Redirect case 3, after attempted cookie creation, should receive no cookie.", runTest);
+                break;
+            case "#step10":
+                setEnableFeature(false, finishJSTest);
+                break;
+        }
+    }
+
+    if (document.location.hash === "") {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function () {
+            if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                testFailed("Localhost was classified as prevalent resource before the test starts.");
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
+            runTest();
+        });
+    } else {
+        runTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database-expected.txt
new file mode 100644 (file)
index 0000000..9cb7994
--- /dev/null
@@ -0,0 +1,18 @@
+Test for cookie blocking when web workers import cross-site scripts.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Did receive firstPartyCookie == value
+PASS Did not receive cookie named firstPartyCookie
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+--------
+Frame: '<!--frame1-->'
+--------
+Should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Client-side document.cookie: firstPartyCookie=value
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database.html b/LayoutTests/http/tests/resourceLoadStatistics/blocking-in-web-worker-script-import-database.html
new file mode 100644 (file)
index 0000000..cc20108
--- /dev/null
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    description("Test for cookie blocking when web workers import cross-site scripts.");
+    jsTestIsAsync = true;
+
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const thirdPartyBaseUrl = thirdPartyOrigin + "/resourceLoadStatistics/resources";
+    const firstPartyCookieName = "firstPartyCookie";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
+    const returnUrl = "http://127.0.0.1:8000/resourceLoadStatistics/blocking-in-web-worker-script-import.html";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName;
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    let receivedMessages = 0;
+    function receiveMessage(event) {
+        if (event.data.indexOf("PASS") === -1)
+            testFailed(event.data.replace("FAIL ", ""));
+        else
+            testPassed(event.data.replace("PASS ", ""));
+
+        ++receivedMessages;
+        if (receivedMessages >= 2) {
+            setEnableFeature(false, finishJSTest);
+        } else
+            runTest();
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step2";
+                break;
+            case "#step2":
+                document.location.hash = "step3";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
+                break;
+            case "#step3":
+                document.location.hash = "step4";
+                let w1 = new Worker("resources/worker-importing-localhost-script.js");
+                w1.onmessage = receiveMessage;
+                w1.postMessage("shouldReceiveCookies=true");
+                break;
+            case "#step4":
+                document.location.hash = "step5";
+                testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                });
+                break;
+            case "#step5":
+                let w2 = new Worker("resources/worker-importing-localhost-script.js");
+                w2.onmessage = receiveMessage;
+                w2.postMessage("shouldNotReceiveCookies");
+                break;
+        }
+    }
+
+    if (document.location.host === partitionHost && document.location.hash === "" && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            document.location.hash = "step1";
+            testRunner.dumpChildFramesAsText();
+            if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                testFailed("Localhost was classified as prevalent resource before the test starts.");
+            runTest();
+        });
+    } else {
+        runTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database-expected.txt
new file mode 100644 (file)
index 0000000..0cce5aa
--- /dev/null
@@ -0,0 +1,14 @@
+Tests that cache max-age is capped for prevalent resources.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS loadedUrl is "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=1234"
+PASS loadedUrl is "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=4321"
+PASS loadedUrl is "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value="
+PASS loadedUrl is "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value="
+PASS loadedUrl is "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value="
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database.html b/LayoutTests/http/tests/resourceLoadStatistics/cap-cache-max-age-for-prevalent-resource-database.html
new file mode 100644 (file)
index 0000000..264a451
--- /dev/null
@@ -0,0 +1,113 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <title>Tests for Capped Cache Max-Age</title>
+</head>
+<body>
+<script>
+    description("Tests that cache max-age is capped for prevalent resources.");
+    jsTestIsAsync = true;
+
+    var loadedUrl;
+    function firstFetch() {
+        // This should create a capped cache entry.
+        fetch("http://localhost:8000/resourceLoadStatistics/resources/cached-permanent-redirect.php",
+            {
+                cache: "reload",
+                headers: {
+                    "X-WebKit": "1234",
+                }
+            }
+        ).then(function(response) {
+            loadedUrl = response.url;
+            shouldBeEqualToString("loadedUrl", "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=1234");
+            secondFetch();
+        }).catch(function(error) {
+            testFailed(error.message);
+            setEnableFeature(false, finishJSTest);
+        });
+    }
+
+    function secondFetch() {
+        // This should not trigger a successful cache hit and instead create another capped cache entry.
+        fetch("http://localhost:8000/resourceLoadStatistics/resources/cached-permanent-redirect.php",
+            {
+                cache: "force-cache",
+                headers: {
+                    "X-WebKit": "4321",
+                }
+            }
+        ).then(function(response) {
+            loadedUrl = response.url;
+            shouldBeEqualToString("loadedUrl", "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=4321");
+            thirdFetch();
+        }).catch(function(error) {
+            testFailed(error.message);
+            setEnableFeature(false, finishJSTest);
+        });
+    }
+
+    function thirdFetch() {
+        // This should not trigger a successful cache hit and instead create another capped cache entry.
+        fetch("http://localhost:8000/resourceLoadStatistics/resources/cached-permanent-redirect.php",
+            {
+                cache: "force-cache",
+            }
+        ).then(function(response) {
+            loadedUrl = response.url;
+            shouldBeEqualToString("loadedUrl", "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=");
+            fourthFetch();
+        }).catch(function(error) {
+            testFailed(error.message);
+            setEnableFeature(false, finishJSTest);
+        });
+    }
+
+    function fourthFetch() {
+        // This should not trigger a successful cache hit but clear capping.
+        fetch("http://localhost:8000/resourceLoadStatistics/resources/cached-permanent-redirect.php",
+            {
+                cache: "force-cache",
+            }
+        ).then(function(response) {
+            loadedUrl = response.url;
+            shouldBeEqualToString("loadedUrl", "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=");
+            fifthFetch();
+        }).catch(function(error) {
+            testFailed(error.message);
+            setEnableFeature(false, finishJSTest);
+        });
+    }
+
+    function fifthFetch() {
+        // This should trigger a regular, successful cache hit.
+        fetch("http://localhost:8000/resourceLoadStatistics/resources/cached-permanent-redirect.php",
+            {
+                headers: {
+                    "X-WebKit": "1234",
+                }
+            }
+        ).then(function(response) {
+            loadedUrl = response.url;
+            shouldBeEqualToString("loadedUrl", "http://localhost:8000/resourceLoadStatistics/resources/echo-query.php?value=");
+            setEnableFeature(false, finishJSTest);
+        }).catch(function(error) {
+            testFailed(error.message);
+            setEnableFeature(false, finishJSTest);
+        });
+    }
+    testRunner.setUseITPDatabase(true);
+    setEnableFeature(true, function() {
+        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
+            testFailed("Localhost was classified as prevalent resource before the test started.");
+
+        testRunner.setStatisticsCacheMaxAgeCap(0);
+        testRunner.setStatisticsPrevalentResource("http://localhost", true, function() {
+            testRunner.statisticsUpdateCookieBlocking(firstFetch);
+        });
+    });
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database-expected.txt
new file mode 100644 (file)
index 0000000..484620d
--- /dev/null
@@ -0,0 +1,11 @@
+Check that cookies created by JavaScript with max-age or expiry longer than a week get capped to a week.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS The two short-lived cookies don't expire after more than 172830 seconds.
+PASS The two long-lived cookies don't expire after more than 604830 seconds.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database.html b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-database.html
new file mode 100644 (file)
index 0000000..e2ffd04
--- /dev/null
@@ -0,0 +1,83 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="/cookies/resources/cookie-utilities.js"></script>
+</head>
+<body>
+<script>
+    description("Check that cookies created by JavaScript with max-age or expiry longer than a week get capped to a week.");
+    jsTestIsAsync = true;
+    testRunner.setUseITPDatabase(true);
+
+    if (internals)
+        internals.setResourceLoadStatisticsEnabled(true);
+
+    let passedTests = 0;
+    function checkThatCookieDoesNotExpireAfter(cookieData, maxAgeInSeconds) {
+        let now = new Date();
+        let maxExpiryDateInMilliseconds = now.getTime() + (maxAgeInSeconds * 1000);
+
+        if (maxExpiryDateInMilliseconds > cookieData["expires"])
+            ++passedTests;
+        else
+            testFailed("Cookie named " + cookieData["name"] + " expires in more than " + maxAgeInSeconds + " seconds.");
+    }
+
+    const twoDaysInSeconds = 2 * 24 * 60 * 60;
+    const shortLivedCookieMaxAge = { name : "shortLivedCookieMaxAge", lifetime : "Max-Age=" + twoDaysInSeconds + ";" };
+    document.cookie = shortLivedCookieMaxAge.name + "=foobar; " + shortLivedCookieMaxAge.lifetime + " path=/";
+
+    const twoDaysAsExpiresDate = createExpiresDateFromMaxAge(twoDaysInSeconds);
+    const shortLivedCookieExpires = { name : "shortLivedCookieExpires", lifetime : "Expires=" + twoDaysAsExpiresDate + ";" };
+    document.cookie = shortLivedCookieExpires.name + "=foobar; " + shortLivedCookieExpires.lifetime + " path=/";
+
+    const oneWeekInSeconds = 7 * 24 * 60 * 60;
+    const twoWeeksInSeconds = 2 * oneWeekInSeconds;
+    const longLivedCookieMaxAge = { name : "longLivedCookieMaxAge", lifetime : "Max-Age=" + twoWeeksInSeconds + ";" };
+    document.cookie = longLivedCookieMaxAge.name + "=foobar; " + longLivedCookieMaxAge.lifetime + " path=/";
+
+    const twoWeeksAsExpiresDate = createExpiresDateFromMaxAge(twoWeeksInSeconds);
+    const longLivedCookieExpires = { name : "longLivedCookieExpires", lifetime : "Expires=" + twoWeeksAsExpiresDate + ";" };
+    document.cookie = longLivedCookieExpires.name + "=foobar; " + longLivedCookieExpires.lifetime + " path=/";
+
+    const overTwoDaysInSeconds = twoDaysInSeconds + 30;
+    const overOneWeekInSeconds = oneWeekInSeconds + 30;
+    if (internals) {
+        let cookies = internals.getCookies();
+        if (!cookies.length)
+            testFailed("No cookies found.");
+        for (let cookie of cookies) {
+            switch (cookie.name) {
+                case shortLivedCookieMaxAge.name:
+                    checkThatCookieDoesNotExpireAfter(cookie, overTwoDaysInSeconds);
+                    break;
+                case shortLivedCookieExpires.name:
+                    checkThatCookieDoesNotExpireAfter(cookie, overTwoDaysInSeconds);
+                    break;
+                case longLivedCookieMaxAge.name:
+                    checkThatCookieDoesNotExpireAfter(cookie, overOneWeekInSeconds);
+                    break;
+                case longLivedCookieExpires.name:
+                    checkThatCookieDoesNotExpireAfter(cookie, overOneWeekInSeconds);
+                    break;
+            }
+        }
+
+        resetCookiesForCurrentOrigin();
+
+        if (passedTests === 4) {
+            testPassed("The two short-lived cookies don't expire after more than " + overTwoDaysInSeconds + " seconds.");
+            testPassed("The two long-lived cookies don't expire after more than " + overOneWeekInSeconds + " seconds.");
+        } else
+            testFailed("At least one cookie's expiry attribute was beyond the test thresholds.");
+    } else
+        testFailed("No internals object.");
+
+    if (internals)
+        internals.setResourceLoadStatisticsEnabled(false);
+
+    finishJSTest();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database-expected.txt
new file mode 100644 (file)
index 0000000..a49545a
--- /dev/null
@@ -0,0 +1,10 @@
+Check that cookies created by JavaScript after a same-site navigation with link decoration don't get capped to 24 hours.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS The two long-lived cookies expire after more than 86430 seconds.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database.html b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site-database.html
new file mode 100644 (file)
index 0000000..ed09991
--- /dev/null
@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="/cookies/resources/cookie-utilities.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body onload="setTimeout('runTest()', 0)">
+<script>
+    description("Check that cookies created by JavaScript after a same-site navigation with link decoration don't get capped to 24 hours.");
+    jsTestIsAsync = true;
+
+    function testCookies() {
+        let passedTests = 0;
+
+        function checkThatCookieDoesExpireAfter(cookieData, maxAgeInSeconds) {
+            let now = new Date();
+            let maxExpiryDateInMilliseconds = now.getTime() + (maxAgeInSeconds * 1000);
+
+            if (maxExpiryDateInMilliseconds < cookieData["expires"])
+                ++passedTests;
+            else
+                testFailed("Cookie named " + cookieData["name"] + " expires in less than " + maxAgeInSeconds + " seconds.");
+        }
+
+        const oneDayInSeconds = 24 * 60 * 60;
+        const twoDaysInSeconds = 2 * oneDayInSeconds;
+        const longLivedCookieMaxAge = { name : "longLivedCookieMaxAge", lifetime : "Max-Age=" + twoDaysInSeconds + ";" };
+        document.cookie = longLivedCookieMaxAge.name + "=foobar; " + longLivedCookieMaxAge.lifetime + " path=/";
+
+        const twoDaysAsExpiresDate = createExpiresDateFromMaxAge(twoDaysInSeconds);
+        const longLivedCookieExpires = { name : "longLivedCookieExpires", lifetime : "Expires=" + twoDaysAsExpiresDate + ";" };
+        document.cookie = longLivedCookieExpires.name + "=foobar; " + longLivedCookieExpires.lifetime + " path=/";
+
+        const overOneDayInSeconds = oneDayInSeconds + 30;
+        if (internals) {
+            let cookies = internals.getCookies();
+            if (!cookies.length)
+                testFailed("No cookies found.");
+            for (let cookie of cookies) {
+                switch (cookie.name) {
+                    case longLivedCookieMaxAge.name:
+                        checkThatCookieDoesExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                    case longLivedCookieExpires.name:
+                        checkThatCookieDoesExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                }
+            }
+
+            resetCookiesForCurrentOrigin();
+
+            if (passedTests === 2) {
+                testPassed("The two long-lived cookies expire after more than " + overOneDayInSeconds + " seconds.");
+            } else
+                testFailed("At least one cookie's expiry attribute was below the test thresholds.");
+        } else
+            testFailed("No internals object.");
+
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function navigateCrossOrigin() {
+        document.location.href = prevalentResourceOrigin + "/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-decoration-same-site.html?link=decoration#fragment";
+    }
+
+    const destinationOrigin = "http://localhost:8000";
+    const prevalentResourceOrigin = "http://127.0.0.1:8000";
+    function runTest() {
+        if (document.location.origin === prevalentResourceOrigin && document.location.hash !== "#fragment") {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function () {
+                testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(prevalentResourceOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(navigateCrossOrigin);
+                });
+
+            });
+        } else {
+            testCookies();
+        }
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database-expected.txt
new file mode 100644 (file)
index 0000000..f7bad03
--- /dev/null
@@ -0,0 +1,11 @@
+Check that cookies created by JavaScript after a cross-site navigation with link fragment get capped to 24 hours.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS The two short-lived cookies don't expire after more than 43230 seconds.
+PASS The two long-lived cookies don't expire after more than 86430 seconds.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database.html b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource-database.html
new file mode 100644 (file)
index 0000000..5c84fb8
--- /dev/null
@@ -0,0 +1,101 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="/cookies/resources/cookie-utilities.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body onload="setTimeout('runTest()', 0)">
+<script>
+    description("Check that cookies created by JavaScript after a cross-site navigation with link fragment get capped to 24 hours.");
+    jsTestIsAsync = true;
+
+    function testCookies() {
+        let passedTests = 0;
+        function checkThatCookieDoesNotExpireAfter(cookieData, maxAgeInSeconds) {
+            let now = new Date();
+            let maxExpiryDateInMilliseconds = now.getTime() + (maxAgeInSeconds * 1000);
+
+            if (maxExpiryDateInMilliseconds > cookieData["expires"])
+                ++passedTests;
+            else
+                testFailed("Cookie named " + cookieData["name"] + " expires in more than " + maxAgeInSeconds + " seconds.");
+        }
+
+        const twelveHoursInSeconds = 12 * 60 * 60;
+        const shortLivedCookieMaxAge = { name : "shortLivedCookieMaxAge", lifetime : "Max-Age=" + twelveHoursInSeconds + ";" };
+        document.cookie = shortLivedCookieMaxAge.name + "=foobar; " + shortLivedCookieMaxAge.lifetime + " path=/";
+
+        const twelveHoursAsExpiresDate = createExpiresDateFromMaxAge(twelveHoursInSeconds);
+        const shortLivedCookieExpires = { name : "shortLivedCookieExpires", lifetime : "Expires=" + twelveHoursAsExpiresDate + ";" };
+        document.cookie = shortLivedCookieExpires.name + "=foobar; " + shortLivedCookieExpires.lifetime + " path=/";
+
+        const oneDayInSeconds = 2 * twelveHoursInSeconds;
+        const twoDaysInSeconds = 2 * oneDayInSeconds;
+        const longLivedCookieMaxAge = { name : "longLivedCookieMaxAge", lifetime : "Max-Age=" + twoDaysInSeconds + ";" };
+        document.cookie = longLivedCookieMaxAge.name + "=foobar; " + longLivedCookieMaxAge.lifetime + " path=/";
+
+        const twoDaysAsExpiresDate = createExpiresDateFromMaxAge(twoDaysInSeconds);
+        const longLivedCookieExpires = { name : "longLivedCookieExpires", lifetime : "Expires=" + twoDaysAsExpiresDate + ";" };
+        document.cookie = longLivedCookieExpires.name + "=foobar; " + longLivedCookieExpires.lifetime + " path=/";
+
+        const overTwelveHoursInSeconds = twelveHoursInSeconds + 30;
+        const overOneDayInSeconds = oneDayInSeconds + 30;
+        if (internals) {
+            let cookies = internals.getCookies();
+            if (!cookies.length)
+                testFailed("No cookies found.");
+            for (let cookie of cookies) {
+                switch (cookie.name) {
+                    case shortLivedCookieMaxAge.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overTwelveHoursInSeconds);
+                        break;
+                    case shortLivedCookieExpires.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overTwelveHoursInSeconds);
+                        break;
+                    case longLivedCookieMaxAge.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                    case longLivedCookieExpires.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                }
+            }
+
+            resetCookiesForCurrentOrigin();
+
+            if (passedTests === 4) {
+                testPassed("The two short-lived cookies don't expire after more than " + overTwelveHoursInSeconds + " seconds.");
+                testPassed("The two long-lived cookies don't expire after more than " + overOneDayInSeconds + " seconds.");
+            } else
+                testFailed("At least one cookie's expiry attribute was beyond the test thresholds.");
+        } else
+            testFailed("No internals object.");
+
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function navigateCrossOrigin() {
+        document.location.href = destinationOrigin + "/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-fragment-from-prevalent-resource.html#link=fragment";
+    }
+
+    const destinationOrigin = "http://localhost:8000";
+    const prevalentResourceOrigin = "http://127.0.0.1:8000";
+    function runTest() {
+        if (document.location.origin === prevalentResourceOrigin) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function () {
+                testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(prevalentResourceOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(navigateCrossOrigin);
+                });
+
+            });
+        } else {
+            testCookies();
+        }
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database-expected.txt
new file mode 100644 (file)
index 0000000..6e98dc8
--- /dev/null
@@ -0,0 +1,11 @@
+Check that cookies created by JavaScript after a cross-site navigation with link query and fragment get capped to 24 hours.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS The two short-lived cookies don't expire after more than 43230 seconds.
+PASS The two long-lived cookies don't expire after more than 86430 seconds.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database.html b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource-database.html
new file mode 100644 (file)
index 0000000..3591eb4
--- /dev/null
@@ -0,0 +1,101 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="/cookies/resources/cookie-utilities.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body onload="setTimeout('runTest()', 0)">
+<script>
+    description("Check that cookies created by JavaScript after a cross-site navigation with link query and fragment get capped to 24 hours.");
+    jsTestIsAsync = true;
+
+    function testCookies() {
+        let passedTests = 0;
+        function checkThatCookieDoesNotExpireAfter(cookieData, maxAgeInSeconds) {
+            let now = new Date();
+            let maxExpiryDateInMilliseconds = now.getTime() + (maxAgeInSeconds * 1000);
+
+            if (maxExpiryDateInMilliseconds > cookieData["expires"])
+                ++passedTests;
+            else
+                testFailed("Cookie named " + cookieData["name"] + " expires in more than " + maxAgeInSeconds + " seconds.");
+        }
+
+        const twelveHoursInSeconds = 12 * 60 * 60;
+        const shortLivedCookieMaxAge = { name : "shortLivedCookieMaxAge", lifetime : "Max-Age=" + twelveHoursInSeconds + ";" };
+        document.cookie = shortLivedCookieMaxAge.name + "=foobar; " + shortLivedCookieMaxAge.lifetime + " path=/";
+
+        const twelveHoursAsExpiresDate = createExpiresDateFromMaxAge(twelveHoursInSeconds);
+        const shortLivedCookieExpires = { name : "shortLivedCookieExpires", lifetime : "Expires=" + twelveHoursAsExpiresDate + ";" };
+        document.cookie = shortLivedCookieExpires.name + "=foobar; " + shortLivedCookieExpires.lifetime + " path=/";
+
+        const oneDayInSeconds = 2 * twelveHoursInSeconds;
+        const twoDaysInSeconds = 2 * oneDayInSeconds;
+        const longLivedCookieMaxAge = { name : "longLivedCookieMaxAge", lifetime : "Max-Age=" + twoDaysInSeconds + ";" };
+        document.cookie = longLivedCookieMaxAge.name + "=foobar; " + longLivedCookieMaxAge.lifetime + " path=/";
+
+        const twoDaysAsExpiresDate = createExpiresDateFromMaxAge(twoDaysInSeconds);
+        const longLivedCookieExpires = { name : "longLivedCookieExpires", lifetime : "Expires=" + twoDaysAsExpiresDate + ";" };
+        document.cookie = longLivedCookieExpires.name + "=foobar; " + longLivedCookieExpires.lifetime + " path=/";
+
+        const overTwelveHoursInSeconds = twelveHoursInSeconds + 30;
+        const overOneDayInSeconds = oneDayInSeconds + 30;
+        if (internals) {
+            let cookies = internals.getCookies();
+            if (!cookies.length)
+                testFailed("No cookies found.");
+            for (let cookie of cookies) {
+                switch (cookie.name) {
+                    case shortLivedCookieMaxAge.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overTwelveHoursInSeconds);
+                        break;
+                    case shortLivedCookieExpires.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overTwelveHoursInSeconds);
+                        break;
+                    case longLivedCookieMaxAge.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                    case longLivedCookieExpires.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                }
+            }
+
+            resetCookiesForCurrentOrigin();
+
+            if (passedTests === 4) {
+                testPassed("The two short-lived cookies don't expire after more than " + overTwelveHoursInSeconds + " seconds.");
+                testPassed("The two long-lived cookies don't expire after more than " + overOneDayInSeconds + " seconds.");
+            } else
+                testFailed("At least one cookie's expiry attribute was beyond the test thresholds.");
+        } else
+            testFailed("No internals object.");
+
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function navigateCrossOrigin() {
+        document.location.href = destinationOrigin + "/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-and-fragment-from-prevalent-resource.html?link=query#link=fragment";
+    }
+
+    const destinationOrigin = "http://localhost:8000";
+    const prevalentResourceOrigin = "http://127.0.0.1:8000";
+    function runTest() {
+        if (document.location.origin === prevalentResourceOrigin) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function () {
+                testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(prevalentResourceOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(navigateCrossOrigin);
+                });
+
+            });
+        } else {
+            testCookies();
+        }
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database-expected.txt
new file mode 100644 (file)
index 0000000..d45dd16
--- /dev/null
@@ -0,0 +1,11 @@
+Check that cookies created by JavaScript after a cross-site navigation with link query get capped to 24 hours.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS The two short-lived cookies don't expire after more than 43230 seconds.
+PASS The two long-lived cookies don't expire after more than 86430 seconds.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database.html b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource-database.html
new file mode 100644 (file)
index 0000000..25f0976
--- /dev/null
@@ -0,0 +1,101 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="/cookies/resources/cookie-utilities.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body onload="setTimeout('runTest()', 0)">
+<script>
+    description("Check that cookies created by JavaScript after a cross-site navigation with link query get capped to 24 hours.");
+    jsTestIsAsync = true;
+
+    function testCookies() {
+        let passedTests = 0;
+        function checkThatCookieDoesNotExpireAfter(cookieData, maxAgeInSeconds) {
+            let now = new Date();
+            let maxExpiryDateInMilliseconds = now.getTime() + (maxAgeInSeconds * 1000);
+
+            if (maxExpiryDateInMilliseconds > cookieData["expires"])
+                ++passedTests;
+            else
+                testFailed("Cookie named " + cookieData["name"] + " expires in more than " + maxAgeInSeconds + " seconds.");
+        }
+
+        const twelveHoursInSeconds = 12 * 60 * 60;
+        const shortLivedCookieMaxAge = { name : "shortLivedCookieMaxAge", lifetime : "Max-Age=" + twelveHoursInSeconds + ";" };
+        document.cookie = shortLivedCookieMaxAge.name + "=foobar; " + shortLivedCookieMaxAge.lifetime + " path=/";
+
+        const twelveHoursAsExpiresDate = createExpiresDateFromMaxAge(twelveHoursInSeconds);
+        const shortLivedCookieExpires = { name : "shortLivedCookieExpires", lifetime : "Expires=" + twelveHoursAsExpiresDate + ";" };
+        document.cookie = shortLivedCookieExpires.name + "=foobar; " + shortLivedCookieExpires.lifetime + " path=/";
+
+        const oneDayInSeconds = 2 * twelveHoursInSeconds;
+        const twoDaysInSeconds = 2 * oneDayInSeconds;
+        const longLivedCookieMaxAge = { name : "longLivedCookieMaxAge", lifetime : "Max-Age=" + twoDaysInSeconds + ";" };
+        document.cookie = longLivedCookieMaxAge.name + "=foobar; " + longLivedCookieMaxAge.lifetime + " path=/";
+
+        const twoDaysAsExpiresDate = createExpiresDateFromMaxAge(twoDaysInSeconds);
+        const longLivedCookieExpires = { name : "longLivedCookieExpires", lifetime : "Expires=" + twoDaysAsExpiresDate + ";" };
+        document.cookie = longLivedCookieExpires.name + "=foobar; " + longLivedCookieExpires.lifetime + " path=/";
+
+        const overTwelveHoursInSeconds = twelveHoursInSeconds + 30;
+        const overOneDayInSeconds = oneDayInSeconds + 30;
+        if (internals) {
+            let cookies = internals.getCookies();
+            if (!cookies.length)
+                testFailed("No cookies found.");
+            for (let cookie of cookies) {
+                switch (cookie.name) {
+                    case shortLivedCookieMaxAge.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overTwelveHoursInSeconds);
+                        break;
+                    case shortLivedCookieExpires.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overTwelveHoursInSeconds);
+                        break;
+                    case longLivedCookieMaxAge.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                    case longLivedCookieExpires.name:
+                        checkThatCookieDoesNotExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                }
+            }
+
+            resetCookiesForCurrentOrigin();
+
+            if (passedTests === 4) {
+                testPassed("The two short-lived cookies don't expire after more than " + overTwelveHoursInSeconds + " seconds.");
+                testPassed("The two long-lived cookies don't expire after more than " + overOneDayInSeconds + " seconds.");
+            } else
+                testFailed("At least one cookie's expiry attribute was beyond the test thresholds.");
+        } else
+            testFailed("No internals object.");
+        
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function navigateCrossOrigin() {
+        document.location.href = destinationOrigin + "/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-with-link-query-from-prevalent-resource.html?link=query";
+    }
+
+    const destinationOrigin = "http://localhost:8000";
+    const prevalentResourceOrigin = "http://127.0.0.1:8000";
+    function runTest() {
+        if (document.location.origin === prevalentResourceOrigin) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function () {
+                testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(prevalentResourceOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(navigateCrossOrigin);
+                });
+
+            });
+        } else {
+            testCookies();
+        }
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database-expected.txt
new file mode 100644 (file)
index 0000000..3bf649a
--- /dev/null
@@ -0,0 +1,10 @@
+Check that cookies created by JavaScript after a cross-site navigation without link decoration don't get capped to 24 hours.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS The two long-lived cookies expire after more than 86430 seconds.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database.html b/LayoutTests/http/tests/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource-database.html
new file mode 100644 (file)
index 0000000..ae47b49
--- /dev/null
@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="/cookies/resources/cookie-utilities.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body onload="setTimeout('runTest()', 0)">
+<script>
+    description("Check that cookies created by JavaScript after a cross-site navigation without link decoration don't get capped to 24 hours.");
+    jsTestIsAsync = true;
+
+    function testCookies() {
+        let passedTests = 0;
+
+        function checkThatCookieDoesExpireAfter(cookieData, maxAgeInSeconds) {
+            let now = new Date();
+            let maxExpiryDateInMilliseconds = now.getTime() + (maxAgeInSeconds * 1000);
+
+            if (maxExpiryDateInMilliseconds < cookieData["expires"])
+                ++passedTests;
+            else
+                testFailed("Cookie named " + cookieData["name"] + " expires in less than " + maxAgeInSeconds + " seconds.");
+        }
+
+        const oneDayInSeconds = 24 * 60 * 60;
+        const twoDaysInSeconds = 2 * oneDayInSeconds;
+        const longLivedCookieMaxAge = { name : "longLivedCookieMaxAge", lifetime : "Max-Age=" + twoDaysInSeconds + ";" };
+        document.cookie = longLivedCookieMaxAge.name + "=foobar; " + longLivedCookieMaxAge.lifetime + " path=/";
+
+        const twoDaysAsExpiresDate = createExpiresDateFromMaxAge(twoDaysInSeconds);
+        const longLivedCookieExpires = { name : "longLivedCookieExpires", lifetime : "Expires=" + twoDaysAsExpiresDate + ";" };
+        document.cookie = longLivedCookieExpires.name + "=foobar; " + longLivedCookieExpires.lifetime + " path=/";
+
+        const overOneDayInSeconds = oneDayInSeconds + 30;
+        if (internals) {
+            let cookies = internals.getCookies();
+            if (!cookies.length)
+                testFailed("No cookies found.");
+            for (let cookie of cookies) {
+                switch (cookie.name) {
+                    case longLivedCookieMaxAge.name:
+                        checkThatCookieDoesExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                    case longLivedCookieExpires.name:
+                        checkThatCookieDoesExpireAfter(cookie, overOneDayInSeconds);
+                        break;
+                }
+            }
+
+            resetCookiesForCurrentOrigin();
+
+            if (passedTests === 2) {
+                testPassed("The two long-lived cookies expire after more than " + overOneDayInSeconds + " seconds.");
+            } else
+                testFailed("At least one cookie's expiry attribute was below the test thresholds.");
+        } else
+            testFailed("No internals object.");
+            
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function navigateCrossOrigin() {
+        document.location.href = destinationOrigin + "/resourceLoadStatistics/capped-lifetime-for-cookie-set-in-js-without-link-decoration-from-prevalent-resource.html";
+    }
+
+    const destinationOrigin = "http://localhost:8000";
+    const prevalentResourceOrigin = "http://127.0.0.1:8000";
+    function runTest() {
+        if (document.location.origin === prevalentResourceOrigin) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function () {
+                testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(prevalentResourceOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(navigateCrossOrigin);
+                });
+
+            });
+        } else {
+            testCookies();
+        }
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database-expected.txt
new file mode 100644 (file)
index 0000000..20c258b
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Host did not get classified as prevalent resource.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics-database.html
new file mode 100644 (file)
index 0000000..4e03fd8
--- /dev/null
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Classification Based on Mixed Statistics</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+
+    function completeTest() {
+        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host classified as prevalent resource.");
+        else
+            testPassed("Host did not get classified as prevalent resource.");
+
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin3);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        runTestRunnerTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt
new file mode 100644 (file)
index 0000000..20c258b
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Host did not get classified as prevalent resource.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins-database.html
new file mode 100644 (file)
index 0000000..b854090
--- /dev/null
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Classification Based on Sub Frame Under Top Frame Origins</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+
+    function completeTest() {
+        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host classified as prevalent resource.");
+        else
+            testPassed("Host did not get classified as prevalent resource.");
+
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin3);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+            testRunner.installStatisticsDidModifyDataRecordsCallback(completeTest);
+
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        runTestRunnerTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt
new file mode 100644 (file)
index 0000000..20c258b
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Host did not get classified as prevalent resource.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins-database.html
new file mode 100644 (file)
index 0000000..161120a
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Classification Based on Subresource Under Top Frame Origins</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+
+    function completeTest() {
+        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host classified as prevalent resource.");
+        else
+            testPassed("Host did not get classified as prevalent resource.");
+
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        runTestRunnerTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt
new file mode 100644 (file)
index 0000000..20c258b
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Host did not get classified as prevalent resource.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to-database.html
new file mode 100644 (file)
index 0000000..1a5a5d4
--- /dev/null
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Classification Based on Subresource Unique Redirects To</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+
+    function completeTest() {
+        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host classified as prevalent resource.");
+        else
+            testPassed("Host did not get classified as prevalent resource.");
+
+        internals.setResourceLoadStatisticsEnabled(false);
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin2);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        runTestRunnerTest();
+        testRunner.setUseITPDatabase(false);
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database-expected.txt
new file mode 100644 (file)
index 0000000..32dd69f
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Host classified as prevalent resource.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics-database.html
new file mode 100644 (file)
index 0000000..3897319
--- /dev/null
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Classification Based on Mixed Statistics</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+    const topFrameOrigin4 = "http://127.0.0.5:8000/temp";
+
+    function completeTest() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get classified as prevalent resource.");
+        if (testRunner.isStatisticsVeryPrevalentResource(statisticsUrl))
+            testFailed("Host got classified as very prevalent resource.");
+        else
+            testPassed("Host classified as prevalent resource.");
+
+        internals.setResourceLoadStatisticsEnabled(false);
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin4);
+
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin3);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin4);
+
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin3);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin1);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        runTestRunnerTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database-expected.txt
new file mode 100644 (file)
index 0000000..32dd69f
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Host classified as prevalent resource.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins-database.html
new file mode 100644 (file)
index 0000000..7ea7620
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Classification Based on Sub Frame Under Top Frame Origins</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+    const topFrameOrigin4 = "http://127.0.0.5:8000/temp";
+
+    function completeTest() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get classified as prevalent resource.");
+        if (testRunner.isStatisticsVeryPrevalentResource(statisticsUrl))
+            testFailed("Host got classified as very prevalent resource.");
+        else
+            testPassed("Host classified as prevalent resource.");
+
+        internals.setResourceLoadStatisticsEnabled(false);
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin3);
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin4);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        runTestRunnerTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database-expected.txt
new file mode 100644 (file)
index 0000000..e4ddce5
--- /dev/null
@@ -0,0 +1,14 @@
+Tests for classification based on subresource redirect collusion.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Colluding host 1 got set as prevalent resource.
+PASS Colluding host 2 got set as prevalent resource.
+PASS Colluding host 3 got set as prevalent resource.
+PASS Colluding host 4 got set as prevalent resource.
+PASS Colluding localhost got set as prevalent resource after actual sub frame redirect.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-collusion-database.html
new file mode 100644 (file)
index 0000000..e4bfb2f
--- /dev/null
@@ -0,0 +1,71 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Tests for classification based on subresource redirect collusion.");
+    jsTestIsAsync = true;
+
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const subresourceOrigin1 = "http://127.0.0.2:8000/temp";
+    const subresourceOrigin2 = "http://127.0.0.3:8000/temp";
+    const subresourceOrigin3 = "http://127.0.0.4:8000/temp";
+    const subresourceOrigin4 = "http://127.0.0.5:8000/temp";
+
+    function runTest() {
+        testRunner.statisticsNotifyObserver();
+
+        testRunner.setStatisticsSubresourceUniqueRedirectFrom(statisticsUrl, subresourceOrigin1);
+        testRunner.setStatisticsSubresourceUniqueRedirectFrom(subresourceOrigin1, subresourceOrigin2);
+        testRunner.setStatisticsSubresourceUniqueRedirectFrom(subresourceOrigin2, subresourceOrigin3);
+        testRunner.setStatisticsSubresourceUniqueRedirectFrom(subresourceOrigin3, subresourceOrigin4);
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
+            if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host explicity set did not get set as prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource(subresourceOrigin1))
+                testPassed("Colluding host 1 got set as prevalent resource.");
+            if (testRunner.isStatisticsVeryPrevalentResource(subresourceOrigin1))
+                testFailed("Colluding host 1 got classified as very prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource(subresourceOrigin2))
+                testPassed("Colluding host 2 got set as prevalent resource.");
+            if (testRunner.isStatisticsVeryPrevalentResource(subresourceOrigin2))
+                testFailed("Colluding host 2 got classified as very prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource(subresourceOrigin3))
+                testPassed("Colluding host 3 got set as prevalent resource.");
+            if (testRunner.isStatisticsVeryPrevalentResource(subresourceOrigin3))
+                testFailed("Colluding host 3 got classified as very prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource(subresourceOrigin4))
+                testPassed("Colluding host 4 got set as prevalent resource.");
+            if (testRunner.isStatisticsVeryPrevalentResource(subresourceOrigin4))
+                testFailed("Colluding host 4 got classified as very prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource("http://localhost:8000"))
+                testPassed("Colluding localhost got set as prevalent resource after actual sub frame redirect.");
+            if (testRunner.isStatisticsVeryPrevalentResource("http://localhost:8000"))
+                testFailed("Colluding localhost got classified as very prevalent resource.");
+            
+            setEnableFeature(false, finishJSTest);
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function () {
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+                if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                    testFailed("Host did not get set as non-prevalent resource.");
+                let iframeElement = document.createElement("iframe");
+                iframeElement.onload = runTest;
+                iframeElement.src = "http://localhost:8000/resourceLoadStatistics/resources/redirect.php?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/onclick.html";
+                document.body.appendChild(iframeElement);
+            });
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database-expected.txt
new file mode 100644 (file)
index 0000000..b8fcbd8
--- /dev/null
@@ -0,0 +1,10 @@
+Tests for classification based on subresource redirect to other prevalent.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Host classified as prevalent resource.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-redirect-to-prevalent-database.html
new file mode 100644 (file)
index 0000000..5580a59
--- /dev/null
@@ -0,0 +1,51 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Tests for classification based on subresource redirect to other prevalent.");
+    jsTestIsAsync = true;
+
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+
+    function completeTest() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get classified as prevalent resource.");
+        else if (testRunner.isStatisticsVeryPrevalentResource(statisticsUrl))
+            testFailed("Host got classified as very prevalent resource.");
+        else
+            testPassed("Host classified as prevalent resource.");
+            
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function runTest() {
+        testRunner.setStatisticsPrevalentResource(topFrameOrigin1, true, function() {
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin1);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+                if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                    testFailed("Host did not get set as non-prevalent resource.");
+                runTest();
+            });
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database-expected.txt
new file mode 100644 (file)
index 0000000..32dd69f
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Host classified as prevalent resource.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins-database.html
new file mode 100644 (file)
index 0000000..2d01ea6
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Classification Based on Subresource Under Top Frame Origins</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+    const topFrameOrigin4 = "http://127.0.0.5:8000/temp";
+
+    function completeTest() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get classified as prevalent resource.");
+        if (testRunner.isStatisticsVeryPrevalentResource(statisticsUrl))
+            testFailed("Host got classified as very prevalent resource.");
+        else
+            testPassed("Host classified as prevalent resource.");
+
+        internals.setResourceLoadStatisticsEnabled(false);
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin3);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin4);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        runTestRunnerTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database-expected.txt
new file mode 100644 (file)
index 0000000..32dd69f
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Host classified as prevalent resource.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to-database.html
new file mode 100644 (file)
index 0000000..78f7f13
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Classification Based on Subresource Unique Redirects To</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+    const topFrameOrigin4 = "http://127.0.0.5:8000/temp";
+
+    function completeTest() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get classified as prevalent resource.");
+        if (testRunner.isStatisticsVeryPrevalentResource(statisticsUrl))
+            testFailed("Host got classified as very prevalent resource.");
+        else
+            testPassed("Host classified as prevalent resource.");
+
+        internals.setResourceLoadStatisticsEnabled(false);
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin2);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin3);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin4);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        runTestRunnerTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database-expected.txt
new file mode 100644 (file)
index 0000000..fd3938b
--- /dev/null
@@ -0,0 +1,14 @@
+Tests for classification based on top frame redirect collusion.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Colluding host 1 got set as prevalent resource.
+PASS Colluding host 2 got set as prevalent resource.
+PASS Colluding host 3 got set as prevalent resource.
+PASS Colluding host 4 got set as prevalent resource.
+PASS Colluding localhost got set as prevalent resource after actual navigational redirect.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion-database.html
new file mode 100644 (file)
index 0000000..4a983bc
--- /dev/null
@@ -0,0 +1,71 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Tests for classification based on top frame redirect collusion.");
+    jsTestIsAsync = true;
+
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+    const topFrameOrigin4 = "http://127.0.0.5:8000/temp";
+    const topFrameOrigin5 = "http://localhost:8000/";
+
+    function runTest() {
+        testRunner.setStatisticsTopFrameUniqueRedirectFrom(statisticsUrl, topFrameOrigin1);
+        testRunner.setStatisticsTopFrameUniqueRedirectFrom(topFrameOrigin1, topFrameOrigin2);
+        testRunner.setStatisticsTopFrameUniqueRedirectFrom(topFrameOrigin2, topFrameOrigin3);
+        testRunner.setStatisticsTopFrameUniqueRedirectFrom(topFrameOrigin3, topFrameOrigin4);
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
+            if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host explicity set did not get set as prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource(topFrameOrigin1))
+                testPassed("Colluding host 1 got set as prevalent resource.");
+            if (testRunner.isStatisticsVeryPrevalentResource(topFrameOrigin1))
+                testFailed("Colluding host 1 got classified as very prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource(topFrameOrigin2))
+                testPassed("Colluding host 2 got set as prevalent resource.");
+            if (testRunner.isStatisticsVeryPrevalentResource(topFrameOrigin2))
+                testFailed("Colluding host 2 got classified as very prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource(topFrameOrigin3))
+                testPassed("Colluding host 3 got set as prevalent resource.");
+            if (testRunner.isStatisticsVeryPrevalentResource(topFrameOrigin3))
+                testFailed("Colluding host 3 got classified as very prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource(topFrameOrigin4))
+                testPassed("Colluding host 4 got set as prevalent resource.");
+            if (testRunner.isStatisticsVeryPrevalentResource(topFrameOrigin4))
+                testFailed("Colluding host 4 got classified as very prevalent resource.");
+            if (testRunner.isStatisticsPrevalentResource(topFrameOrigin5))
+                testPassed("Colluding localhost got set as prevalent resource after actual navigational redirect.");
+            if (testRunner.isStatisticsVeryPrevalentResource(topFrameOrigin5))
+                testFailed("Colluding localhost got classified as very prevalent resource.");
+            
+            setEnableFeature(false, finishJSTest);
+        });
+    }
+
+    if (document.location.hash === "" && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+                if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                    testFailed("Host did not get set as non-prevalent resource.");
+
+                document.location.href = topFrameOrigin5 + "resourceLoadStatistics/resources/redirect.php?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-collusion.html#continue";
+            });
+        });
+    } else {
+        testRunner.statisticsNotifyObserver();
+        runTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database-expected.txt
new file mode 100644 (file)
index 0000000..59f9953
--- /dev/null
@@ -0,0 +1,10 @@
+Tests for classification based on top frame redirect to other prevalent.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Host classified as prevalent resource.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-redirect-to-prevalent-database.html
new file mode 100644 (file)
index 0000000..292c751
--- /dev/null
@@ -0,0 +1,51 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Tests for classification based on top frame redirect to other prevalent.");
+    jsTestIsAsync = true;
+
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+
+    function completeTest() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get classified as prevalent resource.");
+        else if (testRunner.isStatisticsVeryPrevalentResource(statisticsUrl))
+            testFailed("Host got classified as very prevalent resource.");
+        else
+            testPassed("Host classified as prevalent resource.");
+        
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function runTest() {
+        testRunner.setStatisticsPrevalentResource(topFrameOrigin1, true, function() {
+            testRunner.setStatisticsTopFrameUniqueRedirectTo(statisticsUrl, topFrameOrigin1);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+                if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                    testFailed("Host did not get set as non-prevalent resource.");
+                runTest();
+            });
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database-expected.txt
new file mode 100644 (file)
index 0000000..a491bf9
--- /dev/null
@@ -0,0 +1,10 @@
+Tests for classification based on top frame unique redirects to.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Host classified as prevalent resource.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-prevalent-based-on-top-frame-unique-redirects-to-database.html
new file mode 100644 (file)
index 0000000..5c4c7ee
--- /dev/null
@@ -0,0 +1,56 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Tests for classification based on top frame unique redirects to.");
+    jsTestIsAsync = true;
+
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+    const topFrameOrigin4 = "http://127.0.0.5:8000/temp";
+
+    function completeTest() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get classified as prevalent resource.");
+        if (testRunner.isStatisticsVeryPrevalentResource(statisticsUrl))
+            testFailed("Host got classified as very prevalent resource.");
+        else
+            testPassed("Host classified as prevalent resource.");
+
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function runTest() {
+        testRunner.setStatisticsTopFrameUniqueRedirectTo(statisticsUrl, topFrameOrigin1);
+        testRunner.setStatisticsTopFrameUniqueRedirectTo(statisticsUrl, topFrameOrigin2);
+        testRunner.setStatisticsTopFrameUniqueRedirectTo(statisticsUrl, topFrameOrigin3);
+        testRunner.setStatisticsTopFrameUniqueRedirectTo(statisticsUrl, topFrameOrigin4);
+
+        testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+
+        testRunner.statisticsProcessStatisticsAndDataRecords();
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+            testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+                if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                    testFailed("Host did not get set as non-prevalent resource.");
+                runTest();
+            });
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database-expected.txt
new file mode 100644 (file)
index 0000000..b0f031d
--- /dev/null
@@ -0,0 +1,10 @@
+Test for classification as very prevalent based on mixed statistics.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Host classified as very prevalent resource.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database.html b/LayoutTests/http/tests/resourceLoadStatistics/classify-as-very-prevalent-based-on-mixed-statistics-database.html
new file mode 100644 (file)
index 0000000..ab06fa2
--- /dev/null
@@ -0,0 +1,66 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Test for classification as very prevalent based on mixed statistics.");
+    jsTestIsAsync = true;
+
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    var topFrameOrigins = [];
+    const startNum = 2;
+    const numberOfSubresourceDomains = 30;
+    for (var i = startNum; i < numberOfSubresourceDomains + startNum; ++i)
+        topFrameOrigins.push("http://127.0.0." + i + ":8000/temp")
+
+    function completeTest() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get classified as prevalent resource.");
+        if (!testRunner.isStatisticsVeryPrevalentResource(statisticsUrl))
+            testFailed("Host did not get classified as very prevalent resource.");
+        else
+            testPassed("Host classified as very prevalent resource.");
+
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host started out as prevalent resource.");
+
+            var i = 0;
+            while (i < numberOfSubresourceDomains) {
+                testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigins[i]);
+                testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigins[i]);
+                testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigins[i]);
+
+                testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigins[i+1]);
+                testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigins[i+1]);
+                testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigins[i+1]);
+
+                testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigins[i+2]);
+                testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigins[i+2]);
+                testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigins[i+2]);
+                i += 3;
+            }
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, runTestRunnerTest);
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database-expected.txt
new file mode 100644 (file)
index 0000000..bae0033
--- /dev/null
@@ -0,0 +1,11 @@
+Tests clearing of website data store.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Host classified as prevalent resource.
+PASS Host is no longer a prevalent resource after the store was cleared.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database.html b/LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-database.html
new file mode 100644 (file)
index 0000000..217ebab
--- /dev/null
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Test Cleared Store</title>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    description("Tests clearing of website data store.");
+    jsTestIsAsync = true;
+
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+
+    function testStep2() {
+        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testPassed("Host classified as prevalent resource.");
+        else
+            testFailed("Host did not get classified as prevalent resource.");
+
+        testRunner.statisticsClearInMemoryAndPersistentStore(completeTest);
+    }
+
+    function completeTest() {
+        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host is still a prevalent resource after the store was cleared.");
+        else
+            testPassed("Host is no longer a prevalent resource after the store was cleared.");
+
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+            testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+            testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin3);
+            testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin3);
+
+            testRunner.installStatisticsDidScanDataRecordsCallback(testStep2);
+
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function () {
+            runTestRunnerTest();
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database-expected.txt
new file mode 100644 (file)
index 0000000..07f999c
--- /dev/null
@@ -0,0 +1,11 @@
+Tests clearing of website data store (one hour).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Host classified as prevalent resource.
+PASS Host is no longer a prevalent resource after the store was cleared.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database.html b/LayoutTests/http/tests/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour-database.html
new file mode 100644 (file)
index 0000000..a6bb065
--- /dev/null
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title></title>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    description("Tests clearing of website data store (one hour).");
+    jsTestIsAsync = true;
+
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const topFrameOrigin1 = "http://127.0.0.2:8000/temp";
+    const topFrameOrigin2 = "http://127.0.0.3:8000/temp";
+    const topFrameOrigin3 = "http://127.0.0.4:8000/temp";
+
+    function completeTest() {
+        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host is still a prevalent resource after the store was cleared.");
+        else
+            testPassed("Host is no longer a prevalent resource after the store was cleared.");
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function testStep2() {
+        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testPassed("Host classified as prevalent resource.");
+        else
+            testFailed("Host did not get classified as prevalent resource.");
+
+        testRunner.statisticsClearInMemoryAndPersistentStoreModifiedSinceHours(1, completeTest);
+    }
+
+    function runTestRunnerTest() {
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {});
+        if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get set as non-prevalent resource.");
+
+        testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+        testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin1);
+        testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin1);
+        testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+        testRunner.setStatisticsSubframeUnderTopFrameOrigin(statisticsUrl, topFrameOrigin2);
+        testRunner.setStatisticsSubresourceUniqueRedirectTo(statisticsUrl, topFrameOrigin3);
+        testRunner.setStatisticsSubresourceUnderTopFrameOrigin(statisticsUrl, topFrameOrigin3);
+
+        testRunner.installStatisticsDidScanDataRecordsCallback(testStep2);
+
+        testRunner.statisticsProcessStatisticsAndDataRecords();
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function () {
+            runTestRunnerTest();
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/cookie-deletion-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/cookie-deletion-database-expected.txt
new file mode 100644 (file)
index 0000000..8b3fcfa
--- /dev/null
@@ -0,0 +1,55 @@
+Test for partitioned and unpartitioned cookie deletion.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+  
+
+--------
+Frame: '<!--frame1-->'
+--------
+Should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Did not receive cookie named 'thirdPartyCookie'.
+Client-side document.cookie: firstPartyCookie=value
+
+--------
+Frame: '<!--frame2-->'
+--------
+Should receive no cookies.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'thirdPartyCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--frame3-->'
+--------
+Try to set third party cookie.
+
+
+--------
+Frame: '<!--frame4-->'
+--------
+Should receive no cookies.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'thirdPartyCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--frame5-->'
+--------
+After removal, should receive no cookies.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'thirdPartyCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--frame6-->'
+--------
+After declassified, should receive no cookies.
+Did not receive cookie named 'firstPartyCookie'.
+Did not receive cookie named 'thirdPartyCookie'.
+Client-side document.cookie:
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/cookie-deletion-database.html b/LayoutTests/http/tests/resourceLoadStatistics/cookie-deletion-database.html
new file mode 100644 (file)
index 0000000..e834e87
--- /dev/null
@@ -0,0 +1,116 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Test for partitioned and unpartitioned cookie deletion.");
+    jsTestIsAsync = true;
+
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const thirdPartyBaseUrl = thirdPartyOrigin + "/resourceLoadStatistics/resources";
+    const firstPartyCookieName = "firstPartyCookie";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
+    const thirdPartyCookieName = "thirdPartyCookie";
+    const subPathToSetThirdPartyCookie = "/set-cookie.php?name=" + thirdPartyCookieName + "&value=value";
+    const fragmentWithReturnUrl = "http://" + partitionHost + "/resourceLoadStatistics/cookie-deletion.html";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName + "&name2=" + thirdPartyCookieName;
+
+    function finishTest() {
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+
+    function fireDataModificationHandlerAndContinue() {
+        testRunner.installStatisticsDidScanDataRecordsCallback(function() {
+            setTimeout(runTest, 500);
+        });
+        testRunner.statisticsProcessStatisticsAndDataRecords();
+    }
+
+    function setAsNonPrevalentAndContinue() {
+        testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                testFailed("Host still set as prevalent resource.");
+            testRunner.statisticsUpdateCookieBlocking(runTest);
+        });
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                // Set first-party cookie for localhost.
+                document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + fragmentWithReturnUrl + "#step2";
+                break;
+            case "#step2":
+                // Check that the third-party has access to its first-party cookies.
+                document.location.hash = "step3";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
+                break;
+            case "#step3":
+                // Classify localhost as prevalent.
+                document.location.hash = "step4";
+                testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                });
+                break;
+            case "#step4":
+                // Check that the third-party no longer has access to its first-party cookies.
+                document.location.hash = "step5";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive no cookies.", runTest);
+                break;
+            case "#step5":
+                // Try setting a cookie as third-party.
+                document.location.hash = "step6";
+                openIframe(thirdPartyBaseUrl + subPathToSetThirdPartyCookie + "&message=Try to set third party cookie.", runTest);
+                break;
+            case "#step6":
+                // Check that the third-party still has no access to cookies and then fire data record removal.
+                document.location.hash = "step7";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive no cookies.", fireDataModificationHandlerAndContinue);
+                break;
+            case "#step7":
+                // Check that the third-party still has no access to cookies and then declassify localhost.
+                document.location.hash = "step8";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After removal, should receive no cookies.", setAsNonPrevalentAndContinue);
+                break;
+            case "#step8":
+                // Check that the third-party still has no access to cookies.
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After declassified, should receive no cookies.", finishTest);
+                break;
+        }
+    }
+
+    if (document.location.host === partitionHost && document.location.hash === "" && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+            testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
+
+            runTest();
+        });
+    } else {
+        runTest();
+    }
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database-expected.txt
new file mode 100644 (file)
index 0000000..5d1092e
--- /dev/null
@@ -0,0 +1,25 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+  
+
+--------
+Frame: '<!--frame1-->'
+--------
+Should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Client-side document.cookie: firstPartyCookie=value
+
+--------
+Frame: '<!--frame2-->'
+--------
+Should receive no cookies.
+Did not receive cookie named 'firstPartyCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--frame3-->'
+--------
+After user interaction, should still receive no cookies.
+Did not receive cookie named 'firstPartyCookie'.
+Client-side document.cookie:
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database.html b/LayoutTests/http/tests/resourceLoadStatistics/cookies-with-and-without-user-interaction-database.html
new file mode 100644 (file)
index 0000000..9c7a39c
--- /dev/null
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Test for Partitioned Cookies With and Without User Interaction</title>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const thirdPartyBaseUrl = thirdPartyOrigin + "/resourceLoadStatistics/resources";
+    const firstPartyCookieName = "firstPartyCookie";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
+    const fragmentWithReturnUrl = "http://127.0.0.1:8000/resourceLoadStatistics/cookies-with-and-without-user-interaction.html";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName;
+
+    function finishTest() {
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    function setUserInteractionAndContinue() {
+        testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, true, function() {
+            if (!testRunner.isStatisticsHasHadUserInteraction(thirdPartyOrigin))
+                testFailed("Third party did not get logged for user interaction.");
+            runTest();
+        });
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + fragmentWithReturnUrl + "#step2";
+                break;
+            case "#step2":
+                document.location.hash = "step3";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
+                break;
+            case "#step3":
+                document.location.hash = "step4";
+                testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                });
+                break;
+            case "#step4":
+                document.location.hash = "step5";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive no cookies.", setUserInteractionAndContinue);
+                break;
+            case "#step5":
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=After user interaction, should still receive no cookies.", finishTest);
+                break;
+        }
+    }
+
+    if (document.location.host === partitionHost && document.location.hash == "" && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            testRunner.waitUntilDone();
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
+            if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                testFailed("Localhost was classified as prevalent resource before the test starts.");
+            runTest();
+        });
+    } else {
+        runTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database-expected.txt
new file mode 100644 (file)
index 0000000..63407dc
--- /dev/null
@@ -0,0 +1,14 @@
+Check that only HttpOnly cookies remain if all script-accessible cookies are deleted.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Before script-accessible deletion: Client-side cookie exists.
+PASS Before script-accessible deletion: HttpOnly cookie exists.
+PASS Before script-accessible deletion: Regular server-side cookie exists.
+PASS After script-accessible deletion:  HttpOnly cookie exists.
+PASS After full deletion:               All cookies are gone.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database.html b/LayoutTests/http/tests/resourceLoadStatistics/delete-script-accessible-cookies-database.html
new file mode 100644 (file)
index 0000000..60fc537
--- /dev/null
@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body onload="runTest()">
+<script>
+    description("Check that only HttpOnly cookies remain if all script-accessible cookies are deleted.");
+    jsTestIsAsync = true;
+
+    const httpOnlyCookieName = "http-only-cookie";
+    const serverSideCookieName = "server-side-cookie";
+    const clientSideCookieName = "client-side-cookie";
+
+    function sortStringArray(a, b) {
+        a = a.toLowerCase();
+        b = b.toLowerCase();
+
+        return a > b ? 1 : b > a ? -1 : 0;
+    }
+
+    function checkCookies(isAfterScriptAccessibleDeletion) {
+        let unsortedTestPassedMessages = [];
+        let cookies = internals.getCookies();
+        if (!cookies.length)
+            testFailed((isAfterScriptAccessibleDeletion ? "After" : "Before") + " script-accessible deletion: No cookies found.");
+        for (let cookie of cookies) {
+            switch (cookie.name) {
+                case httpOnlyCookieName:
+                    unsortedTestPassedMessages.push((isAfterScriptAccessibleDeletion ? "After" : "Before") + " script-accessible deletion: " + (isAfterScriptAccessibleDeletion ? " " : "") + "HttpOnly cookie exists.");
+                    break;
+                case serverSideCookieName:
+                    if (isAfterScriptAccessibleDeletion)
+                        testFailed("After script-accessible deletion:  Regular server-side cookie exists.");
+                    else
+                        unsortedTestPassedMessages.push("Before script-accessible deletion: Regular server-side cookie exists.");
+                    break;
+                case clientSideCookieName:
+                    if (isAfterScriptAccessibleDeletion)
+                        testFailed("After script-accessible deletion:  Client-side cookie exists.");
+                    else
+                        unsortedTestPassedMessages.push("Before script-accessible deletion: Client-side cookie exists.");
+                    break;
+            }
+        }
+        let sortedTestPassedMessages = unsortedTestPassedMessages.sort(sortStringArray);
+        for (let testPassedMessage of sortedTestPassedMessages)
+            testPassed(testPassedMessage);
+    }
+
+    async function runTest() {
+        if (!testRunner || !internals) {
+            testFailed("No testRunner or no internals.");
+            return;
+        }
+        testRunner.setUseITPDatabase(true);
+        await fetch("/cookies/resources/set-http-only-cookie.php?cookieName=" + httpOnlyCookieName, { credentials: "same-origin" });
+        await fetch("/cookies/resources/setCookies.cgi", { headers: { "Set-Cookie": serverSideCookieName + "=1; path=/;" }, credentials: "same-origin" });
+        document.cookie = clientSideCookieName + "=1";
+        checkCookies(false);
+        testRunner.statisticsDeleteCookiesForHost("http://127.0.0.1", false);
+        checkCookies(true);
+        testRunner.statisticsDeleteCookiesForHost("http://127.0.0.1", true);
+        let cookiesLeft = internals.getCookies().length;
+        if (cookiesLeft === 0)
+            testPassed("After full deletion:               All cookies are gone.");
+        else
+            testFailed("After full deletion:              " + cookiesLeft + " cookie(s) left.");
+        finishJSTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database-expected.txt
new file mode 100644 (file)
index 0000000..3743061
--- /dev/null
@@ -0,0 +1 @@
+PASSED: Cookie successfully set
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database.html b/LayoutTests/http/tests/resourceLoadStatistics/do-not-block-top-level-navigation-redirect-database.html
new file mode 100644 (file)
index 0000000..d219e3d
--- /dev/null
@@ -0,0 +1,30 @@
+<!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 blocking is not applied to top-level navigation redirects.");
+    jsTestIsAsync = true;
+
+    internals.setResourceLoadStatisticsEnabled(true);
+
+    function doRedirect()
+    {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function () {
+            testRunner.setStatisticsPrevalentResource("http://localhost", true, function () {
+                if (!testRunner.isStatisticsPrevalentResource("http://localhost")) {
+                    testFailed("Host did not get set as prevalent resource.");
+                    setEnableFeature(false, finishJSTest);
+                } else
+                    document.location.href = "http://localhost:8000/resourceLoadStatistics/resources/set-cookie-on-redirect.php?step=1";
+            });
+        });
+    }
+</script>
+</head>
+<body onload="setTimeout('doRedirect()', 0)">
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database-expected.txt
new file mode 100644 (file)
index 0000000..069c91c
--- /dev/null
@@ -0,0 +1,11 @@
+Test that a non-redirected top frame navigation doesn't get captured in statistics.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is false
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://127.0.0.1", "http://localhost") is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database.html b/LayoutTests/http/tests/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations-database.html
new file mode 100644 (file)
index 0000000..b80935a
--- /dev/null
@@ -0,0 +1,49 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Test that a non-redirected top frame navigation doesn't get captured in statistics.");
+    jsTestIsAsync = true;
+    testRunner.setUseITPDatabase(true);
+    let timerHandle = 0;
+
+    function finishTest() {
+        if (timerHandle)
+          clearTimeout(timerHandle);
+
+        shouldBeFalse('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+        shouldBeFalse('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://127.0.0.1", "http://localhost")');
+        setEnableFeature(false, finishJSTest);
+    }
+
+    function runTest() {
+        switch (document.location.host) {
+            case "127.0.0.1:8000":
+                setEnableFeature(true, function() {
+                    if (testRunner.isStatisticsPrevalentResource("http://localhost:8000"))
+                        testFailed("Localhost was classified as prevalent resource before the test starts.");
+                    document.location.href = "http://localhost:8000/resourceLoadStatistics/do-not-capture-statistics-for-simple-top-navigations.html";
+                });
+                break;
+            case "localhost:8000":
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(finishTest);
+                if (!testRunner.statisticsNotifyObserver())
+                    timerHandle = setTimeout(finishTest, 100);
+                break;
+            default:
+                testFailed("Unknown host: " + document.location.host);
+                finishTest();
+        }
+    }
+
+    if (window.testRunner && window.internals)
+        runTest();
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database-expected.txt
new file mode 100644 (file)
index 0000000..1ad7d9e
--- /dev/null
@@ -0,0 +1,51 @@
+Tests that blocking is not removed mid-flight in redirects.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+  
+
+--------
+Frame: '<!--frame1-->'
+--------
+Should receive first-party cookie for localhost.
+Did not receive cookie named 'firstPartyCookieIP'.
+Received cookie named 'firstPartyCookieLocalhost'.
+Did not receive cookie named 'thirdPartyCookie'.
+Client-side document.cookie: firstPartyCookieLocalhost=localhost
+
+--------
+Frame: '<!--frame2-->'
+--------
+Redirect case 1, should receive first-party cookie for 127.0.0.1.
+Received cookie named 'firstPartyCookieIP'.
+Did not receive cookie named 'firstPartyCookieLocalhost'.
+Did not receive cookie named 'thirdPartyCookie'.
+Client-side document.cookie: firstPartyCookieIP=127.0.0.1
+
+--------
+Frame: '<!--frame3-->'
+--------
+Try to set third-party cookie for localhost in blocked mode.
+
+
+--------
+Frame: '<!--frame4-->'
+--------
+Should receive no cookie.
+Did not receive cookie named 'firstPartyCookieIP'.
+Did not receive cookie named 'firstPartyCookieLocalhost'.
+Did not receive cookie named 'thirdPartyCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--frame5-->'
+--------
+Redirect case 2, should not receive first-party cookie for 127.0.0.1.
+Did not receive cookie named 'firstPartyCookieIP'.
+Did not receive cookie named 'firstPartyCookieLocalhost'.
+Did not receive cookie named 'thirdPartyCookie'.
+Client-side document.cookie: firstPartyCookieIP=127.0.0.1
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database.html b/LayoutTests/http/tests/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database.html
new file mode 100644 (file)
index 0000000..36d30aa
--- /dev/null
@@ -0,0 +1,100 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Tests that blocking is not removed mid-flight in redirects.");
+    jsTestIsAsync = true;
+
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const resourcePath = "/resourceLoadStatistics/resources";
+    const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath;
+    const firstPartyCookieNamePrefix = "firstPartyCookie";
+    const firstPartyCookieNameIP = firstPartyCookieNamePrefix + "IP";
+    const firstPartyCookieNameLocalhost = firstPartyCookieNamePrefix + "Localhost";
+    const thirdPartyCookieName = "thirdPartyCookie";
+    const subPathToSetThirdPartyCookie = "/set-cookie.php?name=" + thirdPartyCookieName + "&value=value";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieNameIP + "&name2=" + firstPartyCookieNameLocalhost + "&name3=" + thirdPartyCookieName;
+    const redirectChainUrl = thirdPartyOrigin + resourcePath + "/redirect.php?redirectTo=http://" + partitionHost + resourcePath + subPathToGetCookies;
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                // Set first-party cookies for 127.0.0.1 and localhost.
+                if (document.location.origin === thirdPartyOrigin) {
+                    document.cookie = firstPartyCookieNameLocalhost + "=localhost;path='/'";
+                    document.location.href = "http://127.0.0.1:8000/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database.html#step2";
+                } else {
+                    document.cookie = firstPartyCookieNameIP + "=127.0.0.1;path='/'";
+                    document.location.href = "http://localhost:8000/resourceLoadStatistics/do-not-remove-blocking-in-redirect-database.html#step1";
+                }
+                break;
+            case "#step2":
+                // Check that the cookie gets sent for localhost under 127.0.0.1 since localhost is not prevalent.
+                document.location.hash = "step3";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie for localhost.", runTest);
+                break;
+            case "#step3":
+                document.location.hash = "step4";
+                // Load an iframe in a redirect chain that starts with localhost and ends with 127.0.0.1. Expect a cookie for 127.0.0.1.
+                openIframe(redirectChainUrl + "&message=Redirect case 1, should receive first-party cookie for 127.0.0.1.", runTest);
+                break;
+            case "#step4":
+                // Set localhost as prevalent to put it in the blocking category.
+                document.location.hash = "step5";
+                testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                });
+                break;
+            case "#step5":
+                // Try to set partitioned cookie for localhost under 127.0.0.1.
+                document.location.hash = "step6";
+                openIframe(thirdPartyBaseUrl + subPathToSetThirdPartyCookie + "&message=Try to set third-party cookie for localhost in blocked mode.", runTest);
+                break;
+            case "#step6":
+                // Check that no cookie gets sent for localhost under 127.0.0.1 since localhost's cookies are blocked.
+                document.location.hash = "step7";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies +  "&message=Should receive no cookie.", runTest);
+                break;
+            case "#step7":
+                // Load an iframe in a redirect chain that starts with localhost and ends with 127.0.0.1. Expect a cookie for 127.0.0.1.
+                document.location.hash = "step8";
+                openIframe(redirectChainUrl + "&message=Redirect case 2, should not receive first-party cookie for 127.0.0.1.", runTest);
+                break;
+            case "#step8":
+                setEnableFeature(false, finishJSTest);
+                break;
+        }
+    }
+
+    if (document.location.hash === "") {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                testFailed("Localhost was classified as prevalent resource before the test starts.");
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
+            runTest();
+        });
+    } else {
+        runTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database-expected.txt
new file mode 100644 (file)
index 0000000..d05dc09
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that the session is not switched upon top frame navigation to a prevalent resource without user interaction.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Should have and has the session cookie.
+PASS Should have and has the persistent cookie.
+PASS Origin has no isolated session.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database.html b/LayoutTests/http/tests/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction-database.html
new file mode 100644 (file)
index 0000000..6abfdb9
--- /dev/null
@@ -0,0 +1,110 @@
+<!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>
+</head>
+<body onload="runTest()">
+<script>
+    description("Tests that the session is not switched upon top frame navigation to a prevalent resource without user interaction.");
+    jsTestIsAsync = true;
+
+    const prevalentOrigin = "http://127.0.0.1:8000";
+    const nonPrevalentOrigin = "http://localhost:8000";
+    const sessionCookieName = "sessionCookie";
+    const persistentCookieName = "persistentCookie";
+    const twoMinutesInSeconds = 120;
+
+    function setSessionCookie() {
+        document.cookie = sessionCookieName + "=1; path=/";
+    }
+
+    function setPersistentCookie() {
+        document.cookie = persistentCookieName + "=1; path=/; Max-Age=" + twoMinutesInSeconds + ";";
+    }
+
+    function checkCookies(shouldHaveSessionCookie, shouldHavePersistentCookie) {
+        let hasSessionCookie = (document.cookie + "").includes(sessionCookieName),
+            hasPersistentCookie = (document.cookie + "").includes(persistentCookieName);
+
+        if (shouldHaveSessionCookie && hasSessionCookie)
+            testPassed("Should have and has the session cookie.");
+        else if (shouldHaveSessionCookie && !hasSessionCookie) {
+            testFailed("Should have but doesn't have the session cookie.");
+            setEnableFeature(false, finishJSTest);
+        } else if (!shouldHaveSessionCookie && hasSessionCookie) {
+            testFailed("Shouldn't have but has the session cookie.");
+            setEnableFeature(false, finishJSTest);
+        } else
+            testPassed("Shouldn't have and doesn't have the session cookie.");
+
+
+        if (shouldHavePersistentCookie && hasPersistentCookie)
+            testPassed("Should have and has the persistent cookie.");
+        else if (shouldHavePersistentCookie && !hasPersistentCookie) {
+            testFailed("Should have but doesn't have the persistent cookie.");
+            setEnableFeature(false, finishJSTest);
+        } else if (!shouldHavePersistentCookie && hasPersistentCookie) {
+            testFailed("Shouldn't have but has the persistent cookie.");
+            setEnableFeature(false, finishJSTest);
+        } else
+            testPassed("Shouldn't have and doesn't have the persistent cookie.");
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                setSessionCookie();
+                setPersistentCookie();
+                checkCookies(true, true);
+                if (testRunner.hasStatisticsIsolatedSession(prevalentOrigin)) {
+                    testFailed("Origin has isolated session.");
+                    setEnableFeature(false, finishJSTest);
+                } else
+                    testPassed("Origin has no isolated session.");
+                document.location.href = nonPrevalentOrigin + "/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction.html#step2";
+                break;
+            case "#step2":
+                document.location.hash = "step3";
+                if (document.location.origin !== nonPrevalentOrigin)
+                    testFailed("Step 2 is not on " + nonPrevalentOrigin + ".");
+                testRunner.setStatisticsPrevalentResource(prevalentOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(prevalentOrigin)) {
+                        testFailed(prevalentOrigin + " did not get set as prevalent resource.");
+                        setEnableFeature(false, finishJSTest);
+                    }
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                });
+                break;
+            case "#step3":
+                document.location.href = prevalentOrigin + "/resourceLoadStatistics/do-not-switch-session-on-navigation-to-prevalent-without-interaction.html#step4";
+                break;
+            case "#step4":
+                checkCookies(true, true);
+                if (testRunner.hasStatisticsIsolatedSession(prevalentOrigin))
+                    testFailed("Origin has isolated session.");
+                else
+                    testPassed("Origin has no isolated session.");
+                setEnableFeature(false, finishJSTest);
+                break;
+            default:
+                testFailed("Unknown hash.");
+                setEnableFeature(false, finishJSTest);
+        }
+    }
+
+    if (document.location.hash === "") {
+        if (document.location.origin !== prevalentOrigin)
+            testFailed("Test is not starting out on " + prevalentOrigin + ".");
+            
+            testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function () {
+            if (testRunner.isStatisticsPrevalentResource(prevalentOrigin))
+                testFailed(prevalentOrigin + " was classified as prevalent resource before the test starts.");
+            document.location.hash = "step1";
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database-expected.txt
new file mode 100644 (file)
index 0000000..0fba810
--- /dev/null
@@ -0,0 +1,10 @@
+Check that document.referrer is downgraded to the eTLD+1 after a cross-site navigation with link query.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS The referrer is downgraded.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database.html b/LayoutTests/http/tests/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource-database.html
new file mode 100644 (file)
index 0000000..9aebde9
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="/cookies/resources/cookie-utilities.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body onload="setTimeout('runTest()', 0)">
+<script>
+    description("Check that document.referrer is downgraded to the eTLD+1 after a cross-site navigation with link query.");
+    jsTestIsAsync = true;
+
+    let numberOfTries = 0;
+    function testReferrer() {
+        if (document.referrer === prevalentResourceOrigin + "/") {
+            testPassed("The referrer is downgraded.");
+            setEnableFeature(false, finishJSTest);
+        } else if (++numberOfTries <= 5)
+            setTimeout(testReferrer, 200);
+        else {
+            testFailed("The referrer is not downgraded: " + document.referrer);
+            setEnableFeature(false, finishJSTest);
+        }
+    }
+
+    function navigateSameOriginToAddQuery() {
+        document.location.href = prevalentResourceOrigin + "/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource.html?link=query";
+    }
+
+    function navigateCrossOrigin() {
+        document.location.href = destinationOrigin + "/resourceLoadStatistics/downgraded-referrer-for-navigation-with-link-query-from-prevalent-resource.html";
+    }
+
+    const destinationOrigin = "http://localhost:8000";
+    const prevalentResourceOrigin = "http://127.0.0.1:8000";
+    function runTest() {
+        if (document.location.origin === prevalentResourceOrigin && document.location.search === "") {
+            navigateSameOriginToAddQuery();
+        } else if (document.location.origin === prevalentResourceOrigin) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function () {
+                testRunner.setStatisticsPrevalentResource(prevalentResourceOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(prevalentResourceOrigin))
+                        testFailed("Host did not get set as prevalent resource.");
+                    testRunner.statisticsUpdateCookieBlocking(navigateCrossOrigin);
+                });
+            });
+        } else {
+            testReferrer();
+        }
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/enable-debug-mode-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/enable-debug-mode-database-expected.txt
new file mode 100644 (file)
index 0000000..65219dd
--- /dev/null
@@ -0,0 +1,10 @@
+Test for enabling debug mode and that it permanently treats 3rdpartytestwebkit.org as a prevalent resource.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS http://3rdpartytestwebkit.org got set as prevalent resource in debug mode.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/enable-debug-mode-database.html b/LayoutTests/http/tests/resourceLoadStatistics/enable-debug-mode-database.html
new file mode 100644 (file)
index 0000000..637ff92
--- /dev/null
@@ -0,0 +1,34 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Test for enabling debug mode and that it permanently treats 3rdpartytestwebkit.org as a prevalent resource.");
+    jsTestIsAsync = true;
+
+    const thirdPartyOrigin = "http://3rdpartytestwebkit.org";
+
+    if (window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                testFailed(thirdPartyOrigin + " already set as prevalent resource.");
+
+            testRunner.setStatisticsDebugMode(true, function() {
+                if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                    testFailed(thirdPartyOrigin + " didn't get set as prevalent resource.");
+                else
+                    testPassed(thirdPartyOrigin + " got set as prevalent resource in debug mode.");
+                testRunner.setStatisticsDebugMode(false, function() {
+                    setEnableFeature(false, finishJSTest);
+                });
+            });
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/grandfathering-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/grandfathering-database-expected.txt
new file mode 100644 (file)
index 0000000..01803bf
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Grandfathered cookie was not purged.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/grandfathering-database.html b/LayoutTests/http/tests/resourceLoadStatistics/grandfathering-database.html
new file mode 100644 (file)
index 0000000..aaf0b85
--- /dev/null
@@ -0,0 +1,116 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Test for Grandfathering</title>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    const firstPartyOrigin = "http://localhost:8000";
+    const firstPartyBaseUrl = firstPartyOrigin + "/resourceLoadStatistics/resources";
+    const firstPartyCookieName = "firstPartyCookie";
+    const thirdPartyCookieName = "thirdPartyCookie";
+    const cookieValue = "value";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=" + cookieValue;
+    const returnUrl = firstPartyOrigin + "/resourceLoadStatistics/grandfathering.html";
+    const thirdPartyOrigin = "http://127.0.0.1:8000";
+    const thirdPartyBaseUrl = thirdPartyOrigin + "/resourceLoadStatistics/resources";
+    const subPathToSetThirdPartyCookie = "/set-cookie.php?name=" + thirdPartyCookieName + "&value=" + cookieValue;
+
+    function finishTest() {
+        testRunner.setUseITPDatabase(false);
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function fireDataModificationHandlerAndContinue() {
+        testRunner.installStatisticsDidScanDataRecordsCallback(function() {
+            runTest();
+        });
+        testRunner.statisticsProcessStatisticsAndDataRecords();
+    }
+
+    function clearInMemoryAndPersistentStoreAndContinue() {
+        testRunner.statisticsClearInMemoryAndPersistentStore(function() {
+            runTest();
+        });
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                // Set a first-party cookie for localhost.
+                document.location.href = firstPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step2";
+                break;
+            case "#step2":
+                document.location.hash = "step3";
+                // Check that localhost's cookie is there.
+                if (document.cookie !== firstPartyCookieName + "=" + cookieValue)
+                    testFailed("First-party cookie not set.");
+                runTest();
+                break;
+            case "#step3":
+                document.location.hash = "step4";
+                // Clear store to trigger grandfathering.
+                clearInMemoryAndPersistentStoreAndContinue();
+                break;
+            case "#step4":
+                document.location.hash = "step5";
+                // Set localhost as prevalent resource.
+                testRunner.setStatisticsPrevalentResource("http://localhost", true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
+                        testFailed("Localhost did not get set as prevalent resource.");
+                    runTest();
+                });
+                break;
+            case "#step5":
+                // Set a first-party cookie for 127.0.0.1.
+                document.location.href = thirdPartyBaseUrl + subPathToSetThirdPartyCookie + "#" + returnUrl + "#step6";
+                break;
+            case "#step6":
+                document.location.hash = "step7";
+                // Set 127.0.0.1 as prevalent resource
+                testRunner.setStatisticsPrevalentResource("http://127.0.0.1", true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource("http://127.0.0.1"))
+                        testFailed("127.0.0.1 did not get set as prevalent resource.");
+                    runTest();
+                });
+                break;
+            case "#step7":
+                document.location.hash = "step8";
+                // Trigger a purge.
+                fireDataModificationHandlerAndContinue();
+                break;
+            case "#step8":
+                // Check that localhost's cookie is still there.
+                if (document.cookie !== firstPartyCookieName + "=" + cookieValue)
+                    testFailed("First-party cookie purged.");
+                else
+                    testPassed("Grandfathered cookie was not purged.");
+                finishTest();
+                break;
+            default:
+                testFailed("Should not be reached.");
+                finishTest();
+        }
+    }
+
+    if (document.location.hash === "" && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+            testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+
+            testRunner.waitUntilDone();
+            testRunner.dumpChildFramesAsText();
+            document.location.hash = "step1";
+            runTest();
+        });
+    } else
+        runTest();
+</script>
+</body>
+</html>
index c6cb0db..fcc82c5 100644 (file)
@@ -8,6 +8,7 @@
 <div id="output"></div>
 <script>
     if (window.testRunner) {
+        testRunner.setUseITPDatabase(false);
         testRunner.waitUntilDone();
         testRunner.dumpAsText();
     }
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database-expected.txt
new file mode 100644 (file)
index 0000000..c89f855
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Cookie not deleted.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database.html b/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction-database.html
new file mode 100644 (file)
index 0000000..d97e80f
--- /dev/null
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Non-Prevalent Resource With User Interaction</title>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const otherPrevalentUrl = "http://localhost:8000/temp";
+
+    function runTestRunnerTest() {
+        if (document.cookie !== "")
+            testFailed("document.cookie not empty.");
+        const cookie = "testCookie=testValue";
+        document.cookie = cookie + "; max-age=100;";
+        if (document.cookie !== cookie)
+            testFailed("document.cookie did not get set.");
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            // This is done to not have an empty set of prevalent resources.
+            // Otherwise data records are never scanned.
+            testRunner.setStatisticsPrevalentResource(otherPrevalentUrl, true, function() {
+                if (!testRunner.isStatisticsPrevalentResource(otherPrevalentUrl))
+                    testFailed("Other host did not get set as prevalent resource.");
+
+                testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() {
+                    if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
+                        testFailed("Host did not get logged for user interaction.");
+
+                    testRunner.installStatisticsDidScanDataRecordsCallback(function() {
+                        if (document.cookie === cookie)
+                            testPassed("Cookie not deleted.");
+                        else
+                            testFailed("Cookie deleted or document.cookie contains other cookies: " + document.cookie);
+
+                        setEnableFeature(false, function() {
+                            testRunner.notifyDone();
+                        });
+                    });
+                    testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+                    testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+                    testRunner.statisticsProcessStatisticsAndDataRecords();
+                });
+            });
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+            runTestRunnerTest();
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database-expected.txt
new file mode 100644 (file)
index 0000000..c89f855
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Cookie not deleted.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database.html b/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resource-without-user-interaction-database.html
new file mode 100644 (file)
index 0000000..6bce990
--- /dev/null
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Non-Prevalent Resource Without User Interaction</title>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const otherPrevalentUrl = "http://localhost:8000/temp";
+
+    function runTestRunnerTest() {
+        if (document.cookie !== "")
+            testFailed("document.cookie not empty.");
+        const cookie = "testCookie=testValue";
+        document.cookie = cookie + "; max-age=100;";
+        if (document.cookie !== cookie)
+            testFailed("document.cookie did not get set.");
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as non-prevalent resource.");
+
+            // This is done to not have an empty set of prevalent resources.
+            // Otherwise data records are never scanned.
+            testRunner.setStatisticsPrevalentResource(otherPrevalentUrl, true, function() {
+                if (!testRunner.isStatisticsPrevalentResource(otherPrevalentUrl))
+                    testFailed("Other host did not get set as prevalent resource.");
+
+                testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, false, function() {
+                    if (testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
+                        testFailed("Host did not get cleared of user interaction.");
+
+                    testRunner.installStatisticsDidScanDataRecordsCallback(function() {
+                        if (document.cookie === cookie)
+                            testPassed("Cookie not deleted.");
+                        else
+                            testFailed("Cookie deleted or document.cookie contains other cookies: " + document.cookie);
+
+                        setEnableFeature(false, function() {
+                            testRunner.notifyDone();
+                        });
+                    });
+                    testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+                    testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+                    testRunner.statisticsProcessStatisticsAndDataRecords();
+                });
+            });
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+            runTestRunnerTest();
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database-expected.txt
new file mode 100644 (file)
index 0000000..0fb97f9
--- /dev/null
@@ -0,0 +1,11 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+--------
+Frame: '<!--frame1-->'
+--------
+Should receive one cookie.
+Received cookie named 'firstPartyCookie'.
+Client-side document.cookie: firstPartyCookie=value
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database.html b/LayoutTests/http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context-database.html
new file mode 100644 (file)
index 0000000..c64cfcb
--- /dev/null
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Test to ensure non-prevalent resources can access their cookies in a third party context</title>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const thirdPartyBaseUrl = thirdPartyOrigin + "/resourceLoadStatistics/resources";
+    const firstPartyCookieName = "firstPartyCookie";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
+    const fragmentWithReturnUrl = "http://127.0.0.1:8000/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName;
+
+    function finishTest() {
+        setEnableFeature(false, function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                // Set a first-party cookie for localhost.
+                document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + fragmentWithReturnUrl + "#step2";
+                break;
+            case "#step2":
+                // Load localhost under 127.0.0.1 and check that it gets its cookie.
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive one cookie.", finishTest);
+                break;
+        }
+    }
+
+    if (document.location.host === partitionHost && document.location.hash == "" && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        testRunner.dumpChildFramesAsText();
+        setEnableFeature(true, function() {
+            testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, false, function() {
+                testRunner.setStatisticsHasHadUserInteraction(thirdPartyOrigin, false, function() {
+                    document.location.hash = "step1";
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                });
+            });
+        });
+    } else {
+        runTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt
new file mode 100644 (file)
index 0000000..863c720
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a non-sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
new file mode 100644 (file)
index 0000000..b5bda6f
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a non-sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "http://127.0.0.1:8000") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+    </script>
+</head>
+<body>
+<iframe src="http://127.0.0.1:8000/resourceLoadStatistics/resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/resources/iframe-report-back-loaded.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt
new file mode 100644 (file)
index 0000000..863c720
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a non-sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
new file mode 100644 (file)
index 0000000..4b5ee99
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a non-sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "http://localhost:8000") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+    </script>
+</head>
+<body>
+<iframe src="http://localhost:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/iframe-report-back-loaded.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt
new file mode 100644 (file)
index 0000000..9b516f1
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a non-sandboxed iframe nested in a non-sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
new file mode 100644 (file)
index 0000000..2d9ca59
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a non-sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "http://127.0.0.1:8000") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+    </script>
+</head>
+<body>
+<iframe src="http://127.0.0.1:8000/resourceLoadStatistics/resources/page-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt
new file mode 100644 (file)
index 0000000..9b516f1
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a non-sandboxed iframe nested in a non-sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
new file mode 100644 (file)
index 0000000..31e33f6
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a non-sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "http://localhost:8000") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+    </script>
+</head>
+<body>
+<iframe src="http://127.0.0.1:8000/resourceLoadStatistics/resources/page-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt
new file mode 100644 (file)
index 0000000..715c85e
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
new file mode 100644 (file)
index 0000000..9738ea3
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "null") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+    </script>
+</head>
+<body>
+<iframe src="http://127.0.0.1:8000/resourceLoadStatistics/resources/page-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt
new file mode 100644 (file)
index 0000000..715c85e
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html b/LayoutTests/http/tests/resourceLoadStatistics/non-sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
new file mode 100644 (file)
index 0000000..57faf00
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "null") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+    </script>
+</head>
+<body>
+<iframe src="http://127.0.0.1:8000/resourceLoadStatistics/resources/page-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database-expected.txt
new file mode 100644 (file)
index 0000000..549bfb9
--- /dev/null
@@ -0,0 +1,24 @@
+Tests that cookie blocking is applied to ping loads.
+   
+
+--------
+Frame: '<!--frame1-->'
+--------
+Should receive first-party cookie.
+Received cookie named 'firstPartyCookie'.
+Client-side document.cookie: firstPartyCookie=value
+
+--------
+Frame: '<!--frame2-->'
+--------
+Should receive no cookies.
+Did not receive cookie named 'firstPartyCookie'.
+Client-side document.cookie:
+
+--------
+Frame: '<!--frame3-->'
+--------
+Ping received.
+HTTP_HOST: localhost:8000
+REQUEST_URI: /contentextensions/resources/save-ping.php?test=ping-to-prevalent-resource
+No cookies in ping.
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database.html b/LayoutTests/http/tests/resourceLoadStatistics/ping-to-prevalent-resource-database.html
new file mode 100644 (file)
index 0000000..e621281
--- /dev/null
@@ -0,0 +1,100 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <script src="/js-test-resources/ui-helper.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<div id="description">Tests that cookie blocking is applied to ping loads.</div>
+<a id="targetLink" href="#" ping="http://localhost:8000/contentextensions/resources/save-ping.php?test=ping-to-prevalent-resource">The link</a>
+<script>
+    if (testRunner)
+        testRunner.waitUntilDone();
+
+    const partitionHost = "127.0.0.1:8000";
+    const thirdPartyOrigin = "http://localhost:8000";
+    const resourcePath = "/resourceLoadStatistics/resources";
+    const thirdPartyBaseUrl = thirdPartyOrigin + resourcePath;
+    const firstPartyCookieName = "firstPartyCookie";
+    const subPathToSetFirstPartyCookie = "/set-cookie.php?name=" + firstPartyCookieName + "&value=value";
+    const returnUrl = "http://" + partitionHost + "/resourceLoadStatistics/ping-to-prevalent-resource.html";
+    const subPathToGetCookies = "/get-cookies.php?name1=" + firstPartyCookieName;
+
+    function activateElement(elementID, callback) {
+        var element = document.getElementById(elementID);
+        var centerX = element.offsetLeft + element.offsetWidth / 2;
+        var centerY = element.offsetTop + element.offsetHeight / 2;
+        UIHelper.activateAt(centerX, centerY).then(
+            function () {
+                callback();
+            },
+            function () {
+                testRunner.notifyDone();
+            }
+        );
+    }
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                // Set first-party cookie for localhost.
+                document.location.href = thirdPartyBaseUrl + subPathToSetFirstPartyCookie + "#" + returnUrl + "#step2";
+                break;
+            case "#step2":
+                // Check that the cookie gets sent for localhost under 127.0.0.1 since localhost is not prevalent.
+                document.location.hash = "step3";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies + "&message=Should receive first-party cookie.", runTest);
+                break;
+            case "#step3":
+                // Set localhost as prevalent to put it in the blocking category.
+                testRunner.setStatisticsPrevalentResource(thirdPartyOrigin, true, function() {
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                    document.location.hash = "step4";
+                });
+                break;
+            case "#step4":
+                // Check that no cookie gets sent for localhost under 127.0.0.1 since localhost's cookies are blocked.
+                document.location.hash = "step5";
+                openIframe(thirdPartyBaseUrl + subPathToGetCookies +  "&message=Should receive no cookies.", runTest);
+                break;
+            case "#step5":
+                // Click the link to trigger the ping.
+                activateElement("targetLink", function() {
+                    openIframe(thirdPartyOrigin + "/contentextensions/resources/get-ping-data.php?test=ping-to-prevalent-resource", function() {
+                        document.body.removeChild(document.getElementById("targetLink"));
+                        setEnableFeature(false, function() {
+                    fetch("/contentextensions/resources/delete-ping.php?test=ping-to-prevalent-resource").then(()=>{
+                                            testRunner.notifyDone();
+                                });
+                        });
+                    });
+                });
+                break;
+        }
+    }
+
+    if (document.location.hash === "") {
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function () {
+                testRunner.dumpChildFramesAsText();
+                document.location.hash = "step1";
+                runTest();
+            });
+        }
+    } else {
+        runTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database-expected.txt
new file mode 100644 (file)
index 0000000..e4e32c5
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that we grant User Interaction credit for handled keypresses.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Simulate user typing letter 'a' into the field.
+PASS testInput.value is "a"
+PASS Origin was granted user interaction.
+PASS successfullyParsed is true
+
+TEST COMPLETE
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database.html b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-handled-keydown-database.html
new file mode 100644 (file)
index 0000000..7e56a50
--- /dev/null
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="/js-test-resources/js-test.js"></script>
+<script>
+description("Tests that we grant User Interaction credit for handled keypresses.");
+jsTestIsAsync = true;
+
+const statisticsUrl = "http://127.0.0.1:8000/temp";
+
+onload = function() {
+    const testFrame = document.getElementById("testFrame");
+
+    if (window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        internals.setResourceLoadStatisticsEnabled(true);
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+    }
+
+    testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get set as prevalent resource.");
+
+        testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
+                testFailed("Host did not get cleared of user interaction.");
+
+            testInput = document.getElementById("testInput");
+
+            testRunner.installStatisticsDidModifyDataRecordsCallback(function() {
+                shouldBeEqualToString("testInput.value", "a");
+
+                if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
+                    testFailed("Origin did not get user interaction credit.");
+                else
+                    testPassed("Origin was granted user interaction.");
+
+                setTimeout(function() {
+                    testFrame.src = "about:blank";
+                    setTimeout(function() {
+                        testRunner.statisticsResetToConsistentState(function() {
+                            finishJSTest();
+                        });
+                    }, 0);
+                }, 0);
+            });
+            testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+            testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+
+            debug("Simulate user typing letter 'a' into the field.");
+            testInput.focus();
+            if (window.eventSender)
+                eventSender.keyDown("a");
+        });
+    });
+}
+</script>
+<iframe id="testFrame" src="resources/onclick.html"></iframe>
+<input id="testInput" type="text">
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database-expected.txt
new file mode 100644 (file)
index 0000000..36e559b
--- /dev/null
@@ -0,0 +1,11 @@
+Tests that we do not grant User Interaction credit for unhandled keypress.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Simulate an unhandled user key press.
+PASS Origin did not get user interaction credit.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database.html b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-unhandled-keydown-database.html
new file mode 100644 (file)
index 0000000..5acdeb2
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="/js-test-resources/js-test.js"></script>
+<script>
+description("Tests that we do not grant User Interaction credit for unhandled keypress.");
+jsTestIsAsync = true;
+
+const statisticsUrl = "http://127.0.0.1:8000/temp";
+
+onload = function() {
+    const testFrame = document.getElementById("testFrame");
+
+    if (window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        internals.setResourceLoadStatisticsEnabled(true);
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+    }
+
+    testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
+        if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+            testFailed("Host did not get set as prevalent resource.");
+
+        testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, false, function() {
+            if (testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
+                testFailed("Host did not get cleared of user interaction.");
+
+            testRunner.installStatisticsDidModifyDataRecordsCallback(function() {
+
+                if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
+                    testPassed("Origin did not get user interaction credit.");
+
+                setTimeout(function() {
+                    testFrame.src = "about:blank";
+                    setTimeout(function() {
+                        testRunner.statisticsResetToConsistentState(function() {
+                            finishJSTest();
+                        });
+                    }, 0);
+                }, 0);
+            });
+            testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+            testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+            testRunner.statisticsProcessStatisticsAndDataRecords();
+
+            debug("Simulate an unhandled user key press.");
+            if (window.eventSender)
+                eventSender.keyDown("a", ["metaKey"]);
+        });
+    });
+}
+</script>
+<iframe id="testFrame" src="resources/onclick.html"></iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database-expected.txt
new file mode 100644 (file)
index 0000000..c89f855
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Cookie not deleted.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database.html b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-database.html
new file mode 100644 (file)
index 0000000..ec13a50
--- /dev/null
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Prevalent Resource With User Interaction</title>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body onload="setTimeout('setUpAndRun()', 0)">
+<script>
+    if (testRunner)
+        testRunner.waitUntilDone();
+
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    const otherPrevalentUrl = "http://localhost:8000/temp";
+    function runTestRunnerTest() {
+        if (document.cookie !== "")
+            testFailed("document.cookie not empty.");
+        const cookie = "testCookie=testValue";
+        document.cookie = cookie + "; max-age=100;";
+        if (document.cookie !== cookie)
+            testFailed("document.cookie did not get set.");
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
+            if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as prevalent resource.");
+
+            // This is done to not have an empty set of prevalent resources.
+            // Otherwise data records are never scanned.
+            testRunner.setStatisticsPrevalentResource(otherPrevalentUrl, true, function() {
+                if (!testRunner.isStatisticsPrevalentResource(otherPrevalentUrl))
+                    testFailed("Other host did not get set as prevalent resource.");
+
+                testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() {
+                    if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
+                        testFailed("Host did not get logged for user interaction.");
+
+                    testRunner.installStatisticsDidModifyDataRecordsCallback(function() {
+                        if (document.cookie === cookie)
+                            testPassed("Cookie not deleted.");
+                        else
+                            testFailed("Cookie deleted or document.cookie contains other cookies: " + document.cookie);
+                        setEnableFeature(false, function() {
+                            testRunner.notifyDone();
+                        });
+                    });
+                    testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+                    testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+                    testRunner.statisticsProcessStatisticsAndDataRecords();
+                });
+            });
+        });
+    }
+
+    function setUpAndRun() {
+        if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function () {
+                runTestRunnerTest();
+            });
+        } else {
+            testFailed("Wrong host, no testRunner, or no internals.");
+            testRunner.notifyDone();
+        }
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database-expected.txt
new file mode 100644 (file)
index 0000000..f7809e9
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Cookie deleted.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database.html b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout-database.html
new file mode 100644 (file)
index 0000000..b208970
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Prevalent Resource With User Interaction Timeout</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+    function runTestRunnerTest() {
+        if (document.cookie !== "")
+            testFailed("document.cookie not empty.");
+        const cookie = "testCookie=testValue";
+        document.cookie = cookie + "; max-age=100;";
+        if (document.cookie !== cookie)
+            testFailed("document.cookie did not get set.");
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
+            if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as prevalent resource.");
+
+            testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, true, function() {
+                if (!testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
+                    testFailed("Host did not get logged for user interaction.");
+
+                testRunner.installStatisticsDidModifyDataRecordsCallback(function() {
+                    if (document.cookie !== "")
+                        testFailed("Cookie not deleted: " + document.cookie);
+                    else
+                        testPassed("Cookie deleted.");
+                    internals.setResourceLoadStatisticsEnabled(false);
+                    testRunner.statisticsResetToConsistentState(function() {
+                        testRunner.notifyDone();
+                    });
+                });
+                testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+                testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+                testRunner.setStatisticsTimeToLiveUserInteraction(0);
+
+                // This is to ensure the timeout we're testing.
+                setTimeout("testRunner.statisticsProcessStatisticsAndDataRecords()", 1000);
+            });
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+        runTestRunnerTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database-expected.txt
new file mode 100644 (file)
index 0000000..f7809e9
--- /dev/null
@@ -0,0 +1,5 @@
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Cookie deleted.
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database.html b/LayoutTests/http/tests/resourceLoadStatistics/prevalent-resource-without-user-interaction-database.html
new file mode 100644 (file)
index 0000000..27b0b2a
--- /dev/null
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Tests for Prevalent Resource Without User Interaction</title>
+    <script src="/js-test-resources/js-test.js"></script>
+</head>
+<body>
+<script>
+    const hostUnderTest = "127.0.0.1:8000";
+    const statisticsUrl = "http://" + hostUnderTest + "/temp";
+
+    function finishTest () {
+        if (document.cookie !== "")
+            testFailed("Cookie not deleted: " + document.cookie);
+        else
+            testPassed("Cookie deleted.");
+        internals.setResourceLoadStatisticsEnabled(false);
+        testRunner.statisticsResetToConsistentState(function() {
+            testRunner.notifyDone();
+        });
+    }
+
+    function runTestRunnerTest() {
+        if (document.cookie !== "")
+            testFailed("document.cookie not empty.");
+        const cookie = "testCookie=testValue";
+        document.cookie = cookie + "; max-age=100;";
+        if (document.cookie !== cookie)
+            testFailed("document.cookie did not get set.");
+
+        testRunner.setStatisticsPrevalentResource(statisticsUrl, true, function() {
+            if (!testRunner.isStatisticsPrevalentResource(statisticsUrl))
+                testFailed("Host did not get set as prevalent resource.");
+
+            testRunner.setStatisticsHasHadUserInteraction(statisticsUrl, false, function() {
+                if (testRunner.isStatisticsHasHadUserInteraction(statisticsUrl))
+                    testFailed("Host did not get cleared of user interaction.");
+
+                testRunner.installStatisticsDidModifyDataRecordsCallback(function() {
+                    setTimeout("finishTest()", 1000);
+                });
+                testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+                testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+                testRunner.statisticsProcessStatisticsAndDataRecords();
+            });
+        });
+    }
+
+    if (document.location.host === hostUnderTest && window.testRunner && window.internals) {
+        testRunner.waitUntilDone();
+        internals.setResourceLoadStatisticsEnabled(true);
+        testRunner.setUseITPDatabase(true);
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+        runTestRunnerTest();
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prune-statistics-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/prune-statistics-database-expected.txt
new file mode 100644 (file)
index 0000000..e74757b
--- /dev/null
@@ -0,0 +1,17 @@
+Tests that statistics are pruned in the right order.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Test iteration 1 passed.
+PASS Test iteration 2 passed.
+PASS Test iteration 3 passed.
+PASS Test iteration 4 passed.
+PASS Test iteration 5 passed.
+PASS Test iteration 6 passed.
+PASS Test iteration 7 passed.
+PASS Test iteration 8 passed.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/prune-statistics-database.html b/LayoutTests/http/tests/resourceLoadStatistics/prune-statistics-database.html
new file mode 100644 (file)
index 0000000..0cab7d3
--- /dev/null
@@ -0,0 +1,163 @@
+<!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) {
+            testRunner.statisticsResetToConsistentState(function() {
+                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) {
+            testRunner.statisticsResetToConsistentState(function() {
+                finishJSTest();
+            });
+        }
+    }
+
+    function initializeStatisticsAndRunTests(step) {
+        switch (step) {
+            // Non-prevalent without user interaction to be pruned first.
+            case 1:
+                testRunner.setStatisticsLastSeen(urlsToBePruned[0].url, olderTimestamp, function() { initializeStatisticsAndRunTests(2); });
+                break;
+            case 2:
+                testRunner.setStatisticsLastSeen(urlsToBePruned[1].url, newerTimestamp, function() { initializeStatisticsAndRunTests(3); });
+                break;
+            // Prevalent without user interaction to be pruned second.
+            case 3:
+                testRunner.setStatisticsPrevalentResource(urlsToBePruned[2].url, true, function() { initializeStatisticsAndRunTests(4); });
+                break;
+            case 4:
+                testRunner.setStatisticsLastSeen(urlsToBePruned[2].url, olderTimestamp, function() { initializeStatisticsAndRunTests(5); });
+                break;
+            case 5:
+                testRunner.setStatisticsPrevalentResource(urlsToBePruned[3].url, true, function() { initializeStatisticsAndRunTests(6); });
+                break;
+            case 6:
+                testRunner.setStatisticsLastSeen(urlsToBePruned[3].url, newerTimestamp, function() { initializeStatisticsAndRunTests(7); });
+                break;
+            // Non-prevalent with user interaction to be pruned third.
+            case 7:
+                testRunner.setStatisticsHasHadUserInteraction(urlsToBePruned[4].url, true, function() { initializeStatisticsAndRunTests(8); });
+                break;
+            case 8:
+                testRunner.setStatisticsLastSeen(urlsToBePruned[4].url, olderTimestamp, function() { initializeStatisticsAndRunTests(9); });
+                break;
+            case 9:
+                testRunner.setStatisticsHasHadUserInteraction(urlsToBePruned[5].url, true, function() { initializeStatisticsAndRunTests(10); });
+                break;
+            case 10:
+                testRunner.setStatisticsLastSeen(urlsToBePruned[5].url, newerTimestamp, function() { initializeStatisticsAndRunTests(11); });
+                break;
+            // Prevalent with user interaction to be pruned last.
+            case 11:
+                testRunner.setStatisticsPrevalentResource(urlsToBePruned[6].url, true, function() { initializeStatisticsAndRunTests(12); });
+                break;
+            case 12:
+                testRunner.setStatisticsHasHadUserInteraction(urlsToBePruned[6].url, true, function() { initializeStatisticsAndRunTests(13); });
+                break;
+            case 13:
+                testRunner.setStatisticsLastSeen(urlsToBePruned[6].url, olderTimestamp, function() { initializeStatisticsAndRunTests(14); });
+                break;
+            case 14:
+                testRunner.setStatisticsPrevalentResource(urlsToBePruned[7].url, true, function() { initializeStatisticsAndRunTests(15); });
+                break;
+            case 15:
+                testRunner.setStatisticsHasHadUserInteraction(urlsToBePruned[7].url, true, function() { initializeStatisticsAndRunTests(16); });
+                break;
+            case 16:
+                testRunner.setStatisticsLastSeen(urlsToBePruned[7].url, newerTimestamp, function() { initializeStatisticsAndRunTests(17); });
+                break;
+            case 17:
+                checkIfPrevalentAccordingToInitialExpectation(0, urlsToBePruned.length);
+                runTest();
+                break;
+        }
+    }
+
+    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;
+            testRunner.installStatisticsDidScanDataRecordsCallback(checkStatisticsAfterPruning);
+            initializeStatisticsAndRunTests(1);
+        } else {
+            testRunner.statisticsResetToConsistentState(function() {
+                finishJSTest();
+            });
+        }
+    }
+
+    let fillerUrl;
+    function runTest() {
+        fillerUrl = "http://127.0." + currentTest + ".1:8000/temp";
+        testRunner.setStatisticsPrevalentResource(fillerUrl, true, function() {
+            testRunner.setStatisticsHasHadUserInteraction(fillerUrl, true, function() {
+                testRunner.setStatisticsLastSeen(fillerUrl, newestTimestamp, function() {
+                    testRunner.statisticsProcessStatisticsAndDataRecords();
+                });
+            });
+        });
+    }
+
+    if (window.testRunner) {
+            testRunner.setUseITPDatabase(true);
+        testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
+        testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
+        testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+        testRunner.setStatisticsMaxStatisticsEntries(urlsToBePruned.length);
+        testRunner.setStatisticsPruneEntriesDownTo(urlsToBePruned.length);
+
+        currentTest = 1;
+        testRunner.installStatisticsDidScanDataRecordsCallback(checkStatisticsAfterPruning);
+        initializeStatisticsAndRunTests(1);
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt
new file mode 100644 (file)
index 0000000..b7c1438
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for sandboxed iframes get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
new file mode 100644 (file)
index 0000000..6671120
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for sandboxed iframes get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "null") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+    </script>
+</head>
+<body>
+<iframe sandbox="allow-scripts" src="http://127.0.0.1:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/resources/iframe-report-back-loaded.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt
new file mode 100644 (file)
index 0000000..b7c1438
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for sandboxed iframes get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
new file mode 100644 (file)
index 0000000..f026bd9
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for sandboxed iframes get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "null") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+    </script>
+</head>
+<body>
+<iframe sandbox="allow-scripts" src="http://localhost:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://127.0.0.1:8000/resourceLoadStatistics/resources/redirect.php/?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/iframe-report-back-loaded.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt
new file mode 100644 (file)
index 0000000..23658cd
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a non-sandboxed iframe nested in a sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
new file mode 100644 (file)
index 0000000..092d599
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a non-sandboxed iframe nested in a sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "null") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+    </script>
+</head>
+<body>
+<iframe sandbox="allow-scripts" src="http://127.0.0.1:8000/resourceLoadStatistics/resources/page-with-non-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt
new file mode 100644 (file)
index 0000000..23658cd
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a non-sandboxed iframe nested in a sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
new file mode 100644 (file)
index 0000000..df86fe8
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a non-sandboxed iframe nested in a sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "null") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+    </script>
+</head>
+<body>
+<iframe sandbox="allow-scripts" src="http://127.0.0.1:8000/resourceLoadStatistics/resources/page-with-non-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database-expected.txt
new file mode 100644 (file)
index 0000000..715c85e
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip-database.html
new file mode 100644 (file)
index 0000000..d6e94a4
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "null") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+    </script>
+</head>
+<body>
+<iframe sandbox="allow-scripts" src="http://127.0.0.1:8000/resourceLoadStatistics/resources/page-with-sandboxed-iframe-redirect-ip-to-localhost-to-ip.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database-expected.txt
new file mode 100644 (file)
index 0000000..715c85e
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1") is true
+PASS testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html b/LayoutTests/http/tests/resourceLoadStatistics/sandboxed-nesting-iframe-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost-database.html
new file mode 100644 (file)
index 0000000..5e19dd1
--- /dev/null
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+    <script>
+        description("Tests that redirects for a sandboxed iframe nested in a non-sandboxed iframe get counted properly.");
+        jsTestIsAsync = true;
+        window.addEventListener("message", receiveMessage, false);
+
+        function finishTest() {
+            setEnableFeature(false, finishJSTest);
+        }
+
+        if (testRunner) {
+            testRunner.setUseITPDatabase(true);
+            setEnableFeature(true, function() {
+                testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+                testRunner.installStatisticsDidScanDataRecordsCallback(checkStats);
+            });
+        }
+
+        var lastPageInRedirectChainLoaded = false;
+        var statsChecked = false;
+
+        function receiveMessage(event) {
+            if (event.origin === "null") {
+                if (event.data.indexOf("PASS") === -1)
+                    testFailed(event.data.replace("FAIL ", ""));
+            } else
+                testFailed("Received a message from an unexpected origin: " + event.origin);
+
+            lastPageInRedirectChainLoaded = true;
+            if (statsChecked)
+                finishTest();
+            else
+                testRunner.statisticsNotifyObserver();
+        }
+
+        function checkStats() {
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsSubFrameUnder("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://localhost", "http://127.0.0.1")');
+            shouldBeTrue('testRunner.isStatisticsRegisteredAsRedirectingTo("http://127.0.0.1", "http://localhost")');
+
+            statsChecked = true;
+            if (lastPageInRedirectChainLoaded)
+                finishTest();
+        }
+    </script>
+</head>
+<body>
+<iframe sandbox="allow-scripts" src="http://127.0.0.1:8000/resourceLoadStatistics/resources/page-with-sandboxed-iframe-redirect-localhost-to-ip-to-localhost.html">
+</iframe>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database-expected.txt
new file mode 100644 (file)
index 0000000..2dc073d
--- /dev/null
@@ -0,0 +1,10 @@
+Test for enabling debug mode and that it allows setting a custom domain as a prevalent resource.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS http://localhost:8000 got set as a custom prevalent resource in debug mode.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database.html b/LayoutTests/http/tests/resourceLoadStatistics/set-custom-prevalent-resource-in-debug-mode-database.html
new file mode 100644 (file)
index 0000000..5fda812
--- /dev/null
@@ -0,0 +1,36 @@
+<!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>
+</head>
+<body>
+<script>
+    description("Test for enabling debug mode and that it allows setting a custom domain as a prevalent resource.");
+    jsTestIsAsync = true;
+
+    const thirdPartyOrigin = "http://localhost:8000";
+
+    if (window.testRunner && window.internals) {
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function() {
+            if (testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                testFailed(thirdPartyOrigin + " already set as prevalent resource.");
+
+            testRunner.setStatisticsPrevalentResourceForDebugMode(thirdPartyOrigin, function() {
+                testRunner.setStatisticsDebugMode(true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(thirdPartyOrigin))
+                        testFailed(thirdPartyOrigin + " didn't get set as prevalent resource.");
+                    else
+                        testPassed(thirdPartyOrigin + " got set as a custom prevalent resource in debug mode.");
+                    testRunner.setStatisticsDebugMode(false, function() {
+                        setEnableFeature(false, finishJSTest);
+                    });
+                });
+            });
+        });
+    }
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database-expected.txt
new file mode 100644 (file)
index 0000000..7bd543e
--- /dev/null
@@ -0,0 +1,15 @@
+Tests that only the origin is sent as referrer in redirects to prevalent resources without user interaction.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS referrer is "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database.html"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+--------
+Frame: '<!--frame1-->'
+--------
+http://127.0.0.1:8000/
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database.html b/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database.html
new file mode 100644 (file)
index 0000000..b0f8a2f
--- /dev/null
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    description("Tests that only the origin is sent as referrer in redirects to prevalent resources without user interaction.");
+    jsTestIsAsync = true;
+    testRunner.dumpChildFramesAsText();
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    var referrer;
+    testRunner.setUseITPDatabase(true);
+    setEnableFeature(true, function() {
+        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
+            testFailed("Localhost was classified as prevalent resource before the test started.");
+
+        fetch("resources/echo-referrer.php").then(function(response) {
+            return response.text();
+        }).then(function(data) {
+            referrer = data;
+            shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-redirects-database.html");
+
+            testRunner.setStatisticsPrevalentResource("http://localhost", true, function() {
+                if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
+                    testFailed("Host did not get set as prevalent resource.");
+
+                testRunner.statisticsUpdateCookieBlocking(function() {
+                    openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", function() {
+                        setEnableFeature(false, finishJSTest);
+                    });
+                });
+            });
+        }).catch(function(error) {
+            console.log(error.message);
+            setEnableFeature(false, finishJSTest);
+        });
+    });
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database-expected.txt
new file mode 100644 (file)
index 0000000..89ccb9c
--- /dev/null
@@ -0,0 +1,16 @@
+Tests that only the origin is sent as referrer for prevalent resources without user interaction.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS referrer is "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database.html"
+PASS referrer is "http://127.0.0.1:8000/"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+--------
+Frame: '<!--frame1-->'
+--------
+http://127.0.0.1:8000/
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database.html b/LayoutTests/http/tests/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database.html
new file mode 100644 (file)
index 0000000..15d4f03
--- /dev/null
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="/js-test-resources/js-test.js"></script>
+    <script src="resources/util.js"></script>
+</head>
+<body>
+<script>
+    description("Tests that only the origin is sent as referrer for prevalent resources without user interaction.");
+    jsTestIsAsync = true;
+    testRunner.dumpChildFramesAsText();
+
+    function openIframe(url, onLoadHandler) {
+        const element = document.createElement("iframe");
+        element.src = url;
+        if (onLoadHandler) {
+            element.onload = onLoadHandler;
+        }
+        document.body.appendChild(element);
+    }
+
+    var referrer;
+    testRunner.setUseITPDatabase(true);
+    setEnableFeature(true, function() {
+        if (testRunner.isStatisticsPrevalentResource("http://localhost"))
+            testFailed("Localhost was classified as prevalent resource before the test started.");
+
+        fetch("resources/echo-referrer.php").then(function(response) {
+            return response.text();
+        }).then(function(data) {
+            referrer = data;
+            shouldBeEqualToString("referrer", "http://127.0.0.1:8000/resourceLoadStatistics/strip-referrer-to-origin-for-prevalent-subresource-requests-database.html");
+
+            testRunner.setStatisticsPrevalentResource("http://localhost", true, function() {
+                if (!testRunner.isStatisticsPrevalentResource("http://localhost"))
+                    testFailed("Host did not get set as prevalent resource.");
+
+                testRunner.statisticsUpdateCookieBlocking(function() {
+                    fetch("http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php").then(function(response) {
+                        return response.text();
+                    }).then(function(data) {
+                        referrer = data;
+                        shouldBeEqualToString("referrer", "http://127.0.0.1:8000/");
+
+                        openIframe("resources/redirect.php?redirectTo=http://localhost:8000/resourceLoadStatistics/resources/echo-referrer.php", function() {
+                            setEnableFeature(false, finishJSTest);
+                        });
+
+                    }).catch(function(error) {
+                        console.log(error.message);
+                        setEnableFeature(false, finishJSTest);
+                    });
+                });
+            });
+        }).catch(function(error) {
+            console.log(error.message);
+            setEnableFeature(false, finishJSTest);
+        });
+    });
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database-expected.txt
new file mode 100644 (file)
index 0000000..343922f
--- /dev/null
@@ -0,0 +1,12 @@
+Tests that the session is switched upon top frame navigation to a prevalent resource with user interaction.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Should have and has the session cookie.
+PASS Should have and has the persistent cookie.
+PASS Origin has isolated session.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database.html b/LayoutTests/http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database.html
new file mode 100644 (file)
index 0000000..6270c00
--- /dev/null
@@ -0,0 +1,111 @@
+<!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>
+</head>
+<body onload="runTest()">
+<script>
+    description("Tests that the session is switched upon top frame navigation to a prevalent resource with user interaction.");
+    jsTestIsAsync = true;
+
+    const prevalentOrigin = "http://127.0.0.1:8000";
+    const nonPrevalentOrigin = "http://localhost:8000";
+    const sessionCookieName = "sessionCookie";
+    const persistentCookieName = "persistentCookie";
+    const twoMinutesInSeconds = 120;
+
+    function setSessionCookie() {
+        document.cookie = sessionCookieName + "=1; path=/";
+    }
+
+    function setPersistentCookie() {
+        document.cookie = persistentCookieName + "=1; path=/; Max-Age=" + twoMinutesInSeconds + ";";
+    }
+
+    function checkCookies(shouldHaveSessionCookie, shouldHavePersistentCookie) {
+        let hasSessionCookie = (document.cookie + "").includes(sessionCookieName),
+            hasPersistentCookie = (document.cookie + "").includes(persistentCookieName);
+
+        if (shouldHaveSessionCookie && hasSessionCookie)
+            testPassed("Should have and has the session cookie.");
+        else if (shouldHaveSessionCookie && !hasSessionCookie) {
+            testFailed("Should have but doesn't have the session cookie.");
+            setEnableFeature(false, finishJSTest);
+        } else if (!shouldHaveSessionCookie && hasSessionCookie) {
+            testFailed("Shouldn't have but has the session cookie.");
+            setEnableFeature(false, finishJSTest);
+        } else
+            testPassed("Shouldn't have and doesn't have the session cookie.");
+
+
+        if (shouldHavePersistentCookie && hasPersistentCookie)
+            testPassed("Should have and has the persistent cookie.");
+        else if (shouldHavePersistentCookie && !hasPersistentCookie) {
+            testFailed("Should have but doesn't have the persistent cookie.");
+            setEnableFeature(false, finishJSTest);
+        } else if (!shouldHavePersistentCookie && hasPersistentCookie) {
+            testFailed("Shouldn't have but has the persistent cookie.");
+            setEnableFeature(false, finishJSTest);
+        } else
+            testPassed("Shouldn't have and doesn't have the persistent cookie.");
+    }
+
+    function runTest() {
+        switch (document.location.hash) {
+            case "#step1":
+                testRunner.setStatisticsHasHadUserInteraction(prevalentOrigin, true, function() {
+                    setSessionCookie();
+                    setPersistentCookie();
+                    checkCookies(true, true);
+                    if (testRunner.hasStatisticsIsolatedSession(prevalentOrigin)) {
+                        testFailed("Origin has isolated session.");
+                        setEnableFeature(false, finishJSTest);
+                    } else
+                        testPassed("Origin has no isolated session.");
+                    document.location.href = nonPrevalentOrigin + "/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database.html#step2";
+                });
+                break;
+            case "#step2":
+                document.location.hash = "step3";
+                if (document.location.origin !== nonPrevalentOrigin)
+                    testFailed("Step 2 is not on " + nonPrevalentOrigin + ".");
+                testRunner.setStatisticsPrevalentResource(prevalentOrigin, true, function() {
+                    if (!testRunner.isStatisticsPrevalentResource(prevalentOrigin)) {
+                        testFailed(prevalentOrigin + " did not get set as prevalent resource.");
+                        setEnableFeature(false, finishJSTest);
+                    }
+                    testRunner.statisticsUpdateCookieBlocking(runTest);
+                });
+                break;
+            case "#step3":
+                document.location.href = prevalentOrigin + "/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database.html#step4";
+                break;
+            case "#step4":
+                checkCookies(true, true);
+                if (testRunner.hasStatisticsIsolatedSession(prevalentOrigin))
+                    testPassed("Origin has isolated session.");
+                else
+                    testFailed("Origin has no isolated session.");
+                setEnableFeature(false, finishJSTest);
+                break;
+            default:
+                testFailed("Unknown hash.");
+                setEnableFeature(false, finishJSTest);
+        }
+    }
+
+    if (document.location.hash === "") {
+        if (document.location.origin !== prevalentOrigin)
+            testFailed("Test is not starting out on " + prevalentOrigin + ".");
+        testRunner.setUseITPDatabase(true);
+        setEnableFeature(true, function () {
+            if (testRunner.isStatisticsPrevalentResource(prevalentOrigin))
+                testFailed(prevalentOrigin + " was classified as prevalent resource before the test starts.");
+            document.location.hash = "step1";
+        });
+    }
+</script>
+</body>
+</html>
index 8419562..647db30 100644 (file)
@@ -8,6 +8,7 @@
 </head>
 <body>
 <script>
+    testRunner.setUseITPDatabase(false);
     description("Tests that telemetry for prevalent resources is calculated correctly.");
     jsTestIsAsync = true;
 
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database-expected.txt b/LayoutTests/http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database-expected.txt
new file mode 100644 (file)
index 0000000..2842730
--- /dev/null
@@ -0,0 +1,14 @@
+Tests that user interaction is always logged for the top document/frame.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.location.origin is topFrameOrigin
+PASS testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin) is false
+PASS testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin) is false
+PASS testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin) is true
+PASS testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database.html b/LayoutTests/http/tests/resourceLoadStatistics/user-interaction-in-cross-origin-sub-frame-database.html
new file mode 100644 (file)
index 0000000..a674d09
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="/js-test-resources/js-test.js"></script>
+<script src="/js-test-resources/ui-helper.js"></script>
+<script src="resources/util.js"></script>
+<script>
+description("Tests that user interaction is always logged for the top document/frame.");
+jsTestIsAsync = true;
+testRunner.setUseITPDatabase(true);
+
+const topFrameOrigin = "http://127.0.0.1:8000";
+const subFrameOrigin = "http://localhost:8000";
+
+function activateElement(elementId) {
+    var element = document.getElementById(elementId);
+    var centerX = element.offsetLeft + element.offsetWidth / 2;
+    var centerY = element.offsetTop + element.offsetHeight / 2;
+    UIHelper.activateAt(centerX, centerY);
+}
+
+function finishTest() {
+    shouldBeTrue("testRunner.isStatisticsHasHadUserInteraction(topFrameOrigin)");
+    shouldBeFalse("testRunner.isStatisticsHasHadUserInteraction(subFrameOrigin)");
+    setEnableFeature(false, finishJSTest);
+}
+
+onload = function() {
+    setEnableFeature(true, function() {
+        if (testRunner) {
+            testRunner.setStatisticsNotifyPagesWhenDataRecordsWereScanned(true);
+            testRunner.installStatisticsDidScanDataRecordsCallback(finishTest);
+        }
+
+  &nb