OLD | NEW |
---|---|
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" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { | 244 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { |
245 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | 245 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
246 MockObserver observer(item); | 246 MockObserver observer(item); |
247 | 247 |
248 item->TogglePause(); | 248 item->TogglePause(); |
249 ASSERT_TRUE(observer.CheckUpdated()); | 249 ASSERT_TRUE(observer.CheckUpdated()); |
250 | 250 |
251 item->TogglePause(); | 251 item->TogglePause(); |
252 ASSERT_TRUE(observer.CheckUpdated()); | 252 ASSERT_TRUE(observer.CheckUpdated()); |
253 } | 253 } |
254 | |
255 static char external_data_test_string[] = "External data test"; | |
256 static int destructor_called = 0; | |
257 | |
258 class TestExternalData : public DownloadItem::ExternalData { | |
259 public: | |
260 int value; | |
261 virtual ~TestExternalData() { | |
262 destructor_called++; | |
263 } | |
264 }; | |
265 | |
266 TEST_F(DownloadItemTest, ExternalData) { | |
267 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | |
268 | |
269 // Shouldn't be anything there before set. | |
270 EXPECT_EQ(NULL, item->GetExternalData(&external_data_test_string)); | |
271 | |
272 TestExternalData* test1(new TestExternalData()); | |
273 test1->value = 2; | |
274 | |
275 // Should be able to get back what you set. | |
276 item->SetExternalData(&external_data_test_string, test1); | |
277 TestExternalData* test_result = | |
278 static_cast<TestExternalData*>( | |
279 item->GetExternalData(&external_data_test_string)); | |
280 EXPECT_EQ(test1, test_result); | |
281 | |
282 // Destructor should be called if value overwritten. New value | |
283 // should then be retrievable. | |
284 TestExternalData* test2(new TestExternalData()); | |
285 test2->value = 3; | |
286 EXPECT_EQ(0, destructor_called); | |
287 item->SetExternalData(&external_data_test_string, test2); | |
288 EXPECT_EQ(1, destructor_called); | |
289 EXPECT_EQ(test2, item->GetExternalData(&external_data_test_string)); | |
asanka
2011/11/16 03:52:19
Nit: This is comparing a TestExternalData* and a E
Randy Smith (Not in Mondays)
2011/11/18 02:02:57
Done.
| |
290 | |
291 // Overwriting with the same value shouldn't do anything. | |
292 EXPECT_EQ(1, destructor_called); | |
293 item->SetExternalData(&external_data_test_string, test2); | |
294 EXPECT_EQ(1, destructor_called); | |
295 EXPECT_EQ(test2, item->GetExternalData(&external_data_test_string)); | |
296 | |
297 // Ovewrriting with NULL should result in destruction. | |
asanka
2011/11/16 03:52:19
Nit: Overwriting
Randy Smith (Not in Mondays)
2011/11/18 02:02:57
Done.
| |
298 item->SetExternalData(&external_data_test_string, NULL); | |
299 EXPECT_EQ(2, destructor_called); | |
300 | |
301 // Destroying the download item should destroy the external data. | |
302 | |
303 // Need to get this download onto the download history so that it'll | |
304 // be deleted on Remove() | |
305 download_manager_->OnItemAddedToPersistentStore(item->id(), 1); | |
306 TestExternalData* test3(new TestExternalData()); | |
307 item->SetExternalData(&external_data_test_string, test3); | |
308 EXPECT_EQ(test3, item->GetExternalData(&external_data_test_string)); | |
309 item->Remove(); | |
310 EXPECT_EQ(3, destructor_called); | |
311 } | |
OLD | NEW |