Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/download/download_request_limiter.h" | 5 #include "chrome/browser/download/download_request_limiter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | |
| 8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "chrome/browser/download/download_permission_request.h" | |
| 9 #include "chrome/browser/download/download_request_infobar_delegate.h" | 11 #include "chrome/browser/download/download_request_infobar_delegate.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 13 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 14 #include "chrome/common/chrome_switches.h" | |
| 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 17 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 15 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 16 #include "content/public/browser/navigation_details.h" | 19 #include "content/public/browser/navigation_details.h" |
| 17 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/frame_navigate_params.h" | 21 #include "content/public/common/frame_navigate_params.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 23 |
| 21 using content::WebContents; | 24 using content::WebContents; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 CANCEL, | 64 CANCEL, |
| 62 WAIT | 65 WAIT |
| 63 }; | 66 }; |
| 64 | 67 |
| 65 void SetUp() override { | 68 void SetUp() override { |
| 66 ChromeRenderViewHostTestHarness::SetUp(); | 69 ChromeRenderViewHostTestHarness::SetUp(); |
| 67 InfoBarService::CreateForWebContents(web_contents()); | 70 InfoBarService::CreateForWebContents(web_contents()); |
| 68 | 71 |
| 69 PermissionBubbleManager::CreateForWebContents(web_contents()); | 72 PermissionBubbleManager::CreateForWebContents(web_contents()); |
| 70 view_.reset(new FakePermissionBubbleView(this)); | 73 view_.reset(new FakePermissionBubbleView(this)); |
| 71 PermissionBubbleManager* manager = | 74 PermissionBubbleManager::FromWebContents(web_contents())-> |
| 72 PermissionBubbleManager::FromWebContents(web_contents()); | 75 SetView(view_.get()); |
| 73 manager->SetView(view_.get()); | |
| 74 | 76 |
| 75 testing_action_ = ACCEPT; | 77 testing_action_ = ACCEPT; |
| 76 ask_allow_count_ = cancel_count_ = continue_count_ = 0; | 78 ask_allow_count_ = cancel_count_ = continue_count_ = 0; |
| 77 download_request_limiter_ = new DownloadRequestLimiter(); | 79 download_request_limiter_ = new DownloadRequestLimiter(); |
| 78 fake_create_callback_ = base::Bind( | 80 fake_create_callback_ = base::Bind( |
| 79 &DownloadRequestLimiterTest::FakeCreate, base::Unretained(this)); | 81 &DownloadRequestLimiterTest::FakeCreate, base::Unretained(this)); |
| 80 DownloadRequestInfoBarDelegate::SetCallbackForTesting( | 82 DownloadRequestInfoBarDelegate::SetCallbackForTesting( |
| 81 &fake_create_callback_); | 83 &fake_create_callback_); |
| 82 content_settings_ = new HostContentSettingsMap(profile_.GetPrefs(), false); | 84 content_settings_ = new HostContentSettingsMap(profile_.GetPrefs(), false); |
| 83 DownloadRequestLimiter::SetContentSettingsForTesting( | 85 DownloadRequestLimiter::SetContentSettingsForTesting( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 | 177 |
| 176 void SetHostContentSetting(WebContents* contents, ContentSetting setting) { | 178 void SetHostContentSetting(WebContents* contents, ContentSetting setting) { |
| 177 content_settings_->SetContentSetting( | 179 content_settings_->SetContentSetting( |
| 178 ContentSettingsPattern::FromURL(contents->GetURL()), | 180 ContentSettingsPattern::FromURL(contents->GetURL()), |
| 179 ContentSettingsPattern::Wildcard(), | 181 ContentSettingsPattern::Wildcard(), |
| 180 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | 182 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 181 std::string(), | 183 std::string(), |
| 182 setting); | 184 setting); |
| 183 } | 185 } |
| 184 | 186 |
| 187 void BubbleManagerDocumentLoadCompleted() { | |
| 188 PermissionBubbleManager::FromWebContents(web_contents())-> | |
| 189 DocumentOnLoadCompletedInMainFrame(); | |
|
asanka
2014/12/23 20:44:11
Curious: Why does this need to be called explicitl
felt
2015/02/05 18:33:43
There's a good comment here that explains what the
asanka
2015/02/05 19:44:08
That comment is a bit scary because if there's any
felt
2015/02/06 09:31:28
OK. I will investigate. I suspect this is causing
| |
| 190 } | |
| 191 | |
| 185 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; | 192 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; |
| 186 | 193 |
| 187 // The action that FakeCreate() should take. | 194 // The action that FakeCreate() should take. |
| 188 TestingAction testing_action_; | 195 TestingAction testing_action_; |
| 189 | 196 |
| 190 // Number of times ContinueDownload was invoked. | 197 // Number of times ContinueDownload was invoked. |
| 191 int continue_count_; | 198 int continue_count_; |
| 192 | 199 |
| 193 // Number of times CancelDownload was invoked. | 200 // Number of times CancelDownload was invoked. |
| 194 int cancel_count_; | 201 int cancel_count_; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 214 delegate_->Accept(); | 221 delegate_->Accept(); |
| 215 } else if (action == DownloadRequestLimiterTest::CANCEL) { | 222 } else if (action == DownloadRequestLimiterTest::CANCEL) { |
| 216 delegate_->Deny(); | 223 delegate_->Deny(); |
| 217 } else if (action == DownloadRequestLimiterTest::WAIT) { | 224 } else if (action == DownloadRequestLimiterTest::WAIT) { |
| 218 // do nothing. | 225 // do nothing. |
| 219 } else { | 226 } else { |
| 220 delegate_->Closing(); | 227 delegate_->Closing(); |
| 221 } | 228 } |
| 222 } | 229 } |
| 223 | 230 |
| 224 TEST_F(DownloadRequestLimiterTest, | 231 class DownloadRequestLimiterParamTests |
| 232 : public DownloadRequestLimiterTest, | |
| 233 public ::testing::WithParamInterface<bool> { | |
| 234 protected: | |
| 235 DownloadRequestLimiterParamTests() {} | |
| 236 ~DownloadRequestLimiterParamTests() override {} | |
| 237 | |
| 238 void SetUp() override { | |
| 239 DownloadRequestLimiterTest::SetUp(); | |
| 240 #if !defined(OS_ANDROID) | |
| 241 if (GetParam()) { | |
| 242 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 243 switches::kEnablePermissionsBubbles); | |
| 244 EXPECT_TRUE(PermissionBubbleManager::Enabled()); | |
| 245 } else { | |
| 246 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 247 switches::kDisablePermissionsBubbles); | |
| 248 } | |
| 249 } | |
| 250 #endif | |
|
asanka
2014/12/23 20:44:11
Mismatched } for OS_ANDROID.
asanka
2014/12/23 20:44:11
Mismatched } for OS_ANDROID.
felt
2015/02/05 18:33:43
Done.
| |
| 251 private: | |
| 252 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiterParamTests); | |
| 253 }; | |
| 254 | |
| 255 TEST_P(DownloadRequestLimiterParamTests, | |
| 225 DownloadRequestLimiter_Allow) { | 256 DownloadRequestLimiter_Allow) { |
| 257 BubbleManagerDocumentLoadCompleted(); | |
| 258 | |
| 226 // All tabs should initially start at ALLOW_ONE_DOWNLOAD. | 259 // All tabs should initially start at ALLOW_ONE_DOWNLOAD. |
| 227 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 260 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 228 download_request_limiter_->GetDownloadStatus(web_contents())); | 261 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 229 | 262 |
| 230 // Ask if the tab can do a download. This moves to PROMPT_BEFORE_DOWNLOAD. | 263 // Ask if the tab can do a download. This moves to PROMPT_BEFORE_DOWNLOAD. |
| 231 CanDownload(); | 264 CanDownload(); |
| 232 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 265 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 233 download_request_limiter_->GetDownloadStatus(web_contents())); | 266 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 234 // We should have been told we can download. | 267 // We should have been told we can download. |
| 235 ExpectAndResetCounts(1, 0, 0, __LINE__); | 268 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 236 | 269 |
| 237 // Ask again. This triggers asking the delegate for allow/disallow. | 270 // Ask again. This triggers asking the delegate for allow/disallow. |
| 238 testing_action_ = ACCEPT; | 271 testing_action_ = ACCEPT; |
| 239 CanDownload(); | 272 CanDownload(); |
| 240 // This should ask us if the download is allowed. | 273 // This should ask us if the download is allowed. |
| 241 // We should have been told we can download. | 274 // We should have been told we can download. |
| 242 ExpectAndResetCounts(1, 0, 1, __LINE__); | 275 ExpectAndResetCounts(1, 0, 1, __LINE__); |
| 243 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 276 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 244 download_request_limiter_->GetDownloadStatus(web_contents())); | 277 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 245 | 278 |
| 246 // Ask again and make sure continue is invoked. | 279 // Ask again and make sure continue is invoked. |
| 247 CanDownload(); | 280 CanDownload(); |
| 248 // The state is at allow_all, which means the delegate shouldn't be asked. | 281 // The state is at allow_all, which means the delegate shouldn't be asked. |
| 249 // We should have been told we can download. | 282 // We should have been told we can download. |
| 250 ExpectAndResetCounts(1, 0, 0, __LINE__); | 283 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 251 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 284 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 252 download_request_limiter_->GetDownloadStatus(web_contents())); | 285 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 253 } | 286 } |
| 254 | 287 |
| 255 TEST_F(DownloadRequestLimiterTest, | 288 TEST_P(DownloadRequestLimiterParamTests, |
| 256 DownloadRequestLimiter_ResetOnNavigation) { | 289 DownloadRequestLimiter_ResetOnNavigation) { |
| 257 NavigateAndCommit(GURL("http://foo.com/bar")); | 290 NavigateAndCommit(GURL("http://foo.com/bar")); |
| 291 BubbleManagerDocumentLoadCompleted(); | |
| 258 | 292 |
| 259 // Do two downloads, allowing the second so that we end up with allow all. | 293 // Do two downloads, allowing the second so that we end up with allow all. |
| 260 CanDownload(); | 294 CanDownload(); |
| 261 ExpectAndResetCounts(1, 0, 0, __LINE__); | 295 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 262 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 296 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 263 download_request_limiter_->GetDownloadStatus(web_contents())); | 297 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 264 | 298 |
| 265 testing_action_ = ACCEPT; | 299 testing_action_ = ACCEPT; |
| 266 CanDownload(); | 300 CanDownload(); |
| 267 ExpectAndResetCounts(1, 0, 1, __LINE__); | 301 ExpectAndResetCounts(1, 0, 1, __LINE__); |
| 268 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 302 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 269 download_request_limiter_->GetDownloadStatus(web_contents())); | 303 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 270 | 304 |
| 271 // Navigate to a new URL with the same host, which shouldn't reset the allow | 305 // Navigate to a new URL with the same host, which shouldn't reset the allow |
| 272 // all state. | 306 // all state. |
| 273 NavigateAndCommit(GURL("http://foo.com/bar2")); | 307 NavigateAndCommit(GURL("http://foo.com/bar2")); |
| 308 BubbleManagerDocumentLoadCompleted(); | |
| 274 CanDownload(); | 309 CanDownload(); |
| 275 ExpectAndResetCounts(1, 0, 0, __LINE__); | 310 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 276 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 311 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 277 download_request_limiter_->GetDownloadStatus(web_contents())); | 312 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 278 | 313 |
| 279 // Do a user gesture, because we're at allow all, this shouldn't change the | 314 // Do a user gesture, because we're at allow all, this shouldn't change the |
| 280 // state. | 315 // state. |
| 281 OnUserGesture(); | 316 OnUserGesture(); |
| 282 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 317 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 283 download_request_limiter_->GetDownloadStatus(web_contents())); | 318 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 284 | 319 |
| 285 // Navigate to a completely different host, which should reset the state. | 320 // Navigate to a completely different host, which should reset the state. |
| 286 NavigateAndCommit(GURL("http://fooey.com")); | 321 NavigateAndCommit(GURL("http://fooey.com")); |
| 322 BubbleManagerDocumentLoadCompleted(); | |
| 287 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 323 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 288 download_request_limiter_->GetDownloadStatus(web_contents())); | 324 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 289 | 325 |
| 290 // Do two downloads, allowing the second so that we end up with allow all. | 326 // Do two downloads, allowing the second so that we end up with allow all. |
| 291 CanDownload(); | 327 CanDownload(); |
| 292 ExpectAndResetCounts(1, 0, 0, __LINE__); | 328 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 293 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 329 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 294 download_request_limiter_->GetDownloadStatus(web_contents())); | 330 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 295 | 331 |
| 296 testing_action_ = CANCEL; | 332 testing_action_ = CANCEL; |
| 297 CanDownload(); | 333 CanDownload(); |
| 298 ExpectAndResetCounts(0, 1, 1, __LINE__); | 334 ExpectAndResetCounts(0, 1, 1, __LINE__); |
| 299 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 335 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 300 download_request_limiter_->GetDownloadStatus(web_contents())); | 336 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 301 | 337 |
| 302 // Navigate to a new URL with the same host, which shouldn't reset the allow | 338 // Navigate to a new URL with the same host, which shouldn't reset the allow |
| 303 // all state. | 339 // all state. |
| 304 NavigateAndCommit(GURL("http://fooey.com/bar2")); | 340 NavigateAndCommit(GURL("http://fooey.com/bar2")); |
| 341 BubbleManagerDocumentLoadCompleted(); | |
| 305 CanDownload(); | 342 CanDownload(); |
| 306 ExpectAndResetCounts(0, 1, 0, __LINE__); | 343 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 307 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 344 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 308 download_request_limiter_->GetDownloadStatus(web_contents())); | 345 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 309 } | 346 } |
| 310 | 347 |
| 311 TEST_F(DownloadRequestLimiterTest, | 348 TEST_P(DownloadRequestLimiterParamTests, |
| 312 DownloadRequestLimiter_ResetOnUserGesture) { | 349 DownloadRequestLimiter_ResetOnUserGesture) { |
| 313 NavigateAndCommit(GURL("http://foo.com/bar")); | 350 NavigateAndCommit(GURL("http://foo.com/bar")); |
| 351 BubbleManagerDocumentLoadCompleted(); | |
| 314 | 352 |
| 315 // Do one download, which should change to prompt before download. | 353 // Do one download, which should change to prompt before download. |
| 316 CanDownload(); | 354 CanDownload(); |
| 317 ExpectAndResetCounts(1, 0, 0, __LINE__); | 355 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 318 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 356 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 319 download_request_limiter_->GetDownloadStatus(web_contents())); | 357 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 320 | 358 |
| 321 // Do a user gesture, which should reset back to allow one. | 359 // Do a user gesture, which should reset back to allow one. |
| 322 OnUserGesture(); | 360 OnUserGesture(); |
| 323 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 361 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 341 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 379 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 342 download_request_limiter_->GetDownloadStatus(web_contents())); | 380 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 343 // And make sure we really can't download. | 381 // And make sure we really can't download. |
| 344 CanDownload(); | 382 CanDownload(); |
| 345 ExpectAndResetCounts(0, 1, 0, __LINE__); | 383 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 346 // And the state shouldn't have changed. | 384 // And the state shouldn't have changed. |
| 347 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 385 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 348 download_request_limiter_->GetDownloadStatus(web_contents())); | 386 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 349 } | 387 } |
| 350 | 388 |
| 351 TEST_F(DownloadRequestLimiterTest, | 389 TEST_P(DownloadRequestLimiterParamTests, |
| 352 DownloadRequestLimiter_ResetOnReload) { | 390 DownloadRequestLimiter_ResetOnReload) { |
| 353 NavigateAndCommit(GURL("http://foo.com/bar")); | 391 NavigateAndCommit(GURL("http://foo.com/bar")); |
| 392 BubbleManagerDocumentLoadCompleted(); | |
| 354 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 393 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 355 download_request_limiter_->GetDownloadStatus(web_contents())); | 394 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 356 | 395 |
| 357 // If the user refreshes the page without responding to the infobar, pretend | 396 // If the user refreshes the page without responding to the infobar, pretend |
| 358 // like the refresh is the initial load: they get 1 free download (probably | 397 // like the refresh is the initial load: they get 1 free download (probably |
| 359 // the same as the actual initial load), then an infobar. | 398 // the same as the actual initial load), then an infobar. |
| 360 testing_action_ = WAIT; | 399 testing_action_ = WAIT; |
| 361 | 400 |
| 362 CanDownload(); | 401 CanDownload(); |
| 363 ExpectAndResetCounts(1, 0, 0, __LINE__); | 402 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 389 DidNavigateMainFrame(); | 428 DidNavigateMainFrame(); |
| 390 base::RunLoop().RunUntilIdle(); | 429 base::RunLoop().RunUntilIdle(); |
| 391 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 430 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 392 download_request_limiter_->GetDownloadStatus(web_contents())); | 431 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 393 CanDownload(); | 432 CanDownload(); |
| 394 ExpectAndResetCounts(0, 1, 0, __LINE__); | 433 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 395 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 434 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 396 download_request_limiter_->GetDownloadStatus(web_contents())); | 435 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 397 } | 436 } |
| 398 | 437 |
| 399 TEST_F(DownloadRequestLimiterTest, | 438 TEST_P(DownloadRequestLimiterParamTests, |
| 400 DownloadRequestLimiter_RawWebContents) { | 439 DownloadRequestLimiter_RawWebContents) { |
| 401 scoped_ptr<WebContents> web_contents(CreateTestWebContents()); | 440 scoped_ptr<WebContents> web_contents(CreateTestWebContents()); |
| 402 | 441 |
| 403 // DownloadRequestLimiter won't try to make a permission bubble if there's | 442 // DownloadRequestLimiter won't try to make a permission bubble if there's |
| 404 // no permission bubble manager, so don't put one on the test WebContents. | 443 // no permission bubble manager, so don't put one on the test WebContents. |
| 405 | 444 |
| 406 // DownloadRequestLimiter won't try to make an infobar if it doesn't have an | 445 // DownloadRequestLimiter won't try to make an infobar if it doesn't have an |
| 407 // InfoBarService, and we want to test that it will Cancel() instead of | 446 // InfoBarService, and we want to test that it will Cancel() instead of |
| 408 // prompting when it doesn't have a InfoBarService, so unset the delegate. | 447 // prompting when it doesn't have a InfoBarService, so unset the delegate. |
| 409 UnsetDelegate(); | 448 UnsetDelegate(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 428 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 467 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
| 429 OnUserGestureFor(web_contents.get()); | 468 OnUserGestureFor(web_contents.get()); |
| 430 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 469 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 431 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 470 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
| 432 CanDownloadFor(web_contents.get()); | 471 CanDownloadFor(web_contents.get()); |
| 433 ExpectAndResetCounts(1, 0, 0, __LINE__); | 472 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 434 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 473 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 435 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 474 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
| 436 } | 475 } |
| 437 | 476 |
| 438 TEST_F(DownloadRequestLimiterTest, | 477 TEST_P(DownloadRequestLimiterParamTests, |
| 439 DownloadRequestLimiter_SetHostContentSetting) { | 478 DownloadRequestLimiter_SetHostContentSetting) { |
| 440 NavigateAndCommit(GURL("http://foo.com/bar")); | 479 NavigateAndCommit(GURL("http://foo.com/bar")); |
| 480 BubbleManagerDocumentLoadCompleted(); | |
| 441 SetHostContentSetting(web_contents(), CONTENT_SETTING_ALLOW); | 481 SetHostContentSetting(web_contents(), CONTENT_SETTING_ALLOW); |
| 442 | 482 |
| 443 CanDownload(); | 483 CanDownload(); |
| 444 ExpectAndResetCounts(1, 0, 0, __LINE__); | 484 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 445 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 485 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 446 download_request_limiter_->GetDownloadStatus(web_contents())); | 486 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 447 | 487 |
| 448 CanDownload(); | 488 CanDownload(); |
| 449 ExpectAndResetCounts(1, 0, 0, __LINE__); | 489 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 450 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 490 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 451 download_request_limiter_->GetDownloadStatus(web_contents())); | 491 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 452 | 492 |
| 453 SetHostContentSetting(web_contents(), CONTENT_SETTING_BLOCK); | 493 SetHostContentSetting(web_contents(), CONTENT_SETTING_BLOCK); |
| 454 | 494 |
| 455 CanDownload(); | 495 CanDownload(); |
| 456 ExpectAndResetCounts(0, 1, 0, __LINE__); | 496 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 457 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 497 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 458 download_request_limiter_->GetDownloadStatus(web_contents())); | 498 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 459 | 499 |
| 460 CanDownload(); | 500 CanDownload(); |
| 461 ExpectAndResetCounts(0, 1, 0, __LINE__); | 501 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 462 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 502 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 463 download_request_limiter_->GetDownloadStatus(web_contents())); | 503 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 464 } | 504 } |
| 505 | |
| 506 INSTANTIATE_TEST_CASE_P(DownloadRequestLimiterTestsWithAndWithoutBubbles, | |
| 507 DownloadRequestLimiterParamTests, | |
| 508 ::testing::Values(false, true)); | |
| OLD | NEW |