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_history.h" | 5 #include "chrome/browser/download/download_history.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/guid.h" | 12 #include "base/guid.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "components/history/content/browser/download_constants_utils.h" | 18 #include "components/history/content/browser/download_constants_utils.h" |
19 #include "components/history/core/browser/download_constants.h" | 19 #include "components/history/core/browser/download_constants.h" |
20 #include "components/history/core/browser/download_row.h" | 20 #include "components/history/core/browser/download_row.h" |
21 #include "components/history/core/browser/history_service.h" | 21 #include "components/history/core/browser/history_service.h" |
22 #include "content/public/test/mock_download_item.h" | 22 #include "content/public/test/mock_download_item.h" |
23 #include "content/public/test/mock_download_manager.h" | 23 #include "content/public/test/mock_download_manager.h" |
24 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread.h" |
25 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 26 #include "extensions/features/features.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 | 28 |
28 #if defined(ENABLE_EXTENSIONS) | 29 #if BUILDFLAG(ENABLE_EXTENSIONS) |
29 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 30 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
30 #endif | 31 #endif |
31 | 32 |
32 using testing::DoAll; | 33 using testing::DoAll; |
33 using testing::Invoke; | 34 using testing::Invoke; |
34 using testing::Return; | 35 using testing::Return; |
35 using testing::ReturnRefOfCopy; | 36 using testing::ReturnRefOfCopy; |
36 using testing::SetArgPointee; | 37 using testing::SetArgPointee; |
37 using testing::WithArg; | 38 using testing::WithArg; |
38 using testing::_; | 39 using testing::_; |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 .WillRepeatedly(Return(danger_type)); | 431 .WillRepeatedly(Return(danger_type)); |
431 EXPECT_CALL(item(index), GetLastReason()) | 432 EXPECT_CALL(item(index), GetLastReason()) |
432 .WillRepeatedly(Return(interrupt_reason)); | 433 .WillRepeatedly(Return(interrupt_reason)); |
433 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); | 434 EXPECT_CALL(item(index), GetOpened()).WillRepeatedly(Return(opened)); |
434 EXPECT_CALL(item(index), GetTargetDisposition()) | 435 EXPECT_CALL(item(index), GetTargetDisposition()) |
435 .WillRepeatedly( | 436 .WillRepeatedly( |
436 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); | 437 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); |
437 EXPECT_CALL(manager(), GetDownload(id)) | 438 EXPECT_CALL(manager(), GetDownload(id)) |
438 .WillRepeatedly(Return(&item(index))); | 439 .WillRepeatedly(Return(&item(index))); |
439 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); | 440 EXPECT_CALL(item(index), IsTemporary()).WillRepeatedly(Return(false)); |
440 #if defined(ENABLE_EXTENSIONS) | 441 #if BUILDFLAG(ENABLE_EXTENSIONS) |
441 new extensions::DownloadedByExtension( | 442 new extensions::DownloadedByExtension( |
442 &item(index), by_extension_id, by_extension_name); | 443 &item(index), by_extension_id, by_extension_name); |
443 #endif | 444 #endif |
444 | 445 |
445 std::vector<content::DownloadItem*> items; | 446 std::vector<content::DownloadItem*> items; |
446 for (size_t i = 0; i < items_.size(); ++i) { | 447 for (size_t i = 0; i < items_.size(); ++i) { |
447 items.push_back(&item(i)); | 448 items.push_back(&item(i)); |
448 } | 449 } |
449 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)) | 450 EXPECT_CALL(*manager_.get(), GetAllDownloads(_)) |
450 .WillRepeatedly(SetArgPointee<0>(items)); | 451 .WillRepeatedly(SetArgPointee<0>(items)); |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 FinishCreateDownload(); | 896 FinishCreateDownload(); |
896 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); | 897 EXPECT_TRUE(DownloadHistory::IsPersisted(&item(0))); |
897 | 898 |
898 // ItemAdded should call OnDownloadUpdated, which should detect that the item | 899 // ItemAdded should call OnDownloadUpdated, which should detect that the item |
899 // changed while it was being added and call UpdateDownload immediately. | 900 // changed while it was being added and call UpdateDownload immediately. |
900 info.opened = true; | 901 info.opened = true; |
901 ExpectDownloadUpdated(info); | 902 ExpectDownloadUpdated(info); |
902 } | 903 } |
903 | 904 |
904 } // anonymous namespace | 905 } // anonymous namespace |
OLD | NEW |