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" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "base/test/test_file_util.h" | 12 #include "base/test/test_file_util.h" |
13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
14 #include "chrome/browser/api/prefs/pref_member.h" | 14 #include "chrome/browser/api/prefs/pref_member.h" |
15 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 15 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
16 #include "chrome/browser/download/download_history.h" | 16 #include "chrome/browser/download/download_history.h" |
17 #include "chrome/browser/download/download_prefs.h" | 17 #include "chrome/browser/download/download_prefs.h" |
18 #include "chrome/browser/download/download_service.h" | 18 #include "chrome/browser/download/download_service.h" |
19 #include "chrome/browser/download/download_service_factory.h" | 19 #include "chrome/browser/download/download_service_factory.h" |
| 20 #include "chrome/browser/history/download_persistent_store_info.h" |
| 21 #include "chrome/browser/history/history_service_factory.h" |
20 #include "chrome/browser/net/url_request_mock_util.h" | 22 #include "chrome/browser/net/url_request_mock_util.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_commands.h" | 26 #include "chrome/browser/ui/browser_commands.h" |
25 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
26 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
31 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
32 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
33 #include "content/public/browser/download_item.h" | 35 #include "content/public/browser/download_item.h" |
34 #include "content/public/browser/download_manager.h" | 36 #include "content/public/browser/download_manager.h" |
35 #include "content/public/browser/download_persistent_store_info.h" | |
36 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
37 #include "content/public/browser/notification_types.h" | 38 #include "content/public/browser/notification_types.h" |
38 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
39 #include "content/public/test/test_utils.h" | 40 #include "content/public/test/test_utils.h" |
40 #include "content/test/net/url_request_mock_http_job.h" | 41 #include "content/test/net/url_request_mock_http_job.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
42 | 43 |
43 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
44 #include "chrome/browser/download/save_package_file_picker_chromeos.h" | 45 #include "chrome/browser/download/save_package_file_picker_chromeos.h" |
45 #else | 46 #else |
46 #include "chrome/browser/download/save_package_file_picker.h" | 47 #include "chrome/browser/download/save_package_file_picker.h" |
47 #endif | 48 #endif |
48 | 49 |
49 using content::BrowserContext; | 50 using content::BrowserContext; |
50 using content::BrowserThread; | 51 using content::BrowserThread; |
51 using content::DownloadItem; | 52 using content::DownloadItem; |
52 using content::DownloadManager; | 53 using content::DownloadManager; |
53 using content::DownloadPersistentStoreInfo; | |
54 using content::WebContents; | 54 using content::WebContents; |
55 | 55 |
56 namespace { | 56 namespace { |
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 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 DownloadManager* GetDownloadManager() const { | 178 DownloadManager* GetDownloadManager() const { |
179 DownloadManager* download_manager = | 179 DownloadManager* download_manager = |
180 BrowserContext::GetDownloadManager(browser()->profile()); | 180 BrowserContext::GetDownloadManager(browser()->profile()); |
181 EXPECT_TRUE(download_manager); | 181 EXPECT_TRUE(download_manager); |
182 return download_manager; | 182 return download_manager; |
183 } | 183 } |
184 | 184 |
185 void QueryDownloadHistory() { | 185 void QueryDownloadHistory() { |
186 // Query the history system. | 186 // Query the history system. |
187 ChromeDownloadManagerDelegate* delegate = | 187 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
188 static_cast<ChromeDownloadManagerDelegate*>( | 188 browser()->profile(), Profile::EXPLICIT_ACCESS); |
189 GetDownloadManager()->GetDelegate()); | 189 hs->QueryDownloads(base::Bind( |
190 delegate->download_history()->Load( | 190 &SavePageBrowserTest::OnQueryDownloadEntriesComplete, |
191 base::Bind(&SavePageBrowserTest::OnQueryDownloadEntriesComplete, | 191 base::Unretained(this), |
192 base::Unretained(this))); | 192 MessageLoopForUI::current()->QuitClosure())); |
193 | 193 |
194 // Run message loop until a quit message is sent from | 194 // Run message loop until a quit message is sent from |
195 // OnQueryDownloadEntriesComplete(). | 195 // OnQueryDownloadEntriesComplete(). |
196 content::RunMessageLoop(); | 196 content::RunMessageLoop(); |
197 } | 197 } |
198 | 198 |
199 void OnQueryDownloadEntriesComplete( | 199 void OnQueryDownloadEntriesComplete( |
200 std::vector<DownloadPersistentStoreInfo>* entries) { | 200 const base::Closure& done_on_ui, |
201 history_entries_ = *entries; | 201 scoped_ptr<std::vector<DownloadPersistentStoreInfo> > entries) { |
202 | 202 history_entries_ = entries.Pass(); |
203 // Indicate thet we have received the history and can continue. | 203 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done_on_ui); |
204 MessageLoopForUI::current()->Quit(); | |
205 } | 204 } |
206 | 205 |
207 struct DownloadPersistentStoreInfoMatch | |
208 : public std::unary_function<DownloadPersistentStoreInfo, bool> { | |
209 | |
210 DownloadPersistentStoreInfoMatch(const GURL& url, | |
211 const FilePath& path, | |
212 int64 num_files) | |
213 : url_(url), | |
214 path_(path), | |
215 num_files_(num_files) { | |
216 } | |
217 | |
218 bool operator() (const DownloadPersistentStoreInfo& info) const { | |
219 return info.url == url_ && | |
220 info.path == path_ && | |
221 // For non-MHTML save packages, received_bytes is actually the | |
222 // number of files. | |
223 ((num_files_ < 0) || | |
224 (info.received_bytes == num_files_)) && | |
225 info.total_bytes == 0 && | |
226 info.state == DownloadItem::COMPLETE; | |
227 } | |
228 | |
229 GURL url_; | |
230 FilePath path_; | |
231 int64 num_files_; | |
232 }; | |
233 | |
234 void CheckDownloadHistory(const GURL& url, | 206 void CheckDownloadHistory(const GURL& url, |
235 const FilePath& path, | 207 const FilePath& path, |
236 int64 num_files) { | 208 int64 num_files, |
| 209 bool expect_found) { |
237 QueryDownloadHistory(); | 210 QueryDownloadHistory(); |
238 | 211 bool found = false; |
239 std::vector<DownloadPersistentStoreInfo>::iterator found = | 212 for (std::vector<DownloadPersistentStoreInfo>::iterator it = |
240 std::find_if(history_entries_.begin(), history_entries_.end(), | 213 history_entries_->begin(); |
241 DownloadPersistentStoreInfoMatch(url, path, num_files)); | 214 it != history_entries_->end(); ++it) { |
242 | 215 if (it->url != url) { |
243 if (found == history_entries_.end()) { | 216 LOG(WARNING) << it->url.spec() << " != " << url.spec(); |
244 LOG(ERROR) << "Missing url=" << url.spec() | 217 } else if (it->path != path) { |
245 << " path=" << path.value() | 218 LOG(WARNING) << it->path.value() << " != " << path.value(); |
246 << " received=" << num_files; | 219 } else if ((num_files >= 0) && |
247 for (size_t index = 0; index < history_entries_.size(); ++index) { | 220 (it->received_bytes != num_files)) { |
248 LOG(ERROR) << "History@" << index << ": url=" | 221 LOG(WARNING) << it->received_bytes << " != " << num_files; |
249 << history_entries_[index].url.spec() | 222 } else if ((num_files >= 0) && |
250 << " path=" << history_entries_[index].path.value() | 223 (it->total_bytes != num_files)) { |
251 << " received=" << history_entries_[index].received_bytes | 224 LOG(WARNING) << it->total_bytes << " != " << num_files; |
252 << " total=" << history_entries_[index].total_bytes | 225 } else if (it->state != DownloadItem::COMPLETE) { |
253 << " state=" << history_entries_[index].state; | 226 LOG(WARNING) << it->state << " != " << DownloadItem::COMPLETE; |
| 227 } else { |
| 228 found = true; |
| 229 break; |
254 } | 230 } |
255 EXPECT_TRUE(false); | |
256 } | 231 } |
| 232 EXPECT_EQ(found, expect_found); |
257 } | 233 } |
258 | 234 |
259 std::vector<DownloadPersistentStoreInfo> history_entries_; | 235 scoped_ptr<std::vector<DownloadPersistentStoreInfo> > history_entries_; |
260 | 236 |
261 // Path to directory containing test data. | 237 // Path to directory containing test data. |
262 FilePath test_dir_; | 238 FilePath test_dir_; |
263 | 239 |
264 // Temporary directory we will save pages to. | 240 // Temporary directory we will save pages to. |
265 ScopedTempDir save_dir_; | 241 ScopedTempDir save_dir_; |
266 | 242 |
267 private: | 243 private: |
268 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); | 244 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); |
269 }; | 245 }; |
270 | 246 |
271 SavePageBrowserTest::~SavePageBrowserTest() { | 247 SavePageBrowserTest::~SavePageBrowserTest() { |
272 } | 248 } |
273 | 249 |
274 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 250 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { |
275 GURL url = NavigateToMockURL("a"); | 251 GURL url = NavigateToMockURL("a"); |
276 | 252 |
277 FilePath full_file_name, dir; | 253 FilePath full_file_name, dir; |
278 GetDestinationPaths("a", &full_file_name, &dir); | 254 GetDestinationPaths("a", &full_file_name, &dir); |
279 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 255 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
280 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 256 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
281 | 257 |
282 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 258 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
283 | 259 |
284 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 260 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
285 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | 261 CheckDownloadHistory(url, full_file_name, 1, true); // a.htm is 1 file. |
286 | 262 |
287 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 263 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
288 EXPECT_FALSE(file_util::PathExists(dir)); | 264 EXPECT_FALSE(file_util::PathExists(dir)); |
289 EXPECT_TRUE(file_util::ContentsEqual( | 265 EXPECT_TRUE(file_util::ContentsEqual( |
290 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 266 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
291 full_file_name)); | 267 full_file_name)); |
292 } | 268 } |
293 | 269 |
294 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { | 270 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { |
295 GURL url = NavigateToMockURL("a"); | 271 GURL url = NavigateToMockURL("a"); |
296 DownloadManager* manager(GetDownloadManager()); | 272 DownloadManager* manager(GetDownloadManager()); |
297 std::vector<DownloadItem*> downloads; | 273 std::vector<DownloadItem*> downloads; |
298 manager->SearchDownloads(string16(), &downloads); | 274 manager->SearchDownloads(string16(), &downloads); |
299 ASSERT_EQ(0u, downloads.size()); | 275 ASSERT_EQ(0u, downloads.size()); |
300 | 276 |
301 FilePath full_file_name, dir; | 277 FilePath full_file_name, dir; |
302 GetDestinationPaths("a", &full_file_name, &dir); | 278 GetDestinationPaths("a", &full_file_name, &dir); |
303 DownloadItemCreatedObserver creation_observer(manager); | 279 DownloadItemCreatedObserver creation_observer(manager); |
304 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 280 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
305 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 281 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
306 DownloadItem* item = creation_observer.WaitForNewDownloadItem(); | 282 DownloadItem* item = creation_observer.WaitForNewDownloadItem(); |
307 item->Cancel(true); | 283 item->Cancel(true); |
308 | 284 |
309 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. | 285 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. |
310 // Currently it's ignored. | 286 // Currently it's ignored. |
311 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 287 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
312 | 288 |
313 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 289 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
314 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | 290 CheckDownloadHistory(url, full_file_name, 1, true); // a.htm is 1 file. |
315 | 291 |
316 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 292 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
317 EXPECT_FALSE(file_util::PathExists(dir)); | 293 EXPECT_FALSE(file_util::PathExists(dir)); |
318 EXPECT_TRUE(file_util::ContentsEqual( | 294 EXPECT_TRUE(file_util::ContentsEqual( |
319 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 295 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
320 full_file_name)); | 296 full_file_name)); |
321 } | 297 } |
322 | 298 |
323 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. | 299 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. |
324 // See http://crbug.com/144751. | 300 // See http://crbug.com/144751. |
(...skipping 28 matching lines...) Expand all Loading... |
353 ui_test_utils::NavigateToURL(browser(), view_source_url); | 329 ui_test_utils::NavigateToURL(browser(), view_source_url); |
354 | 330 |
355 FilePath full_file_name, dir; | 331 FilePath full_file_name, dir; |
356 GetDestinationPaths("a", &full_file_name, &dir); | 332 GetDestinationPaths("a", &full_file_name, &dir); |
357 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 333 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
358 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 334 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
359 | 335 |
360 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); | 336 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); |
361 | 337 |
362 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 338 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
363 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file. | 339 CheckDownloadHistory(actual_page_url, full_file_name, 1, true); |
364 | 340 |
365 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 341 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
366 EXPECT_FALSE(file_util::PathExists(dir)); | 342 EXPECT_FALSE(file_util::PathExists(dir)); |
367 EXPECT_TRUE(file_util::ContentsEqual( | 343 EXPECT_TRUE(file_util::ContentsEqual( |
368 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 344 test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
369 full_file_name)); | 345 full_file_name)); |
370 } | 346 } |
371 | 347 |
372 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 348 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
373 GURL url = NavigateToMockURL("b"); | 349 GURL url = NavigateToMockURL("b"); |
374 | 350 |
375 FilePath full_file_name, dir; | 351 FilePath full_file_name, dir; |
376 GetDestinationPaths("b", &full_file_name, &dir); | 352 GetDestinationPaths("b", &full_file_name, &dir); |
377 ASSERT_TRUE(GetCurrentTab()->SavePage( | 353 ASSERT_TRUE(GetCurrentTab()->SavePage( |
378 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 354 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
379 | 355 |
380 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 356 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
381 | 357 |
382 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 358 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
383 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. | 359 CheckDownloadHistory(url, full_file_name, 3, true); // b.htm is 3 files. |
384 | 360 |
385 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 361 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
386 EXPECT_TRUE(file_util::PathExists(dir)); | 362 EXPECT_TRUE(file_util::PathExists(dir)); |
387 EXPECT_TRUE(file_util::TextContentsEqual( | 363 EXPECT_TRUE(file_util::TextContentsEqual( |
388 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 364 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
389 full_file_name)); | 365 full_file_name)); |
390 EXPECT_TRUE(file_util::ContentsEqual( | 366 EXPECT_TRUE(file_util::ContentsEqual( |
391 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 367 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
392 dir.AppendASCII("1.png"))); | 368 dir.AppendASCII("1.png"))); |
393 EXPECT_TRUE(file_util::ContentsEqual( | 369 EXPECT_TRUE(file_util::ContentsEqual( |
(...skipping 12 matching lines...) Expand all Loading... |
406 FilePath full_file_name = save_dir_.path().AppendASCII( | 382 FilePath full_file_name = save_dir_.path().AppendASCII( |
407 std::string("Test page for saving page feature") + kAppendedExtension); | 383 std::string("Test page for saving page feature") + kAppendedExtension); |
408 FilePath dir = save_dir_.path().AppendASCII( | 384 FilePath dir = save_dir_.path().AppendASCII( |
409 "Test page for saving page feature_files"); | 385 "Test page for saving page feature_files"); |
410 ASSERT_TRUE(GetCurrentTab()->SavePage( | 386 ASSERT_TRUE(GetCurrentTab()->SavePage( |
411 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 387 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
412 | 388 |
413 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 389 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
414 | 390 |
415 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 391 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
416 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. | 392 CheckDownloadHistory(url, full_file_name, 3, true); // b.htm is 3 files. |
417 | 393 |
418 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 394 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
419 EXPECT_TRUE(file_util::PathExists(dir)); | 395 EXPECT_TRUE(file_util::PathExists(dir)); |
420 EXPECT_TRUE(file_util::TextContentsEqual( | 396 EXPECT_TRUE(file_util::TextContentsEqual( |
421 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 397 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
422 full_file_name)); | 398 full_file_name)); |
423 EXPECT_TRUE(file_util::ContentsEqual( | 399 EXPECT_TRUE(file_util::ContentsEqual( |
424 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 400 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
425 dir.AppendASCII("1.png"))); | 401 dir.AppendASCII("1.png"))); |
426 EXPECT_TRUE(file_util::ContentsEqual( | 402 EXPECT_TRUE(file_util::ContentsEqual( |
427 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 403 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
428 dir.AppendASCII("1.css"))); | 404 dir.AppendASCII("1.css"))); |
429 } | 405 } |
430 | 406 |
431 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { | 407 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { |
432 GURL url = NavigateToMockURL("a"); | 408 GURL url = NavigateToMockURL("a"); |
433 | 409 |
434 FilePath full_file_name, dir; | 410 FilePath full_file_name, dir; |
435 GetDestinationPaths("a", &full_file_name, &dir); | 411 GetDestinationPaths("a", &full_file_name, &dir); |
436 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 412 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
437 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 413 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
438 | 414 |
439 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 415 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
440 | 416 |
441 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 417 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
442 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | 418 CheckDownloadHistory(url, full_file_name, 1, true); // a.htm is 1 file. |
443 | 419 |
444 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); | 420 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); |
445 | 421 |
446 // Should not be in history. | 422 // Should not be in history. |
447 QueryDownloadHistory(); | 423 QueryDownloadHistory(); |
448 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), | 424 CheckDownloadHistory(url, full_file_name, 1, false); |
449 DownloadPersistentStoreInfoMatch(url, full_file_name, 1)), | |
450 history_entries_.end()); | |
451 | 425 |
452 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 426 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
453 EXPECT_FALSE(file_util::PathExists(dir)); | 427 EXPECT_FALSE(file_util::PathExists(dir)); |
454 EXPECT_TRUE(file_util::ContentsEqual( | 428 EXPECT_TRUE(file_util::ContentsEqual( |
455 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 429 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
456 full_file_name)); | 430 full_file_name)); |
457 } | 431 } |
458 | 432 |
459 // This tests that a webpage with the title "test.exe" is saved as | 433 // This tests that a webpage with the title "test.exe" is saved as |
460 // "test.exe.htm". | 434 // "test.exe.htm". |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 #if defined(OS_CHROMEOS) | 487 #if defined(OS_CHROMEOS) |
514 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | 488 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); |
515 #else | 489 #else |
516 SavePackageFilePicker::SetShouldPromptUser(false); | 490 SavePackageFilePicker::SetShouldPromptUser(false); |
517 #endif | 491 #endif |
518 content::WindowedNotificationObserver observer( | 492 content::WindowedNotificationObserver observer( |
519 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 493 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
520 content::NotificationService::AllSources()); | 494 content::NotificationService::AllSources()); |
521 chrome::SavePage(browser()); | 495 chrome::SavePage(browser()); |
522 observer.Wait(); | 496 observer.Wait(); |
523 CheckDownloadHistory(url, full_file_name, -1); | 497 CheckDownloadHistory(url, full_file_name, -1, true); |
524 | 498 |
525 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 499 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
526 int64 actual_file_size = -1; | 500 int64 actual_file_size = -1; |
527 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 501 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
528 EXPECT_LE(kFileSizeMin, actual_file_size); | 502 EXPECT_LE(kFileSizeMin, actual_file_size); |
529 } | 503 } |
OLD | NEW |