OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 10 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
11 #include "chrome/browser/download/download_service.h" | 11 #include "chrome/browser/download/download_core_service.h" |
12 #include "chrome/browser/download/download_service_factory.h" | 12 #include "chrome/browser/download/download_core_service_factory.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/test/base/test_browser_window.h" | 14 #include "chrome/test/base/test_browser_window.h" |
15 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
18 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
19 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
20 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
21 #include "extensions/features/features.h" | 21 #include "extensions/features/features.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 class TestingDownloadService : public DownloadService { | 24 class TestingDownloadCoreService : public DownloadCoreService { |
25 public: | 25 public: |
26 TestingDownloadService() : download_count_(0) {} | 26 TestingDownloadCoreService() : download_count_(0) {} |
27 ~TestingDownloadService() override {} | 27 ~TestingDownloadCoreService() override {} |
28 | 28 |
29 // All methods that aren't expected to be called in the execution of | 29 // All methods that aren't expected to be called in the execution of |
30 // this unit test are marked to result in test failure. Using a simple | 30 // this unit test are marked to result in test failure. Using a simple |
31 // mock for this class should be re-evaluated if any of these | 31 // mock for this class should be re-evaluated if any of these |
32 // methods are being called; it may mean that a more fully featured | 32 // methods are being called; it may mean that a more fully featured |
33 // DownloadService implementation is needed. | 33 // DownloadCoreService implementation is needed. |
34 | 34 |
35 void SetDownloadCount(int download_count) { | 35 void SetDownloadCount(int download_count) { |
36 download_count_ = download_count; | 36 download_count_ = download_count; |
37 } | 37 } |
38 | 38 |
39 // DownloadService | 39 // DownloadCoreService |
40 ChromeDownloadManagerDelegate* GetDownloadManagerDelegate() override { | 40 ChromeDownloadManagerDelegate* GetDownloadManagerDelegate() override { |
41 ADD_FAILURE(); | 41 ADD_FAILURE(); |
42 return nullptr; | 42 return nullptr; |
43 } | 43 } |
44 | 44 |
45 DownloadHistory* GetDownloadHistory() override { | 45 DownloadHistory* GetDownloadHistory() override { |
46 ADD_FAILURE(); | 46 ADD_FAILURE(); |
47 return nullptr; | 47 return nullptr; |
48 } | 48 } |
49 | 49 |
(...skipping 18 matching lines...) Expand all Loading... |
68 bool IsShelfEnabled() override { | 68 bool IsShelfEnabled() override { |
69 return true; | 69 return true; |
70 } | 70 } |
71 | 71 |
72 // KeyedService | 72 // KeyedService |
73 void Shutdown() override {} | 73 void Shutdown() override {} |
74 | 74 |
75 private: | 75 private: |
76 int download_count_; | 76 int download_count_; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(TestingDownloadService); | 78 DISALLOW_COPY_AND_ASSIGN(TestingDownloadCoreService); |
79 }; | 79 }; |
80 | 80 |
81 static std::unique_ptr<KeyedService> CreateTestingDownloadService( | 81 static std::unique_ptr<KeyedService> CreateTestingDownloadCoreService( |
82 content::BrowserContext* browser_context) { | 82 content::BrowserContext* browser_context) { |
83 return std::unique_ptr<KeyedService>(new TestingDownloadService()); | 83 return std::unique_ptr<KeyedService>(new TestingDownloadCoreService()); |
84 } | 84 } |
85 | 85 |
86 class BrowserCloseTest : public testing::Test { | 86 class BrowserCloseTest : public testing::Test { |
87 public: | 87 public: |
88 BrowserCloseTest() | 88 BrowserCloseTest() |
89 : profile_manager_(TestingBrowserProcess::GetGlobal()), name_index_(0) {} | 89 : profile_manager_(TestingBrowserProcess::GetGlobal()), name_index_(0) {} |
90 | 90 |
91 ~BrowserCloseTest() override {} | 91 ~BrowserCloseTest() override {} |
92 | 92 |
93 void SetUp() override { ASSERT_TRUE(profile_manager_.SetUp()); } | 93 void SetUp() override { ASSERT_TRUE(profile_manager_.SetUp()); } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 CHECK(browsers_.end() != browsers_.find(profile)); | 134 CHECK(browsers_.end() != browsers_.find(profile)); |
135 CHECK_GT(browsers_[profile].size(), static_cast<size_t>(index)); | 135 CHECK_GT(browsers_[profile].size(), static_cast<size_t>(index)); |
136 | 136 |
137 return browsers_[profile][index]; | 137 return browsers_[profile][index]; |
138 } | 138 } |
139 | 139 |
140 private: | 140 private: |
141 void ConfigureCreatedProfile(Profile* profile, | 141 void ConfigureCreatedProfile(Profile* profile, |
142 int num_windows, | 142 int num_windows, |
143 int num_downloads) { | 143 int num_downloads) { |
144 DownloadServiceFactory::GetInstance()->SetTestingFactory( | 144 DownloadCoreServiceFactory::GetInstance()->SetTestingFactory( |
145 profile, &CreateTestingDownloadService); | 145 profile, &CreateTestingDownloadCoreService); |
146 DownloadService* download_service( | 146 DownloadCoreService* download_core_service( |
147 DownloadServiceFactory::GetForBrowserContext(profile)); | 147 DownloadCoreServiceFactory::GetForBrowserContext(profile)); |
148 TestingDownloadService* mock_download_service( | 148 TestingDownloadCoreService* mock_download_service( |
149 static_cast<TestingDownloadService*>(download_service)); | 149 static_cast<TestingDownloadCoreService*>(download_core_service)); |
150 mock_download_service->SetDownloadCount(num_downloads); | 150 mock_download_service->SetDownloadCount(num_downloads); |
151 | 151 |
152 CHECK(browser_windows_.end() == browser_windows_.find(profile)); | 152 CHECK(browser_windows_.end() == browser_windows_.find(profile)); |
153 CHECK(browsers_.end() == browsers_.find(profile)); | 153 CHECK(browsers_.end() == browsers_.find(profile)); |
154 | 154 |
155 std::vector<TestBrowserWindow*> windows; | 155 std::vector<TestBrowserWindow*> windows; |
156 std::vector<Browser*> browsers; | 156 std::vector<Browser*> browsers; |
157 for (int i = 0; i < num_windows; ++i) { | 157 for (int i = 0; i < num_windows; ++i) { |
158 TestBrowserWindow* window = new TestBrowserWindow(); | 158 TestBrowserWindow* window = new TestBrowserWindow(); |
159 Browser::CreateParams params(profile, true); | 159 Browser::CreateParams params(profile, true); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 Profile* profile = CreateProfile(1, 0); | 341 Profile* profile = CreateProfile(1, 0); |
342 Profile* incognito_profile = CreateIncognitoProfile(profile, 1, 2); | 342 Profile* incognito_profile = CreateIncognitoProfile(profile, 1, 2); |
343 | 343 |
344 Browser* browser = GetProfileBrowser(incognito_profile, 0); | 344 Browser* browser = GetProfileBrowser(incognito_profile, 0); |
345 | 345 |
346 int num_downloads_blocking = 0; | 346 int num_downloads_blocking = 0; |
347 EXPECT_EQ(Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE, | 347 EXPECT_EQ(Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE, |
348 browser->OkToCloseWithInProgressDownloads(&num_downloads_blocking)); | 348 browser->OkToCloseWithInProgressDownloads(&num_downloads_blocking)); |
349 EXPECT_EQ(2, num_downloads_blocking); | 349 EXPECT_EQ(2, num_downloads_blocking); |
350 } | 350 } |
OLD | NEW |