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

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

Issue 1159363002: [Download Notification] Show preview if downloaded file is image (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase & use embedded server Created 5 years, 6 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_notification_item.h" 5 #include "chrome/browser/download/notification/download_notification_item.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"
11 #include "chrome/browser/download/notification/download_notification_manager.h" 11 #include "chrome/browser/download/notification/download_notification_manager.h"
12 #include "chrome/browser/notifications/notification_test_util.h" 12 #include "chrome/browser/notifications/notification_test_util.h"
13 #include "chrome/browser/notifications/platform_notification_service_impl.h" 13 #include "chrome/browser/notifications/platform_notification_service_impl.h"
14 #include "chrome/test/base/testing_browser_process.h" 14 #include "chrome/test/base/testing_browser_process.h"
15 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
16 #include "chrome/test/base/testing_profile_manager.h" 16 #include "chrome/test/base/testing_profile_manager.h"
17 #include "content/public/test/mock_download_item.h" 17 #include "content/public/test/mock_download_item.h"
18 #include "content/public/test/mock_download_manager.h" 18 #include "content/public/test/mock_download_manager.h"
19 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/message_center/fake_message_center.h" 22 #include "ui/message_center/fake_message_center.h"
23 23
24 using testing::NiceMock; 24 using testing::NiceMock;
25 using testing::Return; 25 using testing::Return;
26 using testing::ReturnRefOfCopy;
26 using testing::_; 27 using testing::_;
27 28
29 namespace {
30
31 const base::FilePath::CharType kDownloadItemTargetPathString[] =
32 FILE_PATH_LITERAL("/tmp/TITLE.bin");
33
34 } // anonymouse namespace
35
28 namespace test { 36 namespace test {
29 37
30 class DownloadNotificationItemTest : public testing::Test { 38 class DownloadNotificationItemTest : public testing::Test {
31 public: 39 public:
32 DownloadNotificationItemTest() 40 DownloadNotificationItemTest()
33 : ui_thread_(content::BrowserThread::UI, &message_loop_), 41 : ui_thread_(content::BrowserThread::UI, &message_loop_),
34 profile_(nullptr) {} 42 profile_(nullptr) {}
35 43
36 void SetUp() override { 44 void SetUp() override {
37 testing::Test::SetUp(); 45 testing::Test::SetUp();
38 message_center::MessageCenter::Initialize(); 46 message_center::MessageCenter::Initialize();
39 47
40 profile_manager_.reset( 48 profile_manager_.reset(
41 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 49 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
42 ASSERT_TRUE(profile_manager_->SetUp()); 50 ASSERT_TRUE(profile_manager_->SetUp());
43 profile_ = profile_manager_->CreateTestingProfile("test-user"); 51 profile_ = profile_manager_->CreateTestingProfile("test-user");
44 52
45 scoped_ptr<NotificationUIManager> ui_manager(new StubNotificationUIManager); 53 scoped_ptr<NotificationUIManager> ui_manager(new StubNotificationUIManager);
46 TestingBrowserProcess::GetGlobal()-> 54 TestingBrowserProcess::GetGlobal()->
47 SetNotificationUIManager(ui_manager.Pass()); 55 SetNotificationUIManager(ui_manager.Pass());
48 56
49 download_notification_manager_.reset( 57 download_notification_manager_.reset(
50 new DownloadNotificationManagerForProfile(profile_, nullptr)); 58 new DownloadNotificationManagerForProfile(profile_, nullptr));
51 59
60 base::FilePath download_item_target_path(kDownloadItemTargetPathString);
52 download_item_.reset(new NiceMock<content::MockDownloadItem>()); 61 download_item_.reset(new NiceMock<content::MockDownloadItem>());
53 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345)); 62 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345));
54 ON_CALL(*download_item_, GetState()) 63 ON_CALL(*download_item_, GetState())
55 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS)); 64 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS));
56 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false)); 65 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false));
57 ON_CALL(*download_item_, GetFileNameToReportUser()) 66 ON_CALL(*download_item_, GetFileNameToReportUser())
58 .WillByDefault(Return(base::FilePath("TITLE.bin"))); 67 .WillByDefault(Return(base::FilePath("TITLE.bin")));
68 ON_CALL(*download_item_, GetTargetFilePath())
69 .WillByDefault(ReturnRefOfCopy(download_item_target_path));
59 ON_CALL(*download_item_, GetDangerType()) 70 ON_CALL(*download_item_, GetDangerType())
60 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)); 71 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS));
61 ON_CALL(*download_item_, IsDone()).WillByDefault(Return(false)); 72 ON_CALL(*download_item_, IsDone()).WillByDefault(Return(false));
62 ON_CALL(*download_item_, GetBrowserContext()) 73 ON_CALL(*download_item_, GetBrowserContext())
63 .WillByDefault(Return(profile_)); 74 .WillByDefault(Return(profile_));
64 } 75 }
65 76
66 void TearDown() override { 77 void TearDown() override {
67 download_notification_item_ = nullptr; // will be free'd in the manager. 78 download_notification_item_ = nullptr; // will be free'd in the manager.
68 download_notification_manager_.reset(); 79 download_notification_manager_.reset();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 EXPECT_CALL(*download_item_, GetState()) 242 EXPECT_CALL(*download_item_, GetState())
232 .WillRepeatedly(Return(content::DownloadItem::COMPLETE)); 243 .WillRepeatedly(Return(content::DownloadItem::COMPLETE));
233 EXPECT_CALL(*download_item_, IsDone()).WillRepeatedly(Return(true)); 244 EXPECT_CALL(*download_item_, IsDone()).WillRepeatedly(Return(true));
234 download_item_->NotifyObserversDownloadUpdated(); 245 download_item_->NotifyObserversDownloadUpdated();
235 246
236 // DownloadItem::OpenDownload must not be called since the file opens 247 // DownloadItem::OpenDownload must not be called since the file opens
237 // automatically due to the open-when-complete flag. 248 // automatically due to the open-when-complete flag.
238 } 249 }
239 250
240 } // namespace test 251 } // namespace test
OLDNEW
« no previous file with comments | « chrome/browser/download/notification/download_notification_item.cc ('k') | chrome/test/data/downloads/image-octet-stream.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698