| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 DownloadPersistentStoreInfoMatch(const GURL& url, | 149 DownloadPersistentStoreInfoMatch(const GURL& url, |
| 150 const FilePath& path, | 150 const FilePath& path, |
| 151 int64 num_files) | 151 int64 num_files) |
| 152 : url_(url), | 152 : url_(url), |
| 153 path_(path), | 153 path_(path), |
| 154 num_files_(num_files) { | 154 num_files_(num_files) { |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool operator() (const DownloadPersistentStoreInfo& info) const { | 157 bool operator() (const DownloadPersistentStoreInfo& info) const { |
| 158 return info.url == url_ && | 158 return info.url == url_ && |
| 159 info.path == path_ && | 159 info.path == path_ && |
| 160 // For save packages, received bytes is actually the number of files. | 160 // For non-MHTML save packages, received_bytes is actually the |
| 161 info.received_bytes == num_files_ && | 161 // number of files. |
| 162 info.total_bytes == 0 && | 162 ((num_files_ < 0) || |
| 163 info.state == DownloadItem::COMPLETE; | 163 (info.received_bytes == num_files_)) && |
| 164 info.total_bytes == 0 && |
| 165 info.state == DownloadItem::COMPLETE; |
| 164 } | 166 } |
| 165 | 167 |
| 166 GURL url_; | 168 GURL url_; |
| 167 FilePath path_; | 169 FilePath path_; |
| 168 int64 num_files_; | 170 int64 num_files_; |
| 169 }; | 171 }; |
| 170 | 172 |
| 171 void CheckDownloadHistory(const GURL& url, | 173 void CheckDownloadHistory(const GURL& url, |
| 172 const FilePath& path, | 174 const FilePath& path, |
| 173 int64 num_files) { | 175 int64 num_files) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 command_line->AppendSwitch(switches::kSavePageAsMHTML); | 383 command_line->AppendSwitch(switches::kSavePageAsMHTML); |
| 382 } | 384 } |
| 383 | 385 |
| 384 private: | 386 private: |
| 385 DISALLOW_COPY_AND_ASSIGN(SavePageAsMHTMLBrowserTest); | 387 DISALLOW_COPY_AND_ASSIGN(SavePageAsMHTMLBrowserTest); |
| 386 }; | 388 }; |
| 387 | 389 |
| 388 SavePageAsMHTMLBrowserTest::~SavePageAsMHTMLBrowserTest() { | 390 SavePageAsMHTMLBrowserTest::~SavePageAsMHTMLBrowserTest() { |
| 389 } | 391 } |
| 390 | 392 |
| 391 // Bug 127527: This test fails when the day of the month is >9. | 393 IN_PROC_BROWSER_TEST_F(SavePageAsMHTMLBrowserTest, SavePageAsMHTML) { |
| 392 IN_PROC_BROWSER_TEST_F(SavePageAsMHTMLBrowserTest, DISABLED_SavePageAsMHTML) { | 394 static const int64 kFileSizeMin = 2758; |
| 393 static const int64 kFileSize = 2759; | |
| 394 GURL url = NavigateToMockURL("b"); | 395 GURL url = NavigateToMockURL("b"); |
| 395 FilePath download_dir = DownloadPrefs::FromDownloadManager( | 396 FilePath download_dir = DownloadPrefs::FromDownloadManager( |
| 396 GetDownloadManager())->download_path(); | 397 GetDownloadManager())->download_path(); |
| 397 FilePath full_file_name = download_dir.AppendASCII(std::string( | 398 FilePath full_file_name = download_dir.AppendASCII(std::string( |
| 398 "Test page for saving page feature.mhtml")); | 399 "Test page for saving page feature.mhtml")); |
| 399 #if defined(OS_CHROMEOS) | 400 #if defined(OS_CHROMEOS) |
| 400 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | 401 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); |
| 401 #else | 402 #else |
| 402 SavePackageFilePicker::SetShouldPromptUser(false); | 403 SavePackageFilePicker::SetShouldPromptUser(false); |
| 403 #endif | 404 #endif |
| 404 ui_test_utils::WindowedNotificationObserver observer( | 405 ui_test_utils::WindowedNotificationObserver observer( |
| 405 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 406 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
| 406 content::NotificationService::AllSources()); | 407 content::NotificationService::AllSources()); |
| 407 browser()->SavePage(); | 408 browser()->SavePage(); |
| 408 observer.Wait(); | 409 observer.Wait(); |
| 409 CheckDownloadHistory(url, full_file_name, kFileSize); | 410 CheckDownloadHistory(url, full_file_name, -1); |
| 410 | 411 |
| 411 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 412 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 412 int64 actual_file_size = -1; | 413 int64 actual_file_size = -1; |
| 413 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 414 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
| 414 EXPECT_EQ(kFileSize, actual_file_size); | 415 EXPECT_LE(kFileSizeMin, actual_file_size); |
| 415 } | 416 } |
| OLD | NEW |