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 // Disable everything on windows only. http://crbug.com/306144 | 5 // Disable everything on windows only. http://crbug.com/306144 |
6 #ifndef OS_WIN | 6 #ifndef OS_WIN |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "content/test/net/url_request_slow_download_job.h" | 44 #include "content/test/net/url_request_slow_download_job.h" |
45 #include "extensions/browser/event_router.h" | 45 #include "extensions/browser/event_router.h" |
46 #include "extensions/browser/notification_types.h" | 46 #include "extensions/browser/notification_types.h" |
47 #include "net/base/data_url.h" | 47 #include "net/base/data_url.h" |
48 #include "net/base/net_util.h" | 48 #include "net/base/net_util.h" |
49 #include "net/url_request/url_request.h" | 49 #include "net/url_request/url_request.h" |
50 #include "net/url_request/url_request_context.h" | 50 #include "net/url_request/url_request_context.h" |
51 #include "net/url_request/url_request_job.h" | 51 #include "net/url_request/url_request_job.h" |
52 #include "net/url_request/url_request_job_factory.h" | 52 #include "net/url_request/url_request_job_factory.h" |
53 #include "net/url_request/url_request_job_factory_impl.h" | 53 #include "net/url_request/url_request_job_factory_impl.h" |
54 #include "webkit/browser/fileapi/file_system_context.h" | 54 #include "storage/browser/fileapi/file_system_context.h" |
55 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 55 #include "storage/browser/fileapi/file_system_operation_runner.h" |
56 #include "webkit/browser/fileapi/file_system_url.h" | 56 #include "storage/browser/fileapi/file_system_url.h" |
57 | 57 |
58 using content::BrowserContext; | 58 using content::BrowserContext; |
59 using content::BrowserThread; | 59 using content::BrowserThread; |
60 using content::DownloadItem; | 60 using content::DownloadItem; |
61 using content::DownloadManager; | 61 using content::DownloadManager; |
62 using content::URLRequestSlowDownloadJob; | 62 using content::URLRequestSlowDownloadJob; |
63 | 63 |
64 namespace errors = download_extension_errors; | 64 namespace errors = download_extension_errors; |
65 | 65 |
66 namespace extensions { | 66 namespace extensions { |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 } | 692 } |
693 | 693 |
694 private: | 694 private: |
695 DownloadManager::DownloadVector* items_; | 695 DownloadManager::DownloadVector* items_; |
696 DISALLOW_COPY_AND_ASSIGN(ScopedItemVectorCanceller); | 696 DISALLOW_COPY_AND_ASSIGN(ScopedItemVectorCanceller); |
697 }; | 697 }; |
698 | 698 |
699 // Writes an HTML5 file so that it can be downloaded. | 699 // Writes an HTML5 file so that it can be downloaded. |
700 class HTML5FileWriter { | 700 class HTML5FileWriter { |
701 public: | 701 public: |
702 static bool CreateFileForTesting(fileapi::FileSystemContext* context, | 702 static bool CreateFileForTesting(storage::FileSystemContext* context, |
703 const fileapi::FileSystemURL& path, | 703 const storage::FileSystemURL& path, |
704 const char*data, | 704 const char* data, |
705 int length) { | 705 int length) { |
706 // Create a temp file. | 706 // Create a temp file. |
707 base::FilePath temp_file; | 707 base::FilePath temp_file; |
708 if (!base::CreateTemporaryFile(&temp_file) || | 708 if (!base::CreateTemporaryFile(&temp_file) || |
709 base::WriteFile(temp_file, data, length) != length) { | 709 base::WriteFile(temp_file, data, length) != length) { |
710 return false; | 710 return false; |
711 } | 711 } |
712 // Invoke the fileapi to copy it into the sandboxed filesystem. | 712 // Invoke the fileapi to copy it into the sandboxed filesystem. |
713 bool result = false; | 713 bool result = false; |
714 base::WaitableEvent done_event(true, false); | 714 base::WaitableEvent done_event(true, false); |
(...skipping 13 matching lines...) Expand all Loading... |
728 private: | 728 private: |
729 static void CopyInCompletion(bool* result, | 729 static void CopyInCompletion(bool* result, |
730 base::WaitableEvent* done_event, | 730 base::WaitableEvent* done_event, |
731 base::File::Error error) { | 731 base::File::Error error) { |
732 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 732 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
733 *result = error == base::File::FILE_OK; | 733 *result = error == base::File::FILE_OK; |
734 done_event->Signal(); | 734 done_event->Signal(); |
735 } | 735 } |
736 | 736 |
737 static void CreateFileForTestingOnIOThread( | 737 static void CreateFileForTestingOnIOThread( |
738 fileapi::FileSystemContext* context, | 738 storage::FileSystemContext* context, |
739 const fileapi::FileSystemURL& path, | 739 const storage::FileSystemURL& path, |
740 const base::FilePath& temp_file, | 740 const base::FilePath& temp_file, |
741 bool* result, | 741 bool* result, |
742 base::WaitableEvent* done_event) { | 742 base::WaitableEvent* done_event) { |
743 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 743 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
744 context->operation_runner()->CopyInForeignFile( | 744 context->operation_runner()->CopyInForeignFile( |
745 temp_file, path, | 745 temp_file, path, |
746 base::Bind(&CopyInCompletion, | 746 base::Bind(&CopyInCompletion, |
747 base::Unretained(result), | 747 base::Unretained(result), |
748 base::Unretained(done_event))); | 748 base::Unretained(done_event))); |
749 } | 749 } |
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2324 MAYBE_DownloadExtensionTest_Download_FileSystemURL) { | 2324 MAYBE_DownloadExtensionTest_Download_FileSystemURL) { |
2325 static const char* kPayloadData = "on the record\ndata"; | 2325 static const char* kPayloadData = "on the record\ndata"; |
2326 GoOnTheRecord(); | 2326 GoOnTheRecord(); |
2327 LoadExtension("downloads_split"); | 2327 LoadExtension("downloads_split"); |
2328 | 2328 |
2329 const std::string download_url = "filesystem:" + GetExtensionURL() + | 2329 const std::string download_url = "filesystem:" + GetExtensionURL() + |
2330 "temporary/on_record.txt"; | 2330 "temporary/on_record.txt"; |
2331 | 2331 |
2332 // Setup a file in the filesystem which we can download. | 2332 // Setup a file in the filesystem which we can download. |
2333 ASSERT_TRUE(HTML5FileWriter::CreateFileForTesting( | 2333 ASSERT_TRUE(HTML5FileWriter::CreateFileForTesting( |
2334 BrowserContext::GetDefaultStoragePartition(browser()->profile())-> | 2334 BrowserContext::GetDefaultStoragePartition(browser()->profile()) |
2335 GetFileSystemContext(), | 2335 ->GetFileSystemContext(), |
2336 fileapi::FileSystemURL::CreateForTest(GURL(download_url)), | 2336 storage::FileSystemURL::CreateForTest(GURL(download_url)), |
2337 kPayloadData, strlen(kPayloadData))); | 2337 kPayloadData, |
| 2338 strlen(kPayloadData))); |
2338 | 2339 |
2339 // Now download it. | 2340 // Now download it. |
2340 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 2341 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
2341 new DownloadsDownloadFunction(), base::StringPrintf( | 2342 new DownloadsDownloadFunction(), base::StringPrintf( |
2342 "[{\"url\": \"%s\"}]", download_url.c_str()))); | 2343 "[{\"url\": \"%s\"}]", download_url.c_str()))); |
2343 ASSERT_TRUE(result.get()); | 2344 ASSERT_TRUE(result.get()); |
2344 int result_id = -1; | 2345 int result_id = -1; |
2345 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2346 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2346 | 2347 |
2347 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2348 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
(...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4125 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); | 4126 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
4126 EXPECT_FALSE(warnings.empty()); | 4127 EXPECT_FALSE(warnings.empty()); |
4127 EXPECT_EQ(ExtensionWarning::kDownloadFilenameConflict, | 4128 EXPECT_EQ(ExtensionWarning::kDownloadFilenameConflict, |
4128 warnings.begin()->warning_type()); | 4129 warnings.begin()->warning_type()); |
4129 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 4130 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
4130 } | 4131 } |
4131 | 4132 |
4132 } // namespace extensions | 4133 } // namespace extensions |
4133 | 4134 |
4134 #endif // http://crbug.com/3061144 | 4135 #endif // http://crbug.com/3061144 |
OLD | NEW |