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

Side by Side Diff: chrome/browser/download/download_item_unittest.cc

Issue 8503018: Split DownloadItem into an ABC, an Impl, and a Mock. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: CamelCase Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "chrome/test/base/testing_profile.h" 6 #include "chrome/test/base/testing_profile.h"
7 #include "content/browser/download/download_create_info.h" 7 #include "content/browser/download/download_create_info.h"
8 #include "content/browser/download/download_id.h" 8 #include "content/browser/download/download_id.h"
9 #include "content/browser/download/download_id_factory.h" 9 #include "content/browser/download/download_id_factory.h"
10 #include "content/browser/download/download_item.h" 10 #include "content/browser/download/download_item.h"
11 #include "content/browser/download/download_status_updater.h" 11 #include "content/browser/download/download_status_updater.h"
12 #include "content/browser/download/interrupt_reasons.h" 12 #include "content/browser/download/interrupt_reasons.h"
13 #include "content/browser/download/mock_download_item.h"
13 #include "content/browser/download/mock_download_manager.h" 14 #include "content/browser/download/mock_download_manager.h"
14 #include "content/browser/download/mock_download_manager_delegate.h" 15 #include "content/browser/download/mock_download_manager_delegate.h"
15 #include "content/test/test_browser_thread.h" 16 #include "content/test/test_browser_thread.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 using content::BrowserThread; 19 using content::BrowserThread;
19 20
20 DownloadId::Domain kValidDownloadItemIdDomain = "valid DownloadId::Domain"; 21 DownloadId::Domain kValidDownloadItemIdDomain = "valid DownloadId::Domain";
21 22
22 class DownloadItemTest : public testing::Test { 23 class DownloadItemTest : public testing::Test {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 185
185 item->Remove(); 186 item->Remove();
186 ASSERT_TRUE(observer.CheckUpdated()); 187 ASSERT_TRUE(observer.CheckUpdated());
187 } 188 }
188 189
189 TEST_F(DownloadItemTest, NotificationAfterSetFileCheckResults) { 190 TEST_F(DownloadItemTest, NotificationAfterSetFileCheckResults) {
190 // Setting to safe should not trigger any notifications 191 // Setting to safe should not trigger any notifications
191 DownloadItem* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 192 DownloadItem* safe_item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
192 MockObserver safe_observer(safe_item); 193 MockObserver safe_observer(safe_item);
193 194
194 DownloadStateInfo state = safe_item->state_info();; 195 DownloadStateInfo state = safe_item->GetStateInfo();;
195 state.is_dangerous_file = false; 196 state.is_dangerous_file = false;
196 state.is_dangerous_url = false; 197 state.is_dangerous_url = false;
197 safe_item->SetFileCheckResults(state); 198 safe_item->SetFileCheckResults(state);
198 ASSERT_FALSE(safe_observer.CheckUpdated()); 199 ASSERT_FALSE(safe_observer.CheckUpdated());
199 200
200 // Setting to unsafe url or unsafe file should trigger notification 201 // Setting to unsafe url or unsafe file should trigger notification
201 DownloadItem* unsafeurl_item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 202 DownloadItem* unsafeurl_item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
202 MockObserver unsafeurl_observer(unsafeurl_item); 203 MockObserver unsafeurl_observer(unsafeurl_item);
203 204
204 state = unsafeurl_item->state_info();; 205 state = unsafeurl_item->GetStateInfo();;
205 state.is_dangerous_file = false; 206 state.is_dangerous_file = false;
206 state.is_dangerous_url = true; 207 state.is_dangerous_url = true;
207 unsafeurl_item->SetFileCheckResults(state); 208 unsafeurl_item->SetFileCheckResults(state);
208 ASSERT_TRUE(unsafeurl_observer.CheckUpdated()); 209 ASSERT_TRUE(unsafeurl_observer.CheckUpdated());
209 210
210 unsafeurl_item->DangerousDownloadValidated(); 211 unsafeurl_item->DangerousDownloadValidated();
211 ASSERT_TRUE(unsafeurl_observer.CheckUpdated()); 212 ASSERT_TRUE(unsafeurl_observer.CheckUpdated());
212 213
213 DownloadItem* unsafefile_item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 214 DownloadItem* unsafefile_item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
214 MockObserver unsafefile_observer(unsafefile_item); 215 MockObserver unsafefile_observer(unsafefile_item);
215 216
216 state = unsafefile_item->state_info();; 217 state = unsafefile_item->GetStateInfo();;
217 state.is_dangerous_file = true; 218 state.is_dangerous_file = true;
218 state.is_dangerous_url = false; 219 state.is_dangerous_url = false;
219 unsafefile_item->SetFileCheckResults(state); 220 unsafefile_item->SetFileCheckResults(state);
220 ASSERT_TRUE(unsafefile_observer.CheckUpdated()); 221 ASSERT_TRUE(unsafefile_observer.CheckUpdated());
221 222
222 unsafefile_item->DangerousDownloadValidated(); 223 unsafefile_item->DangerousDownloadValidated();
223 ASSERT_TRUE(unsafefile_observer.CheckUpdated()); 224 ASSERT_TRUE(unsafefile_observer.CheckUpdated());
224 } 225 }
225 226
226 TEST_F(DownloadItemTest, NotificationAfterOnPathDetermined) { 227 TEST_F(DownloadItemTest, NotificationAfterOnPathDetermined) {
(...skipping 17 matching lines...) Expand all
244 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { 245 TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
245 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); 246 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
246 MockObserver observer(item); 247 MockObserver observer(item);
247 248
248 item->TogglePause(); 249 item->TogglePause();
249 ASSERT_TRUE(observer.CheckUpdated()); 250 ASSERT_TRUE(observer.CheckUpdated());
250 251
251 item->TogglePause(); 252 item->TogglePause();
252 ASSERT_TRUE(observer.CheckUpdated()); 253 ASSERT_TRUE(observer.CheckUpdated());
253 } 254 }
255
256 TEST(MockDownloadItem, Compiles) {
cbentzel 2011/11/16 12:28:44 Do you want to remove this test?
benjhayden 2011/11/18 18:59:34 No, because it ensures that MockDownloadItem doesn
257 MockDownloadItem mock_item;
258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698