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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "base/test/test_file_util.h" | 12 #include "base/test/test_file_util.h" |
13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
14 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 14 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
15 #include "chrome/browser/download/download_history.h" | 15 #include "chrome/browser/download/download_history.h" |
16 #include "chrome/browser/download/download_prefs.h" | 16 #include "chrome/browser/download/download_prefs.h" |
17 #include "chrome/browser/download/download_service.h" | 17 #include "chrome/browser/download/download_service.h" |
18 #include "chrome/browser/download/download_service_factory.h" | 18 #include "chrome/browser/download/download_service_factory.h" |
| 19 #include "chrome/browser/history/history_service_factory.h" |
19 #include "chrome/browser/net/url_request_mock_util.h" | 20 #include "chrome/browser/net/url_request_mock_util.h" |
20 #include "chrome/browser/prefs/pref_member.h" | 21 #include "chrome/browser/prefs/pref_member.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
25 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
26 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 119 |
119 DownloadManager* GetDownloadManager() const { | 120 DownloadManager* GetDownloadManager() const { |
120 DownloadManager* download_manager = | 121 DownloadManager* download_manager = |
121 BrowserContext::GetDownloadManager(browser()->profile()); | 122 BrowserContext::GetDownloadManager(browser()->profile()); |
122 EXPECT_TRUE(download_manager); | 123 EXPECT_TRUE(download_manager); |
123 return download_manager; | 124 return download_manager; |
124 } | 125 } |
125 | 126 |
126 void QueryDownloadHistory() { | 127 void QueryDownloadHistory() { |
127 // Query the history system. | 128 // Query the history system. |
128 ChromeDownloadManagerDelegate* delegate = | 129 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
129 static_cast<ChromeDownloadManagerDelegate*>( | 130 browser()->profile(), Profile::EXPLICIT_ACCESS); |
130 GetDownloadManager()->GetDelegate()); | 131 hs->QueryDownloads(&history_consumer_, base::Bind( |
131 delegate->download_history()->Load( | 132 &SavePageBrowserTest::OnQueryDownloadEntriesComplete, |
132 base::Bind(&SavePageBrowserTest::OnQueryDownloadEntriesComplete, | 133 base::Unretained(this))); |
133 base::Unretained(this))); | |
134 | 134 |
135 // Run message loop until a quit message is sent from | 135 // Run message loop until a quit message is sent from |
136 // OnQueryDownloadEntriesComplete(). | 136 // OnQueryDownloadEntriesComplete(). |
137 content::RunMessageLoop(); | 137 content::RunMessageLoop(); |
138 } | 138 } |
139 | 139 |
140 void OnQueryDownloadEntriesComplete( | 140 void OnQueryDownloadEntriesComplete( |
141 std::vector<DownloadPersistentStoreInfo>* entries) { | 141 std::vector<DownloadPersistentStoreInfo>* entries) { |
142 history_entries_ = *entries; | 142 history_entries_ = *entries; |
143 | 143 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 199 |
200 std::vector<DownloadPersistentStoreInfo> history_entries_; | 200 std::vector<DownloadPersistentStoreInfo> history_entries_; |
201 | 201 |
202 // Path to directory containing test data. | 202 // Path to directory containing test data. |
203 FilePath test_dir_; | 203 FilePath test_dir_; |
204 | 204 |
205 // Temporary directory we will save pages to. | 205 // Temporary directory we will save pages to. |
206 ScopedTempDir save_dir_; | 206 ScopedTempDir save_dir_; |
207 | 207 |
208 private: | 208 private: |
| 209 CancelableRequestConsumer history_consumer_; |
209 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); | 210 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); |
210 }; | 211 }; |
211 | 212 |
212 SavePageBrowserTest::~SavePageBrowserTest() { | 213 SavePageBrowserTest::~SavePageBrowserTest() { |
213 } | 214 } |
214 | 215 |
215 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 216 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { |
216 GURL url = NavigateToMockURL("a"); | 217 GURL url = NavigateToMockURL("a"); |
217 | 218 |
218 FilePath full_file_name, dir; | 219 FilePath full_file_name, dir; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 content::NotificationService::AllSources()); | 409 content::NotificationService::AllSources()); |
409 chrome::SavePage(browser()); | 410 chrome::SavePage(browser()); |
410 observer.Wait(); | 411 observer.Wait(); |
411 CheckDownloadHistory(url, full_file_name, -1); | 412 CheckDownloadHistory(url, full_file_name, -1); |
412 | 413 |
413 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 414 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
414 int64 actual_file_size = -1; | 415 int64 actual_file_size = -1; |
415 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 416 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
416 EXPECT_LE(kFileSizeMin, actual_file_size); | 417 EXPECT_LE(kFileSizeMin, actual_file_size); |
417 } | 418 } |
OLD | NEW |