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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | |
70 } // namespace | 67 } // namespace |
71 | 68 |
72 // Loosely based on logic in DownloadTestObserver. | 69 // Loosely based on logic in DownloadTestObserver. |
73 class DownloadItemCreatedObserver : public DownloadManager::Observer { | 70 class DownloadItemCreatedObserver : public DownloadManager::Observer { |
74 public: | 71 public: |
75 explicit DownloadItemCreatedObserver(DownloadManager* manager) | 72 explicit DownloadItemCreatedObserver(DownloadManager* manager) |
76 : waiting_(false), manager_(manager), created_item_(NULL) { | 73 : waiting_(false), manager_(manager), created_item_(NULL) { |
77 manager->AddObserver(this); | 74 manager->AddObserver(this); |
78 } | 75 } |
79 | 76 |
(...skipping 17 matching lines...) Expand all Loading... |
97 waiting_ = true; | 94 waiting_ = true; |
98 content::RunMessageLoop(); | 95 content::RunMessageLoop(); |
99 waiting_ = false; | 96 waiting_ = false; |
100 } | 97 } |
101 return created_item_; | 98 return created_item_; |
102 } | 99 } |
103 | 100 |
104 private: | 101 private: |
105 | 102 |
106 // DownloadManager::Observer | 103 // DownloadManager::Observer |
107 virtual void OnDownloadCreated( | 104 void OnDownloadCreated(DownloadManager* manager, DownloadItem* item) { |
108 DownloadManager* manager, DownloadItem* item) OVERRIDE { | |
109 DCHECK_EQ(manager, manager_); | 105 DCHECK_EQ(manager, manager_); |
110 if (!created_item_) | 106 if (!created_item_) |
111 created_item_ = item; | 107 created_item_ = item; |
112 | 108 |
113 if (waiting_) | 109 if (waiting_) |
114 MessageLoopForUI::current()->Quit(); | 110 MessageLoopForUI::current()->Quit(); |
115 } | 111 } |
116 | 112 |
117 virtual void ManagerGoingDown(DownloadManager* manager) OVERRIDE { | 113 void ManagerGoingDownload(DownloadManager* manager) { |
118 manager_->RemoveObserver(this); | 114 manager_->RemoveObserver(this); |
119 manager_ = NULL; | 115 manager_ = NULL; |
120 if (waiting_) | 116 if (waiting_) |
121 MessageLoopForUI::current()->Quit(); | 117 MessageLoopForUI::current()->Quit(); |
122 } | 118 } |
123 | 119 |
124 bool waiting_; | 120 bool waiting_; |
125 DownloadManager* manager_; | 121 DownloadManager* manager_; |
126 DownloadItem* created_item_; | 122 DownloadItem* created_item_; |
127 | 123 |
128 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); | 124 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); |
129 }; | 125 }; |
130 | 126 |
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 | |
185 class SavePageBrowserTest : public InProcessBrowserTest { | 127 class SavePageBrowserTest : public InProcessBrowserTest { |
186 public: | 128 public: |
187 SavePageBrowserTest() {} | 129 SavePageBrowserTest() {} |
188 virtual ~SavePageBrowserTest(); | 130 virtual ~SavePageBrowserTest(); |
189 | 131 |
190 protected: | 132 protected: |
191 void SetUp() OVERRIDE { | 133 void SetUp() OVERRIDE { |
192 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); | 134 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); |
193 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); | 135 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); |
194 InProcessBrowserTest::SetUp(); | 136 InProcessBrowserTest::SetUp(); |
(...skipping 21 matching lines...) Expand all Loading... |
216 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); | 158 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); |
217 *dir = save_dir_.path().AppendASCII(prefix + "_files"); | 159 *dir = save_dir_.path().AppendASCII(prefix + "_files"); |
218 } | 160 } |
219 | 161 |
220 WebContents* GetCurrentTab() const { | 162 WebContents* GetCurrentTab() const { |
221 WebContents* current_tab = chrome::GetActiveWebContents(browser()); | 163 WebContents* current_tab = chrome::GetActiveWebContents(browser()); |
222 EXPECT_TRUE(current_tab); | 164 EXPECT_TRUE(current_tab); |
223 return current_tab; | 165 return current_tab; |
224 } | 166 } |
225 | 167 |
| 168 |
226 GURL WaitForSavePackageToFinish() const { | 169 GURL WaitForSavePackageToFinish() const { |
227 content::WindowedNotificationObserver observer( | 170 content::WindowedNotificationObserver observer( |
228 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 171 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
229 content::NotificationService::AllSources()); | 172 content::NotificationService::AllSources()); |
230 observer.Wait(); | 173 observer.Wait(); |
231 | |
232 return content::Details<DownloadItem>(observer.details()).ptr()-> | 174 return content::Details<DownloadItem>(observer.details()).ptr()-> |
233 GetOriginalUrl(); | 175 GetOriginalUrl(); |
234 } | 176 } |
235 | 177 |
236 DownloadManager* GetDownloadManager() const { | 178 DownloadManager* GetDownloadManager() const { |
237 DownloadManager* download_manager = | 179 DownloadManager* download_manager = |
238 BrowserContext::GetDownloadManager(browser()->profile()); | 180 BrowserContext::GetDownloadManager(browser()->profile()); |
239 EXPECT_TRUE(download_manager); | 181 EXPECT_TRUE(download_manager); |
240 return download_manager; | 182 return download_manager; |
241 } | 183 } |
(...skipping 18 matching lines...) Expand all Loading... |
260 | 202 |
261 // Indicate thet we have received the history and can continue. | 203 // Indicate thet we have received the history and can continue. |
262 MessageLoopForUI::current()->Quit(); | 204 MessageLoopForUI::current()->Quit(); |
263 } | 205 } |
264 | 206 |
265 struct DownloadPersistentStoreInfoMatch | 207 struct DownloadPersistentStoreInfoMatch |
266 : public std::unary_function<DownloadPersistentStoreInfo, bool> { | 208 : public std::unary_function<DownloadPersistentStoreInfo, bool> { |
267 | 209 |
268 DownloadPersistentStoreInfoMatch(const GURL& url, | 210 DownloadPersistentStoreInfoMatch(const GURL& url, |
269 const FilePath& path, | 211 const FilePath& path, |
270 int64 num_files, | 212 int64 num_files) |
271 DownloadItem::DownloadState state) | |
272 : url_(url), | 213 : url_(url), |
273 path_(path), | 214 path_(path), |
274 num_files_(num_files), | 215 num_files_(num_files) { |
275 state_(state) {} | 216 } |
276 | 217 |
277 bool operator() (const DownloadPersistentStoreInfo& info) const { | 218 bool operator() (const DownloadPersistentStoreInfo& info) const { |
278 return info.url == url_ && | 219 return info.url == url_ && |
279 info.path == path_ && | 220 info.path == path_ && |
280 // For non-MHTML save packages, received_bytes is actually the | 221 // For non-MHTML save packages, received_bytes is actually the |
281 // number of files. | 222 // number of files. |
282 ((num_files_ < 0) || | 223 ((num_files_ < 0) || |
283 (info.received_bytes == num_files_)) && | 224 (info.received_bytes == num_files_)) && |
284 info.total_bytes == 0 && | 225 info.total_bytes == 0 && |
285 info.state == state_; | 226 info.state == DownloadItem::COMPLETE; |
286 } | 227 } |
287 | 228 |
288 GURL url_; | 229 GURL url_; |
289 FilePath path_; | 230 FilePath path_; |
290 int64 num_files_; | 231 int64 num_files_; |
291 DownloadItem::DownloadState state_; | |
292 }; | 232 }; |
293 | 233 |
294 void CheckDownloadHistory(const GURL& url, | 234 void CheckDownloadHistory(const GURL& url, |
295 const FilePath& path, | 235 const FilePath& path, |
296 int64 num_files, | 236 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 | |
310 QueryDownloadHistory(); | 237 QueryDownloadHistory(); |
311 | 238 |
312 std::vector<DownloadPersistentStoreInfo>::iterator found = | 239 std::vector<DownloadPersistentStoreInfo>::iterator found = |
313 std::find_if(history_entries_.begin(), history_entries_.end(), | 240 std::find_if(history_entries_.begin(), history_entries_.end(), |
314 DownloadPersistentStoreInfoMatch(url, path, num_files, | 241 DownloadPersistentStoreInfoMatch(url, path, num_files)); |
315 state)); | |
316 | 242 |
317 if (found == history_entries_.end()) { | 243 if (found == history_entries_.end()) { |
318 LOG(ERROR) << "Missing url=" << url.spec() | 244 LOG(ERROR) << "Missing url=" << url.spec() |
319 << " path=" << path.value() | 245 << " path=" << path.value() |
320 << " received=" << num_files; | 246 << " received=" << num_files; |
321 for (size_t index = 0; index < history_entries_.size(); ++index) { | 247 for (size_t index = 0; index < history_entries_.size(); ++index) { |
322 LOG(ERROR) << "History@" << index << ": url=" | 248 LOG(ERROR) << "History@" << index << ": url=" |
323 << history_entries_[index].url.spec() | 249 << history_entries_[index].url.spec() |
324 << " path=" << history_entries_[index].path.value() | 250 << " path=" << history_entries_[index].path.value() |
325 << " received=" << history_entries_[index].received_bytes | 251 << " received=" << history_entries_[index].received_bytes |
(...skipping 23 matching lines...) Expand all Loading... |
349 GURL url = NavigateToMockURL("a"); | 275 GURL url = NavigateToMockURL("a"); |
350 | 276 |
351 FilePath full_file_name, dir; | 277 FilePath full_file_name, dir; |
352 GetDestinationPaths("a", &full_file_name, &dir); | 278 GetDestinationPaths("a", &full_file_name, &dir); |
353 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 279 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
354 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 280 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
355 | 281 |
356 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 282 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
357 | 283 |
358 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 284 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
359 // a.htm is 1 file. | 285 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. |
360 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); | |
361 | 286 |
362 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 287 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
363 EXPECT_FALSE(file_util::PathExists(dir)); | 288 EXPECT_FALSE(file_util::PathExists(dir)); |
364 EXPECT_TRUE(file_util::ContentsEqual( | 289 EXPECT_TRUE(file_util::ContentsEqual( |
365 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 290 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
366 full_file_name)); | 291 full_file_name)); |
367 } | 292 } |
368 | 293 |
369 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { | 294 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { |
370 GURL url = NavigateToMockURL("a"); | 295 GURL url = NavigateToMockURL("a"); |
371 DownloadManager* manager(GetDownloadManager()); | 296 DownloadManager* manager(GetDownloadManager()); |
372 std::vector<DownloadItem*> downloads; | 297 std::vector<DownloadItem*> downloads; |
373 manager->SearchDownloads(string16(), &downloads); | 298 manager->SearchDownloads(string16(), &downloads); |
374 ASSERT_EQ(0u, downloads.size()); | 299 ASSERT_EQ(0u, downloads.size()); |
375 | 300 |
376 FilePath full_file_name, dir; | 301 FilePath full_file_name, dir; |
377 GetDestinationPaths("a", &full_file_name, &dir); | 302 GetDestinationPaths("a", &full_file_name, &dir); |
378 DownloadItemCreatedObserver creation_observer(manager); | 303 DownloadItemCreatedObserver creation_observer(manager); |
379 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 304 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
380 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 305 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
381 DownloadItem* item = creation_observer.WaitForNewDownloadItem(); | 306 DownloadItem* item = creation_observer.WaitForNewDownloadItem(); |
382 item->Cancel(true); | 307 item->Cancel(true); |
383 | 308 |
384 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. | 309 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. |
385 // Currently it's ignored. | 310 // Currently it's ignored. |
386 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 311 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
387 | 312 |
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 | |
393 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 313 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 314 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. |
394 | 315 |
395 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 316 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
396 EXPECT_FALSE(file_util::PathExists(dir)); | 317 EXPECT_FALSE(file_util::PathExists(dir)); |
397 EXPECT_TRUE(file_util::ContentsEqual( | 318 EXPECT_TRUE(file_util::ContentsEqual( |
398 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 319 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
399 full_file_name)); | 320 full_file_name)); |
400 } | 321 } |
401 | 322 |
402 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. | 323 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. |
403 // See http://crbug.com/144751. | 324 // See http://crbug.com/144751. |
(...skipping 28 matching lines...) Expand all Loading... |
432 ui_test_utils::NavigateToURL(browser(), view_source_url); | 353 ui_test_utils::NavigateToURL(browser(), view_source_url); |
433 | 354 |
434 FilePath full_file_name, dir; | 355 FilePath full_file_name, dir; |
435 GetDestinationPaths("a", &full_file_name, &dir); | 356 GetDestinationPaths("a", &full_file_name, &dir); |
436 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 357 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
437 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 358 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
438 | 359 |
439 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); | 360 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); |
440 | 361 |
441 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 362 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
442 // a.htm is 1 file. | 363 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file. |
443 CheckDownloadHistory(actual_page_url, full_file_name, 1, | |
444 DownloadItem::COMPLETE); | |
445 | 364 |
446 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 365 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
447 EXPECT_FALSE(file_util::PathExists(dir)); | 366 EXPECT_FALSE(file_util::PathExists(dir)); |
448 EXPECT_TRUE(file_util::ContentsEqual( | 367 EXPECT_TRUE(file_util::ContentsEqual( |
449 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 368 test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
450 full_file_name)); | 369 full_file_name)); |
451 } | 370 } |
452 | 371 |
453 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 372 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
454 GURL url = NavigateToMockURL("b"); | 373 GURL url = NavigateToMockURL("b"); |
455 | 374 |
456 FilePath full_file_name, dir; | 375 FilePath full_file_name, dir; |
457 GetDestinationPaths("b", &full_file_name, &dir); | 376 GetDestinationPaths("b", &full_file_name, &dir); |
458 ASSERT_TRUE(GetCurrentTab()->SavePage( | 377 ASSERT_TRUE(GetCurrentTab()->SavePage( |
459 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 378 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
460 | 379 |
461 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 380 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
462 | 381 |
463 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 382 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
464 // b.htm is 3 files. | 383 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. |
465 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); | |
466 | 384 |
467 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 385 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
468 EXPECT_TRUE(file_util::PathExists(dir)); | 386 EXPECT_TRUE(file_util::PathExists(dir)); |
469 EXPECT_TRUE(file_util::TextContentsEqual( | 387 EXPECT_TRUE(file_util::TextContentsEqual( |
470 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 388 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
471 full_file_name)); | 389 full_file_name)); |
472 EXPECT_TRUE(file_util::ContentsEqual( | 390 EXPECT_TRUE(file_util::ContentsEqual( |
473 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 391 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
474 dir.AppendASCII("1.png"))); | 392 dir.AppendASCII("1.png"))); |
475 EXPECT_TRUE(file_util::ContentsEqual( | 393 EXPECT_TRUE(file_util::ContentsEqual( |
(...skipping 12 matching lines...) Expand all Loading... |
488 FilePath full_file_name = save_dir_.path().AppendASCII( | 406 FilePath full_file_name = save_dir_.path().AppendASCII( |
489 std::string("Test page for saving page feature") + kAppendedExtension); | 407 std::string("Test page for saving page feature") + kAppendedExtension); |
490 FilePath dir = save_dir_.path().AppendASCII( | 408 FilePath dir = save_dir_.path().AppendASCII( |
491 "Test page for saving page feature_files"); | 409 "Test page for saving page feature_files"); |
492 ASSERT_TRUE(GetCurrentTab()->SavePage( | 410 ASSERT_TRUE(GetCurrentTab()->SavePage( |
493 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 411 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
494 | 412 |
495 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 413 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
496 | 414 |
497 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 415 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
498 // b.htm is 3 files. | 416 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. |
499 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); | |
500 | 417 |
501 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 418 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
502 EXPECT_TRUE(file_util::PathExists(dir)); | 419 EXPECT_TRUE(file_util::PathExists(dir)); |
503 EXPECT_TRUE(file_util::TextContentsEqual( | 420 EXPECT_TRUE(file_util::TextContentsEqual( |
504 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 421 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
505 full_file_name)); | 422 full_file_name)); |
506 EXPECT_TRUE(file_util::ContentsEqual( | 423 EXPECT_TRUE(file_util::ContentsEqual( |
507 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 424 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
508 dir.AppendASCII("1.png"))); | 425 dir.AppendASCII("1.png"))); |
509 EXPECT_TRUE(file_util::ContentsEqual( | 426 EXPECT_TRUE(file_util::ContentsEqual( |
510 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 427 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
511 dir.AppendASCII("1.css"))); | 428 dir.AppendASCII("1.css"))); |
512 } | 429 } |
513 | 430 |
514 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { | 431 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { |
515 GURL url = NavigateToMockURL("a"); | 432 GURL url = NavigateToMockURL("a"); |
516 | 433 |
517 FilePath full_file_name, dir; | 434 FilePath full_file_name, dir; |
518 GetDestinationPaths("a", &full_file_name, &dir); | 435 GetDestinationPaths("a", &full_file_name, &dir); |
519 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 436 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
520 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 437 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
521 | 438 |
522 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 439 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
523 | 440 |
524 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 441 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
525 // a.htm is 1 file. | 442 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. |
526 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); | |
527 | 443 |
528 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); | 444 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); |
529 | 445 |
530 // Should not be in history. | 446 // Should not be in history. |
531 QueryDownloadHistory(); | 447 QueryDownloadHistory(); |
532 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), | 448 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), |
533 DownloadPersistentStoreInfoMatch( | 449 DownloadPersistentStoreInfoMatch(url, full_file_name, 1)), |
534 url, full_file_name, 1, DownloadItem::COMPLETE)), | |
535 history_entries_.end()); | 450 history_entries_.end()); |
536 | 451 |
537 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 452 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
538 EXPECT_FALSE(file_util::PathExists(dir)); | 453 EXPECT_FALSE(file_util::PathExists(dir)); |
539 EXPECT_TRUE(file_util::ContentsEqual( | 454 EXPECT_TRUE(file_util::ContentsEqual( |
540 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 455 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
541 full_file_name)); | 456 full_file_name)); |
542 } | 457 } |
543 | 458 |
544 // This tests that a webpage with the title "test.exe" is saved as | 459 // 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 Loading... |
598 #if defined(OS_CHROMEOS) | 513 #if defined(OS_CHROMEOS) |
599 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | 514 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); |
600 #else | 515 #else |
601 SavePackageFilePicker::SetShouldPromptUser(false); | 516 SavePackageFilePicker::SetShouldPromptUser(false); |
602 #endif | 517 #endif |
603 content::WindowedNotificationObserver observer( | 518 content::WindowedNotificationObserver observer( |
604 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 519 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
605 content::NotificationService::AllSources()); | 520 content::NotificationService::AllSources()); |
606 chrome::SavePage(browser()); | 521 chrome::SavePage(browser()); |
607 observer.Wait(); | 522 observer.Wait(); |
608 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE); | 523 CheckDownloadHistory(url, full_file_name, -1); |
609 | 524 |
610 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 525 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
611 int64 actual_file_size = -1; | 526 int64 actual_file_size = -1; |
612 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 527 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
613 EXPECT_LE(kFileSizeMin, actual_file_size); | 528 EXPECT_LE(kFileSizeMin, actual_file_size); |
614 } | 529 } |
OLD | NEW |