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

Side by Side Diff: chrome/browser/download/notification/download_item_notification_unittest.cc

Issue 1403003004: Revert of Update first download notification correctly if there are multiple notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months 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 unified diff | Download patch
OLDNEW
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 "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/test_simple_task_runner.h" 9 #include "base/test/test_simple_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 17 matching lines...) Expand all
28 28
29 namespace { 29 namespace {
30 30
31 const base::FilePath::CharType kDownloadItemTargetPathString[] = 31 const base::FilePath::CharType kDownloadItemTargetPathString[] =
32 FILE_PATH_LITERAL("/tmp/TITLE.bin"); 32 FILE_PATH_LITERAL("/tmp/TITLE.bin");
33 33
34 } // anonymouse namespace 34 } // anonymouse namespace
35 35
36 namespace test { 36 namespace test {
37 37
38 class MockMessageCenter : public message_center::FakeMessageCenter {
39 public:
40 MockMessageCenter() {}
41 ~MockMessageCenter() override {}
42
43 void AddVisibleNotification(message_center::Notification* notification) {
44 visible_notifications_.insert(notification);
45 }
46
47 const message_center::NotificationList::Notifications&
48 GetVisibleNotifications() override {
49 return visible_notifications_;
50 }
51
52 private:
53 message_center::NotificationList::Notifications visible_notifications_;
54
55 DISALLOW_COPY_AND_ASSIGN(MockMessageCenter);
56 };
57
58 class DownloadItemNotificationTest : public testing::Test { 38 class DownloadItemNotificationTest : public testing::Test {
59 public: 39 public:
60 DownloadItemNotificationTest() 40 DownloadItemNotificationTest()
61 : ui_thread_(content::BrowserThread::UI, &message_loop_), 41 : ui_thread_(content::BrowserThread::UI, &message_loop_),
62 profile_(nullptr) {} 42 profile_(nullptr) {}
63 43
64 void SetUp() override { 44 void SetUp() override {
65 testing::Test::SetUp(); 45 testing::Test::SetUp();
66 message_center::MessageCenter::Initialize(); 46 message_center::MessageCenter::Initialize();
67 47
68 profile_manager_.reset( 48 profile_manager_.reset(
69 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 49 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
70 ASSERT_TRUE(profile_manager_->SetUp()); 50 ASSERT_TRUE(profile_manager_->SetUp());
71 profile_ = profile_manager_->CreateTestingProfile("test-user"); 51 profile_ = profile_manager_->CreateTestingProfile("test-user");
72 52
73 scoped_ptr<NotificationUIManager> ui_manager(new StubNotificationUIManager); 53 scoped_ptr<NotificationUIManager> ui_manager(new StubNotificationUIManager);
74 TestingBrowserProcess::GetGlobal()-> 54 TestingBrowserProcess::GetGlobal()->
75 SetNotificationUIManager(ui_manager.Pass()); 55 SetNotificationUIManager(ui_manager.Pass());
76 56
77 download_notification_manager_.reset( 57 download_notification_manager_.reset(
78 new DownloadNotificationManagerForProfile(profile_, nullptr)); 58 new DownloadNotificationManagerForProfile(profile_, nullptr));
79 59
80 message_center_.reset(new MockMessageCenter());
81 download_notification_manager_->OverrideMessageCenterForTest(
82 message_center_.get());
83
84 base::FilePath download_item_target_path(kDownloadItemTargetPathString); 60 base::FilePath download_item_target_path(kDownloadItemTargetPathString);
85 download_item_.reset(new NiceMock<content::MockDownloadItem>()); 61 download_item_.reset(new NiceMock<content::MockDownloadItem>());
86 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345)); 62 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345));
87 ON_CALL(*download_item_, GetState()) 63 ON_CALL(*download_item_, GetState())
88 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS)); 64 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS));
89 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false)); 65 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false));
90 ON_CALL(*download_item_, GetFileNameToReportUser()) 66 ON_CALL(*download_item_, GetFileNameToReportUser())
91 .WillByDefault(Return(base::FilePath("TITLE.bin"))); 67 .WillByDefault(Return(base::FilePath("TITLE.bin")));
92 ON_CALL(*download_item_, GetTargetFilePath()) 68 ON_CALL(*download_item_, GetTargetFilePath())
93 .WillByDefault(ReturnRefOfCopy(download_item_target_path)); 69 .WillByDefault(ReturnRefOfCopy(download_item_target_path));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 128 }
153 129
154 bool ShownAsPopUp() { 130 bool ShownAsPopUp() {
155 return !notification()->shown_as_popup(); 131 return !notification()->shown_as_popup();
156 } 132 }
157 133
158 void CreateDownloadItemNotification() { 134 void CreateDownloadItemNotification() {
159 download_notification_manager_->OnNewDownloadReady(download_item_.get()); 135 download_notification_manager_->OnNewDownloadReady(download_item_.get());
160 download_item_notification_ = 136 download_item_notification_ =
161 download_notification_manager_->items_[download_item_.get()]; 137 download_notification_manager_->items_[download_item_.get()];
162 message_center_->AddVisibleNotification(
163 download_item_notification_->notification_.get());
164 } 138 }
165 139
166 base::MessageLoopForUI message_loop_; 140 base::MessageLoopForUI message_loop_;
167 content::TestBrowserThread ui_thread_; 141 content::TestBrowserThread ui_thread_;
168 142
169 scoped_ptr<TestingProfileManager> profile_manager_; 143 scoped_ptr<TestingProfileManager> profile_manager_;
170 Profile* profile_; 144 Profile* profile_;
171 145
172 scoped_ptr<NiceMock<content::MockDownloadItem>> download_item_; 146 scoped_ptr<NiceMock<content::MockDownloadItem>> download_item_;
173 scoped_ptr<DownloadNotificationManagerForProfile> 147 scoped_ptr<DownloadNotificationManagerForProfile>
174 download_notification_manager_; 148 download_notification_manager_;
175 scoped_ptr<MockMessageCenter> message_center_;
176 DownloadItemNotification* download_item_notification_; 149 DownloadItemNotification* download_item_notification_;
177 }; 150 };
178 151
179 TEST_F(DownloadItemNotificationTest, ShowAndCloseNotification) { 152 TEST_F(DownloadItemNotificationTest, ShowAndCloseNotification) {
180 EXPECT_EQ(0u, NotificationCount()); 153 EXPECT_EQ(0u, NotificationCount());
181 154
182 // Shows a notification 155 // Shows a notification
183 CreateDownloadItemNotification(); 156 CreateDownloadItemNotification();
184 download_item_->NotifyObserversDownloadOpened(); 157 download_item_->NotifyObserversDownloadOpened();
185 158
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 CreateDownloadItemNotification(); 254 CreateDownloadItemNotification();
282 download_item_->NotifyObserversDownloadOpened(); 255 download_item_->NotifyObserversDownloadOpened();
283 256
284 EXPECT_EQ(message_center::DEFAULT_PRIORITY, notification()->priority()); 257 EXPECT_EQ(message_center::DEFAULT_PRIORITY, notification()->priority());
285 258
286 download_item_notification_->DisablePopup(); 259 download_item_notification_->DisablePopup();
287 EXPECT_EQ(message_center::LOW_PRIORITY, notification()->priority()); 260 EXPECT_EQ(message_center::LOW_PRIORITY, notification()->priority());
288 } 261 }
289 262
290 } // namespace test 263 } // namespace test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698