Chromium Code Reviews| 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" | |
| 20 #include "chrome/browser/net/url_request_mock_util.h" | 21 #include "chrome/browser/net/url_request_mock_util.h" |
| 21 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
| 25 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
| 26 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 31 #include "chrome/test/base/in_process_browser_test.h" | 32 #include "chrome/test/base/in_process_browser_test.h" |
| 32 #include "chrome/test/base/ui_test_utils.h" | 33 #include "chrome/test/base/ui_test_utils.h" |
| 33 #include "content/public/browser/download_item.h" | 34 #include "content/public/browser/download_item.h" |
| 34 #include "content/public/browser/download_manager.h" | 35 #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" | 36 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/notification_types.h" | 37 #include "content/public/browser/notification_types.h" |
| 38 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
| 39 #include "content/public/test/test_utils.h" | 39 #include "content/public/test/test_utils.h" |
| 40 #include "content/test/net/url_request_mock_http_job.h" | 40 #include "content/test/net/url_request_mock_http_job.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 42 |
| 43 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
| 44 #include "chrome/browser/download/save_package_file_picker_chromeos.h" | 44 #include "chrome/browser/download/save_package_file_picker_chromeos.h" |
| 45 #else | 45 #else |
| 46 #include "chrome/browser/download/save_package_file_picker.h" | 46 #include "chrome/browser/download/save_package_file_picker.h" |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 using content::BrowserContext; | 49 using content::BrowserContext; |
| 50 using content::BrowserThread; | 50 using content::BrowserThread; |
| 51 using content::DownloadItem; | 51 using content::DownloadItem; |
| 52 using content::DownloadManager; | 52 using content::DownloadManager; |
| 53 using content::DownloadPersistentStoreInfo; | |
| 54 using content::URLRequestMockHTTPJob; | 53 using content::URLRequestMockHTTPJob; |
| 55 using content::WebContents; | 54 using content::WebContents; |
| 56 | 55 |
| 56 class DownloadPersistedObserver : public DownloadHistory::Observer { | |
|
Randy Smith (Not in Mondays)
2012/11/09 21:36:39
A sentence or two in a comment about how to use th
benjhayden
2012/11/12 18:44:16
Done.
| |
| 57 public: | |
| 58 typedef base::Callback<bool( | |
| 59 DownloadItem* item, | |
| 60 const DownloadPersistentStoreInfo&)> PersistedFilter; | |
| 61 | |
| 62 DownloadPersistedObserver(Profile* profile, const PersistedFilter& filter) | |
| 63 : profile_(profile), | |
| 64 filter_(filter) { | |
| 65 DownloadServiceFactory::GetForProfile(profile_)-> | |
| 66 GetDownloadHistory()->AddObserver(this); | |
| 67 } | |
| 68 | |
| 69 virtual ~DownloadPersistedObserver() { | |
| 70 DownloadService* service = DownloadServiceFactory::GetForProfile(profile_); | |
| 71 if (service && service->GetDownloadManagerDelegate()) | |
|
Randy Smith (Not in Mondays)
2012/11/09 21:36:39
Why is the download manager delegate relevant?
benjhayden
2012/11/12 18:44:16
Done.
| |
| 72 service->GetDownloadHistory()->RemoveObserver(this); | |
| 73 } | |
| 74 | |
| 75 bool WaitForPersisted() { | |
| 76 if (persisted_) | |
| 77 return true; | |
| 78 waiting_ = true; | |
| 79 content::RunMessageLoop(); | |
| 80 waiting_ = false; | |
| 81 return persisted_; | |
| 82 } | |
| 83 | |
| 84 virtual void OnDownloadStored(DownloadItem* item, | |
| 85 const DownloadPersistentStoreInfo& info) { | |
| 86 persisted_ = filter_.Run(item, info); | |
| 87 if (persisted_ && waiting_) | |
| 88 MessageLoopForUI::current()->Quit(); | |
| 89 } | |
| 90 | |
| 91 private: | |
| 92 Profile* profile_; | |
| 93 DownloadItem* item_; | |
| 94 PersistedFilter filter_; | |
| 95 bool waiting_; | |
| 96 bool persisted_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(DownloadPersistedObserver); | |
| 99 }; | |
| 100 | |
| 101 class DownloadRemovedObserver : public DownloadPersistedObserver { | |
| 102 public: | |
| 103 DownloadRemovedObserver(Profile* profile, int32 download_id) | |
| 104 : DownloadPersistedObserver(profile, PersistedFilter()), | |
| 105 removed_(false), | |
| 106 waiting_(false), | |
| 107 download_id_(download_id) { | |
| 108 } | |
| 109 virtual ~DownloadRemovedObserver() {} | |
| 110 | |
| 111 bool WaitForRemoved() { | |
| 112 if (removed_) | |
| 113 return true; | |
| 114 waiting_ = true; | |
| 115 content::RunMessageLoop(); | |
| 116 waiting_ = false; | |
| 117 return removed_; | |
| 118 } | |
| 119 | |
| 120 virtual void OnDownloadStored(DownloadItem* item, | |
| 121 const DownloadPersistentStoreInfo& info) { | |
| 122 } | |
| 123 | |
| 124 virtual void OnDownloadsRemoved(const DownloadHistory::IdSet& ids) { | |
| 125 removed_ = ids.find(download_id_) != ids.end(); | |
| 126 if (removed_ && waiting_) | |
| 127 MessageLoopForUI::current()->Quit(); | |
| 128 } | |
| 129 | |
| 130 private: | |
| 131 bool removed_; | |
| 132 bool waiting_; | |
| 133 int32 download_id_; | |
| 134 | |
| 135 DISALLOW_COPY_AND_ASSIGN(DownloadRemovedObserver); | |
| 136 }; | |
| 137 | |
| 138 bool DownloadStoredProperly( | |
| 139 const GURL& expected_url, | |
| 140 const FilePath& expected_path, | |
| 141 int64 num_files, | |
| 142 DownloadItem::DownloadState expected_state, | |
| 143 DownloadItem* item, | |
| 144 const DownloadPersistentStoreInfo& info) { | |
| 145 if (info.path != expected_path) { | |
|
Randy Smith (Not in Mondays)
2012/11/09 21:36:39
Why not EXPECT_EQ? Seems more in line with how te
benjhayden
2012/11/12 18:44:16
DownloadStoredProperly may be called multiple time
Randy Smith (Not in Mondays)
2012/11/12 19:24:30
Whoops--good point.
| |
| 146 LOG(ERROR) << __FUNCTION__ << " " << info.path.value() | |
| 147 << " != " << expected_path.value(); | |
| 148 return false; | |
| 149 } | |
| 150 if (info.url != expected_url) { | |
| 151 LOG(ERROR) << __FUNCTION__ << " " << info.url.spec() | |
| 152 << " != " << expected_url.spec(); | |
| 153 return false; | |
| 154 } | |
| 155 if ((num_files >= 0) && (info.received_bytes != num_files)) { | |
| 156 LOG(ERROR) << __FUNCTION__ << " " << num_files | |
| 157 << " != " << info.received_bytes; | |
| 158 return false; | |
| 159 } | |
| 160 if (info.state != expected_state) { | |
| 161 LOG(ERROR) << __FUNCTION__ << " " << info.state | |
| 162 << " != " << expected_state; | |
| 163 return false; | |
| 164 } | |
| 165 return true; | |
| 166 } | |
| 167 | |
| 57 const FilePath::CharType kTestDir[] = FILE_PATH_LITERAL("save_page"); | 168 const FilePath::CharType kTestDir[] = FILE_PATH_LITERAL("save_page"); |
| 58 | 169 |
| 59 const char kAppendedExtension[] = | 170 static const char kAppendedExtension[] = |
| 60 #if defined(OS_WIN) | 171 #if defined(OS_WIN) |
| 61 ".htm"; | 172 ".htm"; |
| 62 #else | 173 #else |
| 63 ".html"; | 174 ".html"; |
| 64 #endif | 175 #endif |
| 65 | 176 |
| 66 // Loosely based on logic in DownloadTestObserver. | 177 // Loosely based on logic in DownloadTestObserver. |
| 67 class DownloadItemCreatedObserver : public DownloadManager::Observer { | 178 class DownloadItemCreatedObserver : public DownloadManager::Observer { |
| 68 public: | 179 public: |
| 69 explicit DownloadItemCreatedObserver(DownloadManager* manager) | 180 explicit DownloadItemCreatedObserver(DownloadManager* manager) |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 92 waiting_ = true; | 203 waiting_ = true; |
| 93 content::RunMessageLoop(); | 204 content::RunMessageLoop(); |
| 94 waiting_ = false; | 205 waiting_ = false; |
| 95 } | 206 } |
| 96 | 207 |
| 97 *items_seen = items_seen_; | 208 *items_seen = items_seen_; |
| 98 return; | 209 return; |
| 99 } | 210 } |
| 100 | 211 |
| 101 private: | 212 private: |
| 102 | |
| 103 // DownloadManager::Observer | 213 // DownloadManager::Observer |
| 104 virtual void OnDownloadCreated( | 214 virtual void OnDownloadCreated( |
| 105 DownloadManager* manager, DownloadItem* item) OVERRIDE { | 215 DownloadManager* manager, DownloadItem* item) OVERRIDE { |
| 106 DCHECK_EQ(manager, manager_); | 216 DCHECK_EQ(manager, manager_); |
| 107 items_seen_.push_back(item); | 217 items_seen_.push_back(item); |
| 108 | 218 |
| 109 if (waiting_) | 219 if (waiting_) |
| 110 MessageLoopForUI::current()->Quit(); | 220 MessageLoopForUI::current()->Quit(); |
| 111 } | 221 } |
| 112 | 222 |
| 113 virtual void ManagerGoingDown(DownloadManager* manager) OVERRIDE { | 223 virtual void ManagerGoingDown(DownloadManager* manager) OVERRIDE { |
| 114 manager_->RemoveObserver(this); | 224 manager_->RemoveObserver(this); |
| 115 manager_ = NULL; | 225 manager_ = NULL; |
| 116 if (waiting_) | 226 if (waiting_) |
| 117 MessageLoopForUI::current()->Quit(); | 227 MessageLoopForUI::current()->Quit(); |
| 118 } | 228 } |
| 119 | 229 |
| 120 bool waiting_; | 230 bool waiting_; |
| 121 DownloadManager* manager_; | 231 DownloadManager* manager_; |
| 122 std::vector<DownloadItem*> items_seen_; | 232 std::vector<DownloadItem*> items_seen_; |
| 123 | 233 |
| 124 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); | 234 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); |
| 125 }; | 235 }; |
| 126 | 236 |
| 127 class DownloadPersistedObserver : public DownloadItem::Observer { | |
| 128 public: | |
| 129 explicit DownloadPersistedObserver(DownloadItem* item) | |
| 130 : waiting_(false), item_(item) { | |
| 131 item->AddObserver(this); | |
| 132 } | |
| 133 | |
| 134 ~DownloadPersistedObserver() { | |
| 135 if (item_) | |
| 136 item_->RemoveObserver(this); | |
| 137 } | |
| 138 | |
| 139 // Wait for download item to get the persisted bit set. | |
| 140 // Note that this class provides no protection against the download | |
| 141 // being destroyed between creation and return of WaitForPersisted(); | |
| 142 // the caller must guarantee that in some other fashion. | |
| 143 void WaitForPersisted() { | |
| 144 // In combination with OnDownloadDestroyed() below, verify the | |
| 145 // above interface contract. | |
| 146 DCHECK(item_); | |
| 147 | |
| 148 if (item_->IsPersisted()) | |
| 149 return; | |
| 150 | |
| 151 waiting_ = true; | |
| 152 content::RunMessageLoop(); | |
| 153 waiting_ = false; | |
| 154 | |
| 155 return; | |
| 156 } | |
| 157 | |
| 158 private: | |
| 159 // DownloadItem::Observer | |
| 160 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE { | |
| 161 DCHECK_EQ(item, item_); | |
| 162 | |
| 163 if (waiting_ && item->IsPersisted()) | |
| 164 MessageLoopForUI::current()->Quit(); | |
| 165 } | |
| 166 | |
| 167 virtual void OnDownloadDestroyed(DownloadItem* item) OVERRIDE { | |
| 168 if (item != item_) | |
| 169 return; | |
| 170 | |
| 171 item_->RemoveObserver(this); | |
| 172 item_ = NULL; | |
| 173 } | |
| 174 | |
| 175 bool waiting_; | |
| 176 DownloadItem* item_; | |
| 177 | |
| 178 DISALLOW_COPY_AND_ASSIGN(DownloadPersistedObserver); | |
| 179 }; | |
| 180 | |
| 181 class SavePageBrowserTest : public InProcessBrowserTest { | 237 class SavePageBrowserTest : public InProcessBrowserTest { |
| 182 public: | 238 public: |
| 183 SavePageBrowserTest() {} | 239 SavePageBrowserTest() {} |
| 184 virtual ~SavePageBrowserTest(); | 240 virtual ~SavePageBrowserTest(); |
| 185 | 241 |
| 186 protected: | 242 protected: |
| 187 void SetUp() OVERRIDE { | 243 void SetUp() OVERRIDE { |
| 188 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); | 244 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); |
| 189 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); | 245 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); |
| 190 InProcessBrowserTest::SetUp(); | 246 InProcessBrowserTest::SetUp(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 212 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); | 268 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); |
| 213 *dir = save_dir_.path().AppendASCII(prefix + "_files"); | 269 *dir = save_dir_.path().AppendASCII(prefix + "_files"); |
| 214 } | 270 } |
| 215 | 271 |
| 216 WebContents* GetCurrentTab(Browser* browser) const { | 272 WebContents* GetCurrentTab(Browser* browser) const { |
| 217 WebContents* current_tab = chrome::GetActiveWebContents(browser); | 273 WebContents* current_tab = chrome::GetActiveWebContents(browser); |
| 218 EXPECT_TRUE(current_tab); | 274 EXPECT_TRUE(current_tab); |
| 219 return current_tab; | 275 return current_tab; |
| 220 } | 276 } |
| 221 | 277 |
| 222 bool WaitForSavePackageToFinish(Browser* browser, GURL* url_at_finish) const { | 278 // Returns true if and when there was a single download created, and its url |
| 279 // is |expected_url|. | |
|
Randy Smith (Not in Mondays)
2012/11/09 21:36:39
This doesn't feel like an accurate description. "
benjhayden
2012/11/12 18:44:16
Done.
| |
| 280 bool WaitForSavePackageToFinish( | |
| 281 Browser* browser, | |
| 282 const GURL& expected_url, | |
| 283 const DownloadPersistedObserver::PersistedFilter& filter) const { | |
| 223 content::WindowedNotificationObserver observer( | 284 content::WindowedNotificationObserver observer( |
| 224 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 285 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
| 225 content::NotificationService::AllSources()); | 286 content::NotificationService::AllSources()); |
| 226 observer.Wait(); | 287 observer.Wait(); |
| 227 | 288 |
| 228 // Generally, there should only be one download item created | 289 // Generally, there should only be one download item created |
| 229 // in all of these tests. If it's already here, grab it; if not, | 290 // in all of these tests. If it's already here, grab it; if not, |
| 230 // wait for it to show up. | 291 // wait for it to show up. |
| 231 std::vector<DownloadItem*> items; | 292 std::vector<DownloadItem*> items; |
| 232 DownloadManager* manager( | 293 DownloadManager* manager( |
| 233 BrowserContext::GetDownloadManager(browser->profile())); | 294 BrowserContext::GetDownloadManager(browser->profile())); |
| 234 manager->GetAllDownloads(&items); | 295 manager->GetAllDownloads(&items); |
| 235 if (items.size() == 0u) { | 296 if (items.size() == 0u) { |
| 236 DownloadItemCreatedObserver(manager).WaitForDownloadItem(&items); | 297 DownloadItemCreatedObserver(manager).WaitForDownloadItem(&items); |
| 237 } | 298 } |
| 238 | 299 |
| 239 EXPECT_EQ(1u, items.size()); | 300 EXPECT_EQ(1u, items.size()); |
| 240 if (1u != items.size()) | 301 if (1u != items.size()) |
| 241 return false; | 302 return false; |
| 242 DownloadItem* download_item(items[0]); | 303 DownloadItem* download_item(items[0]); |
| 243 | 304 |
| 244 // Note on synchronization: | 305 if (!filter.is_null() && !DownloadHistory::IsPersisted(download_item)) |
| 245 // | 306 DownloadPersistedObserver(browser->profile(), filter).WaitForPersisted(); |
|
Randy Smith (Not in Mondays)
2012/11/09 21:36:39
This feels ... wrong to me. Specifically, the beh
benjhayden
2012/11/12 18:44:16
Done.
| |
| 246 // For each Save Page As operation, we create a corresponding shell | |
| 247 // DownloadItem to display progress to the user. That DownloadItem | |
| 248 // goes through its own state transitions, including being persisted | |
| 249 // out to the history database, and the download shelf is not shown | |
| 250 // until after the persistence occurs. Save Package completion (and | |
| 251 // marking the DownloadItem as completed) occurs asynchronously from | |
| 252 // persistence. Thus if we want to examine either UI state or DB | |
| 253 // state, we need to wait until both the save package operation is | |
| 254 // complete and the relevant download item has been persisted. | |
| 255 DownloadPersistedObserver(download_item).WaitForPersisted(); | |
| 256 | 307 |
| 257 *url_at_finish = content::Details<DownloadItem>(observer.details()).ptr()-> | 308 return ((expected_url == download_item->GetOriginalUrl()) && |
| 258 GetOriginalUrl(); | 309 (expected_url == content::Details<DownloadItem>( |
| 259 return true; | 310 observer.details()).ptr()->GetOriginalUrl())); |
| 260 } | 311 } |
| 261 | 312 |
| 313 // Note on synchronization: | |
| 314 // | |
| 315 // For each Save Page As operation, we create a corresponding shell | |
| 316 // DownloadItem to display progress to the user. That DownloadItem goes | |
| 317 // through its own state transitions, including being persisted out to the | |
| 318 // history database, and the download shelf is not shown until after the | |
| 319 // persistence occurs. Save Package completion (and marking the DownloadItem | |
| 320 // as completed) occurs asynchronously from persistence. Thus if we want to | |
| 321 // examine either UI state or DB state, we need to wait until both the save | |
| 322 // package operation is complete and the relevant download item has been | |
| 323 // persisted. | |
| 324 | |
| 262 DownloadManager* GetDownloadManager() const { | 325 DownloadManager* GetDownloadManager() const { |
| 263 DownloadManager* download_manager = | 326 DownloadManager* download_manager = |
| 264 BrowserContext::GetDownloadManager(browser()->profile()); | 327 BrowserContext::GetDownloadManager(browser()->profile()); |
| 265 EXPECT_TRUE(download_manager); | 328 EXPECT_TRUE(download_manager); |
| 266 return download_manager; | 329 return download_manager; |
| 267 } | 330 } |
| 268 | 331 |
| 269 void QueryDownloadHistory() { | |
| 270 // Query the history system. | |
| 271 ChromeDownloadManagerDelegate* delegate = | |
| 272 static_cast<ChromeDownloadManagerDelegate*>( | |
| 273 GetDownloadManager()->GetDelegate()); | |
| 274 delegate->download_history()->Load( | |
| 275 base::Bind(&SavePageBrowserTest::OnQueryDownloadEntriesComplete, | |
| 276 base::Unretained(this))); | |
| 277 | |
| 278 // Run message loop until a quit message is sent from | |
| 279 // OnQueryDownloadEntriesComplete(). | |
| 280 content::RunMessageLoop(); | |
| 281 } | |
| 282 | |
| 283 void OnQueryDownloadEntriesComplete( | |
| 284 std::vector<DownloadPersistentStoreInfo>* entries) { | |
| 285 history_entries_ = *entries; | |
| 286 | |
| 287 // Indicate thet we have received the history and can continue. | |
| 288 MessageLoopForUI::current()->Quit(); | |
| 289 } | |
| 290 | |
| 291 struct DownloadPersistentStoreInfoMatch | |
| 292 : public std::unary_function<DownloadPersistentStoreInfo, bool> { | |
| 293 | |
| 294 DownloadPersistentStoreInfoMatch(const GURL& url, | |
| 295 const FilePath& path, | |
| 296 int64 num_files, | |
| 297 DownloadItem::DownloadState state) | |
| 298 : url_(url), | |
| 299 path_(path), | |
| 300 num_files_(num_files), | |
| 301 state_(state) {} | |
| 302 | |
| 303 bool operator() (const DownloadPersistentStoreInfo& info) const { | |
| 304 return info.url == url_ && | |
| 305 info.path == path_ && | |
| 306 // For non-MHTML save packages, received_bytes is actually the | |
| 307 // number of files. | |
| 308 ((num_files_ < 0) || | |
| 309 (info.received_bytes == num_files_)) && | |
| 310 info.total_bytes == 0 && | |
| 311 info.state == state_; | |
| 312 } | |
| 313 | |
| 314 GURL url_; | |
| 315 FilePath path_; | |
| 316 int64 num_files_; | |
| 317 DownloadItem::DownloadState state_; | |
| 318 }; | |
| 319 | |
| 320 void CheckDownloadHistory(const GURL& url, | |
| 321 const FilePath& path, | |
| 322 int64 num_files, | |
| 323 DownloadItem::DownloadState state) { | |
| 324 // Make sure the relevant download item made it into the history. | |
| 325 std::vector<DownloadItem*> downloads; | |
| 326 GetDownloadManager()->GetAllDownloads(&downloads); | |
| 327 ASSERT_EQ(1u, downloads.size()); | |
| 328 | |
| 329 QueryDownloadHistory(); | |
| 330 | |
| 331 std::vector<DownloadPersistentStoreInfo>::iterator found = | |
| 332 std::find_if(history_entries_.begin(), history_entries_.end(), | |
| 333 DownloadPersistentStoreInfoMatch(url, path, num_files, | |
| 334 state)); | |
| 335 | |
| 336 if (found == history_entries_.end()) { | |
| 337 LOG(ERROR) << "Missing url=" << url.spec() | |
| 338 << " path=" << path.value() | |
| 339 << " received=" << num_files | |
| 340 << " state=" << state; | |
| 341 for (size_t index = 0; index < history_entries_.size(); ++index) { | |
| 342 LOG(ERROR) << "History@" << index << ": url=" | |
| 343 << history_entries_[index].url.spec() | |
| 344 << " path=" << history_entries_[index].path.value() | |
| 345 << " received=" << history_entries_[index].received_bytes | |
| 346 << " total=" << history_entries_[index].total_bytes | |
| 347 << " state=" << history_entries_[index].state; | |
| 348 } | |
| 349 EXPECT_TRUE(false); | |
| 350 } | |
| 351 } | |
| 352 | |
| 353 std::vector<DownloadPersistentStoreInfo> history_entries_; | |
| 354 | |
| 355 // Path to directory containing test data. | 332 // Path to directory containing test data. |
| 356 FilePath test_dir_; | 333 FilePath test_dir_; |
| 357 | 334 |
| 358 // Temporary directory we will save pages to. | 335 // Temporary directory we will save pages to. |
| 359 ScopedTempDir save_dir_; | 336 ScopedTempDir save_dir_; |
| 360 | 337 |
| 361 private: | 338 private: |
| 362 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); | 339 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); |
| 363 }; | 340 }; |
| 364 | 341 |
| 365 SavePageBrowserTest::~SavePageBrowserTest() { | 342 SavePageBrowserTest::~SavePageBrowserTest() { |
| 366 } | 343 } |
| 367 | 344 |
| 368 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 345 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { |
| 369 GURL url = NavigateToMockURL("a"); | 346 GURL url = NavigateToMockURL("a"); |
| 370 | 347 |
| 371 FilePath full_file_name, dir; | 348 FilePath full_file_name, dir; |
| 372 GetDestinationPaths("a", &full_file_name, &dir); | 349 GetDestinationPaths("a", &full_file_name, &dir); |
| 373 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, | 350 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, |
| 374 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 351 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 375 | 352 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url, base::Bind( |
| 376 GURL output_url; | 353 &DownloadStoredProperly, url, full_file_name, 1, |
| 377 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), &output_url)); | 354 DownloadItem::COMPLETE))); |
| 378 EXPECT_EQ(url, output_url); | |
| 379 | |
| 380 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 355 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 381 // a.htm is 1 file. | |
| 382 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); | |
| 383 | |
| 384 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 356 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 385 EXPECT_FALSE(file_util::PathExists(dir)); | 357 EXPECT_FALSE(file_util::PathExists(dir)); |
| 386 EXPECT_TRUE(file_util::ContentsEqual( | 358 EXPECT_TRUE(file_util::ContentsEqual( |
| 387 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 359 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
| 388 full_file_name)); | 360 full_file_name)); |
| 389 } | 361 } |
| 390 | 362 |
| 391 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { | 363 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { |
| 392 GURL url = NavigateToMockURL("a"); | 364 GURL url = NavigateToMockURL("a"); |
| 393 DownloadManager* manager(GetDownloadManager()); | 365 DownloadManager* manager(GetDownloadManager()); |
| 394 std::vector<DownloadItem*> downloads; | 366 std::vector<DownloadItem*> downloads; |
| 395 manager->GetAllDownloads(&downloads); | 367 manager->GetAllDownloads(&downloads); |
| 396 ASSERT_EQ(0u, downloads.size()); | 368 ASSERT_EQ(0u, downloads.size()); |
| 397 | 369 |
| 398 FilePath full_file_name, dir; | 370 FilePath full_file_name, dir; |
| 399 GetDestinationPaths("a", &full_file_name, &dir); | 371 GetDestinationPaths("a", &full_file_name, &dir); |
| 400 DownloadItemCreatedObserver creation_observer(manager); | 372 DownloadItemCreatedObserver creation_observer(manager); |
| 401 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, | 373 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, |
| 402 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 374 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 403 std::vector<DownloadItem*> items; | 375 std::vector<DownloadItem*> items; |
| 404 creation_observer.WaitForDownloadItem(&items); | 376 creation_observer.WaitForDownloadItem(&items); |
| 405 ASSERT_TRUE(items.size() == 1); | 377 ASSERT_TRUE(items.size() == 1); |
| 406 items[0]->Cancel(true); | 378 items[0]->Cancel(true); |
| 407 | 379 |
| 408 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. | 380 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. |
| 409 // Currently it's ignored. | 381 // Currently it's ignored. |
| 410 GURL output_url; | 382 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url, base::Bind( |
| 411 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), &output_url)); | 383 &DownloadStoredProperly, url, full_file_name, -1, |
| 412 EXPECT_EQ(url, output_url); | 384 DownloadItem::CANCELLED))); |
| 413 | |
| 414 // -1 to disable number of files check; we don't update after cancel, and | 385 // -1 to disable number of files check; we don't update after cancel, and |
| 415 // we don't know when the single file completed in relationship to | 386 // we don't know when the single file completed in relationship to |
| 416 // the cancel. | 387 // the cancel. |
| 417 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::CANCELLED); | |
| 418 | 388 |
| 419 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 389 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 420 | 390 |
| 421 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 391 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 422 EXPECT_FALSE(file_util::PathExists(dir)); | 392 EXPECT_FALSE(file_util::PathExists(dir)); |
| 423 EXPECT_TRUE(file_util::ContentsEqual( | 393 EXPECT_TRUE(file_util::ContentsEqual( |
| 424 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 394 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
| 425 full_file_name)); | 395 full_file_name)); |
| 426 } | 396 } |
| 427 | 397 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 454 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( | 424 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( |
| 455 FilePath(kTestDir).Append(file_name)); | 425 FilePath(kTestDir).Append(file_name)); |
| 456 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( | 426 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( |
| 457 FilePath(kTestDir).Append(file_name)); | 427 FilePath(kTestDir).Append(file_name)); |
| 458 ui_test_utils::NavigateToURL(browser(), view_source_url); | 428 ui_test_utils::NavigateToURL(browser(), view_source_url); |
| 459 | 429 |
| 460 FilePath full_file_name, dir; | 430 FilePath full_file_name, dir; |
| 461 GetDestinationPaths("a", &full_file_name, &dir); | 431 GetDestinationPaths("a", &full_file_name, &dir); |
| 462 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, | 432 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, |
| 463 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 433 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 464 | 434 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), actual_page_url, base::Bind( |
| 465 GURL output_url; | 435 &DownloadStoredProperly, actual_page_url, full_file_name, 1, |
| 466 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), &output_url)); | 436 DownloadItem::COMPLETE))); |
| 467 EXPECT_EQ(actual_page_url, output_url); | |
| 468 | 437 |
| 469 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 438 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 470 // a.htm is 1 file. | |
| 471 CheckDownloadHistory(actual_page_url, full_file_name, 1, | |
| 472 DownloadItem::COMPLETE); | |
| 473 | 439 |
| 474 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 440 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 475 EXPECT_FALSE(file_util::PathExists(dir)); | 441 EXPECT_FALSE(file_util::PathExists(dir)); |
| 476 EXPECT_TRUE(file_util::ContentsEqual( | 442 EXPECT_TRUE(file_util::ContentsEqual( |
| 477 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 443 test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
| 478 full_file_name)); | 444 full_file_name)); |
| 479 } | 445 } |
| 480 | 446 |
| 481 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 447 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
| 482 GURL url = NavigateToMockURL("b"); | 448 GURL url = NavigateToMockURL("b"); |
| 483 | 449 |
| 484 FilePath full_file_name, dir; | 450 FilePath full_file_name, dir; |
| 485 GetDestinationPaths("b", &full_file_name, &dir); | 451 GetDestinationPaths("b", &full_file_name, &dir); |
| 486 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( | 452 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( |
| 487 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 453 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
| 488 | 454 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url, base::Bind( |
| 489 GURL output_url; | 455 &DownloadStoredProperly, url, full_file_name, 3, |
| 490 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), &output_url)); | 456 DownloadItem::COMPLETE))); |
| 491 EXPECT_EQ(url, output_url); | |
| 492 | 457 |
| 493 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 458 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 494 // b.htm is 3 files. | |
| 495 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); | |
| 496 | 459 |
| 497 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 460 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 498 EXPECT_TRUE(file_util::PathExists(dir)); | 461 EXPECT_TRUE(file_util::PathExists(dir)); |
| 499 EXPECT_TRUE(file_util::TextContentsEqual( | 462 EXPECT_TRUE(file_util::TextContentsEqual( |
| 500 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 463 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
| 501 full_file_name)); | 464 full_file_name)); |
| 502 EXPECT_TRUE(file_util::ContentsEqual( | 465 EXPECT_TRUE(file_util::ContentsEqual( |
| 503 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 466 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
| 504 dir.AppendASCII("1.png"))); | 467 dir.AppendASCII("1.png"))); |
| 505 EXPECT_TRUE(file_util::ContentsEqual( | 468 EXPECT_TRUE(file_util::ContentsEqual( |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 524 FilePath(kTestDir).AppendASCII("b.htm")); | 487 FilePath(kTestDir).AppendASCII("b.htm")); |
| 525 NavigateToURLWithDisposition(incognito, url, NEW_FOREGROUND_TAB, | 488 NavigateToURLWithDisposition(incognito, url, NEW_FOREGROUND_TAB, |
| 526 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 489 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 527 | 490 |
| 528 // Save the page before completion. | 491 // Save the page before completion. |
| 529 FilePath full_file_name, dir; | 492 FilePath full_file_name, dir; |
| 530 GetDestinationPaths("b", &full_file_name, &dir); | 493 GetDestinationPaths("b", &full_file_name, &dir); |
| 531 ASSERT_TRUE(GetCurrentTab(incognito)->SavePage( | 494 ASSERT_TRUE(GetCurrentTab(incognito)->SavePage( |
| 532 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 495 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
| 533 | 496 |
| 534 GURL output_url; | 497 ASSERT_TRUE(WaitForSavePackageToFinish( |
| 535 WaitForSavePackageToFinish(incognito, &output_url); | 498 incognito, url, DownloadPersistedObserver::PersistedFilter())); |
| 536 EXPECT_EQ(url, output_url); | |
| 537 | 499 |
| 538 // Confirm download shelf is visible. | 500 // Confirm download shelf is visible. |
| 539 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); | 501 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); |
| 540 | 502 |
| 541 // We can't check more than this because SavePackage is racing with | 503 // We can't check more than this because SavePackage is racing with |
| 542 // the page load. If the page load won the race, then SavePackage | 504 // the page load. If the page load won the race, then SavePackage |
| 543 // might have completed. If the page load lost the race, then | 505 // might have completed. If the page load lost the race, then |
| 544 // SavePackage will cancel because there aren't any resources to | 506 // SavePackage will cancel because there aren't any resources to |
| 545 // save. | 507 // save. |
| 546 } | 508 } |
| 547 | 509 |
| 548 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { | 510 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { |
| 549 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 511 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
| 550 EXPECT_FALSE(chrome::CanSavePage(browser())); | 512 EXPECT_FALSE(chrome::CanSavePage(browser())); |
| 551 } | 513 } |
| 552 | 514 |
| 553 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { | 515 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { |
| 554 GURL url = NavigateToMockURL("b"); | 516 GURL url = NavigateToMockURL("b"); |
| 555 | 517 |
| 556 FilePath full_file_name = save_dir_.path().AppendASCII( | 518 FilePath full_file_name = save_dir_.path().AppendASCII( |
| 557 std::string("Test page for saving page feature") + kAppendedExtension); | 519 std::string("Test page for saving page feature") + kAppendedExtension); |
| 558 FilePath dir = save_dir_.path().AppendASCII( | 520 FilePath dir = save_dir_.path().AppendASCII( |
| 559 "Test page for saving page feature_files"); | 521 "Test page for saving page feature_files"); |
| 560 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( | 522 ASSERT_TRUE(GetCurrentTab(browser())->SavePage( |
| 561 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 523 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
| 562 | 524 |
| 563 GURL output_url; | 525 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url, base::Bind( |
| 564 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), &output_url)); | 526 &DownloadStoredProperly, url, full_file_name, 3, |
| 565 EXPECT_EQ(url, output_url); | 527 DownloadItem::COMPLETE))); |
| 566 | 528 |
| 567 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 529 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 568 // b.htm is 3 files. | |
| 569 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); | |
| 570 | 530 |
| 571 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 531 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 572 EXPECT_TRUE(file_util::PathExists(dir)); | 532 EXPECT_TRUE(file_util::PathExists(dir)); |
| 573 EXPECT_TRUE(file_util::TextContentsEqual( | 533 EXPECT_TRUE(file_util::TextContentsEqual( |
| 574 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 534 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
| 575 full_file_name)); | 535 full_file_name)); |
| 576 EXPECT_TRUE(file_util::ContentsEqual( | 536 EXPECT_TRUE(file_util::ContentsEqual( |
| 577 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 537 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
| 578 dir.AppendASCII("1.png"))); | 538 dir.AppendASCII("1.png"))); |
| 579 EXPECT_TRUE(file_util::ContentsEqual( | 539 EXPECT_TRUE(file_util::ContentsEqual( |
| 580 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 540 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
| 581 dir.AppendASCII("1.css"))); | 541 dir.AppendASCII("1.css"))); |
| 582 } | 542 } |
| 583 | 543 |
| 584 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { | 544 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { |
| 585 GURL url = NavigateToMockURL("a"); | 545 GURL url = NavigateToMockURL("a"); |
| 586 | 546 |
| 587 FilePath full_file_name, dir; | 547 FilePath full_file_name, dir; |
| 588 GetDestinationPaths("a", &full_file_name, &dir); | 548 GetDestinationPaths("a", &full_file_name, &dir); |
| 589 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, | 549 ASSERT_TRUE(GetCurrentTab(browser())->SavePage(full_file_name, dir, |
| 590 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 550 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
| 591 | 551 |
| 592 GURL output_url; | 552 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url, base::Bind( |
| 593 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), &output_url)); | 553 &DownloadStoredProperly, url, full_file_name, 1, |
| 594 EXPECT_EQ(url, output_url); | 554 DownloadItem::COMPLETE))); |
| 595 | 555 |
| 596 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 556 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 597 // a.htm is 1 file. | |
| 598 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); | |
| 599 | 557 |
| 600 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); | 558 DownloadManager* manager(GetDownloadManager()); |
| 559 std::vector<DownloadItem*> downloads; | |
| 560 manager->GetAllDownloads(&downloads); | |
| 561 ASSERT_EQ(1UL, downloads.size()); | |
| 562 DownloadRemovedObserver removed(browser()->profile(), downloads[0]->GetId()); | |
| 601 | 563 |
| 602 // Should not be in history. | 564 EXPECT_EQ(manager->RemoveAllDownloads(), 1); |
| 603 QueryDownloadHistory(); | 565 |
| 604 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), | 566 removed.WaitForRemoved(); |
| 605 DownloadPersistentStoreInfoMatch( | |
| 606 url, full_file_name, 1, DownloadItem::COMPLETE)), | |
| 607 history_entries_.end()); | |
| 608 | 567 |
| 609 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 568 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 610 EXPECT_FALSE(file_util::PathExists(dir)); | 569 EXPECT_FALSE(file_util::PathExists(dir)); |
| 611 EXPECT_TRUE(file_util::ContentsEqual( | 570 EXPECT_TRUE(file_util::ContentsEqual( |
| 612 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 571 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
| 613 full_file_name)); | 572 full_file_name)); |
| 614 } | 573 } |
| 615 | 574 |
| 616 // This tests that a webpage with the title "test.exe" is saved as | 575 // This tests that a webpage with the title "test.exe" is saved as |
| 617 // "test.exe.htm". | 576 // "test.exe.htm". |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 FilePath download_dir = DownloadPrefs::FromDownloadManager( | 625 FilePath download_dir = DownloadPrefs::FromDownloadManager( |
| 667 GetDownloadManager())->DownloadPath(); | 626 GetDownloadManager())->DownloadPath(); |
| 668 FilePath full_file_name = download_dir.AppendASCII(std::string( | 627 FilePath full_file_name = download_dir.AppendASCII(std::string( |
| 669 "Test page for saving page feature.mhtml")); | 628 "Test page for saving page feature.mhtml")); |
| 670 #if defined(OS_CHROMEOS) | 629 #if defined(OS_CHROMEOS) |
| 671 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | 630 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); |
| 672 #else | 631 #else |
| 673 SavePackageFilePicker::SetShouldPromptUser(false); | 632 SavePackageFilePicker::SetShouldPromptUser(false); |
| 674 #endif | 633 #endif |
| 675 chrome::SavePage(browser()); | 634 chrome::SavePage(browser()); |
| 676 GURL output_url; | 635 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), url, base::Bind( |
| 677 ASSERT_TRUE(WaitForSavePackageToFinish(browser(), &output_url)); | 636 &DownloadStoredProperly, url, full_file_name, -1, |
| 678 EXPECT_EQ(url, output_url); | 637 DownloadItem::COMPLETE))); |
| 679 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE); | |
| 680 | 638 |
| 681 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 639 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
| 682 int64 actual_file_size = -1; | 640 int64 actual_file_size = -1; |
| 683 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 641 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
| 684 EXPECT_LE(kFileSizeMin, actual_file_size); | 642 EXPECT_LE(kFileSizeMin, actual_file_size); |
| 685 } | 643 } |
| 686 | 644 |
| OLD | NEW |