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

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: Addressed comments #41 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/notifications/notification_test_util.h" 11 #include "chrome/browser/notifications/notification_test_util.h"
12 #include "chrome/browser/notifications/platform_notification_service_impl.h" 12 #include "chrome/browser/notifications/platform_notification_service_impl.h"
13 #include "chrome/test/base/testing_browser_process.h" 13 #include "chrome/test/base/testing_browser_process.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "chrome/test/base/testing_profile_manager.h" 15 #include "chrome/test/base/testing_profile_manager.h"
16 #include "content/public/test/mock_download_item.h" 16 #include "content/public/test/mock_download_item.h"
17 #include "content/public/test/mock_download_manager.h" 17 #include "content/public/test/mock_download_manager.h"
18 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/message_center/fake_message_center.h" 21 #include "ui/message_center/fake_message_center.h"
22 22
23 using testing::NiceMock; 23 using testing::NiceMock;
24 using testing::Return; 24 using testing::Return;
25 using testing::ReturnRef;
Lei Zhang 2015/06/16 18:35:08 nit: no longer used
yoshiki 2015/06/18 10:48:04 Done.
26 using testing::ReturnRefOfCopy;
25 using testing::_; 27 using testing::_;
26 28
27 namespace { 29 namespace {
28 30
29 class MockDownloadNotificationItemDelegate 31 class MockDownloadNotificationItemDelegate
30 : public DownloadNotificationItem::Delegate { 32 : public DownloadNotificationItem::Delegate {
31 public: 33 public:
32 MockDownloadNotificationItemDelegate() 34 MockDownloadNotificationItemDelegate()
33 : on_download_removed_call_count_(0u), 35 : on_download_removed_call_count_(0u),
34 on_download_started_call_count_(0u), 36 on_download_started_call_count_(0u),
(...skipping 25 matching lines...) Expand all
60 size_t GetOnDownloadStoppedCallCount() { 62 size_t GetOnDownloadStoppedCallCount() {
61 return on_download_stopped_call_count_; 63 return on_download_stopped_call_count_;
62 } 64 }
63 65
64 private: 66 private:
65 size_t on_download_removed_call_count_; 67 size_t on_download_removed_call_count_;
66 size_t on_download_started_call_count_; 68 size_t on_download_started_call_count_;
67 size_t on_download_stopped_call_count_; 69 size_t on_download_stopped_call_count_;
68 }; 70 };
69 71
72 const base::FilePath::CharType kDownloadItemTargetPathString[] =
73 FILE_PATH_LITERAL("/tmp/TITLE.bin");
74
70 } // anonymous namespace 75 } // anonymous namespace
71 76
72 namespace test { 77 namespace test {
73 78
74 class DownloadNotificationItemTest : public testing::Test { 79 class DownloadNotificationItemTest : public testing::Test {
75 public: 80 public:
76 DownloadNotificationItemTest() 81 DownloadNotificationItemTest()
77 : ui_thread_(content::BrowserThread::UI, &message_loop_), 82 : ui_thread_(content::BrowserThread::UI, &message_loop_),
78 profile_(nullptr) {} 83 profile_(nullptr) {}
79 84
80 void SetUp() override { 85 void SetUp() override {
81 testing::Test::SetUp(); 86 testing::Test::SetUp();
82 message_center::MessageCenter::Initialize(); 87 message_center::MessageCenter::Initialize();
83 88
84 profile_manager_.reset( 89 profile_manager_.reset(
85 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 90 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
86 ASSERT_TRUE(profile_manager_->SetUp()); 91 ASSERT_TRUE(profile_manager_->SetUp());
87 profile_ = profile_manager_->CreateTestingProfile("test-user"); 92 profile_ = profile_manager_->CreateTestingProfile("test-user");
88 93
89 ui_manager_.reset(new StubNotificationUIManager); 94 ui_manager_.reset(new StubNotificationUIManager);
90 DownloadNotificationItem::SetStubNotificationUIManagerForTesting( 95 DownloadNotificationItem::SetStubNotificationUIManagerForTesting(
91 ui_manager_.get()); 96 ui_manager_.get());
92 97
98 base::FilePath download_item_target_path(kDownloadItemTargetPathString);
93 download_item_.reset(new NiceMock<content::MockDownloadItem>()); 99 download_item_.reset(new NiceMock<content::MockDownloadItem>());
94 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345)); 100 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345));
95 ON_CALL(*download_item_, GetState()) 101 ON_CALL(*download_item_, GetState())
96 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS)); 102 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS));
97 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false)); 103 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false));
98 ON_CALL(*download_item_, GetFileNameToReportUser()) 104 ON_CALL(*download_item_, GetFileNameToReportUser())
99 .WillByDefault(Return(base::FilePath("TITLE.bin"))); 105 .WillByDefault(Return(base::FilePath("TITLE.bin")));
106 ON_CALL(*download_item_, GetTargetFilePath())
107 .WillByDefault(ReturnRefOfCopy(download_item_target_path));
100 ON_CALL(*download_item_, GetDangerType()) 108 ON_CALL(*download_item_, GetDangerType())
101 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)); 109 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS));
102 ON_CALL(*download_item_, IsDone()).WillByDefault(Return(false)); 110 ON_CALL(*download_item_, IsDone()).WillByDefault(Return(false));
103 } 111 }
104 112
105 void TearDown() override { 113 void TearDown() override {
106 download_notification_item_.reset(); 114 download_notification_item_.reset();
107 profile_manager_.reset(); 115 profile_manager_.reset();
108 message_center::MessageCenter::Shutdown(); 116 message_center::MessageCenter::Shutdown();
109 testing::Test::TearDown(); 117 testing::Test::TearDown();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 297
290 // Checks OnDownloadRemoved(). 298 // Checks OnDownloadRemoved().
291 EXPECT_EQ(0u, delegate_.GetOnDownloadRemovedCallCount()); 299 EXPECT_EQ(0u, delegate_.GetOnDownloadRemovedCallCount());
292 download_item_->NotifyObserversDownloadRemoved(); 300 download_item_->NotifyObserversDownloadRemoved();
293 EXPECT_EQ(1u, delegate_.GetOnDownloadRemovedCallCount()); 301 EXPECT_EQ(1u, delegate_.GetOnDownloadRemovedCallCount());
294 302
295 download_item_.reset(); 303 download_item_.reset();
296 } 304 }
297 305
298 } // namespace test 306 } // namespace test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698