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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
64 ".html"; | 64 ".html"; |
65 #endif | 65 #endif |
66 | 66 |
67 void NullFunction() { | |
68 } | |
69 | |
67 } // namespace | 70 } // namespace |
68 | 71 |
69 // Loosely based on logic in DownloadTestObserver. | 72 // Loosely based on logic in DownloadTestObserver. |
70 class DownloadItemCreatedObserver : public DownloadManager::Observer { | 73 class DownloadItemCreatedObserver : public DownloadManager::Observer { |
71 public: | 74 public: |
72 explicit DownloadItemCreatedObserver(DownloadManager* manager) | 75 explicit DownloadItemCreatedObserver(DownloadManager* manager) |
73 : waiting_(false), manager_(manager), created_item_(NULL) { | 76 : waiting_(false), manager_(manager) { |
74 manager->AddObserver(this); | 77 manager->AddObserver(this); |
75 } | 78 } |
76 | 79 |
77 ~DownloadItemCreatedObserver() { | 80 ~DownloadItemCreatedObserver() { |
78 if (manager_) | 81 if (manager_) |
79 manager_->RemoveObserver(this); | 82 manager_->RemoveObserver(this); |
80 } | 83 } |
81 | 84 |
82 // Wait for the first download item created after object creation. | 85 // Wait for the first download item created after object creation. |
83 // Note that this class provides no protection against the download | 86 // Note that this class provides no protection against the download |
84 // being destroyed between creation and return of WaitForNewDownloadItem(); | 87 // being destroyed between creation and return of WaitForNewDownloadItem(); |
85 // the caller must guarantee that in some other fashion. | 88 // the caller must guarantee that in some other fashion. |
86 DownloadItem* WaitForNewDownloadItem() { | 89 void WaitForDownloadItem(std::vector<DownloadItem*>* items_seen) { |
87 if (!manager_) { | 90 if (!manager_) { |
88 // The manager went away before we were asked to wait; return | 91 // The manager went away before we were asked to wait; return |
89 // what we have, even if it's null. | 92 // what we have, even if it's null. |
90 return created_item_; | 93 *items_seen = items_seen_; |
94 return; | |
91 } | 95 } |
92 | 96 |
93 if (!created_item_) { | 97 if (items_seen_.empty()) { |
94 waiting_ = true; | 98 waiting_ = true; |
95 content::RunMessageLoop(); | 99 content::RunMessageLoop(); |
96 waiting_ = false; | 100 waiting_ = false; |
97 } | 101 } |
98 return created_item_; | 102 |
103 *items_seen = items_seen_; | |
104 return; | |
99 } | 105 } |
100 | 106 |
101 private: | 107 private: |
102 | 108 |
103 // DownloadManager::Observer | 109 // DownloadManager::Observer |
104 void OnDownloadCreated(DownloadManager* manager, DownloadItem* item) { | 110 virtual void OnDownloadCreated( |
111 DownloadManager* manager, DownloadItem* item) OVERRIDE { | |
105 DCHECK_EQ(manager, manager_); | 112 DCHECK_EQ(manager, manager_); |
106 if (!created_item_) | 113 items_seen_.push_back(item); |
107 created_item_ = item; | |
108 | 114 |
109 if (waiting_) | 115 if (waiting_) |
110 MessageLoopForUI::current()->Quit(); | 116 MessageLoopForUI::current()->Quit(); |
111 } | 117 } |
112 | 118 |
113 void ManagerGoingDownload(DownloadManager* manager) { | 119 virtual void ManagerGoingDown(DownloadManager* manager) OVERRIDE { |
114 manager_->RemoveObserver(this); | 120 manager_->RemoveObserver(this); |
115 manager_ = NULL; | 121 manager_ = NULL; |
116 if (waiting_) | 122 if (waiting_) |
117 MessageLoopForUI::current()->Quit(); | 123 MessageLoopForUI::current()->Quit(); |
118 } | 124 } |
119 | 125 |
120 bool waiting_; | 126 bool waiting_; |
121 DownloadManager* manager_; | 127 DownloadManager* manager_; |
122 DownloadItem* created_item_; | 128 std::vector<DownloadItem*> items_seen_; |
123 | 129 |
124 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); | 130 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); |
125 }; | 131 }; |
126 | 132 |
133 class DownloadPersistedObserver : public DownloadItem::Observer { | |
134 public: | |
135 explicit DownloadPersistedObserver(DownloadItem* item) | |
136 : waiting_(false), item_(item) { | |
137 item->AddObserver(this); | |
138 } | |
139 | |
140 ~DownloadPersistedObserver() { | |
141 if (item_) | |
142 item_->RemoveObserver(this); | |
143 } | |
144 | |
145 // Wait for download item to get the persisted bit set. | |
146 // Note that this class provides no protection against the download | |
147 // being destroyed between creation and return of WaitForPersisted(); | |
148 // the caller must guarantee that in some other fashion. | |
149 void WaitForPersisted() { | |
150 // In combination with OnDownloadDestroyed() below, verify the | |
151 // above interface contract. | |
152 DCHECK(item_); | |
153 | |
154 if (item_->IsPersisted()) | |
155 return; | |
156 | |
157 waiting_ = true; | |
158 content::RunMessageLoop(); | |
159 waiting_ = false; | |
160 | |
161 return; | |
162 } | |
163 | |
164 private: | |
165 // DownloadItem::Observer | |
166 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE { | |
167 DCHECK_EQ(item, item_); | |
168 | |
169 if (waiting_ && item->IsPersisted()) | |
170 MessageLoopForUI::current()->Quit(); | |
171 } | |
172 | |
173 virtual void OnDownloadDestroyed(DownloadItem* item) OVERRIDE { | |
174 if (item != item_) | |
175 return; | |
176 | |
177 item_->RemoveObserver(this); | |
178 item_ = NULL; | |
179 } | |
180 | |
181 bool waiting_; | |
182 DownloadItem* item_; | |
183 | |
184 DISALLOW_COPY_AND_ASSIGN(DownloadPersistedObserver); | |
185 }; | |
186 | |
127 class SavePageBrowserTest : public InProcessBrowserTest { | 187 class SavePageBrowserTest : public InProcessBrowserTest { |
128 public: | 188 public: |
129 SavePageBrowserTest() {} | 189 SavePageBrowserTest() {} |
130 virtual ~SavePageBrowserTest(); | 190 virtual ~SavePageBrowserTest(); |
131 | 191 |
132 protected: | 192 protected: |
133 void SetUp() OVERRIDE { | 193 void SetUp() OVERRIDE { |
134 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); | 194 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); |
135 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); | 195 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); |
136 InProcessBrowserTest::SetUp(); | 196 InProcessBrowserTest::SetUp(); |
137 } | 197 } |
138 | 198 |
139 void SetUpOnMainThread() OVERRIDE { | 199 void SetUpOnMainThread() OVERRIDE { |
140 browser()->profile()->GetPrefs()->SetFilePath( | 200 browser()->profile()->GetPrefs()->SetFilePath( |
141 prefs::kDownloadDefaultDirectory, save_dir_.path()); | 201 prefs::kDownloadDefaultDirectory, save_dir_.path()); |
142 BrowserThread::PostTask( | 202 BrowserThread::PostTask( |
143 BrowserThread::IO, FROM_HERE, | 203 BrowserThread::IO, FROM_HERE, |
144 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 204 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
205 item_creation_observer_.reset( | |
206 new DownloadItemCreatedObserver(GetDownloadManager())); | |
145 } | 207 } |
146 | 208 |
147 GURL NavigateToMockURL(const std::string& prefix) { | 209 GURL NavigateToMockURL(const std::string& prefix) { |
148 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 210 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
149 FilePath(kTestDir).AppendASCII(prefix + ".htm")); | 211 FilePath(kTestDir).AppendASCII(prefix + ".htm")); |
150 ui_test_utils::NavigateToURL(browser(), url); | 212 ui_test_utils::NavigateToURL(browser(), url); |
151 return url; | 213 return url; |
152 } | 214 } |
153 | 215 |
154 // Returns full paths of destination file and directory. | 216 // Returns full paths of destination file and directory. |
155 void GetDestinationPaths(const std::string& prefix, | 217 void GetDestinationPaths(const std::string& prefix, |
156 FilePath* full_file_name, | 218 FilePath* full_file_name, |
157 FilePath* dir) { | 219 FilePath* dir) { |
158 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); | 220 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm"); |
159 *dir = save_dir_.path().AppendASCII(prefix + "_files"); | 221 *dir = save_dir_.path().AppendASCII(prefix + "_files"); |
160 } | 222 } |
161 | 223 |
162 WebContents* GetCurrentTab() const { | 224 WebContents* GetCurrentTab() const { |
163 WebContents* current_tab = chrome::GetActiveWebContents(browser()); | 225 WebContents* current_tab = chrome::GetActiveWebContents(browser()); |
164 EXPECT_TRUE(current_tab); | 226 EXPECT_TRUE(current_tab); |
165 return current_tab; | 227 return current_tab; |
166 } | 228 } |
167 | 229 |
168 | |
169 GURL WaitForSavePackageToFinish() const { | 230 GURL WaitForSavePackageToFinish() const { |
170 content::WindowedNotificationObserver observer( | 231 content::WindowedNotificationObserver observer( |
171 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 232 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
172 content::NotificationService::AllSources()); | 233 content::NotificationService::AllSources()); |
173 observer.Wait(); | 234 observer.Wait(); |
235 | |
236 // Generally, there should only be one download item created | |
237 // in all of these tests. Wait for it, and wait for it to | |
238 // be persisted. | |
239 std::vector<DownloadItem*> items; | |
240 item_creation_observer_->WaitForDownloadItem(&items); | |
241 | |
242 DCHECK_EQ(1u, items.size()); | |
benjhayden
2012/09/10 14:39:58
CHECK instead of DCHECK?
Randy Smith (Not in Mondays)
2012/09/10 17:53:16
I think of both CHECKs and DCHECKs as being discou
| |
243 DownloadItem* download_item(items[0]); | |
244 | |
245 // Note on synchronization: | |
246 // | |
247 // For each Save Page As operation, we create a corresponding shell | |
248 // DownloadItem to display progress to the user. That DownloadItem | |
249 // goes through its own state transitions, including being persisted | |
250 // out to the history database, and the download shelf is not shown | |
251 // until after the persistence occurs. Save Package completion (and | |
252 // marking the DownloadItem as completed) occurs asynchronously from | |
253 // persistence. Thus if we want to examine either UI state or DB | |
254 // state, we need to wait until both the save package operation is | |
255 // complete and the relevant download item has been persisted. | |
256 DownloadPersistedObserver(download_item).WaitForPersisted(); | |
257 | |
174 return content::Details<DownloadItem>(observer.details()).ptr()-> | 258 return content::Details<DownloadItem>(observer.details()).ptr()-> |
175 GetOriginalUrl(); | 259 GetOriginalUrl(); |
176 } | 260 } |
177 | 261 |
178 DownloadManager* GetDownloadManager() const { | 262 DownloadManager* GetDownloadManager() const { |
179 DownloadManager* download_manager = | 263 DownloadManager* download_manager = |
180 BrowserContext::GetDownloadManager(browser()->profile()); | 264 BrowserContext::GetDownloadManager(browser()->profile()); |
181 EXPECT_TRUE(download_manager); | 265 EXPECT_TRUE(download_manager); |
182 return download_manager; | 266 return download_manager; |
183 } | 267 } |
(...skipping 18 matching lines...) Expand all Loading... | |
202 | 286 |
203 // Indicate thet we have received the history and can continue. | 287 // Indicate thet we have received the history and can continue. |
204 MessageLoopForUI::current()->Quit(); | 288 MessageLoopForUI::current()->Quit(); |
205 } | 289 } |
206 | 290 |
207 struct DownloadPersistentStoreInfoMatch | 291 struct DownloadPersistentStoreInfoMatch |
208 : public std::unary_function<DownloadPersistentStoreInfo, bool> { | 292 : public std::unary_function<DownloadPersistentStoreInfo, bool> { |
209 | 293 |
210 DownloadPersistentStoreInfoMatch(const GURL& url, | 294 DownloadPersistentStoreInfoMatch(const GURL& url, |
211 const FilePath& path, | 295 const FilePath& path, |
212 int64 num_files) | 296 int64 num_files, |
297 DownloadItem::DownloadState state) | |
213 : url_(url), | 298 : url_(url), |
214 path_(path), | 299 path_(path), |
215 num_files_(num_files) { | 300 num_files_(num_files), |
216 } | 301 state_(state) {} |
217 | 302 |
218 bool operator() (const DownloadPersistentStoreInfo& info) const { | 303 bool operator() (const DownloadPersistentStoreInfo& info) const { |
219 return info.url == url_ && | 304 return info.url == url_ && |
220 info.path == path_ && | 305 info.path == path_ && |
221 // For non-MHTML save packages, received_bytes is actually the | 306 // For non-MHTML save packages, received_bytes is actually the |
222 // number of files. | 307 // number of files. |
223 ((num_files_ < 0) || | 308 ((num_files_ < 0) || |
224 (info.received_bytes == num_files_)) && | 309 (info.received_bytes == num_files_)) && |
225 info.total_bytes == 0 && | 310 info.total_bytes == 0 && |
226 info.state == DownloadItem::COMPLETE; | 311 info.state == state_; |
227 } | 312 } |
228 | 313 |
229 GURL url_; | 314 GURL url_; |
230 FilePath path_; | 315 FilePath path_; |
231 int64 num_files_; | 316 int64 num_files_; |
317 DownloadItem::DownloadState state_; | |
232 }; | 318 }; |
233 | 319 |
234 void CheckDownloadHistory(const GURL& url, | 320 void CheckDownloadHistory(const GURL& url, |
235 const FilePath& path, | 321 const FilePath& path, |
236 int64 num_files) { | 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()->SearchDownloads(string16(), &downloads); | |
327 ASSERT_EQ(1u, downloads.size()); | |
328 | |
237 QueryDownloadHistory(); | 329 QueryDownloadHistory(); |
238 | 330 |
239 std::vector<DownloadPersistentStoreInfo>::iterator found = | 331 std::vector<DownloadPersistentStoreInfo>::iterator found = |
240 std::find_if(history_entries_.begin(), history_entries_.end(), | 332 std::find_if(history_entries_.begin(), history_entries_.end(), |
241 DownloadPersistentStoreInfoMatch(url, path, num_files)); | 333 DownloadPersistentStoreInfoMatch(url, path, num_files, |
334 state)); | |
242 | 335 |
243 if (found == history_entries_.end()) { | 336 if (found == history_entries_.end()) { |
244 LOG(ERROR) << "Missing url=" << url.spec() | 337 LOG(ERROR) << "Missing url=" << url.spec() |
245 << " path=" << path.value() | 338 << " path=" << path.value() |
246 << " received=" << num_files; | 339 << " received=" << num_files; |
247 for (size_t index = 0; index < history_entries_.size(); ++index) { | 340 for (size_t index = 0; index < history_entries_.size(); ++index) { |
248 LOG(ERROR) << "History@" << index << ": url=" | 341 LOG(ERROR) << "History@" << index << ": url=" |
249 << history_entries_[index].url.spec() | 342 << history_entries_[index].url.spec() |
250 << " path=" << history_entries_[index].path.value() | 343 << " path=" << history_entries_[index].path.value() |
251 << " received=" << history_entries_[index].received_bytes | 344 << " received=" << history_entries_[index].received_bytes |
252 << " total=" << history_entries_[index].total_bytes | 345 << " total=" << history_entries_[index].total_bytes |
253 << " state=" << history_entries_[index].state; | 346 << " state=" << history_entries_[index].state; |
254 } | 347 } |
255 EXPECT_TRUE(false); | 348 EXPECT_TRUE(false); |
256 } | 349 } |
257 } | 350 } |
258 | 351 |
259 std::vector<DownloadPersistentStoreInfo> history_entries_; | 352 std::vector<DownloadPersistentStoreInfo> history_entries_; |
260 | 353 |
261 // Path to directory containing test data. | 354 // Path to directory containing test data. |
262 FilePath test_dir_; | 355 FilePath test_dir_; |
263 | 356 |
264 // Temporary directory we will save pages to. | 357 // Temporary directory we will save pages to. |
265 ScopedTempDir save_dir_; | 358 ScopedTempDir save_dir_; |
266 | 359 |
267 private: | 360 private: |
361 scoped_ptr<DownloadItemCreatedObserver> item_creation_observer_; | |
362 | |
268 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); | 363 DISALLOW_COPY_AND_ASSIGN(SavePageBrowserTest); |
269 }; | 364 }; |
270 | 365 |
271 SavePageBrowserTest::~SavePageBrowserTest() { | 366 SavePageBrowserTest::~SavePageBrowserTest() { |
272 } | 367 } |
273 | 368 |
274 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 369 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { |
275 GURL url = NavigateToMockURL("a"); | 370 GURL url = NavigateToMockURL("a"); |
276 | 371 |
277 FilePath full_file_name, dir; | 372 FilePath full_file_name, dir; |
278 GetDestinationPaths("a", &full_file_name, &dir); | 373 GetDestinationPaths("a", &full_file_name, &dir); |
279 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 374 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
280 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 375 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
281 | 376 |
282 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 377 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
283 | 378 |
284 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 379 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
285 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | 380 // a.htm is 1 file. |
381 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); | |
286 | 382 |
287 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 383 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
288 EXPECT_FALSE(file_util::PathExists(dir)); | 384 EXPECT_FALSE(file_util::PathExists(dir)); |
289 EXPECT_TRUE(file_util::ContentsEqual( | 385 EXPECT_TRUE(file_util::ContentsEqual( |
290 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 386 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
291 full_file_name)); | 387 full_file_name)); |
292 } | 388 } |
293 | 389 |
294 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { | 390 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnlyCancel) { |
295 GURL url = NavigateToMockURL("a"); | 391 GURL url = NavigateToMockURL("a"); |
296 DownloadManager* manager(GetDownloadManager()); | 392 DownloadManager* manager(GetDownloadManager()); |
297 std::vector<DownloadItem*> downloads; | 393 std::vector<DownloadItem*> downloads; |
298 manager->SearchDownloads(string16(), &downloads); | 394 manager->SearchDownloads(string16(), &downloads); |
299 ASSERT_EQ(0u, downloads.size()); | 395 ASSERT_EQ(0u, downloads.size()); |
300 | 396 |
301 FilePath full_file_name, dir; | 397 FilePath full_file_name, dir; |
302 GetDestinationPaths("a", &full_file_name, &dir); | 398 GetDestinationPaths("a", &full_file_name, &dir); |
303 DownloadItemCreatedObserver creation_observer(manager); | 399 DownloadItemCreatedObserver creation_observer(manager); |
304 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 400 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
305 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 401 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
306 DownloadItem* item = creation_observer.WaitForNewDownloadItem(); | 402 std::vector<DownloadItem*> items; |
307 item->Cancel(true); | 403 creation_observer.WaitForDownloadItem(&items); |
404 ASSERT_TRUE(items.size() == 1); | |
405 items[0]->Cancel(true); | |
308 | 406 |
309 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. | 407 // TODO(rdsmith): Fix DII::Cancel() to actually cancel the save package. |
310 // Currently it's ignored. | 408 // Currently it's ignored. |
311 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 409 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
312 | 410 |
411 // -1 to disable number of files check; we don't update after cancel, and | |
412 // we don't know when the single file completed in relationship to | |
413 // the cancel. | |
414 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::CANCELLED); | |
415 | |
313 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 416 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
314 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | |
315 | 417 |
316 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 418 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
317 EXPECT_FALSE(file_util::PathExists(dir)); | 419 EXPECT_FALSE(file_util::PathExists(dir)); |
318 EXPECT_TRUE(file_util::ContentsEqual( | 420 EXPECT_TRUE(file_util::ContentsEqual( |
319 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 421 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
320 full_file_name)); | 422 full_file_name)); |
321 } | 423 } |
322 | 424 |
323 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. | 425 // SavePageBrowserTest.SaveHTMLOnlyTabDestroy is flaky. |
324 // See http://crbug.com/144751. | 426 // See http://crbug.com/144751. |
325 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveHTMLOnlyTabDestroy) { | 427 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveHTMLOnlyTabDestroy) { |
326 GURL url = NavigateToMockURL("a"); | 428 GURL url = NavigateToMockURL("a"); |
327 DownloadManager* manager(GetDownloadManager()); | 429 DownloadManager* manager(GetDownloadManager()); |
328 std::vector<DownloadItem*> downloads; | 430 std::vector<DownloadItem*> downloads; |
329 manager->SearchDownloads(string16(), &downloads); | 431 manager->SearchDownloads(string16(), &downloads); |
330 ASSERT_EQ(0u, downloads.size()); | 432 ASSERT_EQ(0u, downloads.size()); |
331 | 433 |
332 FilePath full_file_name, dir; | 434 FilePath full_file_name, dir; |
333 GetDestinationPaths("a", &full_file_name, &dir); | 435 GetDestinationPaths("a", &full_file_name, &dir); |
334 DownloadItemCreatedObserver creation_observer(manager); | 436 DownloadItemCreatedObserver creation_observer(manager); |
335 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 437 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
336 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 438 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
337 DownloadItem* item = creation_observer.WaitForNewDownloadItem(); | 439 std::vector<DownloadItem*> items; |
440 creation_observer.WaitForDownloadItem(&items); | |
441 ASSERT_TRUE(items.size() == 1); | |
338 | 442 |
339 // Close the tab; does this cancel the download? | 443 // Close the tab; does this cancel the download? |
340 GetCurrentTab()->Close(); | 444 GetCurrentTab()->Close(); |
341 EXPECT_TRUE(item->IsCancelled()); | 445 EXPECT_TRUE(items[0]->IsCancelled()); |
342 | 446 |
343 EXPECT_FALSE(file_util::PathExists(full_file_name)); | 447 EXPECT_FALSE(file_util::PathExists(full_file_name)); |
344 EXPECT_FALSE(file_util::PathExists(dir)); | 448 EXPECT_FALSE(file_util::PathExists(dir)); |
345 } | 449 } |
346 | 450 |
347 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { | 451 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { |
348 FilePath file_name(FILE_PATH_LITERAL("a.htm")); | 452 FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
349 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( | 453 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( |
350 FilePath(kTestDir).Append(file_name)); | 454 FilePath(kTestDir).Append(file_name)); |
351 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( | 455 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( |
352 FilePath(kTestDir).Append(file_name)); | 456 FilePath(kTestDir).Append(file_name)); |
353 ui_test_utils::NavigateToURL(browser(), view_source_url); | 457 ui_test_utils::NavigateToURL(browser(), view_source_url); |
354 | 458 |
355 FilePath full_file_name, dir; | 459 FilePath full_file_name, dir; |
356 GetDestinationPaths("a", &full_file_name, &dir); | 460 GetDestinationPaths("a", &full_file_name, &dir); |
357 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 461 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
358 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 462 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
359 | 463 |
360 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); | 464 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); |
361 | 465 |
362 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 466 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
363 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file. | 467 // a.htm is 1 file. |
468 CheckDownloadHistory(actual_page_url, full_file_name, 1, | |
469 DownloadItem::COMPLETE); | |
364 | 470 |
365 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 471 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
366 EXPECT_FALSE(file_util::PathExists(dir)); | 472 EXPECT_FALSE(file_util::PathExists(dir)); |
367 EXPECT_TRUE(file_util::ContentsEqual( | 473 EXPECT_TRUE(file_util::ContentsEqual( |
368 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 474 test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
369 full_file_name)); | 475 full_file_name)); |
370 } | 476 } |
371 | 477 |
372 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 478 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
373 GURL url = NavigateToMockURL("b"); | 479 GURL url = NavigateToMockURL("b"); |
374 | 480 |
375 FilePath full_file_name, dir; | 481 FilePath full_file_name, dir; |
376 GetDestinationPaths("b", &full_file_name, &dir); | 482 GetDestinationPaths("b", &full_file_name, &dir); |
377 ASSERT_TRUE(GetCurrentTab()->SavePage( | 483 ASSERT_TRUE(GetCurrentTab()->SavePage( |
378 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 484 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
379 | 485 |
380 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 486 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
381 | 487 |
382 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 488 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
383 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. | 489 // b.htm is 3 files. |
490 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); | |
384 | 491 |
385 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 492 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
386 EXPECT_TRUE(file_util::PathExists(dir)); | 493 EXPECT_TRUE(file_util::PathExists(dir)); |
387 EXPECT_TRUE(file_util::TextContentsEqual( | 494 EXPECT_TRUE(file_util::TextContentsEqual( |
388 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 495 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
389 full_file_name)); | 496 full_file_name)); |
390 EXPECT_TRUE(file_util::ContentsEqual( | 497 EXPECT_TRUE(file_util::ContentsEqual( |
391 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 498 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
392 dir.AppendASCII("1.png"))); | 499 dir.AppendASCII("1.png"))); |
393 EXPECT_TRUE(file_util::ContentsEqual( | 500 EXPECT_TRUE(file_util::ContentsEqual( |
(...skipping 12 matching lines...) Expand all Loading... | |
406 FilePath full_file_name = save_dir_.path().AppendASCII( | 513 FilePath full_file_name = save_dir_.path().AppendASCII( |
407 std::string("Test page for saving page feature") + kAppendedExtension); | 514 std::string("Test page for saving page feature") + kAppendedExtension); |
408 FilePath dir = save_dir_.path().AppendASCII( | 515 FilePath dir = save_dir_.path().AppendASCII( |
409 "Test page for saving page feature_files"); | 516 "Test page for saving page feature_files"); |
410 ASSERT_TRUE(GetCurrentTab()->SavePage( | 517 ASSERT_TRUE(GetCurrentTab()->SavePage( |
411 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); | 518 full_file_name, dir, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML)); |
412 | 519 |
413 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 520 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
414 | 521 |
415 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 522 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
416 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. | 523 // b.htm is 3 files. |
524 CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); | |
417 | 525 |
418 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 526 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
419 EXPECT_TRUE(file_util::PathExists(dir)); | 527 EXPECT_TRUE(file_util::PathExists(dir)); |
420 EXPECT_TRUE(file_util::TextContentsEqual( | 528 EXPECT_TRUE(file_util::TextContentsEqual( |
421 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 529 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
422 full_file_name)); | 530 full_file_name)); |
423 EXPECT_TRUE(file_util::ContentsEqual( | 531 EXPECT_TRUE(file_util::ContentsEqual( |
424 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 532 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
425 dir.AppendASCII("1.png"))); | 533 dir.AppendASCII("1.png"))); |
426 EXPECT_TRUE(file_util::ContentsEqual( | 534 EXPECT_TRUE(file_util::ContentsEqual( |
427 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 535 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
428 dir.AppendASCII("1.css"))); | 536 dir.AppendASCII("1.css"))); |
429 } | 537 } |
430 | 538 |
431 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { | 539 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { |
432 GURL url = NavigateToMockURL("a"); | 540 GURL url = NavigateToMockURL("a"); |
433 | 541 |
434 FilePath full_file_name, dir; | 542 FilePath full_file_name, dir; |
435 GetDestinationPaths("a", &full_file_name, &dir); | 543 GetDestinationPaths("a", &full_file_name, &dir); |
436 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, | 544 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir, |
437 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); | 545 content::SAVE_PAGE_TYPE_AS_ONLY_HTML)); |
438 | 546 |
439 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 547 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
440 | 548 |
441 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 549 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
442 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. | 550 // a.htm is 1 file. |
551 CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); | |
443 | 552 |
444 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); | 553 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); |
445 | 554 |
446 // Should not be in history. | 555 // Should not be in history. |
447 QueryDownloadHistory(); | 556 QueryDownloadHistory(); |
448 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), | 557 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), |
449 DownloadPersistentStoreInfoMatch(url, full_file_name, 1)), | 558 DownloadPersistentStoreInfoMatch( |
559 url, full_file_name, 1, DownloadItem::COMPLETE)), | |
450 history_entries_.end()); | 560 history_entries_.end()); |
451 | 561 |
452 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 562 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
453 EXPECT_FALSE(file_util::PathExists(dir)); | 563 EXPECT_FALSE(file_util::PathExists(dir)); |
454 EXPECT_TRUE(file_util::ContentsEqual( | 564 EXPECT_TRUE(file_util::ContentsEqual( |
455 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), | 565 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")), |
456 full_file_name)); | 566 full_file_name)); |
457 } | 567 } |
458 | 568 |
459 // This tests that a webpage with the title "test.exe" is saved as | 569 // This tests that a webpage with the title "test.exe" is saved as |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 #if defined(OS_CHROMEOS) | 623 #if defined(OS_CHROMEOS) |
514 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); | 624 SavePackageFilePickerChromeOS::SetShouldPromptUser(false); |
515 #else | 625 #else |
516 SavePackageFilePicker::SetShouldPromptUser(false); | 626 SavePackageFilePicker::SetShouldPromptUser(false); |
517 #endif | 627 #endif |
518 content::WindowedNotificationObserver observer( | 628 content::WindowedNotificationObserver observer( |
519 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 629 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
520 content::NotificationService::AllSources()); | 630 content::NotificationService::AllSources()); |
521 chrome::SavePage(browser()); | 631 chrome::SavePage(browser()); |
522 observer.Wait(); | 632 observer.Wait(); |
523 CheckDownloadHistory(url, full_file_name, -1); | 633 CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE); |
524 | 634 |
525 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 635 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
526 int64 actual_file_size = -1; | 636 int64 actual_file_size = -1; |
527 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); | 637 EXPECT_TRUE(file_util::GetFileSize(full_file_name, &actual_file_size)); |
528 EXPECT_LE(kFileSizeMin, actual_file_size); | 638 EXPECT_LE(kFileSizeMin, actual_file_size); |
529 } | 639 } |
OLD | NEW |