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

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: . 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;
25 using testing::_; 26 using testing::_;
26 27
27 namespace { 28 namespace {
28 29
29 class MockDownloadNotificationItemDelegate 30 class MockDownloadNotificationItemDelegate
30 : public DownloadNotificationItem::Delegate { 31 : public DownloadNotificationItem::Delegate {
31 public: 32 public:
32 MockDownloadNotificationItemDelegate() 33 MockDownloadNotificationItemDelegate()
33 : on_download_removed_call_count_(0u), 34 : on_download_removed_call_count_(0u),
34 on_download_started_call_count_(0u), 35 on_download_started_call_count_(0u),
(...skipping 25 matching lines...) Expand all
60 size_t GetOnDownloadStoppedCallCount() { 61 size_t GetOnDownloadStoppedCallCount() {
61 return on_download_stopped_call_count_; 62 return on_download_stopped_call_count_;
62 } 63 }
63 64
64 private: 65 private:
65 size_t on_download_removed_call_count_; 66 size_t on_download_removed_call_count_;
66 size_t on_download_started_call_count_; 67 size_t on_download_started_call_count_;
67 size_t on_download_stopped_call_count_; 68 size_t on_download_stopped_call_count_;
68 }; 69 };
69 70
71 const base::FilePath::CharType kDownloadItemTargetPathString[] =
72 FILE_PATH_LITERAL("/tmp/TITLE.bin");
73
70 } // anonymous namespace 74 } // anonymous namespace
71 75
72 namespace test { 76 namespace test {
73 77
74 class DownloadNotificationItemTest : public testing::Test { 78 class DownloadNotificationItemTest : public testing::Test {
75 public: 79 public:
76 DownloadNotificationItemTest() 80 DownloadNotificationItemTest()
77 : ui_thread_(content::BrowserThread::UI, &message_loop_), 81 : ui_thread_(content::BrowserThread::UI, &message_loop_),
78 profile_(nullptr) {} 82 profile_(nullptr) {}
79 83
80 void SetUp() override { 84 void SetUp() override {
81 testing::Test::SetUp(); 85 testing::Test::SetUp();
82 message_center::MessageCenter::Initialize(); 86 message_center::MessageCenter::Initialize();
83 87
84 profile_manager_.reset( 88 profile_manager_.reset(
85 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 89 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
86 ASSERT_TRUE(profile_manager_->SetUp()); 90 ASSERT_TRUE(profile_manager_->SetUp());
87 profile_ = profile_manager_->CreateTestingProfile("test-user"); 91 profile_ = profile_manager_->CreateTestingProfile("test-user");
88 92
89 ui_manager_.reset(new StubNotificationUIManager); 93 ui_manager_.reset(new StubNotificationUIManager);
90 DownloadNotificationItem::SetStubNotificationUIManagerForTesting( 94 DownloadNotificationItem::SetStubNotificationUIManagerForTesting(
91 ui_manager_.get()); 95 ui_manager_.get());
92 96
97 base::FilePath download_item_target_path(kDownloadItemTargetPathString);
93 download_item_.reset(new NiceMock<content::MockDownloadItem>()); 98 download_item_.reset(new NiceMock<content::MockDownloadItem>());
94 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345)); 99 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345));
95 ON_CALL(*download_item_, GetState()) 100 ON_CALL(*download_item_, GetState())
96 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS)); 101 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS));
97 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false)); 102 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false));
98 ON_CALL(*download_item_, GetFileNameToReportUser()) 103 ON_CALL(*download_item_, GetFileNameToReportUser())
99 .WillByDefault(Return(base::FilePath("TITLE.bin"))); 104 .WillByDefault(Return(base::FilePath("TITLE.bin")));
105 ON_CALL(*download_item_, GetTargetFilePath())
106 .WillByDefault(ReturnRef(download_item_target_path));
asanka 2015/06/16 15:10:20 You are returning a reference to a local variable.
100 ON_CALL(*download_item_, GetDangerType()) 107 ON_CALL(*download_item_, GetDangerType())
101 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)); 108 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS));
102 ON_CALL(*download_item_, IsDone()).WillByDefault(Return(false)); 109 ON_CALL(*download_item_, IsDone()).WillByDefault(Return(false));
103 } 110 }
104 111
105 void TearDown() override { 112 void TearDown() override {
106 download_notification_item_.reset(); 113 download_notification_item_.reset();
107 profile_manager_.reset(); 114 profile_manager_.reset();
108 message_center::MessageCenter::Shutdown(); 115 message_center::MessageCenter::Shutdown();
109 testing::Test::TearDown(); 116 testing::Test::TearDown();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 296
290 // Checks OnDownloadRemoved(). 297 // Checks OnDownloadRemoved().
291 EXPECT_EQ(0u, delegate_.GetOnDownloadRemovedCallCount()); 298 EXPECT_EQ(0u, delegate_.GetOnDownloadRemovedCallCount());
292 download_item_->NotifyObserversDownloadRemoved(); 299 download_item_->NotifyObserversDownloadRemoved();
293 EXPECT_EQ(1u, delegate_.GetOnDownloadRemovedCallCount()); 300 EXPECT_EQ(1u, delegate_.GetOnDownloadRemovedCallCount());
294 301
295 download_item_.reset(); 302 download_item_.reset();
296 } 303 }
297 304
298 } // namespace test 305 } // namespace test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698