| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 | 12 |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/guid.h" | 15 #include "base/guid.h" |
| 16 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/run_loop.h" |
| 20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 21 #include "base/synchronization/waitable_event.h" | |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "chrome/browser/download/download_file_icon_extractor.h" | 23 #include "chrome/browser/download/download_file_icon_extractor.h" |
| 24 #include "chrome/browser/download/download_service.h" | 24 #include "chrome/browser/download/download_service.h" |
| 25 #include "chrome/browser/download/download_service_factory.h" | 25 #include "chrome/browser/download/download_service_factory.h" |
| 26 #include "chrome/browser/download/download_test_file_activity_observer.h" | 26 #include "chrome/browser/download/download_test_file_activity_observer.h" |
| 27 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 27 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
| 28 #include "chrome/browser/extensions/browser_action_test_util.h" | 28 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 29 #include "chrome/browser/extensions/extension_apitest.h" | 29 #include "chrome/browser/extensions/extension_apitest.h" |
| 30 #include "chrome/browser/extensions/extension_function_test_utils.h" | 30 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 31 #include "chrome/browser/net/url_request_mock_util.h" | 31 #include "chrome/browser/net/url_request_mock_util.h" |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 const char* data, | 696 const char* data, |
| 697 int length) { | 697 int length) { |
| 698 // Create a temp file. | 698 // Create a temp file. |
| 699 base::FilePath temp_file; | 699 base::FilePath temp_file; |
| 700 if (!base::CreateTemporaryFile(&temp_file) || | 700 if (!base::CreateTemporaryFile(&temp_file) || |
| 701 base::WriteFile(temp_file, data, length) != length) { | 701 base::WriteFile(temp_file, data, length) != length) { |
| 702 return false; | 702 return false; |
| 703 } | 703 } |
| 704 // Invoke the fileapi to copy it into the sandboxed filesystem. | 704 // Invoke the fileapi to copy it into the sandboxed filesystem. |
| 705 bool result = false; | 705 bool result = false; |
| 706 base::WaitableEvent done_event( | 706 base::RunLoop run_loop; |
| 707 base::WaitableEvent::ResetPolicy::MANUAL, | |
| 708 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
| 709 BrowserThread::PostTask( | 707 BrowserThread::PostTask( |
| 710 BrowserThread::IO, FROM_HERE, | 708 BrowserThread::IO, FROM_HERE, |
| 711 base::Bind(&CreateFileForTestingOnIOThread, | 709 base::Bind(&CreateFileForTestingOnIOThread, base::Unretained(context), |
| 712 base::Unretained(context), | 710 path, temp_file, base::Unretained(&result), |
| 713 path, temp_file, | 711 run_loop.QuitClosure())); |
| 714 base::Unretained(&result), | |
| 715 base::Unretained(&done_event))); | |
| 716 // Wait for that to finish. | 712 // Wait for that to finish. |
| 717 done_event.Wait(); | 713 run_loop.Run(); |
| 718 base::DeleteFile(temp_file, false); | 714 base::DeleteFile(temp_file, false); |
| 719 return result; | 715 return result; |
| 720 } | 716 } |
| 721 | 717 |
| 722 private: | 718 private: |
| 723 static void CopyInCompletion(bool* result, | 719 static void CopyInCompletion(bool* result, |
| 724 base::WaitableEvent* done_event, | 720 const base::Closure& quit_closure, |
| 725 base::File::Error error) { | 721 base::File::Error error) { |
| 726 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 722 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 727 *result = error == base::File::FILE_OK; | 723 *result = error == base::File::FILE_OK; |
| 728 done_event->Signal(); | 724 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_closure); |
| 729 } | 725 } |
| 730 | 726 |
| 731 static void CreateFileForTestingOnIOThread( | 727 static void CreateFileForTestingOnIOThread( |
| 732 storage::FileSystemContext* context, | 728 storage::FileSystemContext* context, |
| 733 const storage::FileSystemURL& path, | 729 const storage::FileSystemURL& path, |
| 734 const base::FilePath& temp_file, | 730 const base::FilePath& temp_file, |
| 735 bool* result, | 731 bool* result, |
| 736 base::WaitableEvent* done_event) { | 732 const base::Closure& quit_closure) { |
| 737 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 733 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 738 context->operation_runner()->CopyInForeignFile( | 734 context->operation_runner()->CopyInForeignFile( |
| 739 temp_file, path, | 735 temp_file, path, |
| 740 base::Bind(&CopyInCompletion, | 736 base::Bind(&CopyInCompletion, base::Unretained(result), quit_closure)); |
| 741 base::Unretained(result), | |
| 742 base::Unretained(done_event))); | |
| 743 } | 737 } |
| 744 }; | 738 }; |
| 745 | 739 |
| 746 // TODO(benjhayden) Merge this with the other TestObservers. | 740 // TODO(benjhayden) Merge this with the other TestObservers. |
| 747 class JustInProgressDownloadObserver | 741 class JustInProgressDownloadObserver |
| 748 : public content::DownloadTestObserverInProgress { | 742 : public content::DownloadTestObserverInProgress { |
| 749 public: | 743 public: |
| 750 JustInProgressDownloadObserver( | 744 JustInProgressDownloadObserver( |
| 751 DownloadManager* download_manager, size_t wait_count) | 745 DownloadManager* download_manager, size_t wait_count) |
| 752 : content::DownloadTestObserverInProgress(download_manager, wait_count) { | 746 : content::DownloadTestObserverInProgress(download_manager, wait_count) { |
| (...skipping 3550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4303 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); | 4297 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
| 4304 EXPECT_FALSE(warnings.empty()); | 4298 EXPECT_FALSE(warnings.empty()); |
| 4305 EXPECT_EQ(Warning::kDownloadFilenameConflict, | 4299 EXPECT_EQ(Warning::kDownloadFilenameConflict, |
| 4306 warnings.begin()->warning_type()); | 4300 warnings.begin()->warning_type()); |
| 4307 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 4301 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
| 4308 } | 4302 } |
| 4309 | 4303 |
| 4310 } // namespace extensions | 4304 } // namespace extensions |
| 4311 | 4305 |
| 4312 #endif // http://crbug.com/306144 | 4306 #endif // http://crbug.com/306144 |
| OLD | NEW |