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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "chrome/browser/download/download_file_icon_extractor.h" | 14 #include "chrome/browser/download/download_file_icon_extractor.h" |
15 #include "chrome/browser/download/download_service.h" | 15 #include "chrome/browser/download/download_service.h" |
16 #include "chrome/browser/download/download_service_factory.h" | 16 #include "chrome/browser/download/download_service_factory.h" |
17 #include "chrome/browser/download/download_test_observer.h" | 17 #include "chrome/browser/download/download_test_file_chooser_observer.h" |
18 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 18 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
19 #include "chrome/browser/extensions/event_names.h" | 19 #include "chrome/browser/extensions/event_names.h" |
20 #include "chrome/browser/extensions/extension_apitest.h" | 20 #include "chrome/browser/extensions/extension_apitest.h" |
21 #include "chrome/browser/extensions/extension_function_test_utils.h" | 21 #include "chrome/browser/extensions/extension_function_test_utils.h" |
22 #include "chrome/browser/net/url_request_mock_util.h" | 22 #include "chrome/browser/net/url_request_mock_util.h" |
23 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
27 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
30 #include "chrome/test/base/in_process_browser_test.h" | 30 #include "chrome/test/base/in_process_browser_test.h" |
31 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
32 #include "content/public/browser/browser_context.h" | 32 #include "content/public/browser/browser_context.h" |
33 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/download_item.h" | 34 #include "content/public/browser/download_item.h" |
35 #include "content/public/browser/download_manager.h" | 35 #include "content/public/browser/download_manager.h" |
36 #include "content/public/browser/download_persistent_store_info.h" | 36 #include "content/public/browser/download_persistent_store_info.h" |
37 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
38 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
39 #include "content/public/common/page_transition_types.h" | 39 #include "content/public/common/page_transition_types.h" |
40 #include "content/public/test/download_test_observer.h" | |
40 #include "content/test/net/url_request_slow_download_job.h" | 41 #include "content/test/net/url_request_slow_download_job.h" |
41 #include "net/base/data_url.h" | 42 #include "net/base/data_url.h" |
42 #include "net/base/net_util.h" | 43 #include "net/base/net_util.h" |
43 #include "net/url_request/url_request.h" | 44 #include "net/url_request/url_request.h" |
44 #include "net/url_request/url_request_context.h" | 45 #include "net/url_request/url_request_context.h" |
45 #include "net/url_request/url_request_job.h" | 46 #include "net/url_request/url_request_job.h" |
46 #include "net/url_request/url_request_job_factory.h" | 47 #include "net/url_request/url_request_job_factory.h" |
47 #include "ui/gfx/codec/png_codec.h" | 48 #include "ui/gfx/codec/png_codec.h" |
48 #include "webkit/blob/blob_data.h" | 49 #include "webkit/blob/blob_data.h" |
49 #include "webkit/blob/blob_storage_controller.h" | 50 #include "webkit/blob/blob_storage_controller.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 history_info[i].danger_type); | 384 history_info[i].danger_type); |
384 items->at(i)->OnContentCheckCompleted(history_info[i].danger_type); | 385 items->at(i)->OnContentCheckCompleted(history_info[i].danger_type); |
385 } | 386 } |
386 } | 387 } |
387 return true; | 388 return true; |
388 } | 389 } |
389 | 390 |
390 void CreateSlowTestDownloads( | 391 void CreateSlowTestDownloads( |
391 size_t count, DownloadManager::DownloadVector* items) { | 392 size_t count, DownloadManager::DownloadVector* items) { |
392 for (size_t i = 0; i < count; ++i) { | 393 for (size_t i = 0; i < count; ++i) { |
393 scoped_ptr<DownloadTestObserver> observer( | 394 scoped_ptr<content::DownloadTestObserver> observer( |
benjhayden
2012/08/13 16:35:18
using content::DownloadTestObserver?
Randy Smith (Not in Mondays)
2012/08/13 18:57:49
See comment elsewhere about "using".
| |
394 CreateInProgressDownloadObserver(1)); | 395 CreateInProgressDownloadObserver(1)); |
395 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); | 396 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
396 ui_test_utils::NavigateToURLWithDisposition( | 397 ui_test_utils::NavigateToURLWithDisposition( |
397 current_browser(), slow_download_url, CURRENT_TAB, | 398 current_browser(), slow_download_url, CURRENT_TAB, |
398 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 399 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
399 observer->WaitForFinished(); | 400 observer->WaitForFinished(); |
400 EXPECT_EQ( | 401 EXPECT_EQ( |
401 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); | 402 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); |
402 } | 403 } |
403 GetCurrentManager()->GetAllDownloads(FilePath(), items); | 404 GetCurrentManager()->GetAllDownloads(FilePath(), items); |
404 ASSERT_EQ(count, items->size()); | 405 ASSERT_EQ(count, items->size()); |
405 } | 406 } |
406 | 407 |
407 DownloadItem* CreateSlowTestDownload() { | 408 DownloadItem* CreateSlowTestDownload() { |
408 scoped_ptr<DownloadTestObserver> observer( | 409 scoped_ptr<content::DownloadTestObserver> observer( |
409 CreateInProgressDownloadObserver(1)); | 410 CreateInProgressDownloadObserver(1)); |
410 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); | 411 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
411 DownloadManager* manager = GetCurrentManager(); | 412 DownloadManager* manager = GetCurrentManager(); |
412 | 413 |
413 EXPECT_EQ(0, manager->InProgressCount()); | 414 EXPECT_EQ(0, manager->InProgressCount()); |
414 if (manager->InProgressCount() != 0) | 415 if (manager->InProgressCount() != 0) |
415 return NULL; | 416 return NULL; |
416 | 417 |
417 ui_test_utils::NavigateToURLWithDisposition( | 418 ui_test_utils::NavigateToURLWithDisposition( |
418 current_browser(), slow_download_url, CURRENT_TAB, | 419 current_browser(), slow_download_url, CURRENT_TAB, |
(...skipping 11 matching lines...) Expand all Loading... | |
430 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { | 431 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { |
431 // There should be only one IN_PROGRESS item. | 432 // There should be only one IN_PROGRESS item. |
432 EXPECT_EQ(NULL, new_item); | 433 EXPECT_EQ(NULL, new_item); |
433 new_item = *iter; | 434 new_item = *iter; |
434 } | 435 } |
435 } | 436 } |
436 return new_item; | 437 return new_item; |
437 } | 438 } |
438 | 439 |
439 void FinishPendingSlowDownloads() { | 440 void FinishPendingSlowDownloads() { |
440 scoped_ptr<DownloadTestObserver> observer( | 441 scoped_ptr<content::DownloadTestObserver> observer( |
441 CreateDownloadObserver(1)); | 442 CreateDownloadObserver(1)); |
442 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | 443 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
443 ui_test_utils::NavigateToURLWithDisposition( | 444 ui_test_utils::NavigateToURLWithDisposition( |
444 current_browser(), finish_url, NEW_FOREGROUND_TAB, | 445 current_browser(), finish_url, NEW_FOREGROUND_TAB, |
445 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 446 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
446 observer->WaitForFinished(); | 447 observer->WaitForFinished(); |
447 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 448 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
448 } | 449 } |
449 | 450 |
450 DownloadTestObserver* CreateDownloadObserver(size_t download_count) { | 451 content::DownloadTestObserver* CreateDownloadObserver(size_t download_count) { |
451 return new DownloadTestObserverTerminal( | 452 return new content::DownloadTestObserverTerminal( |
452 GetCurrentManager(), download_count, | 453 GetCurrentManager(), download_count, |
453 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 454 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
454 } | 455 } |
455 | 456 |
456 DownloadTestObserver* CreateInProgressDownloadObserver( | 457 content::DownloadTestObserver* CreateInProgressDownloadObserver( |
457 size_t download_count) { | 458 size_t download_count) { |
458 return new DownloadTestObserverInProgress( | 459 return new content::DownloadTestObserverInProgress( |
459 GetCurrentManager(), download_count); | 460 GetCurrentManager(), download_count); |
460 } | 461 } |
461 | 462 |
462 bool RunFunction(UIThreadExtensionFunction* function, | 463 bool RunFunction(UIThreadExtensionFunction* function, |
463 const std::string& args) { | 464 const std::string& args) { |
464 scoped_refptr<UIThreadExtensionFunction> delete_function(function); | 465 scoped_refptr<UIThreadExtensionFunction> delete_function(function); |
465 SetUpExtensionFunction(function); | 466 SetUpExtensionFunction(function); |
466 return extension_function_test_utils::RunFunction( | 467 return extension_function_test_utils::RunFunction( |
467 function, args, browser(), GetFlags()); | 468 function, args, browser(), GetFlags()); |
468 } | 469 } |
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2156 " \"state\": {" | 2157 " \"state\": {" |
2157 " \"previous\": \"in_progress\"," | 2158 " \"previous\": \"in_progress\"," |
2158 " \"current\": \"complete\"}}]", | 2159 " \"current\": \"complete\"}}]", |
2159 result_id, | 2160 result_id, |
2160 GetFilename("on_record.txt.crdownload").c_str(), | 2161 GetFilename("on_record.txt.crdownload").c_str(), |
2161 GetFilename("on_record.txt").c_str()))); | 2162 GetFilename("on_record.txt").c_str()))); |
2162 std::string disk_data; | 2163 std::string disk_data; |
2163 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2164 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
2164 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2165 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
2165 } | 2166 } |
OLD | NEW |