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

Unified Diff: chrome/browser/download/download_item_unittest.cc

Issue 8571023: Implemented ExternalData interface on DownloadItem and used it for SafeBrowsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up a bit. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_item_unittest.cc
diff --git a/chrome/browser/download/download_item_unittest.cc b/chrome/browser/download/download_item_unittest.cc
index 85edae9c42a7d7f08a555eaef4b632ca01454405..ded452c7392cefef46565d6d793245d1e96d97a2 100644
--- a/chrome/browser/download/download_item_unittest.cc
+++ b/chrome/browser/download/download_item_unittest.cc
@@ -251,3 +251,61 @@ TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
item->TogglePause();
ASSERT_TRUE(observer.CheckUpdated());
}
+
+static char external_data_test_string[] = "External data test";
+static int destructor_called = 0;
+
+class TestExternalData : public DownloadItem::ExternalData {
+ public:
+ int value;
+ virtual ~TestExternalData() {
+ destructor_called++;
+ }
+};
+
+TEST_F(DownloadItemTest, ExternalData) {
+ DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS);
+
+ // Shouldn't be anything there before set.
+ EXPECT_EQ(NULL, item->GetExternalData(&external_data_test_string));
+
+ TestExternalData* test1(new TestExternalData());
+ test1->value = 2;
+
+ // Should be able to get back what you set.
+ item->SetExternalData(&external_data_test_string, test1);
+ TestExternalData* test_result =
+ static_cast<TestExternalData*>(
+ item->GetExternalData(&external_data_test_string));
+ EXPECT_EQ(test1, test_result);
+
+ // Destructor should be called if value overwritten. New value
+ // should then be retrievable.
+ TestExternalData* test2(new TestExternalData());
+ test2->value = 3;
+ EXPECT_EQ(0, destructor_called);
+ item->SetExternalData(&external_data_test_string, test2);
+ EXPECT_EQ(1, destructor_called);
+ 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.
+
+ // Overwriting with the same value shouldn't do anything.
+ EXPECT_EQ(1, destructor_called);
+ item->SetExternalData(&external_data_test_string, test2);
+ EXPECT_EQ(1, destructor_called);
+ EXPECT_EQ(test2, item->GetExternalData(&external_data_test_string));
+
+ // 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.
+ item->SetExternalData(&external_data_test_string, NULL);
+ EXPECT_EQ(2, destructor_called);
+
+ // Destroying the download item should destroy the external data.
+
+ // Need to get this download onto the download history so that it'll
+ // be deleted on Remove()
+ download_manager_->OnItemAddedToPersistentStore(item->id(), 1);
+ TestExternalData* test3(new TestExternalData());
+ item->SetExternalData(&external_data_test_string, test3);
+ EXPECT_EQ(test3, item->GetExternalData(&external_data_test_string));
+ item->Remove();
+ EXPECT_EQ(3, destructor_called);
+}

Powered by Google App Engine
This is Rietveld 408576698