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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
7 #include "base/threading/thread.h" | 7 #include "base/threading/thread.h" |
8 #include "content/browser/download/download_create_info.h" | 8 #include "content/browser/download/download_create_info.h" |
9 #include "content/browser/download/download_item_impl.h" | 9 #include "content/browser/download/download_item_impl.h" |
10 #include "content/browser/download/download_request_handle.h" | 10 #include "content/browser/download/download_request_handle.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 class TestExternalData : public DownloadItem::ExternalData { | 287 class TestExternalData : public DownloadItem::ExternalData { |
288 public: | 288 public: |
289 int value; | 289 int value; |
290 virtual ~TestExternalData() { | 290 virtual ~TestExternalData() { |
291 destructor_called++; | 291 destructor_called++; |
292 } | 292 } |
293 }; | 293 }; |
294 | 294 |
295 TEST_F(DownloadItemTest, ExternalData) { | 295 TEST_F(DownloadItemTest, ExternalData) { |
296 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); | 296 DownloadItem* item = CreateDownloadItem(DownloadItem::IN_PROGRESS); |
| 297 const DownloadItem* const_item = item; |
297 | 298 |
298 // Shouldn't be anything there before set. | 299 // Shouldn't be anything there before set. |
299 EXPECT_EQ(NULL, item->GetExternalData(&external_data_test_string)); | 300 EXPECT_EQ(NULL, item->GetExternalData(&external_data_test_string)); |
| 301 EXPECT_EQ(NULL, const_item->GetExternalData(&external_data_test_string)); |
300 | 302 |
301 TestExternalData* test1(new TestExternalData()); | 303 TestExternalData* test1(new TestExternalData()); |
302 test1->value = 2; | 304 test1->value = 2; |
303 | 305 |
304 // Should be able to get back what you set. | 306 // Should be able to get back what you set. |
305 item->SetExternalData(&external_data_test_string, test1); | 307 item->SetExternalData(&external_data_test_string, test1); |
306 TestExternalData* test_result = | 308 TestExternalData* test_result = |
307 static_cast<TestExternalData*>( | 309 static_cast<TestExternalData*>( |
308 item->GetExternalData(&external_data_test_string)); | 310 item->GetExternalData(&external_data_test_string)); |
309 EXPECT_EQ(test1, test_result); | 311 EXPECT_EQ(test1, test_result); |
310 | 312 |
| 313 // Ditto for const lookup. |
| 314 const TestExternalData* test_const_result = |
| 315 static_cast<const TestExternalData*>( |
| 316 const_item->GetExternalData(&external_data_test_string)); |
| 317 EXPECT_EQ(static_cast<const TestExternalData*>(test1), |
| 318 test_const_result); |
| 319 |
311 // Destructor should be called if value overwritten. New value | 320 // Destructor should be called if value overwritten. New value |
312 // should then be retrievable. | 321 // should then be retrievable. |
313 TestExternalData* test2(new TestExternalData()); | 322 TestExternalData* test2(new TestExternalData()); |
314 test2->value = 3; | 323 test2->value = 3; |
315 EXPECT_EQ(0, destructor_called); | 324 EXPECT_EQ(0, destructor_called); |
316 item->SetExternalData(&external_data_test_string, test2); | 325 item->SetExternalData(&external_data_test_string, test2); |
317 EXPECT_EQ(1, destructor_called); | 326 EXPECT_EQ(1, destructor_called); |
318 EXPECT_EQ(static_cast<DownloadItem::ExternalData*>(test2), | 327 EXPECT_EQ(static_cast<DownloadItem::ExternalData*>(test2), |
319 item->GetExternalData(&external_data_test_string)); | 328 item->GetExternalData(&external_data_test_string)); |
320 | 329 |
(...skipping 14 matching lines...) Expand all Loading... |
335 item->SetExternalData(&external_data_test_string, test3); | 344 item->SetExternalData(&external_data_test_string, test3); |
336 EXPECT_EQ(static_cast<DownloadItem::ExternalData*>(test3), | 345 EXPECT_EQ(static_cast<DownloadItem::ExternalData*>(test3), |
337 item->GetExternalData(&external_data_test_string)); | 346 item->GetExternalData(&external_data_test_string)); |
338 DestroyDownloadItem(item); | 347 DestroyDownloadItem(item); |
339 EXPECT_EQ(3, destructor_called); | 348 EXPECT_EQ(3, destructor_called); |
340 } | 349 } |
341 | 350 |
342 TEST(MockDownloadItem, Compiles) { | 351 TEST(MockDownloadItem, Compiles) { |
343 MockDownloadItem mock_item; | 352 MockDownloadItem mock_item; |
344 } | 353 } |
OLD | NEW |