OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/subresource_filter/content/browser/activation_state_computi
ng_navigation_throttle.h" | 5 #include "components/subresource_filter/content/browser/activation_state_computi
ng_navigation_throttle.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/optional.h" | 14 #include "base/optional.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/test/histogram_tester.h" |
16 #include "base/test/test_simple_task_runner.h" | 17 #include "base/test/test_simple_task_runner.h" |
17 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" | 18 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" |
18 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter_test_utils.h" | 19 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter_test_utils.h" |
19 #include "components/subresource_filter/core/common/activation_level.h" | 20 #include "components/subresource_filter/core/common/activation_level.h" |
20 #include "components/subresource_filter/core/common/activation_state.h" | 21 #include "components/subresource_filter/core/common/activation_state.h" |
21 #include "components/subresource_filter/core/common/proto/rules.pb.h" | 22 #include "components/subresource_filter/core/common/proto/rules.pb.h" |
22 #include "components/subresource_filter/core/common/test_ruleset_creator.h" | 23 #include "components/subresource_filter/core/common/test_ruleset_creator.h" |
23 #include "components/subresource_filter/core/common/test_ruleset_utils.h" | 24 #include "components/subresource_filter/core/common/test_ruleset_utils.h" |
24 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
25 #include "content/public/browser/web_contents_observer.h" | 26 #include "content/public/browser/web_contents_observer.h" |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 last_activation_state()); | 430 last_activation_state()); |
430 SimulateStartAndExpectToProceed(); | 431 SimulateStartAndExpectToProceed(); |
431 SimulateCommitAndExpectToProceed(); | 432 SimulateCommitAndExpectToProceed(); |
432 | 433 |
433 state = last_activation_state(); | 434 state = last_activation_state(); |
434 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); | 435 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); |
435 EXPECT_TRUE(state.filtering_disabled_for_document); | 436 EXPECT_TRUE(state.filtering_disabled_for_document); |
436 EXPECT_TRUE(state.generic_blocking_rules_disabled); | 437 EXPECT_TRUE(state.generic_blocking_rules_disabled); |
437 } | 438 } |
438 | 439 |
| 440 TEST_F(ActivationStateComputingThrottleSubFrameTest, DelayMetrics) { |
| 441 base::HistogramTester histogram_tester; |
| 442 NavigateAndCommitMainFrameWithPageActivationState( |
| 443 GURL("http://example.test/"), ActivationState(ActivationLevel::ENABLED)); |
| 444 ActivationState state = last_activation_state(); |
| 445 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); |
| 446 EXPECT_FALSE(state.filtering_disabled_for_document); |
| 447 |
| 448 const char kActivationDelay[] = |
| 449 "SubresourceFilter.DocumentLoad.ActivationComputingDelay"; |
| 450 const char kActivationDelayMainFrame[] = |
| 451 "SubresourceFilter.DocumentLoad.ActivationComputingDelay.MainFrame"; |
| 452 histogram_tester.ExpectTotalCount(kActivationDelay, 1); |
| 453 histogram_tester.ExpectTotalCount(kActivationDelayMainFrame, 1); |
| 454 |
| 455 // Subframe activation should not log main frame metrics. |
| 456 CreateSubframeAndInitTestNavigation(GURL("http://example.test/"), |
| 457 last_committed_frame_host(), |
| 458 last_activation_state()); |
| 459 SimulateStartAndExpectToProceed(); |
| 460 SimulateCommitAndExpectToProceed(); |
| 461 histogram_tester.ExpectTotalCount(kActivationDelay, 2); |
| 462 histogram_tester.ExpectTotalCount(kActivationDelayMainFrame, 1); |
| 463 |
| 464 // No page activation should imply no delay. |
| 465 CreateTestNavigationForMainFrame(GURL("http://example.test2/")); |
| 466 SimulateStartAndExpectToProceed(); |
| 467 SimulateCommitAndExpectToProceed(); |
| 468 |
| 469 state = last_activation_state(); |
| 470 EXPECT_EQ(ActivationLevel::DISABLED, state.activation_level); |
| 471 histogram_tester.ExpectTotalCount(kActivationDelay, 2); |
| 472 histogram_tester.ExpectTotalCount(kActivationDelayMainFrame, 1); |
| 473 } |
| 474 |
439 } // namespace subresource_filter | 475 } // namespace subresource_filter |
OLD | NEW |