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

Side by Side Diff: components/subresource_filter/content/browser/content_subresource_filter_throttle_manager_unittest.cc

Issue 2841933003: [subresource_filter] Remove some state from the driver factory (Closed)
Patch Set: no more dep branch Created 3 years, 7 months 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 unified diff | Download patch
OLDNEW
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/content_subresource_filt er_throttle_manager.h" 5 #include "components/subresource_filter/content/browser/content_subresource_filt er_throttle_manager.h"
6 6
7 #include <map>
7 #include <memory> 8 #include <memory>
9 #include <set>
10 #include <tuple>
8 #include <utility> 11 #include <utility>
9 12
10 #include "base/logging.h" 13 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h" 15 #include "base/run_loop.h"
13 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
14 #include "base/test/test_simple_task_runner.h" 17 #include "base/test/test_simple_task_runner.h"
15 #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"
16 #include "components/subresource_filter/content/common/subresource_filter_messag es.h" 19 #include "components/subresource_filter/content/common/subresource_filter_messag es.h"
17 #include "components/subresource_filter/core/common/activation_level.h" 20 #include "components/subresource_filter/core/common/activation_level.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 const char* GetNameForLogging() override { 79 const char* GetNameForLogging() override {
77 return "MockPageStateActivationThrottle"; 80 return "MockPageStateActivationThrottle";
78 } 81 }
79 82
80 private: 83 private:
81 content::NavigationThrottle::ThrottleCheckResult MaybeNotifyActivation( 84 content::NavigationThrottle::ThrottleCheckResult MaybeNotifyActivation(
82 PageActivationNotificationTiming throttle_state) { 85 PageActivationNotificationTiming throttle_state) {
83 if (throttle_state == activation_throttle_state_) { 86 if (throttle_state == activation_throttle_state_) {
84 auto it = mock_page_activations_.find(navigation_handle()->GetURL()); 87 auto it = mock_page_activations_.find(navigation_handle()->GetURL());
85 if (it != mock_page_activations_.end()) { 88 if (it != mock_page_activations_.end()) {
86 throttle_manager_->NotifyPageActivationComputed(navigation_handle(), 89 throttle_manager_->NotifyPageActivationComputed(
87 it->second); 90 navigation_handle(), it->second, ActivationDecision::ACTIVATED);
91 } else {
92 throttle_manager_->NotifyPageActivationComputed(
93 navigation_handle(), ActivationState(ActivationLevel::DISABLED),
94 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED);
88 } 95 }
89 } 96 }
90 return content::NavigationThrottle::PROCEED; 97 return content::NavigationThrottle::PROCEED;
91 } 98 }
92 99
93 std::map<GURL, ActivationState> mock_page_activations_; 100 std::map<GURL, ActivationState> mock_page_activations_;
94 PageActivationNotificationTiming activation_throttle_state_; 101 PageActivationNotificationTiming activation_throttle_state_;
95 ContentSubresourceFilterThrottleManager* throttle_manager_; 102 ContentSubresourceFilterThrottleManager* throttle_manager_;
96 103
97 DISALLOW_COPY_AND_ASSIGN(MockPageStateActivationThrottle); 104 DISALLOW_COPY_AND_ASSIGN(MockPageStateActivationThrottle);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 content::NavigationHandle* navigation_handle) override { 260 content::NavigationHandle* navigation_handle) override {
254 if (navigation_handle->IsSameDocument()) 261 if (navigation_handle->IsSameDocument())
255 return; 262 return;
256 263
257 // Inject the proper throttles at this time. 264 // Inject the proper throttles at this time.
258 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; 265 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
259 PageActivationNotificationTiming state = 266 PageActivationNotificationTiming state =
260 ::testing::UnitTest::GetInstance()->current_test_info()->value_param() 267 ::testing::UnitTest::GetInstance()->current_test_info()->value_param()
261 ? GetParam() 268 ? GetParam()
262 : WILL_PROCESS_RESPONSE; 269 : WILL_PROCESS_RESPONSE;
263 throttles.push_back(base::MakeUnique<MockPageStateActivationThrottle>( 270 if (navigation_handle->IsInMainFrame()) {
264 navigation_handle, state, throttle_manager_.get())); 271 throttles.push_back(base::MakeUnique<MockPageStateActivationThrottle>(
272 navigation_handle, state, throttle_manager_.get()));
273 }
265 throttle_manager_->MaybeAppendNavigationThrottles(navigation_handle, 274 throttle_manager_->MaybeAppendNavigationThrottles(navigation_handle,
266 &throttles); 275 &throttles);
267 for (auto& it : throttles) { 276 for (auto& it : throttles) {
268 navigation_handle->RegisterThrottleForTesting(std::move(it)); 277 navigation_handle->RegisterThrottleForTesting(std::move(it));
269 } 278 }
270 } 279 }
271 280
272 // ContentSubresourceFilterThrottleManager::Delegate: 281 // ContentSubresourceFilterThrottleManager::Delegate:
273 void OnFirstSubresourceLoadDisallowed() override { 282 void OnFirstSubresourceLoadDisallowed() override {
274 ++disallowed_notification_count_; 283 ++disallowed_notification_count_;
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 EXPECT_EQ(0, disallowed_notification_count()); 703 EXPECT_EQ(0, disallowed_notification_count());
695 EXPECT_EQ(1, attempted_frame_activations()); 704 EXPECT_EQ(1, attempted_frame_activations());
696 } 705 }
697 706
698 // TODO(csharrison): Make sure the following conditions are exercised in tests: 707 // TODO(csharrison): Make sure the following conditions are exercised in tests:
699 // 708 //
700 // - Synchronous navigations to about:blank. These hit issues with the 709 // - Synchronous navigations to about:blank. These hit issues with the
701 // NavigationSimulator currently. 710 // NavigationSimulator currently.
702 711
703 } // namespace subresource_filter 712 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698