Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Unified Diff: components/subresource_filter/content/renderer/subresource_filter_agent_unittest.cc

Issue 2574193002: Make subresource filter activation agnostic of in-page navigations. (Closed)
Patch Set: Final test fix. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/subresource_filter/content/renderer/subresource_filter_agent.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/subresource_filter/content/renderer/subresource_filter_agent_unittest.cc
diff --git a/components/subresource_filter/content/renderer/subresource_filter_agent_unittest.cc b/components/subresource_filter/content/renderer/subresource_filter_agent_unittest.cc
index 29227c0f3042964e329676e6c2cd476ac6e0b008..7839276f4012086b31dfac6d7f7da0ea322cdab5 100644
--- a/components/subresource_filter/content/renderer/subresource_filter_agent_unittest.cc
+++ b/components/subresource_filter/content/renderer/subresource_filter_agent_unittest.cc
@@ -121,6 +121,13 @@ class SubresourceFilterAgentTest : public ::testing::Test {
true /* is_new_navigation */, false /* is_same_page_navigation */);
}
+ void PerformSamePageNavigationWithoutSettingActivationState() {
+ agent_as_rfo()->DidStartProvisionalLoad();
+ agent_as_rfo()->DidCommitProvisionalLoad(
+ true /* is_new_navigation */, true /* is_same_page_navigation */);
+ // No DidFinishLoad is called in this case.
+ }
+
void StartLoadAndSetActivationState(ActivationState activation_state,
bool measure_performance = false) {
agent_as_rfo()->DidStartProvisionalLoad();
@@ -238,10 +245,23 @@ TEST_F(SubresourceFilterAgentTest, Enabled_FilteringIsInEffectForOneLoad) {
ExpectLoadAllowed(kTestSecondURL, true);
FinishLoad();
+ // In-page navigation should not count as a new load.
+ ExpectNoSubresourceFilterGetsInjected();
+ ExpectNoSignalAboutFirstSubresourceDisallowed();
+ PerformSamePageNavigationWithoutSettingActivationState();
+ ExpectLoadAllowed(kTestFirstURL, false);
+ ExpectLoadAllowed(kTestSecondURL, true);
+
ExpectNoSubresourceFilterGetsInjected();
StartLoadWithoutSettingActivationState();
FinishLoad();
+ // Resource loads after the in-page navigation should not be counted toward
+ // the figures below, as they came after the original page load event.
+ histogram_tester.ExpectUniqueSample(kSubresourcesTotal, 2, 1);
+ histogram_tester.ExpectUniqueSample(kSubresourcesEvaluated, 2, 1);
+ histogram_tester.ExpectUniqueSample(kSubresourcesMatchedRules, 1, 1);
+ histogram_tester.ExpectUniqueSample(kSubresourcesDisallowed, 1, 1);
EXPECT_THAT(histogram_tester.GetAllSamples(kDocumentLoadActivationState),
::testing::ElementsAre(
base::Bucket(static_cast<int>(ActivationState::DISABLED), 1),
@@ -249,7 +269,7 @@ TEST_F(SubresourceFilterAgentTest, Enabled_FilteringIsInEffectForOneLoad) {
histogram_tester.ExpectUniqueSample(kDocumentLoadRulesetIsAvailable, 1, 1);
}
-TEST_F(SubresourceFilterAgentTest, Enabled_HistogramSamples) {
+TEST_F(SubresourceFilterAgentTest, Enabled_HistogramSamplesOverTwoLoads) {
for (const bool measure_performance : {false, true}) {
base::HistogramTester histogram_tester;
ASSERT_NO_FATAL_FAILURE(
« no previous file with comments | « components/subresource_filter/content/renderer/subresource_filter_agent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698