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

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

Issue 10867065: Remove DownloadFileManager in favor of direct ownership of DownloadFiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments and added bounce off DB thread. Created 8 years, 3 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
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | content/browser/browser_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); 58 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page");
59 59
60 static const char* kAppendedExtension = 60 static const char* kAppendedExtension =
61 #if defined(OS_WIN) 61 #if defined(OS_WIN)
62 ".htm"; 62 ".htm";
63 #else 63 #else
64 ".html"; 64 ".html";
65 #endif 65 #endif
66 66
67 void NullFunction() {
68 }
69
67 } // namespace 70 } // namespace
68 71
69 // Loosely based on logic in DownloadTestObserver. 72 // Loosely based on logic in DownloadTestObserver.
70 class DownloadItemCreatedObserver : public DownloadManager::Observer { 73 class DownloadItemCreatedObserver : public DownloadManager::Observer {
71 public: 74 public:
72 explicit DownloadItemCreatedObserver(DownloadManager* manager) 75 explicit DownloadItemCreatedObserver(DownloadManager* manager)
73 : waiting_(false), manager_(manager), created_item_(NULL) { 76 : waiting_(false), manager_(manager), created_item_(NULL) {
74 manager->AddObserver(this); 77 manager->AddObserver(this);
75 } 78 }
76 79
(...skipping 17 matching lines...) Expand all
94 waiting_ = true; 97 waiting_ = true;
95 content::RunMessageLoop(); 98 content::RunMessageLoop();
96 waiting_ = false; 99 waiting_ = false;
97 } 100 }
98 return created_item_; 101 return created_item_;
99 } 102 }
100 103
101 private: 104 private:
102 105
103 // DownloadManager::Observer 106 // DownloadManager::Observer
104 void OnDownloadCreated(DownloadManager* manager, DownloadItem* item) { 107 virtual void OnDownloadCreated(
108 DownloadManager* manager, DownloadItem* item) OVERRIDE {
105 DCHECK_EQ(manager, manager_); 109 DCHECK_EQ(manager, manager_);
106 if (!created_item_) 110 if (!created_item_)
107 created_item_ = item; 111 created_item_ = item;
108 112
109 if (waiting_) 113 if (waiting_)
110 MessageLoopForUI::current()->Quit(); 114 MessageLoopForUI::current()->Quit();
111 } 115 }
112 116
113 void ManagerGoingDownload(DownloadManager* manager) { 117 virtual void ManagerGoingDown(DownloadManager* manager) OVERRIDE {
114 manager_->RemoveObserver(this); 118 manager_->RemoveObserver(this);
115 manager_ = NULL; 119 manager_ = NULL;
116 if (waiting_) 120 if (waiting_)
117 MessageLoopForUI::current()->Quit(); 121 MessageLoopForUI::current()->Quit();
118 } 122 }
119 123
120 bool waiting_; 124 bool waiting_;
121 DownloadManager* manager_; 125 DownloadManager* manager_;
122 DownloadItem* created_item_; 126 DownloadItem* created_item_;
123 127
124 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); 128 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver);
125 }; 129 };
126 130
131 class DownloadPersistedObserver : public DownloadItem::Observer {
132 public:
133 explicit DownloadPersistedObserver(DownloadItem* item)
134 : waiting_(false), item_(item) {
135 item->AddObserver(this);
136 }
137
138 ~DownloadPersistedObserver() {
139 if (item_)
140 item_->RemoveObserver(this);
141 }
142
143 // Wait for download item to get the persisted bit set.
144 // Note that this class provides no protection against the download
145 // being destroyed between creation and return of WaitForPersisted();
146 // the caller must guarantee that in some other fashion.
147 void WaitForPersisted() {
148 // In combination with OnDownloadDestroyed() below, verify the
149 // above interface contract.
150 DCHECK(item_);
151
152 if (item_->IsPersisted())
153 return;
154
155 waiting_ = true;
156 content::RunMessageLoop();
157 waiting_ = false;
158
159 return;
160 }
161
162 private:
163 // DownloadItem::Observer
164 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE {
165 DCHECK_EQ(item, item_);
166
167 if (waiting_ && item->IsPersisted())
168 MessageLoopForUI::current()->Quit();
169 }
170
171 virtual void OnDownloadDestroyed(DownloadItem* item) OVERRIDE {
172 if (item != item_)
173 return;
174
175 item_->RemoveObserver(this);
176 item_ = NULL;
177 }
178
179 bool waiting_;
180 DownloadItem* item_;
181
182 DISALLOW_COPY_AND_ASSIGN(DownloadPersistedObserver);
183 };
184
127 class SavePageBrowserTest : public InProcessBrowserTest { 185 class SavePageBrowserTest : public InProcessBrowserTest {
128 public: 186 public:
129 SavePageBrowserTest() {} 187 SavePageBrowserTest() {}
130 virtual ~SavePageBrowserTest(); 188 virtual ~SavePageBrowserTest();
131 189
132 protected: 190 protected:
133 void SetUp() OVERRIDE { 191 void SetUp() OVERRIDE {
134 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); 192 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_));
135 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); 193 ASSERT_TRUE(save_dir_.CreateUniqueTempDir());
136 InProcessBrowserTest::SetUp(); 194 InProcessBrowserTest::SetUp();
(...skipping 21 matching lines...) Expand all
158 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); 216 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm");
159 *dir = save_dir_.path().AppendASCII(prefix + "_files"); 217 *dir = save_dir_.path().AppendASCII(prefix + "_files");
160 } 218 }
161 219
162 WebContents* GetCurrentTab() const { 220 WebContents* GetCurrentTab() const {
163 WebContents* current_tab = chrome::GetActiveWebContents(browser()); 221 WebContents* current_tab = chrome::GetActiveWebContents(browser());
164 EXPECT_TRUE(current_tab); 222 EXPECT_TRUE(current_tab);
165 return current_tab; 223 return current_tab;
166 } 224 }
167 225
168
169 GURL WaitForSavePackageToFinish() const { 226 GURL WaitForSavePackageToFinish() const {
170 content::WindowedNotificationObserver observer( 227 content::WindowedNotificationObserver observer(
171 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 228 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
172 content::NotificationService::AllSources()); 229 content::NotificationService::AllSources());
173 observer.Wait(); 230 observer.Wait();
231
174 return content::Details<DownloadItem>(observer.details()).ptr()-> 232 return content::Details<DownloadItem>(observer.details()).ptr()->
175 GetOriginalUrl(); 233 GetOriginalUrl();
176 } 234 }
177 235
178 DownloadManager* GetDownloadManager() const { 236 DownloadManager* GetDownloadManager() const {
179 DownloadManager* download_manager = 237 DownloadManager* download_manager =
180 BrowserContext::GetDownloadManager(browser()->profile()); 238 BrowserContext::GetDownloadManager(browser()->profile());
181 EXPECT_TRUE(download_manager); 239 EXPECT_TRUE(download_manager);
182 return download_manager; 240 return download_manager;
183 } 241 }
(...skipping 18 matching lines...) Expand all
202 260
203 // Indicate thet we have received the history and can continue. 261 // Indicate thet we have received the history and can continue.
204 MessageLoopForUI::current()->Quit(); 262 MessageLoopForUI::current()->Quit();
205 } 263 }
206 264
207 struct DownloadPersistentStoreInfoMatch 265 struct DownloadPersistentStoreInfoMatch
208 : public std::unary_function<DownloadPersistentStoreInfo, bool> { 266 : public std::unary_function<DownloadPersistentStoreInfo, bool> {
209 267
210 DownloadPersistentStoreInfoMatch(const GURL& url, 268 DownloadPersistentStoreInfoMatch(const GURL& url,
211 const FilePath& path, 269 const FilePath& path,
212 int64 num_files) 270 int64 num_files,
271 DownloadItem::DownloadState state)
213 : url_(url), 272 : url_(url),
214 path_(path), 273 path_(path),
215 num_files_(num_files) { 274 num_files_(num_files),
216 } 275 state_(state) {}
217 276
218 bool operator() (const DownloadPersistentStoreInfo& info) const { 277 bool operator() (const DownloadPersistentStoreInfo& info) const {
219 return info.url == url_ && 278 return info.url == url_ &&
220 info.path == path_ && 279 info.path == path_ &&
221 // For non-MHTML save packages, received_bytes is actually the 280 // For non-MHTML save packages, received_bytes is actually the
222 // number of files. 281 // number of files.
223 ((num_files_ < 0) || 282 ((num_files_ < 0) ||
224 (info.received_bytes == num_files_)) && 283 (info.received_bytes == num_files_)) &&
225 info.total_bytes == 0 && 284 info.total_bytes == 0 &&
226 info.state == DownloadItem::COMPLETE; 285 info.state == state_;
227 } 286 }
228 287
229 GURL url_; 288 GURL url_;
230 FilePath path_; 289 FilePath path_;
231 int64 num_files_; 290 int64 num_files_;
291 DownloadItem::DownloadState state_;
232 }; 292 };
233 293
234 void CheckDownloadHistory(const GURL& url, 294 void CheckDownloadHistory(const GURL& url,
235 const FilePath& path, 295 const FilePath& path,
236 int64 num_files) { 296 int64 num_files,
297 DownloadItem::DownloadState state) {
298 // Make sure the relevant download item made it into the history.
299 std::vector<DownloadItem*> downloads;
300 GetDownloadManager()->SearchDownloads(string16(), &downloads);
301 ASSERT_EQ(1u, downloads.size());
302 DownloadPersistedObserver(downloads[0]).WaitForPersisted();
303
304 // Make sure any final updates have made it to the history DB.
305 BrowserThread::PostTaskAndReply(
306 BrowserThread::DB, FROM_HERE, base::Bind(&NullFunction),
307 MessageLoop::QuitClosure());
308 content::RunMessageLoop();
309
237 QueryDownloadHistory(); 310 QueryDownloadHistory();
238 311
239 std::vector<DownloadPersistentStoreInfo>::iterator found = 312 std::vector<DownloadPersistentStoreInfo>::iterator found =
240 std::find_if(history_entries_.begin(), history_entries_.end(), 313 std::find_if(history_entries_.begin(), history_entries_.end(),
241 DownloadPersistentStoreInfoMatch(url, path, num_files)); 314 DownloadPersistentStoreInfoMatch(url, path, num_files,
315 state));
242 316
243 if (found == history_entries_.end()) { 317 if (found == history_entries_.end()) {
244 LOG(ERROR) << "Missing url=" << url.spec() 318 LOG(ERROR) << "Missing url=" << url.spec()
245 << " path=" << path.value() 319 << " path=" << path.value()
246 << " received=" << num_files; 320 << " received=" << num_files;
247 for (size_t index = 0; index < history_entries_.size(); ++index) { 321 for (size_t index = 0; index < history_entries_.size(); ++index) {
248 LOG(ERROR) << "History@" << index << ": url=" 322 LOG(ERROR) << "History@" << index << ": url="
249 << history_entries_[index].url.spec() 323 << history_entries_[index].url.spec()
250 << " path=" << history_entries_[index].path.value() 324 << " path=" << history_entries_[index].path.value()
251 << " received=" << history_entries_[index].received_bytes 325 << " received=" << history_entries_[index].received_bytes
(...skipping 23 matching lines...) Expand all
275 GURL url = NavigateToMockURL("a"); 349 GURL url = NavigateToMockURL("a");
276 350
277 FilePath full_file_name, dir; 351 FilePath full_file_name, dir;
278 GetDestinationPaths("a", &full_file_name, &dir); 352 GetDestinationPaths("a", &full_file_name, &dir);
279 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, 353 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
280 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 354 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
281 355
282 EXPECT_EQ(url, WaitForSavePackageToFinish()); 356 EXPECT_EQ(url, WaitForSavePackageToFinish());
283 357
284 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 358 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
285 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. 359 // a.htm is 1 file.
360 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE);
286 361
287 EXPECT_TRUE(file_util::PathExists(full_file_name)); 362 EXPECT_TRUE(file_util::PathExists(full_file_name));
288 EXPECT_FALSE(file_util::PathExists(dir)); 363 EXPECT_FALSE(file_util::PathExists(dir));
289 EXPECT_TRUE(file_util::ContentsEqual( 364 EXPECT_TRUE(file_util::ContentsEqual(
290 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), 365 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")),
291 full_file_name)); 366 full_file_name));
292 } 367 }
293 368
294 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { 369 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) {
295 GURL url = NavigateToMockURL("a"); 370 GURL url = NavigateToMockURL("a");
296 DownloadManager* manager(GetDownloadManager()); 371 DownloadManager* manager(GetDownloadManager());
297 std::vector<DownloadItem*> downloads; 372 std::vector<DownloadItem*> downloads;
298 manager->SearchDownloads(string16(), &downloads); 373 manager->SearchDownloads(string16(), &downloads);
299 ASSERT_EQ(0u, downloads.size()); 374 ASSERT_EQ(0u, downloads.size());
300 375
301 FilePath full_file_name, dir; 376 FilePath full_file_name, dir;
302 GetDestinationPaths("a", &full_file_name, &dir); 377 GetDestinationPaths("a", &full_file_name, &dir);
303 DownloadItemCreatedObserver creation_observer(manager); 378 DownloadItemCreatedObserver creation_observer(manager);
304 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, 379 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
305 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 380 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
306 DownloadItem* item = creation_observer.WaitForNewDownloadItem(); 381 DownloadItem* item = creation_observer.WaitForNewDownloadItem();
307 item->Cancel(true); 382 item->Cancel(true);
308 383
309 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. 384 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package.
310 // Currently it's ignored. 385 // Currently it's ignored.
311 EXPECT_EQ(url, WaitForSavePackageToFinish()); 386 EXPECT_EQ(url, WaitForSavePackageToFinish());
312 387
388 // -1 to disable number of files check; we don't update after cancel, and
389 // we don't know when the single file completed in relationship to
390 // the cancel.
391 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::CANCELLED);
392
313 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 393 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
314 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file.
315 394
316 EXPECT_TRUE(file_util::PathExists(full_file_name)); 395 EXPECT_TRUE(file_util::PathExists(full_file_name));
317 EXPECT_FALSE(file_util::PathExists(dir)); 396 EXPECT_FALSE(file_util::PathExists(dir));
318 EXPECT_TRUE(file_util::ContentsEqual( 397 EXPECT_TRUE(file_util::ContentsEqual(
319 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), 398 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")),
320 full_file_name)); 399 full_file_name));
321 } 400 }
322 401
323 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyTabDestroy) { 402 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyTabDestroy) {
324 GURL url = NavigateToMockURL("a"); 403 GURL url = NavigateToMockURL("a");
(...skipping 26 matching lines...) Expand all
351 ui_test_utils::NavigateToURL(browser(), view_source_url); 430 ui_test_utils::NavigateToURL(browser(), view_source_url);
352 431
353 FilePath full_file_name, dir; 432 FilePath full_file_name, dir;
354 GetDestinationPaths("a", &full_file_name, &dir); 433 GetDestinationPaths("a", &full_file_name, &dir);
355 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, 434 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
356 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 435 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
357 436
358 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); 437 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish());
359 438
360 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 439 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
361 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file. 440 // a.htm is 1 file.
441 CheckDownloadHistory(actual_page_url, full_file_name, 1,
442 DownloadItem::COMPLETE);
362 443
363 EXPECT_TRUE(file_util::PathExists(full_file_name)); 444 EXPECT_TRUE(file_util::PathExists(full_file_name));
364 EXPECT_FALSE(file_util::PathExists(dir)); 445 EXPECT_FALSE(file_util::PathExists(dir));
365 EXPECT_TRUE(file_util::ContentsEqual( 446 EXPECT_TRUE(file_util::ContentsEqual(
366 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 447 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
367 full_file_name)); 448 full_file_name));
368 } 449 }
369 450
370 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { 451 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) {
371 GURL url = NavigateToMockURL("b"); 452 GURL url = NavigateToMockURL("b");
372 453
373 FilePath full_file_name, dir; 454 FilePath full_file_name, dir;
374 GetDestinationPaths("b", &full_file_name, &dir); 455 GetDestinationPaths("b", &full_file_name, &dir);
375 ASSERT_TRUE(GetCurrentTab()->SavePage( 456 ASSERT_TRUE(GetCurrentTab()->SavePage(
376 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); 457 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML));
377 458
378 EXPECT_EQ(url, WaitForSavePackageToFinish()); 459 EXPECT_EQ(url, WaitForSavePackageToFinish());
379 460
380 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 461 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
381 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. 462 // b.htm is 3 files.
463 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE);
382 464
383 EXPECT_TRUE(file_util::PathExists(full_file_name)); 465 EXPECT_TRUE(file_util::PathExists(full_file_name));
384 EXPECT_TRUE(file_util::PathExists(dir)); 466 EXPECT_TRUE(file_util::PathExists(dir));
385 EXPECT_TRUE(file_util::TextContentsEqual( 467 EXPECT_TRUE(file_util::TextContentsEqual(
386 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), 468 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"),
387 full_file_name)); 469 full_file_name));
388 EXPECT_TRUE(file_util::ContentsEqual( 470 EXPECT_TRUE(file_util::ContentsEqual(
389 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 471 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
390 dir.AppendASCII("1.png"))); 472 dir.AppendASCII("1.png")));
391 EXPECT_TRUE(file_util::ContentsEqual( 473 EXPECT_TRUE(file_util::ContentsEqual(
(...skipping 12 matching lines...) Expand all
404 FilePath full_file_name = save_dir_.path().AppendASCII( 486 FilePath full_file_name = save_dir_.path().AppendASCII(
405 std::string("Test page for saving page feature") + kAppendedExtension); 487 std::string("Test page for saving page feature") + kAppendedExtension);
406 FilePath dir = save_dir_.path().AppendASCII( 488 FilePath dir = save_dir_.path().AppendASCII(
407 "Test page for saving page feature_files"); 489 "Test page for saving page feature_files");
408 ASSERT_TRUE(GetCurrentTab()->SavePage( 490 ASSERT_TRUE(GetCurrentTab()->SavePage(
409 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); 491 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML));
410 492
411 EXPECT_EQ(url, WaitForSavePackageToFinish()); 493 EXPECT_EQ(url, WaitForSavePackageToFinish());
412 494
413 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 495 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
414 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. 496 // b.htm is 3 files.
497 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE);
415 498
416 EXPECT_TRUE(file_util::PathExists(full_file_name)); 499 EXPECT_TRUE(file_util::PathExists(full_file_name));
417 EXPECT_TRUE(file_util::PathExists(dir)); 500 EXPECT_TRUE(file_util::PathExists(dir));
418 EXPECT_TRUE(file_util::TextContentsEqual( 501 EXPECT_TRUE(file_util::TextContentsEqual(
419 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), 502 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"),
420 full_file_name)); 503 full_file_name));
421 EXPECT_TRUE(file_util::ContentsEqual( 504 EXPECT_TRUE(file_util::ContentsEqual(
422 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 505 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
423 dir.AppendASCII("1.png"))); 506 dir.AppendASCII("1.png")));
424 EXPECT_TRUE(file_util::ContentsEqual( 507 EXPECT_TRUE(file_util::ContentsEqual(
425 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 508 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
426 dir.AppendASCII("1.css"))); 509 dir.AppendASCII("1.css")));
427 } 510 }
428 511
429 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { 512 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) {
430 GURL url = NavigateToMockURL("a"); 513 GURL url = NavigateToMockURL("a");
431 514
432 FilePath full_file_name, dir; 515 FilePath full_file_name, dir;
433 GetDestinationPaths("a", &full_file_name, &dir); 516 GetDestinationPaths("a", &full_file_name, &dir);
434 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, 517 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
435 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); 518 content::SAVE_PAGE_TYPE_AS_ONLY_HTML));
436 519
437 EXPECT_EQ(url, WaitForSavePackageToFinish()); 520 EXPECT_EQ(url, WaitForSavePackageToFinish());
438 521
439 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 522 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
440 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. 523 // a.htm is 1 file.
524 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE);
441 525
442 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); 526 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1);
443 527
444 // Should not be in history. 528 // Should not be in history.
445 QueryDownloadHistory(); 529 QueryDownloadHistory();
446 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), 530 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(),
447 DownloadPersistentStoreInfoMatch(url, full_file_name, 1)), 531 DownloadPersistentStoreInfoMatch(
532 url, full_file_name, 1, DownloadItem::COMPLETE)),
448 history_entries_.end()); 533 history_entries_.end());
449 534
450 EXPECT_TRUE(file_util::PathExists(full_file_name)); 535 EXPECT_TRUE(file_util::PathExists(full_file_name));
451 EXPECT_FALSE(file_util::PathExists(dir)); 536 EXPECT_FALSE(file_util::PathExists(dir));
452 EXPECT_TRUE(file_util::ContentsEqual( 537 EXPECT_TRUE(file_util::ContentsEqual(
453 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), 538 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")),
454 full_file_name)); 539 full_file_name));
455 } 540 }
456 541
457 // This tests that a webpage with the title "test.exe" is saved as 542 // This tests that a webpage with the title "test.exe" is saved as
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 #if defined(OS_CHROMEOS) 596 #if defined(OS_CHROMEOS)
512 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); 597 SavePackageFilePickerChromeOS::SetShouldPromptUser(false);
513 #else 598 #else
514 SavePackageFilePicker::SetShouldPromptUser(false); 599 SavePackageFilePicker::SetShouldPromptUser(false);
515 #endif 600 #endif
516 content::WindowedNotificationObserver observer( 601 content::WindowedNotificationObserver observer(
517 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 602 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
518 content::NotificationService::AllSources()); 603 content::NotificationService::AllSources());
519 chrome::SavePage(browser()); 604 chrome::SavePage(browser());
520 observer.Wait(); 605 observer.Wait();
521 CheckDownloadHistory(url, full_file_name, -1); 606 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE);
522 607
523 EXPECT_TRUE(file_util::PathExists(full_file_name)); 608 EXPECT_TRUE(file_util::PathExists(full_file_name));
524 int64 actual_file_size = -1; 609 int64 actual_file_size = -1;
525 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); 610 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size));
526 EXPECT_LE(kFileSizeMin, actual_file_size); 611 EXPECT_LE(kFileSizeMin, actual_file_size);
527 } 612 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | content/browser/browser_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698