OLD | NEW |
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/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 "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/download/download_item_model.h" | 10 #include "chrome/browser/download/download_item_model.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 using ::testing::Return; | 23 using ::testing::Return; |
24 using ::testing::ReturnRefOfCopy; | 24 using ::testing::ReturnRefOfCopy; |
25 using ::testing::SaveArg; | 25 using ::testing::SaveArg; |
26 using ::testing::_; | 26 using ::testing::_; |
27 using content::DownloadItem; | 27 using content::DownloadItem; |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 KeyedService* CreateDownloadService(content::BrowserContext* context) { | |
32 return new DownloadService(Profile::FromBrowserContext(context)); | |
33 } | |
34 | |
35 class DownloadShelfTest : public testing::Test { | 31 class DownloadShelfTest : public testing::Test { |
36 public: | 32 public: |
37 DownloadShelfTest(); | 33 DownloadShelfTest(); |
38 | 34 |
39 protected: | 35 protected: |
40 content::MockDownloadItem* download_item() { | 36 content::MockDownloadItem* download_item() { |
41 return download_item_.get(); | 37 return download_item_.get(); |
42 } | 38 } |
43 content::MockDownloadManager* download_manager() { | 39 content::MockDownloadManager* download_manager() { |
44 return download_manager_.get(); | 40 return download_manager_.get(); |
45 } | 41 } |
46 TestDownloadShelf* shelf() { | 42 TestDownloadShelf* shelf() { |
47 return &shelf_; | 43 return &shelf_; |
48 } | 44 } |
49 Profile* profile() { return profile_.get(); } | 45 Profile* profile() { return profile_.get(); } |
50 | 46 |
51 void SetUp() override { | 47 void SetUp() override { |
52 DownloadServiceFactory::GetInstance()->SetTestingFactory( | |
53 profile(), &CreateDownloadService); | |
54 } | 48 } |
55 | 49 |
56 void TearDown() override { | 50 void TearDown() override { |
57 DownloadServiceFactory::GetInstance()->SetTestingFactory( | |
58 profile(), NULL); | |
59 } | 51 } |
60 | 52 |
61 private: | 53 private: |
62 scoped_ptr<content::MockDownloadItem> GetInProgressMockDownload(); | 54 scoped_ptr<content::MockDownloadItem> GetInProgressMockDownload(); |
63 | 55 |
64 base::MessageLoopForUI message_loop_; | 56 base::MessageLoopForUI message_loop_; |
65 content::TestBrowserThread ui_thread_; | 57 content::TestBrowserThread ui_thread_; |
66 scoped_ptr<content::MockDownloadItem> download_item_; | 58 scoped_ptr<content::MockDownloadItem> download_item_; |
67 scoped_ptr<content::MockDownloadManager> download_manager_; | 59 scoped_ptr<content::MockDownloadManager> download_manager_; |
68 TestDownloadShelf shelf_; | 60 TestDownloadShelf shelf_; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 .WillRepeatedly(Return(false)); | 198 .WillRepeatedly(Return(false)); |
207 ASSERT_FALSE(DownloadItemModel(download_item()) | 199 ASSERT_FALSE(DownloadItemModel(download_item()) |
208 .ShouldRemoveFromShelfWhenComplete()); | 200 .ShouldRemoveFromShelfWhenComplete()); |
209 | 201 |
210 base::RunLoop run_loop; | 202 base::RunLoop run_loop; |
211 run_loop.RunUntilIdle(); | 203 run_loop.RunUntilIdle(); |
212 | 204 |
213 EXPECT_TRUE(shelf()->did_add_download()); | 205 EXPECT_TRUE(shelf()->did_add_download()); |
214 EXPECT_TRUE(shelf()->IsShowing()); | 206 EXPECT_TRUE(shelf()->IsShowing()); |
215 } | 207 } |
OLD | NEW |