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/hyperbolic_download_item_notifier.h" | 5 #include "chrome/browser/download/all_download_item_notifier.h" |
6 | 6 |
7 #include "content/public/test/mock_download_item.h" | 7 #include "content/public/test/mock_download_item.h" |
8 #include "content/public/test/mock_download_manager.h" | 8 #include "content/public/test/mock_download_manager.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 using testing::NiceMock; | 12 using testing::NiceMock; |
13 using testing::SetArgPointee; | 13 using testing::SetArgPointee; |
14 using testing::_; | 14 using testing::_; |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class MockNotifierObserver : public HyperbolicDownloadItemNotifier::Observer { | 18 class MockNotifierObserver : public AllDownloadItemNotifier::Observer { |
19 public: | 19 public: |
20 MockNotifierObserver() { | 20 MockNotifierObserver() { |
21 } | 21 } |
22 virtual ~MockNotifierObserver() {} | 22 virtual ~MockNotifierObserver() {} |
23 | 23 |
24 MOCK_METHOD2(OnDownloadCreated, void( | 24 MOCK_METHOD2(OnDownloadCreated, void( |
25 content::DownloadManager* manager, content::DownloadItem* item)); | 25 content::DownloadManager* manager, content::DownloadItem* item)); |
26 MOCK_METHOD2(OnDownloadUpdated, void( | 26 MOCK_METHOD2(OnDownloadUpdated, void( |
27 content::DownloadManager* manager, content::DownloadItem* item)); | 27 content::DownloadManager* manager, content::DownloadItem* item)); |
28 MOCK_METHOD2(OnDownloadOpened, void( | 28 MOCK_METHOD2(OnDownloadOpened, void( |
29 content::DownloadManager* manager, content::DownloadItem* item)); | 29 content::DownloadManager* manager, content::DownloadItem* item)); |
30 MOCK_METHOD2(OnDownloadRemoved, void( | 30 MOCK_METHOD2(OnDownloadRemoved, void( |
31 content::DownloadManager* manager, content::DownloadItem* item)); | 31 content::DownloadManager* manager, content::DownloadItem* item)); |
32 | 32 |
33 private: | 33 private: |
34 DISALLOW_COPY_AND_ASSIGN(MockNotifierObserver); | 34 DISALLOW_COPY_AND_ASSIGN(MockNotifierObserver); |
35 }; | 35 }; |
36 | 36 |
37 class HyperbolicDownloadItemNotifierTest : public testing::Test { | 37 class AllDownloadItemNotifierTest : public testing::Test { |
38 public: | 38 public: |
39 HyperbolicDownloadItemNotifierTest() | 39 AllDownloadItemNotifierTest() |
40 : download_manager_(new content::MockDownloadManager) { | 40 : download_manager_(new content::MockDownloadManager) { |
41 } | 41 } |
42 | 42 |
43 virtual ~HyperbolicDownloadItemNotifierTest() {} | 43 virtual ~AllDownloadItemNotifierTest() {} |
44 | 44 |
45 content::MockDownloadManager& manager() { | 45 content::MockDownloadManager& manager() { |
46 return *download_manager_.get(); | 46 return *download_manager_.get(); |
47 } | 47 } |
48 | 48 |
49 content::MockDownloadItem& item() { return item_; } | 49 content::MockDownloadItem& item() { return item_; } |
50 | 50 |
51 content::DownloadItem::Observer* NotifierAsItemObserver() const { | 51 content::DownloadItem::Observer* NotifierAsItemObserver() const { |
52 return notifier_.get(); | 52 return notifier_.get(); |
53 } | 53 } |
54 | 54 |
55 content::DownloadManager::Observer* NotifierAsManagerObserver() const { | 55 content::DownloadManager::Observer* NotifierAsManagerObserver() const { |
56 return notifier_.get(); | 56 return notifier_.get(); |
57 } | 57 } |
58 | 58 |
59 MockNotifierObserver& observer() { return observer_; } | 59 MockNotifierObserver& observer() { return observer_; } |
60 | 60 |
61 void SetNotifier() { | 61 void SetNotifier() { |
62 EXPECT_CALL(*download_manager_.get(), AddObserver(_)); | 62 EXPECT_CALL(*download_manager_.get(), AddObserver(_)); |
63 notifier_.reset(new HyperbolicDownloadItemNotifier( | 63 notifier_.reset(new AllDownloadItemNotifier( |
64 download_manager_.get(), &observer_)); | 64 download_manager_.get(), &observer_)); |
65 } | 65 } |
66 | 66 |
67 void ClearNotifier() { | 67 void ClearNotifier() { |
68 notifier_.reset(); | 68 notifier_.reset(); |
69 } | 69 } |
70 | 70 |
71 private: | 71 private: |
72 NiceMock<content::MockDownloadItem> item_; | 72 NiceMock<content::MockDownloadItem> item_; |
73 scoped_refptr<content::MockDownloadManager> download_manager_; | 73 scoped_refptr<content::MockDownloadManager> download_manager_; |
74 scoped_ptr<HyperbolicDownloadItemNotifier> notifier_; | 74 scoped_ptr<AllDownloadItemNotifier> notifier_; |
75 NiceMock<MockNotifierObserver> observer_; | 75 NiceMock<MockNotifierObserver> observer_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(HyperbolicDownloadItemNotifierTest); | 77 DISALLOW_COPY_AND_ASSIGN(AllDownloadItemNotifierTest); |
78 }; | 78 }; |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 TEST_F(HyperbolicDownloadItemNotifierTest, | 82 TEST_F(AllDownloadItemNotifierTest, |
83 HyperbolicDownloadItemNotifierTest_0) { | 83 AllDownloadItemNotifierTest_0) { |
84 content::DownloadManager::DownloadVector items; | 84 content::DownloadManager::DownloadVector items; |
85 items.push_back(&item()); | 85 items.push_back(&item()); |
86 EXPECT_CALL(manager(), GetAllDownloads(_)) | 86 EXPECT_CALL(manager(), GetAllDownloads(_)) |
87 .WillOnce(SetArgPointee<0>(items)); | 87 .WillOnce(SetArgPointee<0>(items)); |
88 EXPECT_CALL(item(), AddObserver(_)); | 88 EXPECT_CALL(item(), AddObserver(_)); |
89 SetNotifier(); | 89 SetNotifier(); |
90 | 90 |
91 EXPECT_CALL(observer(), OnDownloadUpdated(&manager(), &item())); | 91 EXPECT_CALL(observer(), OnDownloadUpdated(&manager(), &item())); |
92 NotifierAsItemObserver()->OnDownloadUpdated(&item()); | 92 NotifierAsItemObserver()->OnDownloadUpdated(&item()); |
93 | 93 |
94 EXPECT_CALL(observer(), OnDownloadOpened(&manager(), &item())); | 94 EXPECT_CALL(observer(), OnDownloadOpened(&manager(), &item())); |
95 NotifierAsItemObserver()->OnDownloadOpened(&item()); | 95 NotifierAsItemObserver()->OnDownloadOpened(&item()); |
96 | 96 |
97 EXPECT_CALL(observer(), OnDownloadRemoved(&manager(), &item())); | 97 EXPECT_CALL(observer(), OnDownloadRemoved(&manager(), &item())); |
98 NotifierAsItemObserver()->OnDownloadRemoved(&item()); | 98 NotifierAsItemObserver()->OnDownloadRemoved(&item()); |
99 | 99 |
100 EXPECT_CALL(item(), RemoveObserver(NotifierAsItemObserver())); | 100 EXPECT_CALL(item(), RemoveObserver(NotifierAsItemObserver())); |
101 EXPECT_CALL(manager(), RemoveObserver(NotifierAsManagerObserver())); | 101 EXPECT_CALL(manager(), RemoveObserver(NotifierAsManagerObserver())); |
102 ClearNotifier(); | 102 ClearNotifier(); |
103 } | 103 } |
104 | 104 |
105 TEST_F(HyperbolicDownloadItemNotifierTest, | 105 TEST_F(AllDownloadItemNotifierTest, |
106 HyperbolicDownloadItemNotifierTest_1) { | 106 AllDownloadItemNotifierTest_1) { |
107 EXPECT_CALL(manager(), GetAllDownloads(_)); | 107 EXPECT_CALL(manager(), GetAllDownloads(_)); |
108 SetNotifier(); | 108 SetNotifier(); |
109 | 109 |
110 EXPECT_CALL(item(), AddObserver(NotifierAsItemObserver())); | 110 EXPECT_CALL(item(), AddObserver(NotifierAsItemObserver())); |
111 EXPECT_CALL(observer(), OnDownloadCreated(&manager(), &item())); | 111 EXPECT_CALL(observer(), OnDownloadCreated(&manager(), &item())); |
112 NotifierAsManagerObserver()->OnDownloadCreated( | 112 NotifierAsManagerObserver()->OnDownloadCreated( |
113 &manager(), &item()); | 113 &manager(), &item()); |
114 | 114 |
115 EXPECT_CALL(manager(), RemoveObserver(NotifierAsManagerObserver())); | 115 EXPECT_CALL(manager(), RemoveObserver(NotifierAsManagerObserver())); |
116 NotifierAsManagerObserver()->ManagerGoingDown(&manager()); | 116 NotifierAsManagerObserver()->ManagerGoingDown(&manager()); |
117 | 117 |
118 EXPECT_CALL(item(), RemoveObserver(NotifierAsItemObserver())); | 118 EXPECT_CALL(item(), RemoveObserver(NotifierAsItemObserver())); |
119 NotifierAsItemObserver()->OnDownloadDestroyed(&item()); | 119 NotifierAsItemObserver()->OnDownloadDestroyed(&item()); |
120 | 120 |
121 ClearNotifier(); | 121 ClearNotifier(); |
122 } | 122 } |
OLD | NEW |