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