Chromium Code Reviews| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 MessageLoopForUI::current()->Quit(); | 117 MessageLoopForUI::current()->Quit(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool waiting_; | 120 bool waiting_; |
| 121 DownloadManager* manager_; | 121 DownloadManager* manager_; |
| 122 DownloadItem* created_item_; | 122 DownloadItem* created_item_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); | 124 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 class DownloadPersistedObserver : public DownloadItem::Observer { | |
| 128 public: | |
| 129 explicit DownloadPersistedObserver(DownloadItem* item) | |
| 130 : waiting_(false), item_(item) { | |
| 131 item->AddObserver(this); | |
| 132 } | |
| 133 | |
| 134 ~DownloadPersistedObserver() { | |
| 135 if (item_) | |
| 136 item_->RemoveObserver(this); | |
| 137 } | |
| 138 | |
| 139 // Wait for download item to get the persisted bit set. | |
| 140 // Note that this class provides no protection against the download | |
| 141 // being destroyed between creation and return of WaitForPersisted(); | |
| 142 // the caller must guarantee that in some other fashion. | |
| 143 void WaitForPersisted() { | |
| 144 // In combination with OnDownloadDestroyed() below, verify the | |
| 145 // above interface contract. | |
| 146 DCHECK(item_); | |
| 147 | |
| 148 if (item_->IsPersisted()) | |
| 149 return; | |
| 150 | |
| 151 waiting_ = true; | |
| 152 content::RunMessageLoop(); | |
| 153 waiting_ = false; | |
| 154 | |
| 155 return; | |
| 156 } | |
| 157 | |
| 158 private: | |
| 159 // DownloadItem::Observer | |
| 160 void OnDownloadUpdated(DownloadItem* item) { | |
| 161 DCHECK_EQ(item, item_); | |
| 162 | |
| 163 if (waiting_ && item->IsPersisted()) | |
| 164 MessageLoopForUI::current()->Quit(); | |
| 165 } | |
| 166 | |
| 167 void OnDownloadDestroyed(DownloadItem* item) { | |
| 168 if (item != item_) | |
| 169 return; | |
| 170 | |
| 171 item_->RemoveObserver(this); | |
| 172 item_ = NULL; | |
| 173 } | |
| 174 | |
| 175 bool waiting_; | |
| 176 DownloadItem* item_; | |
| 177 | |
| 178 DISALLOW_COPY_AND_ASSIGN(DownloadPersistedObserver); | |
| 179 }; | |
| 180 | |
| 127 class SavePageBrowserTest : public InProcessBrowserTest { | 181 class SavePageBrowserTest : public InProcessBrowserTest { |
| 128 public: | 182 public: |
| 129 SavePageBrowserTest() {} | 183 SavePageBrowserTest() {} |
| 130 virtual ~SavePageBrowserTest(); | 184 virtual ~SavePageBrowserTest(); |
| 131 | 185 |
| 132 protected: | 186 protected: |
| 133 void SetUp() OVERRIDE { | 187 void SetUp() OVERRIDE { |
| 134 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); | 188 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); |
| 135 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); | 189 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); |
| 136 InProcessBrowserTest::SetUp(); | 190 InProcessBrowserTest::SetUp(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 158 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); | 212 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); |
| 159 *dir = save_dir_.path().AppendASCII(prefix + "_files"); | 213 *dir = save_dir_.path().AppendASCII(prefix + "_files"); |
| 160 } | 214 } |
| 161 | 215 |
| 162 WebContents* GetCurrentTab() const { | 216 WebContents* GetCurrentTab() const { |
| 163 WebContents* current_tab = chrome::GetActiveWebContents(browser()); | 217 WebContents* current_tab = chrome::GetActiveWebContents(browser()); |
| 164 EXPECT_TRUE(current_tab); | 218 EXPECT_TRUE(current_tab); |
| 165 return current_tab; | 219 return current_tab; |
| 166 } | 220 } |
| 167 | 221 |
| 168 | |
| 169 GURL WaitForSavePackageToFinish() const { | 222 GURL WaitForSavePackageToFinish() const { |
| 170 content::WindowedNotificationObserver observer( | 223 content::WindowedNotificationObserver observer( |
| 171 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 224 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
| 172 content::NotificationService::AllSources()); | 225 content::NotificationService::AllSources()); |
| 173 observer.Wait(); | 226 observer.Wait(); |
| 174 return content::Details<DownloadItem>(observer.details()).ptr()-> | 227 return content::Details<DownloadItem>(observer.details()).ptr()-> |
| 175 GetOriginalUrl(); | 228 GetOriginalUrl(); |
| 176 } | 229 } |
| 177 | 230 |
| 231 void WaitForPersistedDownloadItem() const { | |
|
benjhayden
2012/08/26 16:17:03
Why not inline this in CheckDownloadHistory()?
Randy Smith (Not in Mondays)
2012/08/27 15:02:50
Quite right. Done.
| |
| 232 std::vector<DownloadItem*> downloads; | |
| 233 GetDownloadManager()->SearchDownloads(string16(), &downloads); | |
| 234 ASSERT_EQ(1u, downloads.size()); | |
| 235 DownloadPersistedObserver(downloads[0]).WaitForPersisted(); | |
| 236 } | |
| 237 | |
| 178 DownloadManager* GetDownloadManager() const { | 238 DownloadManager* GetDownloadManager() const { |
| 179 DownloadManager* download_manager = | 239 DownloadManager* download_manager = |
| 180 BrowserContext::GetDownloadManager(browser()->profile()); | 240 BrowserContext::GetDownloadManager(browser()->profile()); |
| 181 EXPECT_TRUE(download_manager); | 241 EXPECT_TRUE(download_manager); |
| 182 return download_manager; | 242 return download_manager; |
| 183 } | 243 } |
| 184 | 244 |
| 185 void QueryDownloadHistory() { | 245 void QueryDownloadHistory() { |
| 186 // Query the history system. | 246 // Query the history system. |
| 187 ChromeDownloadManagerDelegate* delegate = | 247 ChromeDownloadManagerDelegate* delegate = |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 202 | 262 |
| 203 // Indicate thet we have received the history and can continue. | 263 // Indicate thet we have received the history and can continue. |
| 204 MessageLoopForUI::current()->Quit(); | 264 MessageLoopForUI::current()->Quit(); |
| 205 } | 265 } |
| 206 | 266 |
| 207 struct DownloadPersistentStoreInfoMatch | 267 struct DownloadPersistentStoreInfoMatch |
| 208 : public std::unary_function<DownloadPersistentStoreInfo, bool> { | 268 : public std::unary_function<DownloadPersistentStoreInfo, bool> { |
| 209 | 269 |
| 210 DownloadPersistentStoreInfoMatch(const GURL& url, | 270 DownloadPersistentStoreInfoMatch(const GURL& url, |
| 211 const FilePath& path, | 271 const FilePath& path, |
| 212 int64 num_files) | 272 int64 num_files, |
| 273 DownloadItem::DownloadState state) | |
| 213 : url_(url), | 274 : url_(url), |
| 214 path_(path), | 275 path_(path), |
| 215 num_files_(num_files) { | 276 num_files_(num_files), |
| 216 } | 277 state_(state) {} |
| 217 | 278 |
| 218 bool operator() (const DownloadPersistentStoreInfo& info) const { | 279 bool operator() (const DownloadPersistentStoreInfo& info) const { |
| 219 return info.url == url_ && | 280 return info.url == url_ && |
| 220 info.path == path_ && | 281 info.path == path_ && |
| 221 // For non-MHTML save packages, received_bytes is actually the | 282 // For non-MHTML save packages, received_bytes is actually the |
| 222 // number of files. | 283 // number of files. |
| 223 ((num_files_ < 0) || | 284 ((num_files_ < 0) || |
| 224 (info.received_bytes == num_files_)) && | 285 (info.received_bytes == num_files_)) && |
| 225 info.total_bytes == 0 && | 286 info.total_bytes == 0 && |
| 226 info.state == DownloadItem::COMPLETE; | 287 info.state == state_; |
| 227 } | 288 } |
| 228 | 289 |
| 229 GURL url_; | 290 GURL url_; |
| 230 FilePath path_; | 291 FilePath path_; |
| 231 int64 num_files_; | 292 int64 num_files_; |
| 293 DownloadItem::DownloadState state_; | |
| 232 }; | 294 }; |
| 233 | 295 |
| 234 void CheckDownloadHistory(const GURL& url, | 296 void CheckDownloadHistory(const GURL& url, |
| 235 const FilePath& path, | 297 const FilePath& path, |
| 236 int64 num_files) { | 298 int64 num_files, |
| 299 DownloadItem::DownloadState state) { | |
| 237 QueryDownloadHistory(); | 300 QueryDownloadHistory(); |
| 238 | 301 |
| 239 std::vector<DownloadPersistentStoreInfo>::iterator found = | 302 std::vector<DownloadPersistentStoreInfo>::iterator found = |
| 240 std::find_if(history_entries_.begin(), history_entries_.end(), | 303 std::find_if(history_entries_.begin(), history_entries_.end(), |
| 241 DownloadPersistentStoreInfoMatch(url, path, num_files)); | 304 DownloadPersistentStoreInfoMatch(url, path, num_files, |
| 305 state)); | |
| 242 | 306 |
| 243 if (found == history_entries_.end()) { | 307 if (found == history_entries_.end()) { |
| 244 LOG(ERROR) << "Missing url=" << url.spec() | 308 LOG(ERROR) << "Missing url=" << url.spec() |
| 245 << " path=" << path.value() | 309 << " path=" << path.value() |
| 246 << " received=" << num_files; | 310 << " received=" << num_files; |
| 247 for (size_t index = 0; index < history_entries_.size(); ++index) { | 311 for (size_t index = 0; index < history_entries_.size(); ++index) { |
| 248 LOG(ERROR) << "History@" << index << ": url=" | 312 LOG(ERROR) << "History@" << index << ": url=" |
| 249 << history_entries_[index].url.spec() | 313 << history_entries_[index].url.spec() |
| 250 << " path=" << history_entries_[index].path.value() | 314 << " path=" << history_entries_[index].path.value() |
| 251 << " received=" << history_entries_[index].received_bytes | 315 << " received=" << history_entries_[index].received_bytes |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 273 | 337 |
| 274 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 338 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { |
| 275 GURL url = NavigateToMockURL("a"); | 339 GURL url = NavigateToMockURL("a"); |
| 276 | 340 |
| 277 FilePath full_file_name, dir; | 341 FilePath full_file_name, dir; |
| 278 GetDestinationPaths("a", &full_file_name, &dir); | 342 GetDestinationPaths("a", &full_file_name, &dir); |
| 279 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 343 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
| 280 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 344 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 281 | 345 |
| 282 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 346 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
| 347 WaitForPersistedDownloadItem(); | |
| 283 | 348 |
| 284 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 349 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 285 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | 350 // a.htm is 1 file. |
| 351 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); | |
| 286 | 352 |
| 287 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 353 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 288 EXPECT_FALSE(file_util::PathExists(dir)); | 354 EXPECT_FALSE(file_util::PathExists(dir)); |
| 289 EXPECT_TRUE(file_util::ContentsEqual( | 355 EXPECT_TRUE(file_util::ContentsEqual( |
| 290 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 356 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
| 291 full_file_name)); | 357 full_file_name)); |
| 292 } | 358 } |
| 293 | 359 |
| 294 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { | 360 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { |
| 295 GURL url = NavigateToMockURL("a"); | 361 GURL url = NavigateToMockURL("a"); |
| 296 DownloadManager* manager(GetDownloadManager()); | 362 DownloadManager* manager(GetDownloadManager()); |
| 297 std::vector<DownloadItem*> downloads; | 363 std::vector<DownloadItem*> downloads; |
| 298 manager->SearchDownloads(string16(), &downloads); | 364 manager->SearchDownloads(string16(), &downloads); |
| 299 ASSERT_EQ(0u, downloads.size()); | 365 ASSERT_EQ(0u, downloads.size()); |
| 300 | 366 |
| 301 FilePath full_file_name, dir; | 367 FilePath full_file_name, dir; |
| 302 GetDestinationPaths("a", &full_file_name, &dir); | 368 GetDestinationPaths("a", &full_file_name, &dir); |
| 303 DownloadItemCreatedObserver creation_observer(manager); | 369 DownloadItemCreatedObserver creation_observer(manager); |
| 304 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 370 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
| 305 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 371 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 306 DownloadItem* item = creation_observer.WaitForNewDownloadItem(); | 372 DownloadItem* item = creation_observer.WaitForNewDownloadItem(); |
| 307 item->Cancel(true); | 373 item->Cancel(true); |
| 308 | 374 |
| 309 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. | 375 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. |
| 310 // Currently it's ignored. | 376 // Currently it's ignored. |
| 311 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 377 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
| 378 WaitForPersistedDownloadItem(); | |
| 379 DownloadPersistedObserver(item).WaitForPersisted(); | |
| 380 // -1 to disable number of files check; we don't update after cancel, and | |
| 381 // we don't know when the single file completed in relationship to | |
| 382 // the cancel. | |
| 383 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::CANCELLED); | |
| 312 | 384 |
| 313 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 385 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 314 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | |
| 315 | 386 |
| 316 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 387 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 317 EXPECT_FALSE(file_util::PathExists(dir)); | 388 EXPECT_FALSE(file_util::PathExists(dir)); |
| 318 EXPECT_TRUE(file_util::ContentsEqual( | 389 EXPECT_TRUE(file_util::ContentsEqual( |
| 319 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 390 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
| 320 full_file_name)); | 391 full_file_name)); |
| 321 } | 392 } |
| 322 | 393 |
| 323 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyTabDestroy) { | 394 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyTabDestroy) { |
| 324 GURL url = NavigateToMockURL("a"); | 395 GURL url = NavigateToMockURL("a"); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 349 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( | 420 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( |
| 350 FilePath(kTestDir).Append(file_name)); | 421 FilePath(kTestDir).Append(file_name)); |
| 351 ui_test_utils::NavigateToURL(browser(), view_source_url); | 422 ui_test_utils::NavigateToURL(browser(), view_source_url); |
| 352 | 423 |
| 353 FilePath full_file_name, dir; | 424 FilePath full_file_name, dir; |
| 354 GetDestinationPaths("a", &full_file_name, &dir); | 425 GetDestinationPaths("a", &full_file_name, &dir); |
| 355 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 426 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
| 356 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 427 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 357 | 428 |
| 358 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); | 429 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); |
| 430 WaitForPersistedDownloadItem(); | |
| 359 | 431 |
| 360 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 432 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 361 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file. | 433 // a.htm is 1 file. |
| 434 CheckDownloadHistory(actual_page_url, full_file_name, 1, | |
| 435 DownloadItem::COMPLETE); | |
| 362 | 436 |
| 363 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 437 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 364 EXPECT_FALSE(file_util::PathExists(dir)); | 438 EXPECT_FALSE(file_util::PathExists(dir)); |
| 365 EXPECT_TRUE(file_util::ContentsEqual( | 439 EXPECT_TRUE(file_util::ContentsEqual( |
| 366 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 440 test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
| 367 full_file_name)); | 441 full_file_name)); |
| 368 } | 442 } |
| 369 | 443 |
| 370 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 444 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
| 371 GURL url = NavigateToMockURL("b"); | 445 GURL url = NavigateToMockURL("b"); |
| 372 | 446 |
| 373 FilePath full_file_name, dir; | 447 FilePath full_file_name, dir; |
| 374 GetDestinationPaths("b", &full_file_name, &dir); | 448 GetDestinationPaths("b", &full_file_name, &dir); |
| 375 ASSERT_TRUE(GetCurrentTab()->SavePage( | 449 ASSERT_TRUE(GetCurrentTab()->SavePage( |
| 376 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 450 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
| 377 | 451 |
| 378 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 452 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
| 453 WaitForPersistedDownloadItem(); | |
| 379 | 454 |
| 380 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 455 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 381 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. | 456 // b.htm is 3 files. |
| 457 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); | |
| 382 | 458 |
| 383 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 459 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 384 EXPECT_TRUE(file_util::PathExists(dir)); | 460 EXPECT_TRUE(file_util::PathExists(dir)); |
| 385 EXPECT_TRUE(file_util::TextContentsEqual( | 461 EXPECT_TRUE(file_util::TextContentsEqual( |
| 386 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 462 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
| 387 full_file_name)); | 463 full_file_name)); |
| 388 EXPECT_TRUE(file_util::ContentsEqual( | 464 EXPECT_TRUE(file_util::ContentsEqual( |
| 389 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 465 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
| 390 dir.AppendASCII("1.png"))); | 466 dir.AppendASCII("1.png"))); |
| 391 EXPECT_TRUE(file_util::ContentsEqual( | 467 EXPECT_TRUE(file_util::ContentsEqual( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 402 GURL url = NavigateToMockURL("b"); | 478 GURL url = NavigateToMockURL("b"); |
| 403 | 479 |
| 404 FilePath full_file_name = save_dir_.path().AppendASCII( | 480 FilePath full_file_name = save_dir_.path().AppendASCII( |
| 405 std::string("Test page for saving page feature") + kAppendedExtension); | 481 std::string("Test page for saving page feature") + kAppendedExtension); |
| 406 FilePath dir = save_dir_.path().AppendASCII( | 482 FilePath dir = save_dir_.path().AppendASCII( |
| 407 "Test page for saving page feature_files"); | 483 "Test page for saving page feature_files"); |
| 408 ASSERT_TRUE(GetCurrentTab()->SavePage( | 484 ASSERT_TRUE(GetCurrentTab()->SavePage( |
| 409 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 485 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
| 410 | 486 |
| 411 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 487 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
| 488 WaitForPersistedDownloadItem(); | |
| 412 | 489 |
| 413 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 490 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 414 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. | 491 // b.htm is 3 files. |
| 492 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); | |
| 415 | 493 |
| 416 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 494 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 417 EXPECT_TRUE(file_util::PathExists(dir)); | 495 EXPECT_TRUE(file_util::PathExists(dir)); |
| 418 EXPECT_TRUE(file_util::TextContentsEqual( | 496 EXPECT_TRUE(file_util::TextContentsEqual( |
| 419 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 497 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
| 420 full_file_name)); | 498 full_file_name)); |
| 421 EXPECT_TRUE(file_util::ContentsEqual( | 499 EXPECT_TRUE(file_util::ContentsEqual( |
| 422 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 500 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
| 423 dir.AppendASCII("1.png"))); | 501 dir.AppendASCII("1.png"))); |
| 424 EXPECT_TRUE(file_util::ContentsEqual( | 502 EXPECT_TRUE(file_util::ContentsEqual( |
| 425 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 503 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
| 426 dir.AppendASCII("1.css"))); | 504 dir.AppendASCII("1.css"))); |
| 427 } | 505 } |
| 428 | 506 |
| 429 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { | 507 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { |
| 430 GURL url = NavigateToMockURL("a"); | 508 GURL url = NavigateToMockURL("a"); |
| 431 | 509 |
| 432 FilePath full_file_name, dir; | 510 FilePath full_file_name, dir; |
| 433 GetDestinationPaths("a", &full_file_name, &dir); | 511 GetDestinationPaths("a", &full_file_name, &dir); |
| 434 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 512 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
| 435 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 513 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 436 | 514 |
| 437 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 515 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
| 516 WaitForPersistedDownloadItem(); | |
| 438 | 517 |
| 439 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 518 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 440 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | 519 // a.htm is 1 file. |
| 520 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); | |
| 441 | 521 |
| 442 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); | 522 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); |
| 443 | 523 |
| 444 // Should not be in history. | 524 // Should not be in history. |
| 445 QueryDownloadHistory(); | 525 QueryDownloadHistory(); |
| 446 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), | 526 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), |
| 447 DownloadPersistentStoreInfoMatch(url, full_file_name, 1)), | 527 DownloadPersistentStoreInfoMatch( |
| 528 url, full_file_name, 1, DownloadItem::COMPLETE)), | |
| 448 history_entries_.end()); | 529 history_entries_.end()); |
| 449 | 530 |
| 450 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 531 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 451 EXPECT_FALSE(file_util::PathExists(dir)); | 532 EXPECT_FALSE(file_util::PathExists(dir)); |
| 452 EXPECT_TRUE(file_util::ContentsEqual( | 533 EXPECT_TRUE(file_util::ContentsEqual( |
| 453 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 534 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
| 454 full_file_name)); | 535 full_file_name)); |
| 455 } | 536 } |
| 456 | 537 |
| 457 // This tests that a webpage with the title "test.exe" is saved as | 538 // 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... | |
| 511 #if defined(OS_CHROMEOS) | 592 #if defined(OS_CHROMEOS) |
| 512 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | 593 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); |
| 513 #else | 594 #else |
| 514 SavePackageFilePicker::SetShouldPromptUser(false); | 595 SavePackageFilePicker::SetShouldPromptUser(false); |
| 515 #endif | 596 #endif |
| 516 content::WindowedNotificationObserver observer( | 597 content::WindowedNotificationObserver observer( |
| 517 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 598 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
| 518 content::NotificationService::AllSources()); | 599 content::NotificationService::AllSources()); |
| 519 chrome::SavePage(browser()); | 600 chrome::SavePage(browser()); |
| 520 observer.Wait(); | 601 observer.Wait(); |
| 521 CheckDownloadHistory(url, full_file_name, -1); | 602 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE); |
| 522 | 603 |
| 523 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 604 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 524 int64 actual_file_size = -1; | 605 int64 actual_file_size = -1; |
| 525 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 606 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
| 526 EXPECT_LE(kFileSizeMin, actual_file_size); | 607 EXPECT_LE(kFileSizeMin, actual_file_size); |
| 527 } | 608 } |
| OLD | NEW |