| 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 class DownloadPersistedObserver : public DownloadItem::Observer { | 
|  | 59  public: | 
|  | 60   DownloadPersistedObserver(DownloadItem* item) | 
|  | 61     : item_(item) { | 
|  | 62     item->AddObserver(this); | 
|  | 63   } | 
|  | 64 | 
|  | 65   ~DownloadPersistedObserver() { | 
|  | 66     if (item_) | 
|  | 67       item_->RemoveObserver(this); | 
|  | 68   } | 
|  | 69 | 
|  | 70   void WaitForPersisted() { | 
|  | 71     if (persisted_) | 
|  | 72       return; | 
|  | 73     waiting_ = true; | 
|  | 74     content::RunMessageLoop(); | 
|  | 75     waiting_ = false; | 
|  | 76   } | 
|  | 77 | 
|  | 78   virtual void OnDownloadDestroyed(DownloadItem* item) { | 
|  | 79     item_->RemoveObserver(this); | 
|  | 80     item_ = NULL; | 
|  | 81   } | 
|  | 82 | 
|  | 83   virtual void OnDownloadUpdated(DownloadItem* item) { | 
|  | 84     CHECK_EQ(item_, item); | 
|  | 85     persisted_ = true; | 
|  | 86     if (waiting_) | 
|  | 87       MessageLoopForUI::current()->Quit(); | 
|  | 88   } | 
|  | 89 | 
|  | 90  private: | 
|  | 91   DownloadItem* item_; | 
|  | 92   bool waiting_; | 
|  | 93   bool persisted_; | 
|  | 94   DISALLOW_COPY_AND_ASSIGN(DownloadPersistedObserver); | 
|  | 95 }; | 
|  | 96 | 
| 58 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); | 97 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); | 
| 59 | 98 | 
| 60 static const char* kAppendedExtension = | 99 static const char* kAppendedExtension = | 
| 61 #if defined(OS_WIN) | 100 #if defined(OS_WIN) | 
| 62     ".htm"; | 101     ".htm"; | 
| 63 #else | 102 #else | 
| 64     ".html"; | 103     ".html"; | 
| 65 #endif | 104 #endif | 
| 66 | 105 | 
| 67 }  // namespace | 106 }  // namespace | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 92 | 131 | 
| 93     if (!created_item_) { | 132     if (!created_item_) { | 
| 94       waiting_ = true; | 133       waiting_ = true; | 
| 95       content::RunMessageLoop(); | 134       content::RunMessageLoop(); | 
| 96       waiting_ = false; | 135       waiting_ = false; | 
| 97     } | 136     } | 
| 98     return created_item_; | 137     return created_item_; | 
| 99   } | 138   } | 
| 100 | 139 | 
| 101  private: | 140  private: | 
| 102 |  | 
| 103   // DownloadManager::Observer | 141   // DownloadManager::Observer | 
| 104   void OnDownloadCreated(DownloadManager* manager, DownloadItem* item) { | 142   void OnDownloadCreated(DownloadManager* manager, DownloadItem* item) { | 
| 105     DCHECK_EQ(manager, manager_); | 143     DCHECK_EQ(manager, manager_); | 
| 106     if (!created_item_) | 144     if (!created_item_) | 
| 107       created_item_ = item; | 145       created_item_ = item; | 
| 108 | 146 | 
| 109     if (waiting_) | 147     if (waiting_) | 
| 110       MessageLoopForUI::current()->Quit(); | 148       MessageLoopForUI::current()->Quit(); | 
| 111   } | 149   } | 
| 112 | 150 | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 177 | 215 | 
| 178   DownloadManager* GetDownloadManager() const { | 216   DownloadManager* GetDownloadManager() const { | 
| 179     DownloadManager* download_manager = | 217     DownloadManager* download_manager = | 
| 180         BrowserContext::GetDownloadManager(browser()->profile()); | 218         BrowserContext::GetDownloadManager(browser()->profile()); | 
| 181     EXPECT_TRUE(download_manager); | 219     EXPECT_TRUE(download_manager); | 
| 182     return download_manager; | 220     return download_manager; | 
| 183   } | 221   } | 
| 184 | 222 | 
| 185   void QueryDownloadHistory() { | 223   void QueryDownloadHistory() { | 
| 186     // Query the history system. | 224     // Query the history system. | 
| 187     ChromeDownloadManagerDelegate* delegate = | 225     HistoryService* hs = HistoryServiceFactory::GetForProfile( | 
| 188       static_cast<ChromeDownloadManagerDelegate*>( | 226         browser()->profile(), Profile::EXPLICIT_ACCESS); | 
| 189           GetDownloadManager()->GetDelegate()); | 227     hs->QueryDownloads(base::Bind( | 
| 190     delegate->download_history()->Load( | 228         &SavePageBrowserTest::OnQueryDownloadEntriesComplete, | 
| 191         base::Bind(&SavePageBrowserTest::OnQueryDownloadEntriesComplete, | 229         base::Unretained(this), | 
| 192                    base::Unretained(this))); | 230         MessageLoopForUI::current()->QuitClosure())); | 
| 193 | 231 | 
| 194     // Run message loop until a quit message is sent from | 232     // Run message loop until a quit message is sent from | 
| 195     // OnQueryDownloadEntriesComplete(). | 233     // OnQueryDownloadEntriesComplete(). | 
| 196     content::RunMessageLoop(); | 234     content::RunMessageLoop(); | 
| 197   } | 235   } | 
| 198 | 236 | 
| 199   void OnQueryDownloadEntriesComplete( | 237   void OnQueryDownloadEntriesComplete( | 
| 200       std::vector<DownloadPersistentStoreInfo>* entries) { | 238       const base::Closure& done_on_ui, | 
| 201     history_entries_ = *entries; | 239       scoped_ptr<std::vector<DownloadPersistentStoreInfo> > entries) { | 
| 202 | 240     history_entries_ = entries.Pass(); | 
| 203     // Indicate thet we have received the history and can continue. | 241     BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done_on_ui); | 
| 204     MessageLoopForUI::current()->Quit(); |  | 
| 205   } | 242   } | 
| 206 | 243 | 
| 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, | 244   void CheckDownloadHistory(const GURL& url, | 
| 235                             const FilePath& path, | 245                             const FilePath& path, | 
| 236                             int64 num_files) { | 246                             int64 num_files, | 
|  | 247                             bool expect_found) { | 
| 237     QueryDownloadHistory(); | 248     QueryDownloadHistory(); | 
| 238 | 249     bool found = false; | 
| 239     std::vector<DownloadPersistentStoreInfo>::iterator found = | 250     for (std::vector<DownloadPersistentStoreInfo>::iterator it = | 
| 240       std::find_if(history_entries_.begin(), history_entries_.end(), | 251          history_entries_->begin(); | 
| 241                    DownloadPersistentStoreInfoMatch(url, path, num_files)); | 252          it != history_entries_->end(); ++it) { | 
| 242 | 253       if (it->url != url) { | 
| 243     if (found == history_entries_.end()) { | 254         LOG(WARNING) << it->url.spec() << " != " << url.spec(); | 
| 244       LOG(ERROR) << "Missing url=" << url.spec() | 255       } else if (it->path != path) { | 
| 245                  << " path=" << path.value() | 256         LOG(WARNING) << it->path.value() << " != " << path.value(); | 
| 246                  << " received=" << num_files; | 257       } else if ((num_files >= 0) && | 
| 247       for (size_t index = 0; index < history_entries_.size(); ++index) { | 258           (it->received_bytes != num_files)) { | 
| 248         LOG(ERROR) << "History@" << index << ": url=" | 259         LOG(WARNING) << it->received_bytes << " != " << num_files; | 
| 249                    << history_entries_[index].url.spec() | 260       } else if ((num_files >= 0) && | 
| 250                    << " path=" << history_entries_[index].path.value() | 261           (it->total_bytes != num_files)) { | 
| 251                    << " received=" << history_entries_[index].received_bytes | 262         LOG(WARNING) << it->total_bytes << " != " << num_files; | 
| 252                    << " total=" << history_entries_[index].total_bytes | 263       } else if (it->state != DownloadItem::COMPLETE) { | 
| 253                    << " state=" << history_entries_[index].state; | 264         LOG(WARNING) << it->state << " != " << DownloadItem::COMPLETE; | 
|  | 265       } else { | 
|  | 266         found = true; | 
|  | 267         break; | 
| 254       } | 268       } | 
| 255       EXPECT_TRUE(false); |  | 
| 256     } | 269     } | 
|  | 270     EXPECT_EQ(found, expect_found); | 
| 257   } | 271   } | 
| 258 | 272 | 
| 259   std::vector<DownloadPersistentStoreInfo> history_entries_; | 273   scoped_ptr<std::vector<DownloadPersistentStoreInfo> > history_entries_; | 
| 260 | 274 | 
| 261   // Path to directory containing test data. | 275   // Path to directory containing test data. | 
| 262   FilePath test_dir_; | 276   FilePath test_dir_; | 
| 263 | 277 | 
| 264   // Temporary directory we will save pages to. | 278   // Temporary directory we will save pages to. | 
| 265   ScopedTempDir save_dir_; | 279   ScopedTempDir save_dir_; | 
| 266 | 280 | 
| 267  private: | 281  private: | 
| 268   DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); | 282   DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); | 
| 269 }; | 283 }; | 
| 270 | 284 | 
| 271 SavePageBrowserTest::~SavePageBrowserTest() { | 285 SavePageBrowserTest::~SavePageBrowserTest() { | 
| 272 } | 286 } | 
| 273 | 287 | 
| 274 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 288 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 
| 275   GURL url = NavigateToMockURL("a"); | 289   GURL url = NavigateToMockURL("a"); | 
| 276 | 290 | 
| 277   FilePath full_file_name, dir; | 291   FilePath full_file_name, dir; | 
| 278   GetDestinationPaths("a", &full_file_name, &dir); | 292   GetDestinationPaths("a", &full_file_name, &dir); | 
| 279   ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 293   ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 
| 280                                         content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 294                                         content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 
| 281 | 295 | 
| 282   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 296   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 
| 283 | 297 | 
| 284   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 298   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 
| 285   CheckDownloadHistory(url, full_file_name, 1);  // a.htm is 1 file. | 299   CheckDownloadHistory(url, full_file_name, 1, true);  // a.htm is 1 file. | 
| 286 | 300 | 
| 287   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 301   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 
| 288   EXPECT_FALSE(file_util::PathExists(dir)); | 302   EXPECT_FALSE(file_util::PathExists(dir)); | 
| 289   EXPECT_TRUE(file_util::ContentsEqual( | 303   EXPECT_TRUE(file_util::ContentsEqual( | 
| 290       test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 304       test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 
| 291       full_file_name)); | 305       full_file_name)); | 
| 292 } | 306 } | 
| 293 | 307 | 
| 294 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { | 308 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { | 
| 295   GURL url = NavigateToMockURL("a"); | 309   GURL url = NavigateToMockURL("a"); | 
| 296   DownloadManager* manager(GetDownloadManager()); | 310   DownloadManager* manager(GetDownloadManager()); | 
| 297   std::vector<DownloadItem*> downloads; | 311   std::vector<DownloadItem*> downloads; | 
| 298   manager->SearchDownloads(string16(), &downloads); | 312   manager->SearchDownloads(string16(), &downloads); | 
| 299   ASSERT_EQ(0u, downloads.size()); | 313   ASSERT_EQ(0u, downloads.size()); | 
| 300 | 314 | 
| 301   FilePath full_file_name, dir; | 315   FilePath full_file_name, dir; | 
| 302   GetDestinationPaths("a", &full_file_name, &dir); | 316   GetDestinationPaths("a", &full_file_name, &dir); | 
| 303   DownloadItemCreatedObserver creation_observer(manager); | 317   DownloadItemCreatedObserver creation_observer(manager); | 
| 304   ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 318   ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 
| 305                                         content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 319                                         content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 
| 306   DownloadItem* item = creation_observer.WaitForNewDownloadItem(); | 320   DownloadItem* item = creation_observer.WaitForNewDownloadItem(); | 
| 307   item->Cancel(true); | 321   item->Cancel(true); | 
| 308 | 322 | 
| 309   // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. | 323   // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. | 
| 310   // Currently it's ignored. | 324   // Currently it's ignored. | 
| 311   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 325   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 
| 312 | 326 | 
| 313   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 327   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 
| 314   CheckDownloadHistory(url, full_file_name, 1);  // a.htm is 1 file. | 328   CheckDownloadHistory(url, full_file_name, 1, true);  // a.htm is 1 file. | 
| 315 | 329 | 
| 316   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 330   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 
| 317   EXPECT_FALSE(file_util::PathExists(dir)); | 331   EXPECT_FALSE(file_util::PathExists(dir)); | 
| 318   EXPECT_TRUE(file_util::ContentsEqual( | 332   EXPECT_TRUE(file_util::ContentsEqual( | 
| 319       test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 333       test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 
| 320       full_file_name)); | 334       full_file_name)); | 
| 321 } | 335 } | 
| 322 | 336 | 
| 323 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. | 337 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. | 
| 324 // See http://crbug.com/144751. | 338 // See http://crbug.com/144751. | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 353   ui_test_utils::NavigateToURL(browser(), view_source_url); | 367   ui_test_utils::NavigateToURL(browser(), view_source_url); | 
| 354 | 368 | 
| 355   FilePath full_file_name, dir; | 369   FilePath full_file_name, dir; | 
| 356   GetDestinationPaths("a", &full_file_name, &dir); | 370   GetDestinationPaths("a", &full_file_name, &dir); | 
| 357   ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 371   ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 
| 358                                         content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 372                                         content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 
| 359 | 373 | 
| 360   EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); | 374   EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); | 
| 361 | 375 | 
| 362   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 376   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 
| 363   CheckDownloadHistory(actual_page_url, full_file_name, 1);  // a.htm is 1 file. | 377   CheckDownloadHistory(actual_page_url, full_file_name, 1, true); | 
| 364 | 378 | 
| 365   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 379   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 
| 366   EXPECT_FALSE(file_util::PathExists(dir)); | 380   EXPECT_FALSE(file_util::PathExists(dir)); | 
| 367   EXPECT_TRUE(file_util::ContentsEqual( | 381   EXPECT_TRUE(file_util::ContentsEqual( | 
| 368       test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 382       test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 
| 369       full_file_name)); | 383       full_file_name)); | 
| 370 } | 384 } | 
| 371 | 385 | 
| 372 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 386 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 
| 373   GURL url = NavigateToMockURL("b"); | 387   GURL url = NavigateToMockURL("b"); | 
| 374 | 388 | 
| 375   FilePath full_file_name, dir; | 389   FilePath full_file_name, dir; | 
| 376   GetDestinationPaths("b", &full_file_name, &dir); | 390   GetDestinationPaths("b", &full_file_name, &dir); | 
| 377   ASSERT_TRUE(GetCurrentTab()->SavePage( | 391   ASSERT_TRUE(GetCurrentTab()->SavePage( | 
| 378       full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 392       full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 
| 379 | 393 | 
| 380   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 394   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 
| 381 | 395 | 
| 382   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 396   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 
| 383   CheckDownloadHistory(url, full_file_name, 3);  // b.htm is 3 files. | 397   CheckDownloadHistory(url, full_file_name, 3, true);  // b.htm is 3 files. | 
| 384 | 398 | 
| 385   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 399   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 
| 386   EXPECT_TRUE(file_util::PathExists(dir)); | 400   EXPECT_TRUE(file_util::PathExists(dir)); | 
| 387   EXPECT_TRUE(file_util::TextContentsEqual( | 401   EXPECT_TRUE(file_util::TextContentsEqual( | 
| 388       test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 402       test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 
| 389       full_file_name)); | 403       full_file_name)); | 
| 390   EXPECT_TRUE(file_util::ContentsEqual( | 404   EXPECT_TRUE(file_util::ContentsEqual( | 
| 391       test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 405       test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 
| 392       dir.AppendASCII("1.png"))); | 406       dir.AppendASCII("1.png"))); | 
| 393   EXPECT_TRUE(file_util::ContentsEqual( | 407   EXPECT_TRUE(file_util::ContentsEqual( | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 406   FilePath full_file_name = save_dir_.path().AppendASCII( | 420   FilePath full_file_name = save_dir_.path().AppendASCII( | 
| 407       std::string("Test page for saving page feature") + kAppendedExtension); | 421       std::string("Test page for saving page feature") + kAppendedExtension); | 
| 408   FilePath dir = save_dir_.path().AppendASCII( | 422   FilePath dir = save_dir_.path().AppendASCII( | 
| 409       "Test page for saving page feature_files"); | 423       "Test page for saving page feature_files"); | 
| 410   ASSERT_TRUE(GetCurrentTab()->SavePage( | 424   ASSERT_TRUE(GetCurrentTab()->SavePage( | 
| 411       full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 425       full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 
| 412 | 426 | 
| 413   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 427   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 
| 414 | 428 | 
| 415   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 429   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 
| 416   CheckDownloadHistory(url, full_file_name, 3);  // b.htm is 3 files. | 430   CheckDownloadHistory(url, full_file_name, 3, true);  // b.htm is 3 files. | 
| 417 | 431 | 
| 418   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 432   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 
| 419   EXPECT_TRUE(file_util::PathExists(dir)); | 433   EXPECT_TRUE(file_util::PathExists(dir)); | 
| 420   EXPECT_TRUE(file_util::TextContentsEqual( | 434   EXPECT_TRUE(file_util::TextContentsEqual( | 
| 421       test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 435       test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 
| 422       full_file_name)); | 436       full_file_name)); | 
| 423   EXPECT_TRUE(file_util::ContentsEqual( | 437   EXPECT_TRUE(file_util::ContentsEqual( | 
| 424       test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 438       test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 
| 425       dir.AppendASCII("1.png"))); | 439       dir.AppendASCII("1.png"))); | 
| 426   EXPECT_TRUE(file_util::ContentsEqual( | 440   EXPECT_TRUE(file_util::ContentsEqual( | 
| 427       test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 441       test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 
| 428       dir.AppendASCII("1.css"))); | 442       dir.AppendASCII("1.css"))); | 
| 429 } | 443 } | 
| 430 | 444 | 
| 431 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { | 445 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { | 
| 432   GURL url = NavigateToMockURL("a"); | 446   GURL url = NavigateToMockURL("a"); | 
| 433 | 447 | 
| 434   FilePath full_file_name, dir; | 448   FilePath full_file_name, dir; | 
| 435   GetDestinationPaths("a", &full_file_name, &dir); | 449   GetDestinationPaths("a", &full_file_name, &dir); | 
| 436   ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 450   ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 
| 437                                         content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 451                                         content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 
| 438 | 452 | 
| 439   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 453   EXPECT_EQ(url, WaitForSavePackageToFinish()); | 
| 440 | 454 | 
| 441   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 455   EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 
| 442   CheckDownloadHistory(url, full_file_name, 1);  // a.htm is 1 file. | 456   CheckDownloadHistory(url, full_file_name, 1, true);  // a.htm is 1 file. | 
| 443 | 457 | 
| 444   EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); | 458   EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); | 
| 445 | 459 | 
| 446   // Should not be in history. | 460   // Should not be in history. | 
| 447   QueryDownloadHistory(); | 461   QueryDownloadHistory(); | 
| 448   EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), | 462   CheckDownloadHistory(url, full_file_name, 1, false); | 
| 449       DownloadPersistentStoreInfoMatch(url, full_file_name, 1)), |  | 
| 450       history_entries_.end()); |  | 
| 451 | 463 | 
| 452   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 464   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 
| 453   EXPECT_FALSE(file_util::PathExists(dir)); | 465   EXPECT_FALSE(file_util::PathExists(dir)); | 
| 454   EXPECT_TRUE(file_util::ContentsEqual( | 466   EXPECT_TRUE(file_util::ContentsEqual( | 
| 455       test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 467       test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 
| 456       full_file_name)); | 468       full_file_name)); | 
| 457 } | 469 } | 
| 458 | 470 | 
| 459 // This tests that a webpage with the title "test.exe" is saved as | 471 // This tests that a webpage with the title "test.exe" is saved as | 
| 460 // "test.exe.htm". | 472 // "test.exe.htm". | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 513 #if defined(OS_CHROMEOS) | 525 #if defined(OS_CHROMEOS) | 
| 514   SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | 526   SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | 
| 515 #else | 527 #else | 
| 516   SavePackageFilePicker::SetShouldPromptUser(false); | 528   SavePackageFilePicker::SetShouldPromptUser(false); | 
| 517 #endif | 529 #endif | 
| 518   content::WindowedNotificationObserver observer( | 530   content::WindowedNotificationObserver observer( | 
| 519         content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 531         content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 
| 520         content::NotificationService::AllSources()); | 532         content::NotificationService::AllSources()); | 
| 521   chrome::SavePage(browser()); | 533   chrome::SavePage(browser()); | 
| 522   observer.Wait(); | 534   observer.Wait(); | 
| 523   CheckDownloadHistory(url, full_file_name, -1); | 535   CheckDownloadHistory(url, full_file_name, -1, true); | 
| 524 | 536 | 
| 525   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 537   EXPECT_TRUE(file_util::PathExists(full_file_name)); | 
| 526   int64 actual_file_size = -1; | 538   int64 actual_file_size = -1; | 
| 527   EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 539   EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 
| 528   EXPECT_LE(kFileSizeMin, actual_file_size); | 540   EXPECT_LE(kFileSizeMin, actual_file_size); | 
| 529 } | 541 } | 
| OLD | NEW | 
|---|