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

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

Issue 2540563002: Move SafeBrowsingUIManager::UnsafeResource to security_interstitials namespace (Closed)
Patch Set: rebase update Created 4 years 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ~SafeBrowsingUIManagerTest() override{}; 72 ~SafeBrowsingUIManagerTest() override{};
73 73
74 void SetUp() override { 74 void SetUp() override {
75 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); 75 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD);
76 ChromeRenderViewHostTestHarness::SetUp(); 76 ChromeRenderViewHostTestHarness::SetUp();
77 SafeBrowsingUIManager::CreateWhitelistForTesting(web_contents()); 77 SafeBrowsingUIManager::CreateWhitelistForTesting(web_contents());
78 } 78 }
79 79
80 void TearDown() override { ChromeRenderViewHostTestHarness::TearDown(); } 80 void TearDown() override { ChromeRenderViewHostTestHarness::TearDown(); }
81 81
82 bool IsWhitelisted(SafeBrowsingUIManager::UnsafeResource resource) { 82 bool IsWhitelisted(security_interstitials::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(security_interstitials::UnsafeResource resource) {
87 ui_manager_->AddToWhitelistUrlSet( 87 ui_manager_->AddToWhitelistUrlSet(
88 SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting( 88 SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting(
89 resource), 89 resource),
90 web_contents(), false, resource.threat_type); 90 web_contents(), false, resource.threat_type);
91 } 91 }
92 92
93 SafeBrowsingUIManager::UnsafeResource MakeUnsafeResource( 93 security_interstitials::UnsafeResource MakeUnsafeResource(
94 const char* url, 94 const char* url,
95 bool is_subresource) { 95 bool is_subresource) {
96 SafeBrowsingUIManager::UnsafeResource resource; 96 security_interstitials::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 security_interstitials::UnsafeResource::GetWebContentsGetter(
101 web_contents()->GetRenderProcessHost()->GetID(), 101 web_contents()->GetRenderProcessHost()->GetID(),
102 web_contents()->GetMainFrame()->GetRoutingID()); 102 web_contents()->GetMainFrame()->GetRoutingID());
103 resource.threat_type = SB_THREAT_TYPE_URL_MALWARE; 103 resource.threat_type = SB_THREAT_TYPE_URL_MALWARE;
104 return resource; 104 return resource;
105 } 105 }
106 106
107 SafeBrowsingUIManager::UnsafeResource MakeUnsafeResourceAndStartNavigation( 107 security_interstitials::UnsafeResource MakeUnsafeResourceAndStartNavigation(
108 const char* url) { 108 const char* url) {
109 SafeBrowsingUIManager::UnsafeResource resource = 109 security_interstitials::UnsafeResource resource =
110 MakeUnsafeResource(url, false /* is_subresource */); 110 MakeUnsafeResource(url, false /* is_subresource */);
111 111
112 // The WC doesn't have a URL without a navigation. A main-frame malware 112 // The WC doesn't have a URL without a navigation. A main-frame malware
113 // unsafe resource must be a pending navigation. 113 // unsafe resource must be a pending navigation.
114 content::WebContentsTester::For(web_contents())->StartNavigation(GURL(url)); 114 content::WebContentsTester::For(web_contents())->StartNavigation(GURL(url));
115 return resource; 115 return resource;
116 } 116 }
117 117
118 void SimulateBlockingPageDone( 118 void SimulateBlockingPageDone(
119 const std::vector<SafeBrowsingUIManager::UnsafeResource>& resources, 119 const std::vector<security_interstitials::UnsafeResource>& resources,
120 bool proceed) { 120 bool proceed) {
121 GURL main_frame_url; 121 GURL main_frame_url;
122 content::NavigationEntry* entry = 122 content::NavigationEntry* entry =
123 web_contents()->GetController().GetVisibleEntry(); 123 web_contents()->GetController().GetVisibleEntry();
124 if (entry) 124 if (entry)
125 main_frame_url = entry->GetURL(); 125 main_frame_url = entry->GetURL();
126 126
127 ui_manager_->OnBlockingPageDone(resources, proceed, web_contents(), 127 ui_manager_->OnBlockingPageDone(resources, proceed, web_contents(),
128 main_frame_url); 128 main_frame_url);
129 } 129 }
130 130
131 protected: 131 protected:
132 SafeBrowsingUIManager* ui_manager() { return ui_manager_.get(); } 132 SafeBrowsingUIManager* ui_manager() { return ui_manager_.get(); }
133 133
134 private: 134 private:
135 scoped_refptr<SafeBrowsingUIManager> ui_manager_; 135 scoped_refptr<SafeBrowsingUIManager> ui_manager_;
136 }; 136 };
137 137
138 TEST_F(SafeBrowsingUIManagerTest, Whitelist) { 138 TEST_F(SafeBrowsingUIManagerTest, Whitelist) {
139 SafeBrowsingUIManager::UnsafeResource resource = 139 security_interstitials::UnsafeResource resource =
140 MakeUnsafeResourceAndStartNavigation(kBadURL); 140 MakeUnsafeResourceAndStartNavigation(kBadURL);
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 security_interstitials::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) { 151 TEST_F(SafeBrowsingUIManagerTest, WhitelistRemembersThreatType) {
152 SafeBrowsingUIManager::UnsafeResource resource = 152 security_interstitials::UnsafeResource resource =
153 MakeUnsafeResourceAndStartNavigation(kBadURL); 153 MakeUnsafeResourceAndStartNavigation(kBadURL);
154 AddToWhitelist(resource); 154 AddToWhitelist(resource);
155 EXPECT_TRUE(IsWhitelisted(resource)); 155 EXPECT_TRUE(IsWhitelisted(resource));
156 SBThreatType threat_type; 156 SBThreatType threat_type;
157 content::NavigationEntry* entry = 157 content::NavigationEntry* entry =
158 web_contents()->GetController().GetVisibleEntry(); 158 web_contents()->GetController().GetVisibleEntry();
159 ASSERT_TRUE(entry); 159 ASSERT_TRUE(entry);
160 EXPECT_TRUE(ui_manager()->IsUrlWhitelistedOrPendingForWebContents( 160 EXPECT_TRUE(ui_manager()->IsUrlWhitelistedOrPendingForWebContents(
161 resource.url, resource.is_subresource, entry, 161 resource.url, resource.is_subresource, entry,
162 resource.web_contents_getter.Run(), true, &threat_type)); 162 resource.web_contents_getter.Run(), true, &threat_type));
163 EXPECT_EQ(resource.threat_type, threat_type); 163 EXPECT_EQ(resource.threat_type, threat_type);
164 } 164 }
165 165
166 TEST_F(SafeBrowsingUIManagerTest, WhitelistIgnoresPath) { 166 TEST_F(SafeBrowsingUIManagerTest, WhitelistIgnoresPath) {
167 SafeBrowsingUIManager::UnsafeResource resource = 167 security_interstitials::UnsafeResource resource =
168 MakeUnsafeResourceAndStartNavigation(kBadURL); 168 MakeUnsafeResourceAndStartNavigation(kBadURL);
169 AddToWhitelist(resource); 169 AddToWhitelist(resource);
170 EXPECT_TRUE(IsWhitelisted(resource)); 170 EXPECT_TRUE(IsWhitelisted(resource));
171 171
172 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 172 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
173 173
174 SafeBrowsingUIManager::UnsafeResource resource_path = 174 security_interstitials::UnsafeResource resource_path =
175 MakeUnsafeResourceAndStartNavigation(kBadURLWithPath); 175 MakeUnsafeResourceAndStartNavigation(kBadURLWithPath);
176 EXPECT_TRUE(IsWhitelisted(resource_path)); 176 EXPECT_TRUE(IsWhitelisted(resource_path));
177 } 177 }
178 178
179 TEST_F(SafeBrowsingUIManagerTest, WhitelistIgnoresThreatType) { 179 TEST_F(SafeBrowsingUIManagerTest, WhitelistIgnoresThreatType) {
180 SafeBrowsingUIManager::UnsafeResource resource = 180 security_interstitials::UnsafeResource resource =
181 MakeUnsafeResourceAndStartNavigation(kBadURL); 181 MakeUnsafeResourceAndStartNavigation(kBadURL);
182 AddToWhitelist(resource); 182 AddToWhitelist(resource);
183 EXPECT_TRUE(IsWhitelisted(resource)); 183 EXPECT_TRUE(IsWhitelisted(resource));
184 184
185 SafeBrowsingUIManager::UnsafeResource resource_phishing = 185 security_interstitials::UnsafeResource resource_phishing =
186 MakeUnsafeResource(kBadURL, false /* is_subresource */); 186 MakeUnsafeResource(kBadURL, false /* is_subresource */);
187 resource_phishing.threat_type = SB_THREAT_TYPE_URL_PHISHING; 187 resource_phishing.threat_type = SB_THREAT_TYPE_URL_PHISHING;
188 EXPECT_TRUE(IsWhitelisted(resource_phishing)); 188 EXPECT_TRUE(IsWhitelisted(resource_phishing));
189 } 189 }
190 190
191 TEST_F(SafeBrowsingUIManagerTest, WhitelistWithUnrelatedPendingLoad) { 191 TEST_F(SafeBrowsingUIManagerTest, WhitelistWithUnrelatedPendingLoad) {
192 // Commit load of landing page. 192 // Commit load of landing page.
193 NavigateAndCommit(GURL(kLandingURL)); 193 NavigateAndCommit(GURL(kLandingURL));
194 { 194 {
195 // Simulate subresource malware hit on the landing page. 195 // Simulate subresource malware hit on the landing page.
196 SafeBrowsingUIManager::UnsafeResource resource = 196 security_interstitials::UnsafeResource resource =
197 MakeUnsafeResource(kBadURL, true /* is_subresource */); 197 MakeUnsafeResource(kBadURL, true /* is_subresource */);
198 198
199 // Start pending load to unrelated site. 199 // Start pending load to unrelated site.
200 content::WebContentsTester::For(web_contents()) 200 content::WebContentsTester::For(web_contents())
201 ->StartNavigation(GURL(kGoodURL)); 201 ->StartNavigation(GURL(kGoodURL));
202 202
203 // Whitelist the resource on the landing page. 203 // Whitelist the resource on the landing page.
204 AddToWhitelist(resource); 204 AddToWhitelist(resource);
205 EXPECT_TRUE(IsWhitelisted(resource)); 205 EXPECT_TRUE(IsWhitelisted(resource));
206 } 206 }
207 207
208 // Commit the pending load of unrelated site. 208 // Commit the pending load of unrelated site.
209 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 209 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
210 { 210 {
211 // The unrelated site is not on the whitelist, even if the same subresource 211 // The unrelated site is not on the whitelist, even if the same subresource
212 // was on it. 212 // was on it.
213 SafeBrowsingUIManager::UnsafeResource resource = 213 security_interstitials::UnsafeResource resource =
214 MakeUnsafeResource(kBadURL, true /* is_subresource */); 214 MakeUnsafeResource(kBadURL, true /* is_subresource */);
215 EXPECT_FALSE(IsWhitelisted(resource)); 215 EXPECT_FALSE(IsWhitelisted(resource));
216 } 216 }
217 217
218 // Navigate back to the original landing url. 218 // Navigate back to the original landing url.
219 NavigateAndCommit(GURL(kLandingURL)); 219 NavigateAndCommit(GURL(kLandingURL));
220 { 220 {
221 SafeBrowsingUIManager::UnsafeResource resource = 221 security_interstitials::UnsafeResource resource =
222 MakeUnsafeResource(kBadURL, true /* is_subresource */); 222 MakeUnsafeResource(kBadURL, true /* is_subresource */);
223 // Original resource url is whitelisted. 223 // Original resource url is whitelisted.
224 EXPECT_TRUE(IsWhitelisted(resource)); 224 EXPECT_TRUE(IsWhitelisted(resource));
225 } 225 }
226 { 226 {
227 // A different malware subresource on the same page is also whitelisted. 227 // A different malware subresource on the same page is also whitelisted.
228 // (The whitelist is by the page url, not the resource url.) 228 // (The whitelist is by the page url, not the resource url.)
229 SafeBrowsingUIManager::UnsafeResource resource2 = 229 security_interstitials::UnsafeResource resource2 =
230 MakeUnsafeResource(kAnotherBadURL, true /* is_subresource */); 230 MakeUnsafeResource(kAnotherBadURL, true /* is_subresource */);
231 EXPECT_TRUE(IsWhitelisted(resource2)); 231 EXPECT_TRUE(IsWhitelisted(resource2));
232 } 232 }
233 } 233 }
234 234
235 TEST_F(SafeBrowsingUIManagerTest, UICallbackProceed) { 235 TEST_F(SafeBrowsingUIManagerTest, UICallbackProceed) {
236 SafeBrowsingUIManager::UnsafeResource resource = 236 security_interstitials::UnsafeResource resource =
237 MakeUnsafeResourceAndStartNavigation(kBadURL); 237 MakeUnsafeResourceAndStartNavigation(kBadURL);
238 SafeBrowsingCallbackWaiter waiter; 238 SafeBrowsingCallbackWaiter waiter;
239 resource.callback = 239 resource.callback =
240 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDone, 240 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDone,
241 base::Unretained(&waiter)); 241 base::Unretained(&waiter));
242 resource.callback_thread = 242 resource.callback_thread =
243 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI); 243 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI);
244 std::vector<SafeBrowsingUIManager::UnsafeResource> resources; 244 std::vector<security_interstitials::UnsafeResource> resources;
245 resources.push_back(resource); 245 resources.push_back(resource);
246 SimulateBlockingPageDone(resources, true); 246 SimulateBlockingPageDone(resources, true);
247 EXPECT_TRUE(IsWhitelisted(resource)); 247 EXPECT_TRUE(IsWhitelisted(resource));
248 waiter.WaitForCallback(); 248 waiter.WaitForCallback();
249 EXPECT_TRUE(waiter.callback_called()); 249 EXPECT_TRUE(waiter.callback_called());
250 EXPECT_TRUE(waiter.proceed()); 250 EXPECT_TRUE(waiter.proceed());
251 } 251 }
252 252
253 TEST_F(SafeBrowsingUIManagerTest, UICallbackDontProceed) { 253 TEST_F(SafeBrowsingUIManagerTest, UICallbackDontProceed) {
254 SafeBrowsingUIManager::UnsafeResource resource = 254 security_interstitials::UnsafeResource resource =
255 MakeUnsafeResourceAndStartNavigation(kBadURL); 255 MakeUnsafeResourceAndStartNavigation(kBadURL);
256 SafeBrowsingCallbackWaiter waiter; 256 SafeBrowsingCallbackWaiter waiter;
257 resource.callback = 257 resource.callback =
258 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDone, 258 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDone,
259 base::Unretained(&waiter)); 259 base::Unretained(&waiter));
260 resource.callback_thread = 260 resource.callback_thread =
261 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI); 261 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI);
262 std::vector<SafeBrowsingUIManager::UnsafeResource> resources; 262 std::vector<security_interstitials::UnsafeResource> resources;
263 resources.push_back(resource); 263 resources.push_back(resource);
264 SimulateBlockingPageDone(resources, false); 264 SimulateBlockingPageDone(resources, false);
265 EXPECT_FALSE(IsWhitelisted(resource)); 265 EXPECT_FALSE(IsWhitelisted(resource));
266 waiter.WaitForCallback(); 266 waiter.WaitForCallback();
267 EXPECT_TRUE(waiter.callback_called()); 267 EXPECT_TRUE(waiter.callback_called());
268 EXPECT_FALSE(waiter.proceed()); 268 EXPECT_FALSE(waiter.proceed());
269 } 269 }
270 270
271 TEST_F(SafeBrowsingUIManagerTest, IOCallbackProceed) { 271 TEST_F(SafeBrowsingUIManagerTest, IOCallbackProceed) {
272 SafeBrowsingUIManager::UnsafeResource resource = 272 security_interstitials::UnsafeResource resource =
273 MakeUnsafeResourceAndStartNavigation(kBadURL); 273 MakeUnsafeResourceAndStartNavigation(kBadURL);
274 SafeBrowsingCallbackWaiter waiter; 274 SafeBrowsingCallbackWaiter waiter;
275 resource.callback = 275 resource.callback =
276 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDoneOnIO, 276 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDoneOnIO,
277 base::Unretained(&waiter)); 277 base::Unretained(&waiter));
278 resource.callback_thread = 278 resource.callback_thread =
279 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); 279 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
280 std::vector<SafeBrowsingUIManager::UnsafeResource> resources; 280 std::vector<security_interstitials::UnsafeResource> resources;
281 resources.push_back(resource); 281 resources.push_back(resource);
282 SimulateBlockingPageDone(resources, true); 282 SimulateBlockingPageDone(resources, true);
283 EXPECT_TRUE(IsWhitelisted(resource)); 283 EXPECT_TRUE(IsWhitelisted(resource));
284 waiter.WaitForCallback(); 284 waiter.WaitForCallback();
285 EXPECT_TRUE(waiter.callback_called()); 285 EXPECT_TRUE(waiter.callback_called());
286 EXPECT_TRUE(waiter.proceed()); 286 EXPECT_TRUE(waiter.proceed());
287 } 287 }
288 288
289 TEST_F(SafeBrowsingUIManagerTest, IOCallbackDontProceed) { 289 TEST_F(SafeBrowsingUIManagerTest, IOCallbackDontProceed) {
290 SafeBrowsingUIManager::UnsafeResource resource = 290 security_interstitials::UnsafeResource resource =
291 MakeUnsafeResourceAndStartNavigation(kBadURL); 291 MakeUnsafeResourceAndStartNavigation(kBadURL);
292 SafeBrowsingCallbackWaiter waiter; 292 SafeBrowsingCallbackWaiter waiter;
293 resource.callback = 293 resource.callback =
294 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDoneOnIO, 294 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDoneOnIO,
295 base::Unretained(&waiter)); 295 base::Unretained(&waiter));
296 resource.callback_thread = 296 resource.callback_thread =
297 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); 297 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
298 std::vector<SafeBrowsingUIManager::UnsafeResource> resources; 298 std::vector<security_interstitials::UnsafeResource> resources;
299 resources.push_back(resource); 299 resources.push_back(resource);
300 SimulateBlockingPageDone(resources, false); 300 SimulateBlockingPageDone(resources, false);
301 EXPECT_FALSE(IsWhitelisted(resource)); 301 EXPECT_FALSE(IsWhitelisted(resource));
302 waiter.WaitForCallback(); 302 waiter.WaitForCallback();
303 EXPECT_TRUE(waiter.callback_called()); 303 EXPECT_TRUE(waiter.callback_called());
304 EXPECT_FALSE(waiter.proceed()); 304 EXPECT_FALSE(waiter.proceed());
305 } 305 }
306 306
307 namespace { 307 namespace {
308 308
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // Tests that the WebContentsDelegate is notified of a visible security 371 // Tests that the WebContentsDelegate is notified of a visible security
372 // state change when a blocking page is shown for a subresource. 372 // state change when a blocking page is shown for a subresource.
373 TEST_F(SafeBrowsingUIManagerTest, 373 TEST_F(SafeBrowsingUIManagerTest,
374 VisibleSecurityStateChangedForUnsafeSubresource) { 374 VisibleSecurityStateChangedForUnsafeSubresource) {
375 TestSafeBrowsingBlockingPageFactory factory; 375 TestSafeBrowsingBlockingPageFactory factory;
376 SafeBrowsingBlockingPage::RegisterFactory(&factory); 376 SafeBrowsingBlockingPage::RegisterFactory(&factory);
377 SecurityStateWebContentsDelegate delegate; 377 SecurityStateWebContentsDelegate delegate;
378 web_contents()->SetDelegate(&delegate); 378 web_contents()->SetDelegate(&delegate);
379 379
380 // Simulate a blocking page showing for an unsafe subresource. 380 // Simulate a blocking page showing for an unsafe subresource.
381 SafeBrowsingUIManager::UnsafeResource resource = 381 security_interstitials::UnsafeResource resource =
382 MakeUnsafeResource(kBadURL, true /* is_subresource */); 382 MakeUnsafeResource(kBadURL, true /* is_subresource */);
383 // Needed for showing the blocking page. 383 // Needed for showing the blocking page.
384 resource.threat_source = safe_browsing::ThreatSource::REMOTE; 384 resource.threat_source = safe_browsing::ThreatSource::REMOTE;
385 NavigateAndCommit(GURL("http://example.test")); 385 NavigateAndCommit(GURL("http://example.test"));
386 386
387 delegate.ClearVisibleSecurityStateChanged(); 387 delegate.ClearVisibleSecurityStateChanged();
388 EXPECT_FALSE(delegate.visible_security_state_changed()); 388 EXPECT_FALSE(delegate.visible_security_state_changed());
389 ui_manager()->DisplayBlockingPage(resource); 389 ui_manager()->DisplayBlockingPage(resource);
390 EXPECT_TRUE(delegate.visible_security_state_changed()); 390 EXPECT_TRUE(delegate.visible_security_state_changed());
391 391
392 // Simulate proceeding through the blocking page. 392 // Simulate proceeding through the blocking page.
393 SafeBrowsingCallbackWaiter waiter; 393 SafeBrowsingCallbackWaiter waiter;
394 resource.callback = 394 resource.callback =
395 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDoneOnIO, 395 base::Bind(&SafeBrowsingCallbackWaiter::OnBlockingPageDoneOnIO,
396 base::Unretained(&waiter)); 396 base::Unretained(&waiter));
397 resource.callback_thread = 397 resource.callback_thread =
398 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); 398 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
399 std::vector<SafeBrowsingUIManager::UnsafeResource> resources; 399 std::vector<security_interstitials::UnsafeResource> resources;
400 resources.push_back(resource); 400 resources.push_back(resource);
401 401
402 delegate.ClearVisibleSecurityStateChanged(); 402 delegate.ClearVisibleSecurityStateChanged();
403 EXPECT_FALSE(delegate.visible_security_state_changed()); 403 EXPECT_FALSE(delegate.visible_security_state_changed());
404 SimulateBlockingPageDone(resources, true); 404 SimulateBlockingPageDone(resources, true);
405 EXPECT_TRUE(delegate.visible_security_state_changed()); 405 EXPECT_TRUE(delegate.visible_security_state_changed());
406 406
407 waiter.WaitForCallback(); 407 waiter.WaitForCallback();
408 EXPECT_TRUE(waiter.callback_called()); 408 EXPECT_TRUE(waiter.callback_called());
409 EXPECT_TRUE(waiter.proceed()); 409 EXPECT_TRUE(waiter.proceed());
410 EXPECT_TRUE(IsWhitelisted(resource)); 410 EXPECT_TRUE(IsWhitelisted(resource));
411 } 411 }
412 412
413 } // namespace safe_browsing 413 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/ui_manager.cc ('k') | chrome/browser/ui/webui/interstitials/interstitial_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698