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

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

Issue 2556433003: Support optional performance measuring in SubresourceFilter. (Closed)
Patch Set: Link TODO to a bug. 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 992053a3ad725b2f11c0ffe61582bbc5f1d0092b..f55a97c827e89237e576d095488a5e7b8717a16b 100644
--- a/components/subresource_filter/content/renderer/subresource_filter_agent_unittest.cc
+++ b/components/subresource_filter/content/renderer/subresource_filter_agent_unittest.cc
@@ -121,11 +121,12 @@ class SubresourceFilterAgentTest : public ::testing::Test {
true /* is_new_navigation */, false /* is_same_page_navigation */);
}
- void StartLoadAndSetActivationState(ActivationState activation_state) {
+ void StartLoadAndSetActivationState(ActivationState activation_state,
+ bool measure_performance = false) {
agent_as_rfo()->DidStartProvisionalLoad();
EXPECT_TRUE(agent_as_rfo()->OnMessageReceived(
- SubresourceFilterMsg_ActivateForProvisionalLoad(0, activation_state,
- GURL())));
+ SubresourceFilterMsg_ActivateForProvisionalLoad(
+ 0, activation_state, GURL(), measure_performance)));
agent_as_rfo()->DidCommitProvisionalLoad(
true /* is_new_navigation */, false /* is_same_page_navigation */);
}
@@ -252,7 +253,7 @@ TEST_F(SubresourceFilterAgentTest,
agent_as_rfo()->DidStartProvisionalLoad();
EXPECT_TRUE(agent_as_rfo()->OnMessageReceived(
SubresourceFilterMsg_ActivateForProvisionalLoad(
- 0, ActivationState::ENABLED, GURL())));
+ 0, ActivationState::ENABLED, GURL(), true)));
agent_as_rfo()->DidStartProvisionalLoad();
agent_as_rfo()->DidCommitProvisionalLoad(true /* is_new_navigation */,
false /* is_same_page_navigation */);
@@ -388,9 +389,37 @@ TEST_F(SubresourceFilterAgentTest, Enabled_HistogramSamples) {
EXPECT_THAT(histogram_tester.GetAllSamples(kSubresourcesDisallowed),
::testing::ElementsAre(base::Bucket(1, 1), base::Bucket(2, 1)));
- histogram_tester.ExpectTotalCount(kEvaluationTotalWallDuration, 2);
+ // Performance measurement is switched off.
+ histogram_tester.ExpectTotalCount(kEvaluationTotalWallDuration, 0);
+ histogram_tester.ExpectTotalCount(kEvaluationTotalCPUDuration, 0);
+}
+
+TEST_F(SubresourceFilterAgentTest, Enabled_PerformanceMeasurementSamples) {
+ base::HistogramTester histogram_tester;
+ ASSERT_NO_FATAL_FAILURE(
+ SetTestRulesetToDisallowURLsWithPathSuffix(kTestFirstURLPathSuffix));
+ ExpectSubresourceFilterGetsInjected();
+ StartLoadAndSetActivationState(ActivationState::ENABLED, true);
+ ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent()));
+
+ ExpectSignalAboutFirstSubresourceDisallowed();
+ ExpectLoadAllowed(kTestFirstURL, false);
+ ExpectLoadAllowed(kTestFirstURL, false);
+ ExpectLoadAllowed(kTestSecondURL, true);
+ FinishLoad();
+
+ ExpectSubresourceFilterGetsInjected();
+ StartLoadAndSetActivationState(ActivationState::ENABLED, true);
+ ASSERT_TRUE(::testing::Mock::VerifyAndClearExpectations(agent()));
+
+ ExpectSignalAboutFirstSubresourceDisallowed();
+ ExpectLoadAllowed(kTestFirstURL, false);
+ ExpectLoadAllowed(kTestSecondURL, true);
+ FinishLoad();
+
const base::HistogramBase::Count total_count =
base::ThreadTicks::IsSupported() ? 2 : 0;
+ histogram_tester.ExpectTotalCount(kEvaluationTotalWallDuration, total_count);
histogram_tester.ExpectTotalCount(kEvaluationTotalCPUDuration, total_count);
}
@@ -420,10 +449,9 @@ TEST_F(SubresourceFilterAgentTest, DryRun_HistogramSamples) {
histogram_tester.ExpectUniqueSample(kSubresourcesMatchedRules, 2, 1);
histogram_tester.ExpectUniqueSample(kSubresourcesDisallowed, 0, 1);
- histogram_tester.ExpectTotalCount(kEvaluationTotalWallDuration, 1);
- const base::HistogramBase::Count total_count =
- base::ThreadTicks::IsSupported() ? 1 : 0;
- histogram_tester.ExpectTotalCount(kEvaluationTotalCPUDuration, total_count);
+ // Performance measurement is switched off.
+ histogram_tester.ExpectTotalCount(kEvaluationTotalWallDuration, 0);
+ histogram_tester.ExpectTotalCount(kEvaluationTotalCPUDuration, 0);
}
} // namespace subresource_filter
« 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