OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/notification/download_item_notification.h" | 5 #include "chrome/browser/download/notification/download_item_notification.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
13 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
15 #include "chrome/browser/download/notification/download_notification_manager.h" | 14 #include "chrome/browser/download/notification/download_notification_manager.h" |
16 #include "chrome/browser/notifications/notification_test_util.h" | 15 #include "chrome/browser/notifications/notification_test_util.h" |
17 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 16 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
18 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
19 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
20 #include "chrome/test/base/testing_profile_manager.h" | 19 #include "chrome/test/base/testing_profile_manager.h" |
21 #include "content/public/test/mock_download_item.h" | 20 #include "content/public/test/mock_download_item.h" |
22 #include "content/public/test/mock_download_manager.h" | 21 #include "content/public/test/mock_download_manager.h" |
23 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "ui/message_center/fake_message_center.h" | 25 #include "ui/message_center/fake_message_center.h" |
27 | 26 |
28 using testing::NiceMock; | 27 using testing::NiceMock; |
29 using testing::Return; | 28 using testing::Return; |
30 using testing::ReturnRefOfCopy; | 29 using testing::ReturnRefOfCopy; |
31 using testing::_; | 30 using testing::_; |
32 | 31 |
33 namespace { | 32 namespace { |
(...skipping 20 matching lines...) Expand all Loading... |
54 } | 53 } |
55 | 54 |
56 private: | 55 private: |
57 message_center::NotificationList::Notifications visible_notifications_; | 56 message_center::NotificationList::Notifications visible_notifications_; |
58 | 57 |
59 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); | 58 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter); |
60 }; | 59 }; |
61 | 60 |
62 class DownloadItemNotificationTest : public testing::Test { | 61 class DownloadItemNotificationTest : public testing::Test { |
63 public: | 62 public: |
64 DownloadItemNotificationTest() | 63 DownloadItemNotificationTest() : profile_(nullptr) {} |
65 : ui_thread_(content::BrowserThread::UI, &message_loop_), | |
66 profile_(nullptr) {} | |
67 | 64 |
68 void SetUp() override { | 65 void SetUp() override { |
69 testing::Test::SetUp(); | 66 testing::Test::SetUp(); |
70 message_center::MessageCenter::Initialize(); | 67 message_center::MessageCenter::Initialize(); |
71 | 68 |
72 profile_manager_.reset( | 69 profile_manager_.reset( |
73 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 70 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
74 ASSERT_TRUE(profile_manager_->SetUp()); | 71 ASSERT_TRUE(profile_manager_->SetUp()); |
75 profile_ = profile_manager_->CreateTestingProfile("test-user"); | 72 profile_ = profile_manager_->CreateTestingProfile("test-user"); |
76 | 73 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 158 } |
162 | 159 |
163 void CreateDownloadItemNotification() { | 160 void CreateDownloadItemNotification() { |
164 download_notification_manager_->OnNewDownloadReady(download_item_.get()); | 161 download_notification_manager_->OnNewDownloadReady(download_item_.get()); |
165 download_item_notification_ = | 162 download_item_notification_ = |
166 download_notification_manager_->items_[download_item_.get()].get(); | 163 download_notification_manager_->items_[download_item_.get()].get(); |
167 message_center_->AddVisibleNotification( | 164 message_center_->AddVisibleNotification( |
168 download_item_notification_->notification_.get()); | 165 download_item_notification_->notification_.get()); |
169 } | 166 } |
170 | 167 |
171 base::MessageLoopForUI message_loop_; | 168 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
172 content::TestBrowserThread ui_thread_; | |
173 | 169 |
174 std::unique_ptr<TestingProfileManager> profile_manager_; | 170 std::unique_ptr<TestingProfileManager> profile_manager_; |
175 Profile* profile_; | 171 Profile* profile_; |
176 | 172 |
177 std::unique_ptr<NiceMock<content::MockDownloadItem>> download_item_; | 173 std::unique_ptr<NiceMock<content::MockDownloadItem>> download_item_; |
178 std::unique_ptr<DownloadNotificationManagerForProfile> | 174 std::unique_ptr<DownloadNotificationManagerForProfile> |
179 download_notification_manager_; | 175 download_notification_manager_; |
180 std::unique_ptr<MockMessageCenter> message_center_; | 176 std::unique_ptr<MockMessageCenter> message_center_; |
181 DownloadItemNotification* download_item_notification_; | 177 DownloadItemNotification* download_item_notification_; |
182 }; | 178 }; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 EXPECT_CALL(*download_item_, GetState()) | 292 EXPECT_CALL(*download_item_, GetState()) |
297 .WillRepeatedly(Return(content::DownloadItem::COMPLETE)); | 293 .WillRepeatedly(Return(content::DownloadItem::COMPLETE)); |
298 EXPECT_CALL(*download_item_, IsDone()).WillRepeatedly(Return(true)); | 294 EXPECT_CALL(*download_item_, IsDone()).WillRepeatedly(Return(true)); |
299 download_item_->NotifyObserversDownloadUpdated(); | 295 download_item_->NotifyObserversDownloadUpdated(); |
300 | 296 |
301 // Priority is updated back to normal. | 297 // Priority is updated back to normal. |
302 EXPECT_EQ(message_center::DEFAULT_PRIORITY, notification()->priority()); | 298 EXPECT_EQ(message_center::DEFAULT_PRIORITY, notification()->priority()); |
303 } | 299 } |
304 | 300 |
305 } // namespace test | 301 } // namespace test |
OLD | NEW |