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

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

Issue 10069014: Save Page As MHTML (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments 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/prefs/pref_member.h"
21 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/webui/chromeos/active_downloads_ui.h" 25 #include "chrome/browser/ui/webui/chromeos/active_downloads_ui.h"
24 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
26 #include "chrome/test/base/in_process_browser_test.h" 29 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/ui_test_utils.h" 30 #include "chrome/test/base/ui_test_utils.h"
28 #include "content/public/browser/download_item.h" 31 #include "content/public/browser/download_item.h"
29 #include "content/public/browser/download_manager.h" 32 #include "content/public/browser/download_manager.h"
30 #include "content/public/browser/download_persistent_store_info.h" 33 #include "content/public/browser/download_persistent_store_info.h"
31 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/notification_types.h" 35 #include "content/public/browser/notification_types.h"
33 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
34 #include "content/test/net/url_request_mock_http_job.h" 37 #include "content/test/net/url_request_mock_http_job.h"
(...skipping 20 matching lines...) Expand all
55 58
56 class SavePageBrowserTest : public InProcessBrowserTest { 59 class SavePageBrowserTest : public InProcessBrowserTest {
57 protected: 60 protected:
58 void SetUp() OVERRIDE { 61 void SetUp() OVERRIDE {
59 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); 62 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_));
60 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); 63 ASSERT_TRUE(save_dir_.CreateUniqueTempDir());
61 InProcessBrowserTest::SetUp(); 64 InProcessBrowserTest::SetUp();
62 } 65 }
63 66
64 void SetUpOnMainThread() OVERRIDE { 67 void SetUpOnMainThread() OVERRIDE {
68 browser()->profile()->GetPrefs()->SetFilePath(
69 prefs::kDownloadDefaultDirectory, save_dir_.path());
65 BrowserThread::PostTask( 70 BrowserThread::PostTask(
66 BrowserThread::IO, FROM_HERE, 71 BrowserThread::IO, FROM_HERE,
67 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 72 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
68 } 73 }
69 74
70 GURL NavigateToMockURL(const std::string& prefix) { 75 GURL NavigateToMockURL(const std::string& prefix) {
71 GURL url = URLRequestMockHTTPJob::GetMockUrl( 76 GURL url = URLRequestMockHTTPJob::GetMockUrl(
72 FilePath(kTestDir).AppendASCII(prefix + ".htm")); 77 FilePath(kTestDir).AppendASCII(prefix + ".htm"));
73 ui_test_utils::NavigateToURL(browser(), url); 78 ui_test_utils::NavigateToURL(browser(), url);
74 return url; 79 return url;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 info.state == DownloadItem::COMPLETE; 182 info.state == DownloadItem::COMPLETE;
178 } 183 }
179 184
180 GURL url_; 185 GURL url_;
181 FilePath path_; 186 FilePath path_;
182 int64 num_files_; 187 int64 num_files_;
183 }; 188 };
184 189
185 void CheckDownloadHistory(const GURL& url, 190 void CheckDownloadHistory(const GURL& url,
186 const FilePath& path, 191 const FilePath& path,
187 int64 num_files_) { 192 int64 num_files) {
188 QueryDownloadHistory(); 193 QueryDownloadHistory();
189 194
190 EXPECT_NE(std::find_if(history_entries_.begin(), history_entries_.end(), 195 std::vector<DownloadPersistentStoreInfo>::iterator found =
191 DownloadPersistentStoreInfoMatch(url, path, num_files_)), 196 std::find_if(history_entries_.begin(), history_entries_.end(),
192 history_entries_.end()); 197 DownloadPersistentStoreInfoMatch(url, path, num_files));
198
199 if (found == history_entries_.end()) {
200 LOG(ERROR) << "Missing url=" << url.spec()
201 << " path=" << path.value()
202 << " received=" << num_files;
203 for (size_t index = 0; index < history_entries_.size(); ++index) {
204 LOG(ERROR) << "History@" << index << ": url="
205 << history_entries_[index].url.spec()
206 << " path=" << history_entries_[index].path.value()
207 << " received=" << history_entries_[index].received_bytes
208 << " total=" << history_entries_[index].total_bytes
209 << " state=" << history_entries_[index].state;
210 }
211 EXPECT_TRUE(false);
212 }
193 } 213 }
194 214
195 std::vector<DownloadPersistentStoreInfo> history_entries_; 215 std::vector<DownloadPersistentStoreInfo> history_entries_;
196 216
197 // Path to directory containing test data. 217 // Path to directory containing test data.
198 FilePath test_dir_; 218 FilePath test_dir_;
199 219
200 // Temporary directory we will save pages to. 220 // Temporary directory we will save pages to.
201 ScopedTempDir save_dir_; 221 ScopedTempDir save_dir_;
202 }; 222 };
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 content::NotificationService::AllSources()); 382 content::NotificationService::AllSources());
363 browser()->SavePage(); 383 browser()->SavePage();
364 observer.Wait(); 384 observer.Wait();
365 385
366 EXPECT_TRUE(file_util::PathExists(full_file_name)); 386 EXPECT_TRUE(file_util::PathExists(full_file_name));
367 387
368 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false)); 388 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false));
369 EXPECT_TRUE(file_util::DieFileDie(dir, true)); 389 EXPECT_TRUE(file_util::DieFileDie(dir, true));
370 } 390 }
371 #endif 391 #endif
392
393 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SavePageAsMHTML) {
394 GURL url = NavigateToMockURL("b");
395 FilePath download_dir = DownloadPrefs::FromDownloadManager(
396 GetDownloadManager())->download_path();
397 FilePath full_file_name = download_dir.AppendASCII(std::string(
398 "Test page for saving page feature.mht"));
399 SavePackageFilePicker::SetShouldPromptUser(false);
400 browser()->profile()->GetPrefs()->SetInteger(
401 prefs::kSaveFileType, content::SAVE_PAGE_TYPE_AS_MHTML);
402 ui_test_utils::WindowedNotificationObserver observer(
403 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
404 content::NotificationService::AllSources());
405 browser()->SavePage();
406 observer.Wait();
407 CheckDownloadUI(full_file_name);
408 CheckDownloadHistory(url, full_file_name, 1);
409
410 EXPECT_TRUE(file_util::PathExists(full_file_name));
411 int64 actual_file_size = -1;
412 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size));
413 EXPECT_EQ(2760, actual_file_size);
414 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698