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

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

Issue 10073017: Remove Active Downloads UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
11 #include "base/test/test_file_util.h" 11 #include "base/test/test_file_util.h"
12 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
13 #include "chrome/browser/download/chrome_download_manager_delegate.h" 13 #include "chrome/browser/download/chrome_download_manager_delegate.h"
14 #include "chrome/browser/download/download_history.h" 14 #include "chrome/browser/download/download_history.h"
15 #include "chrome/browser/download/download_prefs.h" 15 #include "chrome/browser/download/download_prefs.h"
16 #include "chrome/browser/download/download_service.h" 16 #include "chrome/browser/download/download_service.h"
17 #include "chrome/browser/download/download_service_factory.h" 17 #include "chrome/browser/download/download_service_factory.h"
18 #include "chrome/browser/download/save_package_file_picker.h" 18 #include "chrome/browser/download/save_package_file_picker.h"
19 #include "chrome/browser/net/url_request_mock_util.h" 19 #include "chrome/browser/net/url_request_mock_util.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/webui/chromeos/active_downloads_ui.h"
24 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
26 #include "chrome/test/base/in_process_browser_test.h" 25 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/ui_test_utils.h" 26 #include "chrome/test/base/ui_test_utils.h"
28 #include "content/public/browser/download_item.h" 27 #include "content/public/browser/download_item.h"
29 #include "content/public/browser/download_manager.h" 28 #include "content/public/browser/download_manager.h"
30 #include "content/public/browser/download_persistent_store_info.h" 29 #include "content/public/browser/download_persistent_store_info.h"
31 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/notification_types.h" 31 #include "content/public/browser/notification_types.h"
33 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 90
92 GURL WaitForSavePackageToFinish() const { 91 GURL WaitForSavePackageToFinish() const {
93 ui_test_utils::TestNotificationObserver observer; 92 ui_test_utils::TestNotificationObserver observer;
94 ui_test_utils::RegisterAndWait(&observer, 93 ui_test_utils::RegisterAndWait(&observer,
95 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 94 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
96 content::NotificationService::AllSources()); 95 content::NotificationService::AllSources());
97 return content::Details<DownloadItem>(observer.details()).ptr()-> 96 return content::Details<DownloadItem>(observer.details()).ptr()->
98 GetOriginalUrl(); 97 GetOriginalUrl();
99 } 98 }
100 99
101 #if defined(OS_CHROMEOS) && !defined(USE_AURA) 100 void CheckDownloadShelfIsVisible() const {
achuithb 2012/04/16 14:27:05 Not sure if the indirection is worthwhile. Might b
asanka 2012/04/17 20:02:25 Done.
102 const ActiveDownloadsUI::DownloadList& GetDownloads() const {
103 Browser* popup = ActiveDownloadsUI::GetPopup();
104 EXPECT_TRUE(popup);
105 ActiveDownloadsUI* downloads_ui = static_cast<ActiveDownloadsUI*>(
106 popup->GetSelectedWebContents()->GetWebUI()->GetController());
107 EXPECT_TRUE(downloads_ui);
108 return downloads_ui->GetDownloads();
109 }
110 #endif
111
112 void CheckDownloadUI(const FilePath& download_path) const {
113 #if defined(OS_CHROMEOS) && !defined(USE_AURA)
114 const ActiveDownloadsUI::DownloadList& downloads = GetDownloads();
115 EXPECT_EQ(downloads.size(), 1U);
116
117 bool found = false;
118 for (size_t i = 0; i < downloads.size(); ++i) {
119 if (downloads[i]->GetFullPath() == download_path) {
120 found = true;
121 break;
122 }
123 }
124 EXPECT_TRUE(found);
125 #else
126 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 101 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
127 #endif
128 } 102 }
129 103
130 DownloadManager* GetDownloadManager() const { 104 DownloadManager* GetDownloadManager() const {
131 DownloadManager* download_manager = 105 DownloadManager* download_manager =
132 DownloadServiceFactory::GetForProfile( 106 DownloadServiceFactory::GetForProfile(
133 browser()->profile())->GetDownloadManager(); 107 browser()->profile())->GetDownloadManager();
134 EXPECT_TRUE(download_manager); 108 EXPECT_TRUE(download_manager);
135 return download_manager; 109 return download_manager;
136 } 110 }
137 111
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { 178 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) {
205 GURL url = NavigateToMockURL("a"); 179 GURL url = NavigateToMockURL("a");
206 180
207 FilePath full_file_name, dir; 181 FilePath full_file_name, dir;
208 GetDestinationPaths("a", &full_file_name, &dir); 182 GetDestinationPaths("a", &full_file_name, &dir);
209 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, 183 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
210 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 184 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
211 185
212 EXPECT_EQ(url, WaitForSavePackageToFinish()); 186 EXPECT_EQ(url, WaitForSavePackageToFinish());
213 187
214 CheckDownloadUI(full_file_name); 188 CheckDownloadShelfIsVisible();
215 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. 189 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file.
216 190
217 EXPECT_TRUE(file_util::PathExists(full_file_name)); 191 EXPECT_TRUE(file_util::PathExists(full_file_name));
218 EXPECT_FALSE(file_util::PathExists(dir)); 192 EXPECT_FALSE(file_util::PathExists(dir));
219 EXPECT_TRUE(file_util::ContentsEqual( 193 EXPECT_TRUE(file_util::ContentsEqual(
220 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), 194 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")),
221 full_file_name)); 195 full_file_name));
222 } 196 }
223 197
224 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { 198 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) {
225 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 199 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
226 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( 200 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
227 FilePath(kTestDir).Append(file_name)); 201 FilePath(kTestDir).Append(file_name));
228 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( 202 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl(
229 FilePath(kTestDir).Append(file_name)); 203 FilePath(kTestDir).Append(file_name));
230 ui_test_utils::NavigateToURL(browser(), view_source_url); 204 ui_test_utils::NavigateToURL(browser(), view_source_url);
231 205
232 FilePath full_file_name, dir; 206 FilePath full_file_name, dir;
233 GetDestinationPaths("a", &full_file_name, &dir); 207 GetDestinationPaths("a", &full_file_name, &dir);
234 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, 208 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
235 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 209 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
236 210
237 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); 211 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish());
238 212
239 CheckDownloadUI(full_file_name); 213 CheckDownloadShelfIsVisible();
240 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file. 214 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file.
241 215
242 EXPECT_TRUE(file_util::PathExists(full_file_name)); 216 EXPECT_TRUE(file_util::PathExists(full_file_name));
243 EXPECT_FALSE(file_util::PathExists(dir)); 217 EXPECT_FALSE(file_util::PathExists(dir));
244 EXPECT_TRUE(file_util::ContentsEqual( 218 EXPECT_TRUE(file_util::ContentsEqual(
245 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 219 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
246 full_file_name)); 220 full_file_name));
247 } 221 }
248 222
249 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { 223 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) {
250 GURL url = NavigateToMockURL("b"); 224 GURL url = NavigateToMockURL("b");
251 225
252 FilePath full_file_name, dir; 226 FilePath full_file_name, dir;
253 GetDestinationPaths("b", &full_file_name, &dir); 227 GetDestinationPaths("b", &full_file_name, &dir);
254 ASSERT_TRUE(GetCurrentTab()->SavePage( 228 ASSERT_TRUE(GetCurrentTab()->SavePage(
255 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); 229 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML));
256 230
257 EXPECT_EQ(url, WaitForSavePackageToFinish()); 231 EXPECT_EQ(url, WaitForSavePackageToFinish());
258 232
259 CheckDownloadUI(full_file_name); 233 CheckDownloadShelfIsVisible();
260 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. 234 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files.
261 235
262 EXPECT_TRUE(file_util::PathExists(full_file_name)); 236 EXPECT_TRUE(file_util::PathExists(full_file_name));
263 EXPECT_TRUE(file_util::PathExists(dir)); 237 EXPECT_TRUE(file_util::PathExists(dir));
264 EXPECT_TRUE(file_util::TextContentsEqual( 238 EXPECT_TRUE(file_util::TextContentsEqual(
265 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), 239 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"),
266 full_file_name)); 240 full_file_name));
267 EXPECT_TRUE(file_util::ContentsEqual( 241 EXPECT_TRUE(file_util::ContentsEqual(
268 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 242 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
269 dir.AppendASCII("1.png"))); 243 dir.AppendASCII("1.png")));
(...skipping 13 matching lines...) Expand all
283 257
284 FilePath full_file_name = save_dir_.path().AppendASCII( 258 FilePath full_file_name = save_dir_.path().AppendASCII(
285 std::string("Test page for saving page feature") + kAppendedExtension); 259 std::string("Test page for saving page feature") + kAppendedExtension);
286 FilePath dir = save_dir_.path().AppendASCII( 260 FilePath dir = save_dir_.path().AppendASCII(
287 "Test page for saving page feature_files"); 261 "Test page for saving page feature_files");
288 ASSERT_TRUE(GetCurrentTab()->SavePage( 262 ASSERT_TRUE(GetCurrentTab()->SavePage(
289 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); 263 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML));
290 264
291 EXPECT_EQ(url, WaitForSavePackageToFinish()); 265 EXPECT_EQ(url, WaitForSavePackageToFinish());
292 266
293 CheckDownloadUI(full_file_name); 267 CheckDownloadShelfIsVisible();
294 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. 268 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files.
295 269
296 EXPECT_TRUE(file_util::PathExists(full_file_name)); 270 EXPECT_TRUE(file_util::PathExists(full_file_name));
297 EXPECT_TRUE(file_util::PathExists(dir)); 271 EXPECT_TRUE(file_util::PathExists(dir));
298 EXPECT_TRUE(file_util::TextContentsEqual( 272 EXPECT_TRUE(file_util::TextContentsEqual(
299 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), 273 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"),
300 full_file_name)); 274 full_file_name));
301 EXPECT_TRUE(file_util::ContentsEqual( 275 EXPECT_TRUE(file_util::ContentsEqual(
302 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 276 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
303 dir.AppendASCII("1.png"))); 277 dir.AppendASCII("1.png")));
304 EXPECT_TRUE(file_util::ContentsEqual( 278 EXPECT_TRUE(file_util::ContentsEqual(
305 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 279 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
306 dir.AppendASCII("1.css"))); 280 dir.AppendASCII("1.css")));
307 } 281 }
308 282
309 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { 283 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) {
310 GURL url = NavigateToMockURL("a"); 284 GURL url = NavigateToMockURL("a");
311 285
312 FilePath full_file_name, dir; 286 FilePath full_file_name, dir;
313 GetDestinationPaths("a", &full_file_name, &dir); 287 GetDestinationPaths("a", &full_file_name, &dir);
314 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, 288 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
315 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 289 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
316 290
317 EXPECT_EQ(url, WaitForSavePackageToFinish()); 291 EXPECT_EQ(url, WaitForSavePackageToFinish());
318 292
319 CheckDownloadUI(full_file_name); 293 CheckDownloadShelfIsVisible();
320 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. 294 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file.
321 295
322 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); 296 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1);
323 297
324 #if defined(OS_CHROMEOS) && !defined(USE_AURA)
325 EXPECT_EQ(GetDownloads().size(), 0U);
326 #endif
327
328 // Should not be in history. 298 // Should not be in history.
329 QueryDownloadHistory(); 299 QueryDownloadHistory();
330 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), 300 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(),
331 DownloadPersistentStoreInfoMatch(url, full_file_name, 1)), 301 DownloadPersistentStoreInfoMatch(url, full_file_name, 1)),
332 history_entries_.end()); 302 history_entries_.end());
333 303
334 EXPECT_TRUE(file_util::PathExists(full_file_name)); 304 EXPECT_TRUE(file_util::PathExists(full_file_name));
335 EXPECT_FALSE(file_util::PathExists(dir)); 305 EXPECT_FALSE(file_util::PathExists(dir));
336 EXPECT_TRUE(file_util::ContentsEqual( 306 EXPECT_TRUE(file_util::ContentsEqual(
337 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), 307 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")),
(...skipping 24 matching lines...) Expand all
362 content::NotificationService::AllSources()); 332 content::NotificationService::AllSources());
363 browser()->SavePage(); 333 browser()->SavePage();
364 observer.Wait(); 334 observer.Wait();
365 335
366 EXPECT_TRUE(file_util::PathExists(full_file_name)); 336 EXPECT_TRUE(file_util::PathExists(full_file_name));
367 337
368 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false)); 338 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false));
369 EXPECT_TRUE(file_util::DieFileDie(dir, true)); 339 EXPECT_TRUE(file_util::DieFileDie(dir, true));
370 } 340 }
371 #endif 341 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698