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

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

Issue 2795053002: [subresource_filter] Implement the "Smart" UI on Android (Closed)
Patch Set: fix tests Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_driver_factory.h" 5 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 MockSubresourceFilterClient() {} 182 MockSubresourceFilterClient() {}
183 183
184 ~MockSubresourceFilterClient() override = default; 184 ~MockSubresourceFilterClient() override = default;
185 185
186 bool IsWhitelistedByContentSettings(const GURL& url) override { 186 bool IsWhitelistedByContentSettings(const GURL& url) override {
187 return false; 187 return false;
188 } 188 }
189 189
190 void WhitelistByContentSettings(const GURL& url) override {} 190 void WhitelistByContentSettings(const GURL& url) override {}
191 191
192 MOCK_METHOD1(ToggleNotificationVisibility, void(bool)); 192 MOCK_METHOD2(ToggleNotificationVisibility, void(const GURL&, bool));
193 193
194 private: 194 private:
195 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient); 195 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient);
196 }; 196 };
197 197
198 } // namespace 198 } // namespace
199 199
200 class ContentSubresourceFilterDriverFactoryTest 200 class ContentSubresourceFilterDriverFactoryTest
201 : public content::RenderViewHostTestHarness { 201 : public content::RenderViewHostTestHarness {
202 public: 202 public:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 const std::vector<GURL>& navigation_chain, 254 const std::vector<GURL>& navigation_chain,
255 safe_browsing::SBThreatType threat_type, 255 safe_browsing::SBThreatType threat_type,
256 safe_browsing::ThreatPatternType threat_type_metadata, 256 safe_browsing::ThreatPatternType threat_type_metadata,
257 const content::Referrer& referrer, 257 const content::Referrer& referrer,
258 ui::PageTransition transition, 258 ui::PageTransition transition,
259 RedirectChainMatchPattern expected_pattern, 259 RedirectChainMatchPattern expected_pattern,
260 ActivationDecision expected_activation_decision) { 260 ActivationDecision expected_activation_decision) {
261 const bool expected_activation = 261 const bool expected_activation =
262 expected_activation_decision == ActivationDecision::ACTIVATED; 262 expected_activation_decision == ActivationDecision::ACTIVATED;
263 base::HistogramTester tester; 263 base::HistogramTester tester;
264 EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1); 264 EXPECT_CALL(*client(),
265 ToggleNotificationVisibility(navigation_chain.front(), false))
266 .Times(1);
265 267
266 std::unique_ptr<content::NavigationSimulator> navigation_simulator = 268 std::unique_ptr<content::NavigationSimulator> navigation_simulator =
267 content::NavigationSimulator::CreateRendererInitiated( 269 content::NavigationSimulator::CreateRendererInitiated(
268 navigation_chain.front(), main_rfh()); 270 navigation_chain.front(), main_rfh());
269 navigation_simulator->SetReferrer(referrer); 271 navigation_simulator->SetReferrer(referrer);
270 navigation_simulator->SetTransition(transition); 272 navigation_simulator->SetTransition(transition);
271 navigation_simulator->Start(); 273 navigation_simulator->Start();
272 274
273 if (blacklisted_urls.front()) { 275 if (blacklisted_urls.front()) {
274 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( 276 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 // Check that we recorded only what is needed. 314 // Check that we recorded only what is needed.
313 EXPECT_EQ(1u, all_pattern); 315 EXPECT_EQ(1u, all_pattern);
314 EXPECT_EQ(1u, all_chain_size); 316 EXPECT_EQ(1u, all_chain_size);
315 } else { 317 } else {
316 EXPECT_EQ(0u, all_pattern); 318 EXPECT_EQ(0u, all_pattern);
317 EXPECT_EQ(0u, all_chain_size); 319 EXPECT_EQ(0u, all_chain_size);
318 } 320 }
319 } 321 }
320 322
321 void NavigateAndCommitSubframe(const GURL& url, bool expected_activation) { 323 void NavigateAndCommitSubframe(const GURL& url, bool expected_activation) {
322 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); 324 EXPECT_CALL(*client(),
325 ToggleNotificationVisibility(::testing::_, ::testing::_))
326 .Times(0);
323 327
324 content::NavigationSimulator::NavigateAndCommitFromDocument( 328 content::NavigationSimulator::NavigateAndCommitFromDocument(
325 url, GetSubframeRFH()); 329 url, GetSubframeRFH());
326 ExpectActivationSignalForFrame(GetSubframeRFH(), expected_activation); 330 ExpectActivationSignalForFrame(GetSubframeRFH(), expected_activation);
327 ::testing::Mock::VerifyAndClearExpectations(client()); 331 ::testing::Mock::VerifyAndClearExpectations(client());
328 } 332 }
329 333
330 void NavigateAndExpectActivation( 334 void NavigateAndExpectActivation(
331 const std::vector<bool>& blacklisted_urls, 335 const std::vector<bool>& blacklisted_urls,
332 const std::vector<GURL>& navigation_chain, 336 const std::vector<GURL>& navigation_chain,
(...skipping 26 matching lines...) Expand all
359 } 363 }
360 364
361 void EmulateDidDisallowFirstSubresourceMessage() { 365 void EmulateDidDisallowFirstSubresourceMessage() {
362 factory()->OnMessageReceived( 366 factory()->OnMessageReceived(
363 SubresourceFilterHostMsg_DidDisallowFirstSubresource( 367 SubresourceFilterHostMsg_DidDisallowFirstSubresource(
364 main_rfh()->GetRoutingID()), 368 main_rfh()->GetRoutingID()),
365 main_rfh()); 369 main_rfh());
366 } 370 }
367 371
368 void EmulateFailedNavigationAndExpectNoActivation(const GURL& url) { 372 void EmulateFailedNavigationAndExpectNoActivation(const GURL& url) {
369 EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1); 373 EXPECT_CALL(*client(), ToggleNotificationVisibility(url, false)).Times(1);
370 374
371 // With browser-side navigation enabled, ReadyToCommitNavigation is invoked 375 // With browser-side navigation enabled, ReadyToCommitNavigation is invoked
372 // even for failed navigations. This is correctly simulated by 376 // even for failed navigations. This is correctly simulated by
373 // NavigationSimulator. Make sure no activation message is sent in this 377 // NavigationSimulator. Make sure no activation message is sent in this
374 // case. 378 // case.
375 content::NavigationSimulator::NavigateAndFailFromDocument( 379 content::NavigationSimulator::NavigateAndFailFromDocument(
376 url, net::ERR_TIMED_OUT, main_rfh()); 380 url, net::ERR_TIMED_OUT, main_rfh());
377 ExpectActivationSignalForFrame(main_rfh(), false); 381 ExpectActivationSignalForFrame(main_rfh(), false);
378 ::testing::Mock::VerifyAndClearExpectations(client()); 382 ::testing::Mock::VerifyAndClearExpectations(client());
379 } 383 }
380 384
381 void EmulateInPageNavigation( 385 void EmulateInPageNavigation(
382 const std::vector<bool>& blacklisted_urls, 386 const std::vector<bool>& blacklisted_urls,
383 RedirectChainMatchPattern expected_pattern, 387 RedirectChainMatchPattern expected_pattern,
384 ActivationDecision expected_activation_decision) { 388 ActivationDecision expected_activation_decision) {
385 // This test examines the navigation with the following sequence of events: 389 // This test examines the navigation with the following sequence of events:
386 // DidStartProvisional(main, "example.com") 390 // DidStartProvisional(main, "example.com")
387 // ReadyToCommitNavigation(“example.com”) 391 // ReadyToCommitNavigation(“example.com”)
388 // DidCommitProvisional(main, "example.com") 392 // DidCommitProvisional(main, "example.com")
389 // DidStartProvisional(sub, "example.com/login") 393 // DidStartProvisional(sub, "example.com/login")
390 // DidCommitProvisional(sub, "example.com/login") 394 // DidCommitProvisional(sub, "example.com/login")
391 // DidCommitProvisional(main, "example.com#ref") 395 // DidCommitProvisional(main, "example.com#ref")
392 396
393 NavigateAndExpectActivation(blacklisted_urls, {GURL(kExampleUrl)}, 397 NavigateAndExpectActivation(blacklisted_urls, {GURL(kExampleUrl)},
394 expected_pattern, expected_activation_decision); 398 expected_pattern, expected_activation_decision);
395 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); 399 EXPECT_CALL(*client(),
400 ToggleNotificationVisibility(::testing::_, ::testing::_))
401 .Times(0);
396 std::unique_ptr<content::NavigationSimulator> navigation_simulator = 402 std::unique_ptr<content::NavigationSimulator> navigation_simulator =
397 content::NavigationSimulator::CreateRendererInitiated(GURL(kExampleUrl), 403 content::NavigationSimulator::CreateRendererInitiated(GURL(kExampleUrl),
398 main_rfh()); 404 main_rfh());
399 navigation_simulator->CommitSameDocument(); 405 navigation_simulator->CommitSameDocument();
400 ExpectActivationSignalForFrame(main_rfh(), false); 406 ExpectActivationSignalForFrame(main_rfh(), false);
401 ::testing::Mock::VerifyAndClearExpectations(client()); 407 ::testing::Mock::VerifyAndClearExpectations(client());
402 } 408 }
403 409
404 private: 410 private:
405 static bool expected_measure_performance() { 411 static bool expected_measure_performance() {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 #endif 623 #endif
618 } 624 }
619 } 625 }
620 626
621 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { 627 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) {
622 base::FieldTrialList field_trial_list(nullptr); 628 base::FieldTrialList field_trial_list(nullptr);
623 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 629 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
624 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, 630 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled,
625 kActivationScopeAllSites); 631 kActivationScopeAllSites);
626 632
627 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, 633 GURL url(kExampleUrl);
634 NavigateAndExpectActivation({false}, {url}, EMPTY,
628 ActivationDecision::ACTIVATED); 635 ActivationDecision::ACTIVATED);
629 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); 636 EXPECT_CALL(*client(), ToggleNotificationVisibility(url, true)).Times(1);
630 EmulateDidDisallowFirstSubresourceMessage(); 637 EmulateDidDisallowFirstSubresourceMessage();
631 } 638 }
632 639
633 TEST_F(ContentSubresourceFilterDriverFactoryTest, 640 TEST_F(ContentSubresourceFilterDriverFactoryTest,
634 SuppressNotificationVisibility) { 641 SuppressNotificationVisibility) {
635 base::FieldTrialList field_trial_list(nullptr); 642 base::FieldTrialList field_trial_list(nullptr);
636 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 643 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
637 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, 644 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled,
638 kActivationScopeAllSites, "" /* activation_lists */, 645 kActivationScopeAllSites, "" /* activation_lists */,
639 "" /* performance_measurement_rate */, 646 "" /* performance_measurement_rate */,
640 "true" /* suppress_notifications */); 647 "true" /* suppress_notifications */);
641 648
642 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, 649 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY,
643 ActivationDecision::ACTIVATED); 650 ActivationDecision::ACTIVATED);
644 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); 651 EXPECT_CALL(*client(),
652 ToggleNotificationVisibility(::testing::_, ::testing::_))
653 .Times(0);
645 EmulateDidDisallowFirstSubresourceMessage(); 654 EmulateDidDisallowFirstSubresourceMessage();
646 } 655 }
647 656
648 TEST_F(ContentSubresourceFilterDriverFactoryTest, WhitelistSiteOnReload) { 657 TEST_F(ContentSubresourceFilterDriverFactoryTest, WhitelistSiteOnReload) {
649 const struct { 658 const struct {
650 content::Referrer referrer; 659 content::Referrer referrer;
651 ui::PageTransition transition; 660 ui::PageTransition transition;
652 ActivationDecision expected_activation_decision; 661 ActivationDecision expected_activation_decision;
653 } kTestCases[] = { 662 } kTestCases[] = {
654 {content::Referrer(), ui::PAGE_TRANSITION_LINK, 663 {content::Referrer(), ui::PAGE_TRANSITION_LINK,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 ActivationScopeTest, 808 ActivationScopeTest,
800 ContentSubresourceFilterDriverFactoryActivationScopeTest, 809 ContentSubresourceFilterDriverFactoryActivationScopeTest,
801 ::testing::ValuesIn(kActivationScopeTestData)); 810 ::testing::ValuesIn(kActivationScopeTestData));
802 811
803 INSTANTIATE_TEST_CASE_P( 812 INSTANTIATE_TEST_CASE_P(
804 ActivationLevelTest, 813 ActivationLevelTest,
805 ContentSubresourceFilterDriverFactoryActivationLevelTest, 814 ContentSubresourceFilterDriverFactoryActivationLevelTest,
806 ::testing::ValuesIn(kActivationLevelTestData)); 815 ::testing::ValuesIn(kActivationLevelTestData));
807 816
808 } // namespace subresource_filter 817 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698