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

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: Read file content in the browser process 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 static base::FilePath kDownloadItemTargetPath("/tmp/TITLE.bin");
Lei Zhang 2015/06/12 07:26:37 This generates a static initializer. If this wasn'
Lei Zhang 2015/06/12 07:26:37 You don't need static in an anonymous namespace.
yoshiki 2015/06/12 08:00:20 Done.
Lei Zhang 2015/06/13 00:27:26 Please remove the static keyword.
yoshiki 2015/06/16 16:41:42 Done.
72
70 } // anonymous namespace 73 } // anonymous namespace
71 74
72 namespace test { 75 namespace test {
73 76
74 class DownloadNotificationItemTest : public testing::Test { 77 class DownloadNotificationItemTest : public testing::Test {
75 public: 78 public:
76 DownloadNotificationItemTest() 79 DownloadNotificationItemTest()
77 : ui_thread_(content::BrowserThread::UI, &message_loop_), 80 : ui_thread_(content::BrowserThread::UI, &message_loop_),
78 profile_(nullptr) {} 81 profile_(nullptr) {}
79 82
(...skipping 10 matching lines...) Expand all
90 DownloadNotificationItem::SetStubNotificationUIManagerForTesting( 93 DownloadNotificationItem::SetStubNotificationUIManagerForTesting(
91 ui_manager_.get()); 94 ui_manager_.get());
92 95
93 download_item_.reset(new NiceMock<content::MockDownloadItem>()); 96 download_item_.reset(new NiceMock<content::MockDownloadItem>());
94 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345)); 97 ON_CALL(*download_item_, GetId()).WillByDefault(Return(12345));
95 ON_CALL(*download_item_, GetState()) 98 ON_CALL(*download_item_, GetState())
96 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS)); 99 .WillByDefault(Return(content::DownloadItem::IN_PROGRESS));
97 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false)); 100 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false));
98 ON_CALL(*download_item_, GetFileNameToReportUser()) 101 ON_CALL(*download_item_, GetFileNameToReportUser())
99 .WillByDefault(Return(base::FilePath("TITLE.bin"))); 102 .WillByDefault(Return(base::FilePath("TITLE.bin")));
103 ON_CALL(*download_item_, GetTargetFilePath())
104 .WillByDefault(ReturnRef(kDownloadItemTargetPath));
100 ON_CALL(*download_item_, GetDangerType()) 105 ON_CALL(*download_item_, GetDangerType())
101 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)); 106 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS));
102 ON_CALL(*download_item_, IsDone()).WillByDefault(Return(false)); 107 ON_CALL(*download_item_, IsDone()).WillByDefault(Return(false));
103 } 108 }
104 109
105 void TearDown() override { 110 void TearDown() override {
106 download_notification_item_.reset(); 111 download_notification_item_.reset();
107 profile_manager_.reset(); 112 profile_manager_.reset();
108 message_center::MessageCenter::Shutdown(); 113 message_center::MessageCenter::Shutdown();
109 testing::Test::TearDown(); 114 testing::Test::TearDown();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 294
290 // Checks OnDownloadRemoved(). 295 // Checks OnDownloadRemoved().
291 EXPECT_EQ(0u, delegate_.GetOnDownloadRemovedCallCount()); 296 EXPECT_EQ(0u, delegate_.GetOnDownloadRemovedCallCount());
292 download_item_->NotifyObserversDownloadRemoved(); 297 download_item_->NotifyObserversDownloadRemoved();
293 EXPECT_EQ(1u, delegate_.GetOnDownloadRemovedCallCount()); 298 EXPECT_EQ(1u, delegate_.GetOnDownloadRemovedCallCount());
294 299
295 download_item_.reset(); 300 download_item_.reset();
296 } 301 }
297 302
298 } // namespace test 303 } // namespace test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698