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/command_line.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 13 #include "chrome/browser/download/download_permission_request.h" |
| 14 #include "chrome/browser/permissions/permission_request_manager.h" |
13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" |
14 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "components/content_settings/core/browser/host_content_settings_map.h" | 19 #include "components/content_settings/core/browser/host_content_settings_map.h" |
17 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_details.h" | 21 #include "content/public/browser/navigation_details.h" |
19 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
21 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/frame_navigate_params.h" | 25 #include "content/public/common/frame_navigate_params.h" |
23 #include "content/public/test/web_contents_tester.h" | 26 #include "content/public/test/web_contents_tester.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
25 | 28 |
26 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
27 #include "chrome/browser/download/download_request_infobar_delegate_android.h" | 30 #include "chrome/browser/download/download_request_infobar_delegate_android.h" |
28 #include "chrome/browser/infobars/infobar_service.h" | 31 #include "chrome/browser/infobars/infobar_service.h" |
29 #else | 32 #else |
30 #include "chrome/browser/download/download_permission_request.h" | |
31 #include "chrome/browser/permissions/permission_request_manager.h" | |
32 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" | |
33 #endif | 33 #endif |
34 | 34 |
35 using content::WebContents; | 35 using content::WebContents; |
36 | 36 |
37 namespace { | 37 namespace { |
38 enum TestingAction { | 38 enum TestingAction { |
39 ACCEPT, | 39 ACCEPT, |
40 CANCEL, | 40 CANCEL, |
41 WAIT | 41 WAIT |
42 }; | 42 }; |
43 | |
44 #if defined(OS_ANDROID) | |
45 class TestingDelegate { | |
46 public: | |
47 void SetUp(WebContents* web_contents) { | |
48 InfoBarService::CreateForWebContents(web_contents); | |
49 fake_create_callback_ = | |
50 base::Bind(&TestingDelegate::FakeCreate, base::Unretained(this)); | |
51 DownloadRequestInfoBarDelegateAndroid::SetCallbackForTesting( | |
52 &fake_create_callback_); | |
53 ResetCounts(); | |
54 } | |
55 | |
56 void TearDown() { UnsetInfobarDelegate(); } | |
57 | |
58 void LoadCompleted(WebContents* /*web_contents*/) { | |
59 // No action needed on OS_ANDROID. | |
60 } | |
61 | |
62 void ResetCounts() { ask_allow_count_ = 0; } | |
63 | |
64 int AllowCount() { return ask_allow_count_; } | |
65 | |
66 void UpdateExpectations(TestingAction action) { testing_action_ = action; } | |
67 | |
68 void FakeCreate( | |
69 InfoBarService* infobar_service, | |
70 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host) { | |
71 ask_allow_count_++; | |
72 switch (testing_action_) { | |
73 case ACCEPT: | |
74 host->Accept(); | |
75 break; | |
76 case CANCEL: | |
77 host->Cancel(); | |
78 break; | |
79 case WAIT: | |
80 break; | |
81 } | |
82 } | |
83 | |
84 void UnsetInfobarDelegate() { | |
85 DownloadRequestInfoBarDelegateAndroid::SetCallbackForTesting(nullptr); | |
86 } | |
87 | |
88 private: | |
89 // Number of times ShouldAllowDownload was invoked. | |
90 int ask_allow_count_; | |
91 | |
92 // The action that FakeCreate() should take. | |
93 TestingAction testing_action_; | |
94 | |
95 DownloadRequestInfoBarDelegateAndroid::FakeCreateCallback | |
96 fake_create_callback_; | |
97 }; | |
98 #else | |
99 class TestingDelegate { | |
100 public: | |
101 void SetUp(WebContents* web_contents) { | |
102 PermissionRequestManager::CreateForWebContents(web_contents); | |
103 mock_permission_prompt_factory_.reset(new MockPermissionPromptFactory( | |
104 PermissionRequestManager::FromWebContents(web_contents))); | |
105 PermissionRequestManager::FromWebContents(web_contents) | |
106 ->DisplayPendingRequests(); | |
107 } | |
108 | |
109 void TearDown() { mock_permission_prompt_factory_.reset(); } | |
110 | |
111 void LoadCompleted(WebContents* web_contents) { | |
112 mock_permission_prompt_factory_->DocumentOnLoadCompletedInMainFrame(); | |
113 } | |
114 | |
115 void ResetCounts() { mock_permission_prompt_factory_->ResetCounts(); } | |
116 | |
117 int AllowCount() { return mock_permission_prompt_factory_->show_count(); } | |
118 | |
119 void UpdateExpectations(TestingAction action) { | |
120 // Set expectations for PermissionRequestManager. | |
121 PermissionRequestManager::AutoResponseType response_type = | |
122 PermissionRequestManager::DISMISS; | |
123 switch (action) { | |
124 case ACCEPT: | |
125 response_type = PermissionRequestManager::ACCEPT_ALL; | |
126 break; | |
127 case CANCEL: | |
128 response_type = PermissionRequestManager::DENY_ALL; | |
129 break; | |
130 case WAIT: | |
131 response_type = PermissionRequestManager::NONE; | |
132 break; | |
133 } | |
134 mock_permission_prompt_factory_->set_response_type(response_type); | |
135 } | |
136 | |
137 private: | |
138 std::unique_ptr<MockPermissionPromptFactory> mock_permission_prompt_factory_; | |
139 }; | |
140 #endif | |
141 } // namespace | 43 } // namespace |
142 | 44 |
143 class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { | 45 class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { |
144 public: | 46 public: |
145 void SetUp() override { | 47 void SetUp() override { |
146 ChromeRenderViewHostTestHarness::SetUp(); | 48 ChromeRenderViewHostTestHarness::SetUp(); |
147 testing_delegate_.SetUp(web_contents()); | 49 |
| 50 use_permission_request_manager_ = PermissionRequestManager::IsEnabled(); |
| 51 |
| 52 if (use_permission_request_manager_) { |
| 53 PermissionRequestManager::CreateForWebContents(web_contents()); |
| 54 PermissionRequestManager* manager = |
| 55 PermissionRequestManager::FromWebContents(web_contents()); |
| 56 mock_permission_prompt_factory_.reset( |
| 57 new MockPermissionPromptFactory(manager)); |
| 58 manager->DisplayPendingRequests(); |
| 59 } else { |
| 60 #if defined(OS_ANDROID) |
| 61 InfoBarService::CreateForWebContents(web_contents()); |
| 62 fake_create_callback_ = base::Bind( |
| 63 &DownloadRequestLimiterTest::FakeCreate, base::Unretained(this)); |
| 64 DownloadRequestInfoBarDelegateAndroid::SetCallbackForTesting( |
| 65 &fake_create_callback_); |
| 66 #endif |
| 67 } |
148 | 68 |
149 UpdateExpectations(ACCEPT); | 69 UpdateExpectations(ACCEPT); |
150 cancel_count_ = continue_count_ = 0; | 70 ask_allow_count_ = cancel_count_ = continue_count_ = 0; |
151 download_request_limiter_ = new DownloadRequestLimiter(); | 71 download_request_limiter_ = new DownloadRequestLimiter(); |
152 } | 72 } |
153 | 73 |
154 void TearDown() override { | 74 void TearDown() override { |
155 testing_delegate_.TearDown(); | 75 if (use_permission_request_manager_) { |
| 76 mock_permission_prompt_factory_.reset(); |
| 77 } else { |
| 78 #if defined(OS_ANDROID) |
| 79 UnsetInfobarDelegate(); |
| 80 #endif |
| 81 } |
156 | 82 |
157 ChromeRenderViewHostTestHarness::TearDown(); | 83 ChromeRenderViewHostTestHarness::TearDown(); |
158 } | 84 } |
159 | 85 |
160 void CanDownload() { | 86 void CanDownload() { |
161 CanDownloadFor(web_contents()); | 87 CanDownloadFor(web_contents()); |
162 } | 88 } |
163 | 89 |
164 void CanDownloadFor(WebContents* web_contents) { | 90 void CanDownloadFor(WebContents* web_contents) { |
165 download_request_limiter_->CanDownloadImpl( | 91 download_request_limiter_->CanDownloadImpl( |
(...skipping 19 matching lines...) Expand all Loading... |
185 | 111 |
186 void ExpectAndResetCounts( | 112 void ExpectAndResetCounts( |
187 int expect_continues, | 113 int expect_continues, |
188 int expect_cancels, | 114 int expect_cancels, |
189 int expect_asks, | 115 int expect_asks, |
190 int line) { | 116 int line) { |
191 EXPECT_EQ(expect_continues, continue_count_) << "line " << line; | 117 EXPECT_EQ(expect_continues, continue_count_) << "line " << line; |
192 EXPECT_EQ(expect_cancels, cancel_count_) << "line " << line; | 118 EXPECT_EQ(expect_cancels, cancel_count_) << "line " << line; |
193 EXPECT_EQ(expect_asks, AskAllowCount()) << "line " << line; | 119 EXPECT_EQ(expect_asks, AskAllowCount()) << "line " << line; |
194 continue_count_ = cancel_count_ = 0; | 120 continue_count_ = cancel_count_ = 0; |
195 testing_delegate_.ResetCounts(); | 121 if (use_permission_request_manager_) |
| 122 mock_permission_prompt_factory_->ResetCounts(); |
| 123 else |
| 124 ask_allow_count_ = 0; |
196 } | 125 } |
197 | 126 |
198 void UpdateContentSettings(WebContents* web_contents, | 127 void UpdateContentSettings(WebContents* web_contents, |
199 ContentSetting setting) { | 128 ContentSetting setting) { |
200 // Ensure a download state exists. | 129 // Ensure a download state exists. |
201 download_request_limiter_->GetDownloadState(web_contents, nullptr, true); | 130 download_request_limiter_->GetDownloadState(web_contents, nullptr, true); |
202 SetHostContentSetting(web_contents, setting); | 131 SetHostContentSetting(web_contents, setting); |
203 } | 132 } |
204 | 133 |
205 protected: | 134 protected: |
206 void ContinueDownload(bool allow) { | 135 void ContinueDownload(bool allow) { |
207 if (allow) { | 136 if (allow) { |
208 continue_count_++; | 137 continue_count_++; |
209 } else { | 138 } else { |
210 cancel_count_++; | 139 cancel_count_++; |
211 } | 140 } |
212 } | 141 } |
213 | 142 |
214 void SetHostContentSetting(WebContents* contents, ContentSetting setting) { | 143 void SetHostContentSetting(WebContents* contents, ContentSetting setting) { |
215 HostContentSettingsMapFactory::GetForProfile( | 144 HostContentSettingsMapFactory::GetForProfile( |
216 Profile::FromBrowserContext(contents->GetBrowserContext())) | 145 Profile::FromBrowserContext(contents->GetBrowserContext())) |
217 ->SetContentSettingDefaultScope( | 146 ->SetContentSettingDefaultScope( |
218 contents->GetURL(), GURL(), | 147 contents->GetURL(), GURL(), |
219 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), setting); | 148 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), setting); |
220 } | 149 } |
221 | 150 |
222 void LoadCompleted() { testing_delegate_.LoadCompleted(web_contents()); } | 151 void LoadCompleted() { |
| 152 if (use_permission_request_manager_) |
| 153 mock_permission_prompt_factory_->DocumentOnLoadCompletedInMainFrame(); |
| 154 } |
223 | 155 |
224 int AskAllowCount() { return testing_delegate_.AllowCount(); } | 156 int AskAllowCount() { |
| 157 if (use_permission_request_manager_) |
| 158 return mock_permission_prompt_factory_->show_count(); |
| 159 return ask_allow_count_; |
| 160 } |
225 | 161 |
226 void UpdateExpectations(TestingAction action) { | 162 void UpdateExpectations(TestingAction action) { |
227 testing_delegate_.UpdateExpectations(action); | 163 if (use_permission_request_manager_) { |
| 164 // Set expectations for PermissionRequestManager. |
| 165 PermissionRequestManager::AutoResponseType response_type = |
| 166 PermissionRequestManager::DISMISS; |
| 167 switch (action) { |
| 168 case ACCEPT: |
| 169 response_type = PermissionRequestManager::ACCEPT_ALL; |
| 170 break; |
| 171 case CANCEL: |
| 172 response_type = PermissionRequestManager::DENY_ALL; |
| 173 break; |
| 174 case WAIT: |
| 175 response_type = PermissionRequestManager::NONE; |
| 176 break; |
| 177 } |
| 178 mock_permission_prompt_factory_->set_response_type(response_type); |
| 179 } else { |
| 180 testing_action_ = action; |
| 181 } |
228 } | 182 } |
229 | 183 |
| 184 #if defined(OS_ANDROID) |
| 185 void FakeCreate( |
| 186 InfoBarService* infobar_service, |
| 187 base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host) { |
| 188 ask_allow_count_++; |
| 189 switch (testing_action_) { |
| 190 case ACCEPT: |
| 191 host->Accept(); |
| 192 break; |
| 193 case CANCEL: |
| 194 host->Cancel(); |
| 195 break; |
| 196 case WAIT: |
| 197 break; |
| 198 } |
| 199 } |
| 200 |
| 201 void UnsetInfobarDelegate() { |
| 202 if (!use_permission_request_manager_) |
| 203 DownloadRequestInfoBarDelegateAndroid::SetCallbackForTesting(nullptr); |
| 204 } |
| 205 #endif |
| 206 |
230 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; | 207 scoped_refptr<DownloadRequestLimiter> download_request_limiter_; |
231 | 208 |
232 // Number of times ContinueDownload was invoked. | 209 // Number of times ContinueDownload was invoked. |
233 int continue_count_; | 210 int continue_count_; |
234 | 211 |
235 // Number of times CancelDownload was invoked. | 212 // Number of times CancelDownload was invoked. |
236 int cancel_count_; | 213 int cancel_count_; |
237 | 214 |
238 TestingDelegate testing_delegate_; | 215 std::unique_ptr<MockPermissionPromptFactory> mock_permission_prompt_factory_; |
| 216 |
| 217 // TODO(timloh): Remove the members below here after crbug.com/606138 is done. |
| 218 |
| 219 bool use_permission_request_manager_; |
| 220 |
| 221 // Number of times ShouldAllowDownload was invoked. |
| 222 int ask_allow_count_; |
| 223 // The action that FakeCreate() should take. |
| 224 TestingAction testing_action_; |
| 225 #if defined(OS_ANDROID) |
| 226 DownloadRequestInfoBarDelegateAndroid::FakeCreateCallback |
| 227 fake_create_callback_; |
| 228 #endif |
239 }; | 229 }; |
240 | 230 |
241 TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_Allow) { | 231 TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_Allow) { |
242 NavigateAndCommit(GURL("http://foo.com/bar")); | 232 NavigateAndCommit(GURL("http://foo.com/bar")); |
243 LoadCompleted(); | 233 LoadCompleted(); |
244 | 234 |
245 // All tabs should initially start at ALLOW_ONE_DOWNLOAD. | 235 // All tabs should initially start at ALLOW_ONE_DOWNLOAD. |
246 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 236 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
247 download_request_limiter_->GetDownloadStatus(web_contents())); | 237 download_request_limiter_->GetDownloadStatus(web_contents())); |
248 | 238 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 LoadCompleted(); | 554 LoadCompleted(); |
565 base::RunLoop().RunUntilIdle(); | 555 base::RunLoop().RunUntilIdle(); |
566 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 556 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
567 download_request_limiter_->GetDownloadStatus(web_contents())); | 557 download_request_limiter_->GetDownloadStatus(web_contents())); |
568 CanDownload(); | 558 CanDownload(); |
569 ExpectAndResetCounts(0, 1, 0, __LINE__); | 559 ExpectAndResetCounts(0, 1, 0, __LINE__); |
570 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 560 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
571 download_request_limiter_->GetDownloadStatus(web_contents())); | 561 download_request_limiter_->GetDownloadStatus(web_contents())); |
572 } | 562 } |
573 | 563 |
574 #if defined(OS_ANDROID) | |
575 TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_RawWebContents) { | 564 TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_RawWebContents) { |
576 std::unique_ptr<WebContents> web_contents(CreateTestWebContents()); | 565 std::unique_ptr<WebContents> web_contents(CreateTestWebContents()); |
577 | 566 |
578 GURL url("http://foo.com/bar"); | 567 GURL url("http://foo.com/bar"); |
579 web_contents->GetController().LoadURL( | 568 web_contents->GetController().LoadURL( |
580 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); | 569 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
581 | 570 |
582 // DownloadRequestLimiter won't try to make a permission bubble if there's | 571 // DownloadRequestLimiter won't try to make a permission request or infobar |
583 // no permission bubble manager, so don't put one on the test WebContents. | 572 // if there is no PermissionRequestManager/InfoBarService, and we want to |
584 | 573 // test that it will Cancel() instead of prompting. |
585 // DownloadRequestLimiter won't try to make an infobar if it doesn't have an | 574 #if defined(OS_ANDROID) |
586 // InfoBarService, and we want to test that it will Cancel() instead of | 575 UnsetInfobarDelegate(); |
587 // prompting when it doesn't have a InfoBarService, so unset the delegate. | 576 #endif |
588 testing_delegate_.UnsetInfobarDelegate(); | |
589 ExpectAndResetCounts(0, 0, 0, __LINE__); | 577 ExpectAndResetCounts(0, 0, 0, __LINE__); |
590 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 578 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
591 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 579 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
592 // You get one freebie. | 580 // You get one freebie. |
593 CanDownloadFor(web_contents.get()); | 581 CanDownloadFor(web_contents.get()); |
594 ExpectAndResetCounts(1, 0, 0, __LINE__); | 582 ExpectAndResetCounts(1, 0, 0, __LINE__); |
595 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 583 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
596 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 584 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
597 OnUserInteractionFor(web_contents.get(), blink::WebInputEvent::kTouchStart); | 585 OnUserInteractionFor(web_contents.get(), blink::WebInputEvent::kTouchStart); |
598 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 586 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
599 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 587 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
600 CanDownloadFor(web_contents.get()); | 588 CanDownloadFor(web_contents.get()); |
601 ExpectAndResetCounts(1, 0, 0, __LINE__); | 589 ExpectAndResetCounts(1, 0, 0, __LINE__); |
602 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 590 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
603 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 591 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
604 CanDownloadFor(web_contents.get()); | 592 CanDownloadFor(web_contents.get()); |
605 ExpectAndResetCounts(0, 1, 0, __LINE__); | 593 ExpectAndResetCounts(0, 1, 0, __LINE__); |
606 EXPECT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 594 EXPECT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
607 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 595 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
608 OnUserInteractionFor(web_contents.get(), blink::WebInputEvent::kRawKeyDown); | 596 OnUserInteractionFor(web_contents.get(), blink::WebInputEvent::kRawKeyDown); |
609 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 597 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
610 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 598 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
611 CanDownloadFor(web_contents.get()); | 599 CanDownloadFor(web_contents.get()); |
612 ExpectAndResetCounts(1, 0, 0, __LINE__); | 600 ExpectAndResetCounts(1, 0, 0, __LINE__); |
613 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 601 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
614 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 602 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
615 } | 603 } |
616 #endif | |
617 | 604 |
618 TEST_F(DownloadRequestLimiterTest, | 605 TEST_F(DownloadRequestLimiterTest, |
619 DownloadRequestLimiter_SetHostContentSetting) { | 606 DownloadRequestLimiter_SetHostContentSetting) { |
620 NavigateAndCommit(GURL("http://foo.com/bar")); | 607 NavigateAndCommit(GURL("http://foo.com/bar")); |
621 LoadCompleted(); | 608 LoadCompleted(); |
622 SetHostContentSetting(web_contents(), CONTENT_SETTING_ALLOW); | 609 SetHostContentSetting(web_contents(), CONTENT_SETTING_ALLOW); |
623 | 610 |
624 CanDownload(); | 611 CanDownload(); |
625 ExpectAndResetCounts(1, 0, 0, __LINE__); | 612 ExpectAndResetCounts(1, 0, 0, __LINE__); |
626 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 613 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 // changing the content setting). | 679 // changing the content setting). |
693 UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK); | 680 UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK); |
694 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 681 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
695 download_request_limiter_->GetDownloadStatus(web_contents())); | 682 download_request_limiter_->GetDownloadStatus(web_contents())); |
696 UpdateExpectations(WAIT); | 683 UpdateExpectations(WAIT); |
697 CanDownload(); | 684 CanDownload(); |
698 ExpectAndResetCounts(0, 0, 1, __LINE__); | 685 ExpectAndResetCounts(0, 0, 1, __LINE__); |
699 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 686 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
700 download_request_limiter_->GetDownloadStatus(web_contents())); | 687 download_request_limiter_->GetDownloadStatus(web_contents())); |
701 } | 688 } |
OLD | NEW |