Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / download / all_download_item_notifier_unittest.cc
blob99d0f58a858dd5dad2f54cdfea1e5261a1c74ec4
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/download/all_download_item_notifier.h"
7 #include "content/public/test/mock_download_item.h"
8 #include "content/public/test/mock_download_manager.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using testing::NiceMock;
13 using testing::SetArgPointee;
14 using testing::_;
16 namespace {
18 class MockNotifierObserver : public AllDownloadItemNotifier::Observer {
19 public:
20 MockNotifierObserver() {
22 virtual ~MockNotifierObserver() {}
24 MOCK_METHOD2(OnDownloadCreated, void(
25 content::DownloadManager* manager, content::DownloadItem* item));
26 MOCK_METHOD2(OnDownloadUpdated, void(
27 content::DownloadManager* manager, content::DownloadItem* item));
28 MOCK_METHOD2(OnDownloadOpened, void(
29 content::DownloadManager* manager, content::DownloadItem* item));
30 MOCK_METHOD2(OnDownloadRemoved, void(
31 content::DownloadManager* manager, content::DownloadItem* item));
33 private:
34 DISALLOW_COPY_AND_ASSIGN(MockNotifierObserver);
37 class AllDownloadItemNotifierTest : public testing::Test {
38 public:
39 AllDownloadItemNotifierTest()
40 : download_manager_(new content::MockDownloadManager) {
43 virtual ~AllDownloadItemNotifierTest() {}
45 content::MockDownloadManager& manager() {
46 return *download_manager_.get();
49 content::MockDownloadItem& item() { return item_; }
51 content::DownloadItem::Observer* NotifierAsItemObserver() const {
52 return notifier_.get();
55 content::DownloadManager::Observer* NotifierAsManagerObserver() const {
56 return notifier_.get();
59 MockNotifierObserver& observer() { return observer_; }
61 void SetNotifier() {
62 EXPECT_CALL(*download_manager_.get(), AddObserver(_));
63 notifier_.reset(new AllDownloadItemNotifier(
64 download_manager_.get(), &observer_));
67 void ClearNotifier() {
68 notifier_.reset();
71 private:
72 NiceMock<content::MockDownloadItem> item_;
73 scoped_ptr<content::MockDownloadManager> download_manager_;
74 scoped_ptr<AllDownloadItemNotifier> notifier_;
75 NiceMock<MockNotifierObserver> observer_;
77 DISALLOW_COPY_AND_ASSIGN(AllDownloadItemNotifierTest);
80 } // namespace
82 TEST_F(AllDownloadItemNotifierTest,
83 AllDownloadItemNotifierTest_0) {
84 content::DownloadManager::DownloadVector items;
85 items.push_back(&item());
86 EXPECT_CALL(manager(), GetAllDownloads(_))
87 .WillOnce(SetArgPointee<0>(items));
88 SetNotifier();
90 EXPECT_CALL(observer(), OnDownloadUpdated(&manager(), &item()));
91 NotifierAsItemObserver()->OnDownloadUpdated(&item());
93 EXPECT_CALL(observer(), OnDownloadOpened(&manager(), &item()));
94 NotifierAsItemObserver()->OnDownloadOpened(&item());
96 EXPECT_CALL(observer(), OnDownloadRemoved(&manager(), &item()));
97 NotifierAsItemObserver()->OnDownloadRemoved(&item());
99 EXPECT_CALL(manager(), RemoveObserver(NotifierAsManagerObserver()));
100 ClearNotifier();
103 TEST_F(AllDownloadItemNotifierTest,
104 AllDownloadItemNotifierTest_1) {
105 EXPECT_CALL(manager(), GetAllDownloads(_));
106 SetNotifier();
108 EXPECT_CALL(observer(), OnDownloadCreated(&manager(), &item()));
109 NotifierAsManagerObserver()->OnDownloadCreated(
110 &manager(), &item());
112 EXPECT_CALL(manager(), RemoveObserver(NotifierAsManagerObserver()));
113 NotifierAsManagerObserver()->ManagerGoingDown(&manager());
115 ClearNotifier();