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/subframe_navigation_filt
ering_throttle.h" | 5 #include "components/subresource_filter/content/browser/subframe_navigation_filt
ering_throttle.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/test/histogram_tester.h" |
14 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" | 15 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter.h" |
15 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter_test_utils.h" | 16 #include "components/subresource_filter/content/browser/async_document_subresour
ce_filter_test_utils.h" |
16 #include "components/subresource_filter/core/common/activation_level.h" | 17 #include "components/subresource_filter/core/common/activation_level.h" |
17 #include "components/subresource_filter/core/common/activation_state.h" | 18 #include "components/subresource_filter/core/common/activation_state.h" |
18 #include "components/subresource_filter/core/common/test_ruleset_creator.h" | 19 #include "components/subresource_filter/core/common/test_ruleset_creator.h" |
19 #include "content/public/browser/navigation_handle.h" | 20 #include "content/public/browser/navigation_handle.h" |
20 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
21 #include "content/public/test/navigation_simulator.h" | 22 #include "content/public/test/navigation_simulator.h" |
22 #include "content/public/test/test_renderer_host.h" | 23 #include "content/public/test/test_renderer_host.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 ->SimulateNavigationStart(test_url); | 184 ->SimulateNavigationStart(test_url); |
184 InitializeDocumentSubresourceFilter(GURL("https://example.test")); | 185 InitializeDocumentSubresourceFilter(GURL("https://example.test")); |
185 content::RenderFrameHostTester::For(parent_subframe) | 186 content::RenderFrameHostTester::For(parent_subframe) |
186 ->SimulateNavigationCommit(test_url); | 187 ->SimulateNavigationCommit(test_url); |
187 | 188 |
188 CreateTestSubframeAndInitNavigation( | 189 CreateTestSubframeAndInitNavigation( |
189 GURL("https://example.test/disallowed.html"), parent_subframe); | 190 GURL("https://example.test/disallowed.html"), parent_subframe); |
190 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); | 191 SimulateStartAndExpectResult(content::NavigationThrottle::CANCEL); |
191 } | 192 } |
192 | 193 |
| 194 TEST_F(SubframeNavigationFilteringThrottleTest, DelayMetrics) { |
| 195 base::HistogramTester histogram_tester; |
| 196 InitializeDocumentSubresourceFilter(GURL("https://example.test")); |
| 197 CreateTestSubframeAndInitNavigation(GURL("https://example.test/allowed.html"), |
| 198 main_rfh()); |
| 199 |
| 200 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 201 SimulateRedirectAndExpectResult(GURL("https://example.test/disallowed.html"), |
| 202 content::NavigationThrottle::CANCEL); |
| 203 |
| 204 const char kFilterDelayDisallowed[] = |
| 205 "SubresourceFilter.DocumentLoad.SubframeFilteringDelay.Disallowed"; |
| 206 const char kFilterDelayAllowed[] = |
| 207 "SubresourceFilter.DocumentLoad.SubframeFilteringDelay.Allowed"; |
| 208 histogram_tester.ExpectTotalCount(kFilterDelayDisallowed, 1); |
| 209 histogram_tester.ExpectTotalCount(kFilterDelayAllowed, 0); |
| 210 |
| 211 CreateTestSubframeAndInitNavigation(GURL("https://example.test/allowed.html"), |
| 212 main_rfh()); |
| 213 SimulateStartAndExpectResult(content::NavigationThrottle::PROCEED); |
| 214 SimulateCommitAndExpectResult(content::NavigationThrottle::PROCEED); |
| 215 histogram_tester.ExpectTotalCount(kFilterDelayDisallowed, 1); |
| 216 histogram_tester.ExpectTotalCount(kFilterDelayAllowed, 1); |
| 217 } |
| 218 |
193 } // namespace subresource_filter | 219 } // namespace subresource_filter |
OLD | NEW |