| Index: chrome/browser/download/download_request_limiter_unittest.cc
|
| diff --git a/chrome/browser/download/download_request_limiter_unittest.cc b/chrome/browser/download/download_request_limiter_unittest.cc
|
| index 33c3c21403714d7f80680a9e5a6163e2acbfd7e8..9dfa16506a1f12a0093e2d9ee1489967f9961719 100644
|
| --- a/chrome/browser/download/download_request_limiter_unittest.cc
|
| +++ b/chrome/browser/download/download_request_limiter_unittest.cc
|
| @@ -5,10 +5,13 @@
|
| #include "chrome/browser/download/download_request_limiter.h"
|
|
|
| #include "base/bind.h"
|
| +#include "base/command_line.h"
|
| #include "base/run_loop.h"
|
| +#include "chrome/browser/download/download_permission_request.h"
|
| #include "chrome/browser/download/download_request_infobar_delegate.h"
|
| #include "chrome/browser/infobars/infobar_service.h"
|
| #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| #include "chrome/test/base/chrome_render_view_host_test_harness.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "components/content_settings/core/browser/host_content_settings_map.h"
|
| @@ -68,9 +71,8 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
|
|
|
| PermissionBubbleManager::CreateForWebContents(web_contents());
|
| view_.reset(new FakePermissionBubbleView(this));
|
| - PermissionBubbleManager* manager =
|
| - PermissionBubbleManager::FromWebContents(web_contents());
|
| - manager->SetView(view_.get());
|
| + PermissionBubbleManager::FromWebContents(web_contents())->
|
| + SetView(view_.get());
|
|
|
| testing_action_ = ACCEPT;
|
| ask_allow_count_ = cancel_count_ = continue_count_ = 0;
|
| @@ -182,6 +184,13 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
|
| setting);
|
| }
|
|
|
| + void BubbleManagerDocumentLoadCompleted(bool bubbles_enabled) {
|
| + if (!bubbles_enabled)
|
| + return;
|
| + PermissionBubbleManager::FromWebContents(web_contents())->
|
| + DocumentOnLoadCompletedInMainFrame();
|
| + }
|
| +
|
| scoped_refptr<DownloadRequestLimiter> download_request_limiter_;
|
|
|
| // The action that FakeCreate() should take.
|
| @@ -221,8 +230,42 @@ void FakePermissionBubbleView::Show(
|
| }
|
| }
|
|
|
| -TEST_F(DownloadRequestLimiterTest,
|
| +class DownloadRequestLimiterParamTests
|
| + : public DownloadRequestLimiterTest,
|
| + public ::testing::WithParamInterface<bool> {
|
| + protected:
|
| + DownloadRequestLimiterParamTests() {}
|
| + ~DownloadRequestLimiterParamTests() override {}
|
| +
|
| + void SetUp() override {
|
| + DownloadRequestLimiterTest::SetUp();
|
| +#if !defined(OS_ANDROID)
|
| + if (GetParam()) {
|
| + base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + switches::kEnablePermissionsBubbles);
|
| + EXPECT_TRUE(PermissionBubbleManager::Enabled());
|
| + } else {
|
| + base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + switches::kDisablePermissionsBubbles);
|
| + }
|
| +#endif
|
| + }
|
| +
|
| + void BubbleManagerDocumentLoadCompleted() {
|
| +#if defined(OS_ANDROID)
|
| + DownloadRequestLimiterTest::BubbleManagerDocumentLoadCompleted(false);
|
| +#else
|
| + DownloadRequestLimiterTest::BubbleManagerDocumentLoadCompleted(GetParam());
|
| +#endif
|
| + }
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(DownloadRequestLimiterParamTests);
|
| +};
|
| +
|
| +TEST_P(DownloadRequestLimiterParamTests,
|
| DownloadRequestLimiter_Allow) {
|
| + BubbleManagerDocumentLoadCompleted();
|
| +
|
| // All tabs should initially start at ALLOW_ONE_DOWNLOAD.
|
| ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD,
|
| download_request_limiter_->GetDownloadStatus(web_contents()));
|
| @@ -252,9 +295,10 @@ TEST_F(DownloadRequestLimiterTest,
|
| download_request_limiter_->GetDownloadStatus(web_contents()));
|
| }
|
|
|
| -TEST_F(DownloadRequestLimiterTest,
|
| +TEST_P(DownloadRequestLimiterParamTests,
|
| DownloadRequestLimiter_ResetOnNavigation) {
|
| NavigateAndCommit(GURL("http://foo.com/bar"));
|
| + BubbleManagerDocumentLoadCompleted();
|
|
|
| // Do two downloads, allowing the second so that we end up with allow all.
|
| CanDownload();
|
| @@ -271,6 +315,7 @@ TEST_F(DownloadRequestLimiterTest,
|
| // Navigate to a new URL with the same host, which shouldn't reset the allow
|
| // all state.
|
| NavigateAndCommit(GURL("http://foo.com/bar2"));
|
| + BubbleManagerDocumentLoadCompleted();
|
| CanDownload();
|
| ExpectAndResetCounts(1, 0, 0, __LINE__);
|
| ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS,
|
| @@ -284,6 +329,7 @@ TEST_F(DownloadRequestLimiterTest,
|
|
|
| // Navigate to a completely different host, which should reset the state.
|
| NavigateAndCommit(GURL("http://fooey.com"));
|
| + BubbleManagerDocumentLoadCompleted();
|
| ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD,
|
| download_request_limiter_->GetDownloadStatus(web_contents()));
|
|
|
| @@ -302,15 +348,17 @@ TEST_F(DownloadRequestLimiterTest,
|
| // Navigate to a new URL with the same host, which shouldn't reset the allow
|
| // all state.
|
| NavigateAndCommit(GURL("http://fooey.com/bar2"));
|
| + BubbleManagerDocumentLoadCompleted();
|
| CanDownload();
|
| ExpectAndResetCounts(0, 1, 0, __LINE__);
|
| ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
|
| download_request_limiter_->GetDownloadStatus(web_contents()));
|
| }
|
|
|
| -TEST_F(DownloadRequestLimiterTest,
|
| +TEST_P(DownloadRequestLimiterParamTests,
|
| DownloadRequestLimiter_ResetOnUserGesture) {
|
| NavigateAndCommit(GURL("http://foo.com/bar"));
|
| + BubbleManagerDocumentLoadCompleted();
|
|
|
| // Do one download, which should change to prompt before download.
|
| CanDownload();
|
| @@ -348,9 +396,10 @@ TEST_F(DownloadRequestLimiterTest,
|
| download_request_limiter_->GetDownloadStatus(web_contents()));
|
| }
|
|
|
| -TEST_F(DownloadRequestLimiterTest,
|
| +TEST_P(DownloadRequestLimiterParamTests,
|
| DownloadRequestLimiter_ResetOnReload) {
|
| NavigateAndCommit(GURL("http://foo.com/bar"));
|
| + BubbleManagerDocumentLoadCompleted();
|
| ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD,
|
| download_request_limiter_->GetDownloadStatus(web_contents()));
|
|
|
| @@ -396,7 +445,7 @@ TEST_F(DownloadRequestLimiterTest,
|
| download_request_limiter_->GetDownloadStatus(web_contents()));
|
| }
|
|
|
| -TEST_F(DownloadRequestLimiterTest,
|
| +TEST_P(DownloadRequestLimiterParamTests,
|
| DownloadRequestLimiter_RawWebContents) {
|
| scoped_ptr<WebContents> web_contents(CreateTestWebContents());
|
|
|
| @@ -435,9 +484,10 @@ TEST_F(DownloadRequestLimiterTest,
|
| download_request_limiter_->GetDownloadStatus(web_contents.get()));
|
| }
|
|
|
| -TEST_F(DownloadRequestLimiterTest,
|
| +TEST_P(DownloadRequestLimiterParamTests,
|
| DownloadRequestLimiter_SetHostContentSetting) {
|
| NavigateAndCommit(GURL("http://foo.com/bar"));
|
| + BubbleManagerDocumentLoadCompleted();
|
| SetHostContentSetting(web_contents(), CONTENT_SETTING_ALLOW);
|
|
|
| CanDownload();
|
| @@ -462,3 +512,7 @@ TEST_F(DownloadRequestLimiterTest,
|
| ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
|
| download_request_limiter_->GetDownloadStatus(web_contents()));
|
| }
|
| +
|
| +INSTANTIATE_TEST_CASE_P(DownloadRequestLimiterTestsWithAndWithoutBubbles,
|
| + DownloadRequestLimiterParamTests,
|
| + ::testing::Values(false, true));
|
|
|