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

Side by Side Diff: chrome/browser/subresource_filter/subresource_filter_unittest.cc

Issue 2844063002: Add support for multiple simultaneous subresource_filter::Configurations. (Closed)
Patch Set: Rebase. 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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 18 matching lines...) Expand all
29 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" 29 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h"
30 #include "components/subresource_filter/core/common/test_ruleset_creator.h" 30 #include "components/subresource_filter/core/common/test_ruleset_creator.h"
31 #include "content/public/browser/navigation_throttle.h" 31 #include "content/public/browser/navigation_throttle.h"
32 #include "content/public/test/navigation_simulator.h" 32 #include "content/public/test/navigation_simulator.h"
33 #include "content/public/test/test_renderer_host.h" 33 #include "content/public/test/test_renderer_host.h"
34 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
35 #include "url/gurl.h" 35 #include "url/gurl.h"
36 36
37 namespace { 37 namespace {
38 using subresource_filter::testing::ScopedSubresourceFilterConfigurator; 38 using subresource_filter::testing::ScopedSubresourceFilterConfigurator;
39 using subresource_filter::testing::ScopedSubresourceFilterFeatureToggle;
39 } // namespace 40 } // namespace
40 41
41 // End to end unit test harness of (most of) the browser process portions of the 42 // End to end unit test harness of (most of) the browser process portions of the
42 // subresource filtering code. 43 // subresource filtering code.
43 class SubresourceFilterTest : public ChromeRenderViewHostTestHarness { 44 class SubresourceFilterTest : public ChromeRenderViewHostTestHarness {
44 public: 45 public:
45 SubresourceFilterTest() {} 46 SubresourceFilterTest() {}
46 ~SubresourceFilterTest() override {} 47 ~SubresourceFilterTest() override {}
47 48
48 // ChromeRenderViewHostTestHarness: 49 // ChromeRenderViewHostTestHarness:
49 void SetUp() override { 50 void SetUp() override {
50 ChromeRenderViewHostTestHarness::SetUp(); 51 ChromeRenderViewHostTestHarness::SetUp();
51 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); 52 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
52 53
53 // Ensure correct features. 54 // Ensure correct features.
54 scoped_feature_list_.InitFromCommandLine("SafeBrowsingV4OnlyEnabled", ""); 55 scoped_feature_toggle_.ResetSubresourceFilterState(
56 base::FeatureList::OVERRIDE_ENABLE_FEATURE,
57 "SafeBrowsingV4OnlyEnabled" /* additional_features */);
55 scoped_configuration_.ResetConfiguration(subresource_filter::Configuration( 58 scoped_configuration_.ResetConfiguration(subresource_filter::Configuration(
56 subresource_filter::ActivationLevel::ENABLED, 59 subresource_filter::ActivationLevel::ENABLED,
57 subresource_filter::ActivationScope::ACTIVATION_LIST, 60 subresource_filter::ActivationScope::ACTIVATION_LIST,
58 subresource_filter::ActivationList::SUBRESOURCE_FILTER)); 61 subresource_filter::ActivationList::SUBRESOURCE_FILTER));
59 62
60 NavigateAndCommit(GURL("https://example.first")); 63 NavigateAndCommit(GURL("https://example.first"));
61 64
62 // Set up safe browsing service with the fake database manager. 65 // Set up safe browsing service with the fake database manager.
63 // 66 //
64 // TODO(csharrison): This is a bit ugly. See if the instructions in 67 // TODO(csharrison): This is a bit ugly. See if the instructions in
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER); 150 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER);
148 } 151 }
149 152
150 ChromeSubresourceFilterClient* client() { 153 ChromeSubresourceFilterClient* client() {
151 return ChromeSubresourceFilterClient::FromWebContents(web_contents()); 154 return ChromeSubresourceFilterClient::FromWebContents(web_contents());
152 } 155 }
153 156
154 private: 157 private:
155 base::ScopedTempDir ruleset_service_dir_; 158 base::ScopedTempDir ruleset_service_dir_;
156 TestingPrefServiceSimple pref_service_; 159 TestingPrefServiceSimple pref_service_;
157 base::test::ScopedFeatureList scoped_feature_list_; 160 ScopedSubresourceFilterFeatureToggle scoped_feature_toggle_;
158 ScopedSubresourceFilterConfigurator scoped_configuration_; 161 ScopedSubresourceFilterConfigurator scoped_configuration_;
159 162
160 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; 163 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_;
161 164
162 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterTest); 165 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterTest);
163 }; 166 };
164 167
165 TEST_F(SubresourceFilterTest, SimpleAllowedLoad) { 168 TEST_F(SubresourceFilterTest, SimpleAllowedLoad) {
166 GURL url("https://example.test"); 169 GURL url("https://example.test");
167 SimulateNavigateAndCommit(url, main_rfh()); 170 SimulateNavigateAndCommit(url, main_rfh());
168 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh())); 171 EXPECT_TRUE(CreateAndNavigateDisallowedSubframe(main_rfh()));
169 EXPECT_FALSE(client()->did_show_ui_for_navigation()); 172 EXPECT_FALSE(client()->did_show_ui_for_navigation());
170 } 173 }
171 174
172 TEST_F(SubresourceFilterTest, SimpleDisallowedLoad) { 175 TEST_F(SubresourceFilterTest, SimpleDisallowedLoad) {
173 GURL url("https://example.test"); 176 GURL url("https://example.test");
174 ConfigureAsSubresourceFilterOnlyURL(url); 177 ConfigureAsSubresourceFilterOnlyURL(url);
175 SimulateNavigateAndCommit(url, main_rfh()); 178 SimulateNavigateAndCommit(url, main_rfh());
176 EXPECT_FALSE(CreateAndNavigateDisallowedSubframe(main_rfh())); 179 EXPECT_FALSE(CreateAndNavigateDisallowedSubframe(main_rfh()));
177 EXPECT_TRUE(client()->did_show_ui_for_navigation()); 180 EXPECT_TRUE(client()->did_show_ui_for_navigation());
178 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698