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

Side by Side Diff: chrome/browser/safe_browsing/ui_manager_unittest.cc

Issue 2481743009: Expose malware/phishing/etc. distinction from SafeBrowsingUIManager (Closed)
Patch Set: rebase Created 4 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/safe_browsing/ui_manager.h" 5 #include "chrome/browser/safe_browsing/ui_manager.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 8 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
10 #include "chrome/browser/safe_browsing/ui_manager.h" 10 #include "chrome/browser/safe_browsing/ui_manager.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 void TearDown() override { ChromeRenderViewHostTestHarness::TearDown(); } 80 void TearDown() override { ChromeRenderViewHostTestHarness::TearDown(); }
81 81
82 bool IsWhitelisted(SafeBrowsingUIManager::UnsafeResource resource) { 82 bool IsWhitelisted(SafeBrowsingUIManager::UnsafeResource resource) {
83 return ui_manager_->IsWhitelisted(resource); 83 return ui_manager_->IsWhitelisted(resource);
84 } 84 }
85 85
86 void AddToWhitelist(SafeBrowsingUIManager::UnsafeResource resource) { 86 void AddToWhitelist(SafeBrowsingUIManager::UnsafeResource resource) {
87 ui_manager_->AddToWhitelistUrlSet( 87 ui_manager_->AddToWhitelistUrlSet(
88 SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting( 88 SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting(
89 resource), 89 resource),
90 web_contents(), false); 90 web_contents(), false, resource.threat_type);
91 } 91 }
92 92
93 SafeBrowsingUIManager::UnsafeResource MakeUnsafeResource( 93 SafeBrowsingUIManager::UnsafeResource MakeUnsafeResource(
94 const char* url, 94 const char* url,
95 bool is_subresource) { 95 bool is_subresource) {
96 SafeBrowsingUIManager::UnsafeResource resource; 96 SafeBrowsingUIManager::UnsafeResource resource;
97 resource.url = GURL(url); 97 resource.url = GURL(url);
98 resource.is_subresource = is_subresource; 98 resource.is_subresource = is_subresource;
99 resource.web_contents_getter = 99 resource.web_contents_getter =
100 SafeBrowsingUIManager::UnsafeResource::GetWebContentsGetter( 100 SafeBrowsingUIManager::UnsafeResource::GetWebContentsGetter(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 AddToWhitelist(resource); 141 AddToWhitelist(resource);
142 EXPECT_TRUE(IsWhitelisted(resource)); 142 EXPECT_TRUE(IsWhitelisted(resource));
143 } 143 }
144 144
145 TEST_F(SafeBrowsingUIManagerTest, WhitelistIgnoresSitesNotAdded) { 145 TEST_F(SafeBrowsingUIManagerTest, WhitelistIgnoresSitesNotAdded) {
146 SafeBrowsingUIManager::UnsafeResource resource = 146 SafeBrowsingUIManager::UnsafeResource resource =
147 MakeUnsafeResourceAndStartNavigation(kGoodURL); 147 MakeUnsafeResourceAndStartNavigation(kGoodURL);
148 EXPECT_FALSE(IsWhitelisted(resource)); 148 EXPECT_FALSE(IsWhitelisted(resource));
149 } 149 }
150 150
151 TEST_F(SafeBrowsingUIManagerTest, WhitelistRemembersThreatType) {
152 SafeBrowsingUIManager::UnsafeResource resource =
153 MakeUnsafeResourceAndStartNavigation(kBadURL);
154 AddToWhitelist(resource);
155 EXPECT_TRUE(IsWhitelisted(resource));
156 SBThreatType threat_type;
157 content::NavigationEntry* entry =
158 web_contents()->GetController().GetVisibleEntry();
159 ASSERT_TRUE(entry);
160 EXPECT_TRUE(ui_manager()->IsUrlWhitelistedOrPendingForWebContents(
161 resource.url, resource.is_subresource, entry,
162 resource.web_contents_getter.Run(), true, &threat_type));
163 EXPECT_EQ(resource.threat_type, threat_type);
164 }
165
151 TEST_F(SafeBrowsingUIManagerTest, WhitelistIgnoresPath) { 166 TEST_F(SafeBrowsingUIManagerTest, WhitelistIgnoresPath) {
152 SafeBrowsingUIManager::UnsafeResource resource = 167 SafeBrowsingUIManager::UnsafeResource resource =
153 MakeUnsafeResourceAndStartNavigation(kBadURL); 168 MakeUnsafeResourceAndStartNavigation(kBadURL);
154 AddToWhitelist(resource); 169 AddToWhitelist(resource);
155 EXPECT_TRUE(IsWhitelisted(resource)); 170 EXPECT_TRUE(IsWhitelisted(resource));
156 171
157 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 172 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
158 173
159 SafeBrowsingUIManager::UnsafeResource resource_path = 174 SafeBrowsingUIManager::UnsafeResource resource_path =
160 MakeUnsafeResourceAndStartNavigation(kBadURLWithPath); 175 MakeUnsafeResourceAndStartNavigation(kBadURLWithPath);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 SimulateBlockingPageDone(resources, true); 404 SimulateBlockingPageDone(resources, true);
390 EXPECT_TRUE(delegate.visible_security_state_changed()); 405 EXPECT_TRUE(delegate.visible_security_state_changed());
391 406
392 waiter.WaitForCallback(); 407 waiter.WaitForCallback();
393 EXPECT_TRUE(waiter.callback_called()); 408 EXPECT_TRUE(waiter.callback_called());
394 EXPECT_TRUE(waiter.proceed()); 409 EXPECT_TRUE(waiter.proceed());
395 EXPECT_TRUE(IsWhitelisted(resource)); 410 EXPECT_TRUE(IsWhitelisted(resource));
396 } 411 }
397 412
398 } // namespace safe_browsing 413 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/ui_manager.cc ('k') | chrome/browser/ssl/chrome_security_state_model_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698