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 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/optional.h" | 13 #include "base/optional.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/test/histogram_tester.h" |
15 #include "base/test/test_simple_task_runner.h" | 16 #include "base/test/test_simple_task_runner.h" |
16 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" | 17 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" |
17 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter_test_utils.h" | 18 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter_test_utils.h" |
18 #include "components/subresource_filter/core/common/activation_level.h" | 19 #include "components/subresource_filter/core/common/activation_level.h" |
19 #include "components/subresource_filter/core/common/activation_state.h" | 20 #include "components/subresource_filter/core/common/activation_state.h" |
20 #include "components/subresource_filter/core/common/proto/rules.pb.h" | 21 #include "components/subresource_filter/core/common/proto/rules.pb.h" |
21 #include "components/subresource_filter/core/common/test_ruleset_creator.h" | 22 #include "components/subresource_filter/core/common/test_ruleset_creator.h" |
22 #include "components/subresource_filter/core/common/test_ruleset_utils.h" | 23 #include "components/subresource_filter/core/common/test_ruleset_utils.h" |
23 #include "content/public/browser/navigation_handle.h" | 24 #include "content/public/browser/navigation_handle.h" |
24 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.h" |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 last_activation_state()); | 407 last_activation_state()); |
407 SimulateStartAndExpectToProceed(); | 408 SimulateStartAndExpectToProceed(); |
408 SimulateCommitAndExpectToProceed(); | 409 SimulateCommitAndExpectToProceed(); |
409 | 410 |
410 state = last_activation_state(); | 411 state = last_activation_state(); |
411 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); | 412 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); |
412 EXPECT_TRUE(state.filtering_disabled_for_document); | 413 EXPECT_TRUE(state.filtering_disabled_for_document); |
413 EXPECT_TRUE(state.generic_blocking_rules_disabled); | 414 EXPECT_TRUE(state.generic_blocking_rules_disabled); |
414 } | 415 } |
415 | 416 |
| 417 TEST_F(ActivationStateComputingThrottleSubFrameTest, DelayMetrics) { |
| 418 base::HistogramTester histogram_tester; |
| 419 NavigateAndCommitMainFrameWithPageActivationState( |
| 420 GURL("http://example.test/"), ActivationState(ActivationLevel::ENABLED)); |
| 421 ActivationState state = last_activation_state(); |
| 422 EXPECT_EQ(ActivationLevel::ENABLED, state.activation_level); |
| 423 EXPECT_FALSE(state.filtering_disabled_for_document); |
| 424 |
| 425 const char kActivationDelay[] = |
| 426 "SubresourceFilter.DocumentLoad.ActivationComputingDelay"; |
| 427 const char kActivationDelayMainFrame[] = |
| 428 "SubresourceFilter.DocumentLoad.ActivationComputingDelay.MainFrame"; |
| 429 histogram_tester.ExpectTotalCount(kActivationDelay, 1); |
| 430 histogram_tester.ExpectTotalCount(kActivationDelayMainFrame, 1); |
| 431 |
| 432 // Subframe activation should not log main frame metrics. |
| 433 CreateSubframeAndInitTestNavigation(GURL("http://example.test/"), |
| 434 last_committed_frame_host(), |
| 435 last_activation_state()); |
| 436 SimulateStartAndExpectToProceed(); |
| 437 SimulateCommitAndExpectToProceed(); |
| 438 histogram_tester.ExpectTotalCount(kActivationDelay, 2); |
| 439 histogram_tester.ExpectTotalCount(kActivationDelayMainFrame, 1); |
| 440 |
| 441 // No page activation should imply no delay. |
| 442 CreateTestNavigationForMainFrame(GURL("http://example.test2/")); |
| 443 SimulateStartAndExpectToProceed(); |
| 444 SimulateCommitAndExpectToProceed(); |
| 445 |
| 446 state = last_activation_state(); |
| 447 EXPECT_EQ(ActivationLevel::DISABLED, state.activation_level); |
| 448 histogram_tester.ExpectTotalCount(kActivationDelay, 2); |
| 449 histogram_tester.ExpectTotalCount(kActivationDelayMainFrame, 1); |
| 450 } |
| 451 |
416 } // namespace subresource_filter | 452 } // namespace subresource_filter |
OLD | NEW |