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

Side by Side Diff: chrome/browser/download/download_shelf_unittest.cc

Issue 14593012: BrowserContext should simply own DownloadManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "chrome/browser/download/download_item_model.h" 9 #include "chrome/browser/download/download_item_model.h"
10 #include "chrome/browser/download/test_download_shelf.h" 10 #include "chrome/browser/download/test_download_shelf.h"
(...skipping 13 matching lines...) Expand all
24 24
25 class DownloadShelfTest : public testing::Test { 25 class DownloadShelfTest : public testing::Test {
26 public: 26 public:
27 DownloadShelfTest(); 27 DownloadShelfTest();
28 28
29 protected: 29 protected:
30 content::MockDownloadItem* download_item() { 30 content::MockDownloadItem* download_item() {
31 return download_item_.get(); 31 return download_item_.get();
32 } 32 }
33 content::MockDownloadManager* download_manager() { 33 content::MockDownloadManager* download_manager() {
34 return download_manager_.get(); 34 return download_manager_;
35 } 35 }
36 TestDownloadShelf* shelf() { 36 TestDownloadShelf* shelf() {
37 return &shelf_; 37 return &shelf_;
38 } 38 }
39 39
40 private: 40 private:
41 scoped_ptr<content::MockDownloadItem> GetInProgressMockDownload(); 41 scoped_ptr<content::MockDownloadItem> GetInProgressMockDownload();
42 42
43 MessageLoopForUI message_loop_; 43 MessageLoopForUI message_loop_;
44 content::TestBrowserThread ui_thread_; 44 content::TestBrowserThread ui_thread_;
45 scoped_ptr<content::MockDownloadItem> download_item_; 45 scoped_ptr<content::MockDownloadItem> download_item_;
46 scoped_refptr<content::MockDownloadManager> download_manager_; 46 content::MockDownloadManager* download_manager_;
benjhayden 2013/05/17 14:50:03 Should this be a scoped_ptr?
cmarcelo 2013/05/20 15:22:06 Indeed, thanks.
47 TestDownloadShelf shelf_; 47 TestDownloadShelf shelf_;
48 }; 48 };
49 49
50 DownloadShelfTest::DownloadShelfTest() 50 DownloadShelfTest::DownloadShelfTest()
51 : ui_thread_(content::BrowserThread::UI, &message_loop_) { 51 : ui_thread_(content::BrowserThread::UI, &message_loop_) {
52 download_item_.reset(new ::testing::NiceMock<content::MockDownloadItem>()); 52 download_item_.reset(new ::testing::NiceMock<content::MockDownloadItem>());
53 ON_CALL(*download_item_, GetAutoOpened()).WillByDefault(Return(false)); 53 ON_CALL(*download_item_, GetAutoOpened()).WillByDefault(Return(false));
54 ON_CALL(*download_item_, GetMimeType()).WillByDefault(Return("text/plain")); 54 ON_CALL(*download_item_, GetMimeType()).WillByDefault(Return("text/plain"));
55 ON_CALL(*download_item_, GetOpenWhenComplete()).WillByDefault(Return(false)); 55 ON_CALL(*download_item_, GetOpenWhenComplete()).WillByDefault(Return(false));
56 ON_CALL(*download_item_, GetTargetDisposition()) 56 ON_CALL(*download_item_, GetTargetDisposition())
57 .WillByDefault(Return(DownloadItem::TARGET_DISPOSITION_OVERWRITE)); 57 .WillByDefault(Return(DownloadItem::TARGET_DISPOSITION_OVERWRITE));
58 ON_CALL(*download_item_, GetURL()) 58 ON_CALL(*download_item_, GetURL())
59 .WillByDefault(ReturnRefOfCopy(GURL("http://example.com/foo"))); 59 .WillByDefault(ReturnRefOfCopy(GURL("http://example.com/foo")));
60 ON_CALL(*download_item_, IsComplete()).WillByDefault(Return(false)); 60 ON_CALL(*download_item_, IsComplete()).WillByDefault(Return(false));
61 ON_CALL(*download_item_, IsInProgress()).WillByDefault(Return(true)); 61 ON_CALL(*download_item_, IsInProgress()).WillByDefault(Return(true));
62 ON_CALL(*download_item_, IsTemporary()).WillByDefault(Return(false)); 62 ON_CALL(*download_item_, IsTemporary()).WillByDefault(Return(false));
63 ON_CALL(*download_item_, ShouldOpenFileBasedOnExtension()) 63 ON_CALL(*download_item_, ShouldOpenFileBasedOnExtension())
64 .WillByDefault(Return(false)); 64 .WillByDefault(Return(false));
65 65
66 download_manager_ = new ::testing::NiceMock<content::MockDownloadManager>(); 66 download_manager_ = new ::testing::NiceMock<content::MockDownloadManager>();
67 ON_CALL(*download_manager_, GetDownload(_)) 67 ON_CALL(*download_manager_, GetDownload(_))
68 .WillByDefault(Return(download_item_.get())); 68 .WillByDefault(Return(download_item_.get()));
69 69
70 shelf_.set_download_manager(download_manager_.get()); 70 shelf_.set_download_manager(download_manager_);
71 } 71 }
72 72
73 } // namespace 73 } // namespace
74 74
75 TEST_F(DownloadShelfTest, ClosesShelfWhenHidden) { 75 TEST_F(DownloadShelfTest, ClosesShelfWhenHidden) {
76 shelf()->Show(); 76 shelf()->Show();
77 EXPECT_TRUE(shelf()->IsShowing()); 77 EXPECT_TRUE(shelf()->IsShowing());
78 shelf()->Hide(); 78 shelf()->Hide();
79 EXPECT_FALSE(shelf()->IsShowing()); 79 EXPECT_FALSE(shelf()->IsShowing());
80 shelf()->Unhide(); 80 shelf()->Unhide();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 .WillRepeatedly(Return(false)); 176 .WillRepeatedly(Return(false));
177 ASSERT_FALSE(DownloadItemModel(download_item()) 177 ASSERT_FALSE(DownloadItemModel(download_item())
178 .ShouldRemoveFromShelfWhenComplete()); 178 .ShouldRemoveFromShelfWhenComplete());
179 179
180 base::RunLoop run_loop; 180 base::RunLoop run_loop;
181 run_loop.RunUntilIdle(); 181 run_loop.RunUntilIdle();
182 182
183 EXPECT_TRUE(shelf()->did_add_download()); 183 EXPECT_TRUE(shelf()->did_add_download());
184 EXPECT_TRUE(shelf()->IsShowing()); 184 EXPECT_TRUE(shelf()->IsShowing());
185 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698