| 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(bool bubbles_enabled) { |
| 188 if (!bubbles_enabled) |
| 189 return; |
| 190 PermissionBubbleManager::FromWebContents(web_contents())-> |
| 191 DocumentOnLoadCompletedInMainFrame(); |
| 192 } |
| 193 |
| 185 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; | 194 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; |
| 186 | 195 |
| 187 // The action that FakeCreate() should take. | 196 // The action that FakeCreate() should take. |
| 188 TestingAction testing_action_; | 197 TestingAction testing_action_; |
| 189 | 198 |
| 190 // Number of times ContinueDownload was invoked. | 199 // Number of times ContinueDownload was invoked. |
| 191 int continue_count_; | 200 int continue_count_; |
| 192 | 201 |
| 193 // Number of times CancelDownload was invoked. | 202 // Number of times CancelDownload was invoked. |
| 194 int cancel_count_; | 203 int cancel_count_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 214 delegate_->Accept(); | 223 delegate_->Accept(); |
| 215 } else if (action == DownloadRequestLimiterTest::CANCEL) { | 224 } else if (action == DownloadRequestLimiterTest::CANCEL) { |
| 216 delegate_->Deny(); | 225 delegate_->Deny(); |
| 217 } else if (action == DownloadRequestLimiterTest::WAIT) { | 226 } else if (action == DownloadRequestLimiterTest::WAIT) { |
| 218 // do nothing. | 227 // do nothing. |
| 219 } else { | 228 } else { |
| 220 delegate_->Closing(); | 229 delegate_->Closing(); |
| 221 } | 230 } |
| 222 } | 231 } |
| 223 | 232 |
| 224 TEST_F(DownloadRequestLimiterTest, | 233 class DownloadRequestLimiterParamTests |
| 234 : public DownloadRequestLimiterTest, |
| 235 public ::testing::WithParamInterface<bool> { |
| 236 protected: |
| 237 DownloadRequestLimiterParamTests() {} |
| 238 ~DownloadRequestLimiterParamTests() override {} |
| 239 |
| 240 void SetUp() override { |
| 241 DownloadRequestLimiterTest::SetUp(); |
| 242 #if !defined(OS_ANDROID) |
| 243 if (GetParam()) { |
| 244 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 245 switches::kEnablePermissionsBubbles); |
| 246 EXPECT_TRUE(PermissionBubbleManager::Enabled()); |
| 247 } else { |
| 248 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 249 switches::kDisablePermissionsBubbles); |
| 250 } |
| 251 #endif |
| 252 } |
| 253 |
| 254 void BubbleManagerDocumentLoadCompleted() { |
| 255 #if defined(OS_ANDROID) |
| 256 DownloadRequestLimiterTest::BubbleManagerDocumentLoadCompleted(false); |
| 257 #else |
| 258 DownloadRequestLimiterTest::BubbleManagerDocumentLoadCompleted(GetParam()); |
| 259 #endif |
| 260 } |
| 261 private: |
| 262 DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiterParamTests); |
| 263 }; |
| 264 |
| 265 TEST_P(DownloadRequestLimiterParamTests, |
| 225 DownloadRequestLimiter_Allow) { | 266 DownloadRequestLimiter_Allow) { |
| 267 BubbleManagerDocumentLoadCompleted(); |
| 268 |
| 226 // All tabs should initially start at ALLOW_ONE_DOWNLOAD. | 269 // All tabs should initially start at ALLOW_ONE_DOWNLOAD. |
| 227 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 270 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 228 download_request_limiter_->GetDownloadStatus(web_contents())); | 271 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 229 | 272 |
| 230 // Ask if the tab can do a download. This moves to PROMPT_BEFORE_DOWNLOAD. | 273 // Ask if the tab can do a download. This moves to PROMPT_BEFORE_DOWNLOAD. |
| 231 CanDownload(); | 274 CanDownload(); |
| 232 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 275 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 233 download_request_limiter_->GetDownloadStatus(web_contents())); | 276 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 234 // We should have been told we can download. | 277 // We should have been told we can download. |
| 235 ExpectAndResetCounts(1, 0, 0, __LINE__); | 278 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 236 | 279 |
| 237 // Ask again. This triggers asking the delegate for allow/disallow. | 280 // Ask again. This triggers asking the delegate for allow/disallow. |
| 238 testing_action_ = ACCEPT; | 281 testing_action_ = ACCEPT; |
| 239 CanDownload(); | 282 CanDownload(); |
| 240 // This should ask us if the download is allowed. | 283 // This should ask us if the download is allowed. |
| 241 // We should have been told we can download. | 284 // We should have been told we can download. |
| 242 ExpectAndResetCounts(1, 0, 1, __LINE__); | 285 ExpectAndResetCounts(1, 0, 1, __LINE__); |
| 243 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 286 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 244 download_request_limiter_->GetDownloadStatus(web_contents())); | 287 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 245 | 288 |
| 246 // Ask again and make sure continue is invoked. | 289 // Ask again and make sure continue is invoked. |
| 247 CanDownload(); | 290 CanDownload(); |
| 248 // The state is at allow_all, which means the delegate shouldn't be asked. | 291 // The state is at allow_all, which means the delegate shouldn't be asked. |
| 249 // We should have been told we can download. | 292 // We should have been told we can download. |
| 250 ExpectAndResetCounts(1, 0, 0, __LINE__); | 293 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 251 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 294 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 252 download_request_limiter_->GetDownloadStatus(web_contents())); | 295 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 253 } | 296 } |
| 254 | 297 |
| 255 TEST_F(DownloadRequestLimiterTest, | 298 TEST_P(DownloadRequestLimiterParamTests, |
| 256 DownloadRequestLimiter_ResetOnNavigation) { | 299 DownloadRequestLimiter_ResetOnNavigation) { |
| 257 NavigateAndCommit(GURL("http://foo.com/bar")); | 300 NavigateAndCommit(GURL("http://foo.com/bar")); |
| 301 BubbleManagerDocumentLoadCompleted(); |
| 258 | 302 |
| 259 // Do two downloads, allowing the second so that we end up with allow all. | 303 // Do two downloads, allowing the second so that we end up with allow all. |
| 260 CanDownload(); | 304 CanDownload(); |
| 261 ExpectAndResetCounts(1, 0, 0, __LINE__); | 305 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 262 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 306 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 263 download_request_limiter_->GetDownloadStatus(web_contents())); | 307 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 264 | 308 |
| 265 testing_action_ = ACCEPT; | 309 testing_action_ = ACCEPT; |
| 266 CanDownload(); | 310 CanDownload(); |
| 267 ExpectAndResetCounts(1, 0, 1, __LINE__); | 311 ExpectAndResetCounts(1, 0, 1, __LINE__); |
| 268 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 312 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 269 download_request_limiter_->GetDownloadStatus(web_contents())); | 313 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 270 | 314 |
| 271 // Navigate to a new URL with the same host, which shouldn't reset the allow | 315 // Navigate to a new URL with the same host, which shouldn't reset the allow |
| 272 // all state. | 316 // all state. |
| 273 NavigateAndCommit(GURL("http://foo.com/bar2")); | 317 NavigateAndCommit(GURL("http://foo.com/bar2")); |
| 318 BubbleManagerDocumentLoadCompleted(); |
| 274 CanDownload(); | 319 CanDownload(); |
| 275 ExpectAndResetCounts(1, 0, 0, __LINE__); | 320 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 276 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 321 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 277 download_request_limiter_->GetDownloadStatus(web_contents())); | 322 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 278 | 323 |
| 279 // Do a user gesture, because we're at allow all, this shouldn't change the | 324 // Do a user gesture, because we're at allow all, this shouldn't change the |
| 280 // state. | 325 // state. |
| 281 OnUserGesture(); | 326 OnUserGesture(); |
| 282 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, | 327 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| 283 download_request_limiter_->GetDownloadStatus(web_contents())); | 328 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 284 | 329 |
| 285 // Navigate to a completely different host, which should reset the state. | 330 // Navigate to a completely different host, which should reset the state. |
| 286 NavigateAndCommit(GURL("http://fooey.com")); | 331 NavigateAndCommit(GURL("http://fooey.com")); |
| 332 BubbleManagerDocumentLoadCompleted(); |
| 287 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 333 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 288 download_request_limiter_->GetDownloadStatus(web_contents())); | 334 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 289 | 335 |
| 290 // Do two downloads, allowing the second so that we end up with allow all. | 336 // Do two downloads, allowing the second so that we end up with allow all. |
| 291 CanDownload(); | 337 CanDownload(); |
| 292 ExpectAndResetCounts(1, 0, 0, __LINE__); | 338 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 293 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 339 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 294 download_request_limiter_->GetDownloadStatus(web_contents())); | 340 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 295 | 341 |
| 296 testing_action_ = CANCEL; | 342 testing_action_ = CANCEL; |
| 297 CanDownload(); | 343 CanDownload(); |
| 298 ExpectAndResetCounts(0, 1, 1, __LINE__); | 344 ExpectAndResetCounts(0, 1, 1, __LINE__); |
| 299 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 345 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 300 download_request_limiter_->GetDownloadStatus(web_contents())); | 346 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 301 | 347 |
| 302 // Navigate to a new URL with the same host, which shouldn't reset the allow | 348 // Navigate to a new URL with the same host, which shouldn't reset the allow |
| 303 // all state. | 349 // all state. |
| 304 NavigateAndCommit(GURL("http://fooey.com/bar2")); | 350 NavigateAndCommit(GURL("http://fooey.com/bar2")); |
| 351 BubbleManagerDocumentLoadCompleted(); |
| 305 CanDownload(); | 352 CanDownload(); |
| 306 ExpectAndResetCounts(0, 1, 0, __LINE__); | 353 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 307 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 354 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 308 download_request_limiter_->GetDownloadStatus(web_contents())); | 355 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 309 } | 356 } |
| 310 | 357 |
| 311 TEST_F(DownloadRequestLimiterTest, | 358 TEST_P(DownloadRequestLimiterParamTests, |
| 312 DownloadRequestLimiter_ResetOnUserGesture) { | 359 DownloadRequestLimiter_ResetOnUserGesture) { |
| 313 NavigateAndCommit(GURL("http://foo.com/bar")); | 360 NavigateAndCommit(GURL("http://foo.com/bar")); |
| 361 BubbleManagerDocumentLoadCompleted(); |
| 314 | 362 |
| 315 // Do one download, which should change to prompt before download. | 363 // Do one download, which should change to prompt before download. |
| 316 CanDownload(); | 364 CanDownload(); |
| 317 ExpectAndResetCounts(1, 0, 0, __LINE__); | 365 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 318 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 366 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 319 download_request_limiter_->GetDownloadStatus(web_contents())); | 367 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 320 | 368 |
| 321 // Do a user gesture, which should reset back to allow one. | 369 // Do a user gesture, which should reset back to allow one. |
| 322 OnUserGesture(); | 370 OnUserGesture(); |
| 323 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 371 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 341 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 389 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 342 download_request_limiter_->GetDownloadStatus(web_contents())); | 390 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 343 // And make sure we really can't download. | 391 // And make sure we really can't download. |
| 344 CanDownload(); | 392 CanDownload(); |
| 345 ExpectAndResetCounts(0, 1, 0, __LINE__); | 393 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 346 // And the state shouldn't have changed. | 394 // And the state shouldn't have changed. |
| 347 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 395 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 348 download_request_limiter_->GetDownloadStatus(web_contents())); | 396 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 349 } | 397 } |
| 350 | 398 |
| 351 TEST_F(DownloadRequestLimiterTest, | 399 TEST_P(DownloadRequestLimiterParamTests, |
| 352 DownloadRequestLimiter_ResetOnReload) { | 400 DownloadRequestLimiter_ResetOnReload) { |
| 353 NavigateAndCommit(GURL("http://foo.com/bar")); | 401 NavigateAndCommit(GURL("http://foo.com/bar")); |
| 402 BubbleManagerDocumentLoadCompleted(); |
| 354 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 403 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 355 download_request_limiter_->GetDownloadStatus(web_contents())); | 404 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 356 | 405 |
| 357 // If the user refreshes the page without responding to the infobar, pretend | 406 // 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 | 407 // like the refresh is the initial load: they get 1 free download (probably |
| 359 // the same as the actual initial load), then an infobar. | 408 // the same as the actual initial load), then an infobar. |
| 360 testing_action_ = WAIT; | 409 testing_action_ = WAIT; |
| 361 | 410 |
| 362 CanDownload(); | 411 CanDownload(); |
| 363 ExpectAndResetCounts(1, 0, 0, __LINE__); | 412 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 389 DidNavigateMainFrame(); | 438 DidNavigateMainFrame(); |
| 390 base::RunLoop().RunUntilIdle(); | 439 base::RunLoop().RunUntilIdle(); |
| 391 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 440 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 392 download_request_limiter_->GetDownloadStatus(web_contents())); | 441 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 393 CanDownload(); | 442 CanDownload(); |
| 394 ExpectAndResetCounts(0, 1, 0, __LINE__); | 443 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 395 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 444 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 396 download_request_limiter_->GetDownloadStatus(web_contents())); | 445 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 397 } | 446 } |
| 398 | 447 |
| 399 TEST_F(DownloadRequestLimiterTest, | 448 TEST_P(DownloadRequestLimiterParamTests, |
| 400 DownloadRequestLimiter_RawWebContents) { | 449 DownloadRequestLimiter_RawWebContents) { |
| 401 scoped_ptr<WebContents> web_contents(CreateTestWebContents()); | 450 scoped_ptr<WebContents> web_contents(CreateTestWebContents()); |
| 402 | 451 |
| 403 // DownloadRequestLimiter won't try to make a permission bubble if there's | 452 // 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. | 453 // no permission bubble manager, so don't put one on the test WebContents. |
| 405 | 454 |
| 406 // DownloadRequestLimiter won't try to make an infobar if it doesn't have an | 455 // 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 | 456 // 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. | 457 // prompting when it doesn't have a InfoBarService, so unset the delegate. |
| 409 UnsetDelegate(); | 458 UnsetDelegate(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 428 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 477 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
| 429 OnUserGestureFor(web_contents.get()); | 478 OnUserGestureFor(web_contents.get()); |
| 430 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 479 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 431 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 480 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
| 432 CanDownloadFor(web_contents.get()); | 481 CanDownloadFor(web_contents.get()); |
| 433 ExpectAndResetCounts(1, 0, 0, __LINE__); | 482 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 434 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 483 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 435 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 484 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
| 436 } | 485 } |
| 437 | 486 |
| 438 TEST_F(DownloadRequestLimiterTest, | 487 TEST_P(DownloadRequestLimiterParamTests, |
| 439 DownloadRequestLimiter_SetHostContentSetting) { | 488 DownloadRequestLimiter_SetHostContentSetting) { |
| 440 NavigateAndCommit(GURL("http://foo.com/bar")); | 489 NavigateAndCommit(GURL("http://foo.com/bar")); |
| 490 BubbleManagerDocumentLoadCompleted(); |
| 441 SetHostContentSetting(web_contents(), CONTENT_SETTING_ALLOW); | 491 SetHostContentSetting(web_contents(), CONTENT_SETTING_ALLOW); |
| 442 | 492 |
| 443 CanDownload(); | 493 CanDownload(); |
| 444 ExpectAndResetCounts(1, 0, 0, __LINE__); | 494 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 445 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 495 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 446 download_request_limiter_->GetDownloadStatus(web_contents())); | 496 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 447 | 497 |
| 448 CanDownload(); | 498 CanDownload(); |
| 449 ExpectAndResetCounts(1, 0, 0, __LINE__); | 499 ExpectAndResetCounts(1, 0, 0, __LINE__); |
| 450 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 500 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 451 download_request_limiter_->GetDownloadStatus(web_contents())); | 501 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 452 | 502 |
| 453 SetHostContentSetting(web_contents(), CONTENT_SETTING_BLOCK); | 503 SetHostContentSetting(web_contents(), CONTENT_SETTING_BLOCK); |
| 454 | 504 |
| 455 CanDownload(); | 505 CanDownload(); |
| 456 ExpectAndResetCounts(0, 1, 0, __LINE__); | 506 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 457 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 507 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 458 download_request_limiter_->GetDownloadStatus(web_contents())); | 508 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 459 | 509 |
| 460 CanDownload(); | 510 CanDownload(); |
| 461 ExpectAndResetCounts(0, 1, 0, __LINE__); | 511 ExpectAndResetCounts(0, 1, 0, __LINE__); |
| 462 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 512 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 463 download_request_limiter_->GetDownloadStatus(web_contents())); | 513 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 464 } | 514 } |
| 515 |
| 516 INSTANTIATE_TEST_CASE_P(DownloadRequestLimiterTestsWithAndWithoutBubbles, |
| 517 DownloadRequestLimiterParamTests, |
| 518 ::testing::Values(false, true)); |
| OLD | NEW |