| 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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 const char* data, | 694 const char* data, |
| 695 int length) { | 695 int length) { |
| 696 // Create a temp file. | 696 // Create a temp file. |
| 697 base::FilePath temp_file; | 697 base::FilePath temp_file; |
| 698 if (!base::CreateTemporaryFile(&temp_file) || | 698 if (!base::CreateTemporaryFile(&temp_file) || |
| 699 base::WriteFile(temp_file, data, length) != length) { | 699 base::WriteFile(temp_file, data, length) != length) { |
| 700 return false; | 700 return false; |
| 701 } | 701 } |
| 702 // Invoke the fileapi to copy it into the sandboxed filesystem. | 702 // Invoke the fileapi to copy it into the sandboxed filesystem. |
| 703 bool result = false; | 703 bool result = false; |
| 704 base::WaitableEvent done_event( | 704 base::RunLoop run_loop; |
| 705 base::WaitableEvent::ResetPolicy::MANUAL, | |
| 706 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
| 707 BrowserThread::PostTask( | 705 BrowserThread::PostTask( |
| 708 BrowserThread::IO, FROM_HERE, | 706 BrowserThread::IO, FROM_HERE, |
| 709 base::Bind(&CreateFileForTestingOnIOThread, | 707 base::Bind(&CreateFileForTestingOnIOThread, base::Unretained(context), |
| 710 base::Unretained(context), | 708 path, temp_file, base::Unretained(&result), |
| 711 path, temp_file, | 709 run_loop.QuitClosure())); |
| 712 base::Unretained(&result), | |
| 713 base::Unretained(&done_event))); | |
| 714 // Wait for that to finish. | 710 // Wait for that to finish. |
| 715 done_event.Wait(); | 711 run_loop.Run(); |
| 716 base::DeleteFile(temp_file, false); | 712 base::DeleteFile(temp_file, false); |
| 717 return result; | 713 return result; |
| 718 } | 714 } |
| 719 | 715 |
| 720 private: | 716 private: |
| 721 static void CopyInCompletion(bool* result, | 717 static void CopyInCompletion(bool* result, |
| 722 base::WaitableEvent* done_event, | 718 const base::Closure& quit_closure, |
| 723 base::File::Error error) { | 719 base::File::Error error) { |
| 724 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 720 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 725 *result = error == base::File::FILE_OK; | 721 *result = error == base::File::FILE_OK; |
| 726 done_event->Signal(); | 722 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_closure); |
| 727 } | 723 } |
| 728 | 724 |
| 729 static void CreateFileForTestingOnIOThread( | 725 static void CreateFileForTestingOnIOThread( |
| 730 storage::FileSystemContext* context, | 726 storage::FileSystemContext* context, |
| 731 const storage::FileSystemURL& path, | 727 const storage::FileSystemURL& path, |
| 732 const base::FilePath& temp_file, | 728 const base::FilePath& temp_file, |
| 733 bool* result, | 729 bool* result, |
| 734 base::WaitableEvent* done_event) { | 730 const base::Closure& quit_closure) { |
| 735 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 731 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 736 context->operation_runner()->CopyInForeignFile( | 732 context->operation_runner()->CopyInForeignFile( |
| 737 temp_file, path, | 733 temp_file, path, |
| 738 base::Bind(&CopyInCompletion, | 734 base::Bind(&CopyInCompletion, base::Unretained(result), quit_closure)); |
| 739 base::Unretained(result), | |
| 740 base::Unretained(done_event))); | |
| 741 } | 735 } |
| 742 }; | 736 }; |
| 743 | 737 |
| 744 // TODO(benjhayden) Merge this with the other TestObservers. | 738 // TODO(benjhayden) Merge this with the other TestObservers. |
| 745 class JustInProgressDownloadObserver | 739 class JustInProgressDownloadObserver |
| 746 : public content::DownloadTestObserverInProgress { | 740 : public content::DownloadTestObserverInProgress { |
| 747 public: | 741 public: |
| 748 JustInProgressDownloadObserver( | 742 JustInProgressDownloadObserver( |
| 749 DownloadManager* download_manager, size_t wait_count) | 743 DownloadManager* download_manager, size_t wait_count) |
| 750 : content::DownloadTestObserverInProgress(download_manager, wait_count) { | 744 : content::DownloadTestObserverInProgress(download_manager, wait_count) { |
| (...skipping 3556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4307 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); | 4301 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
| 4308 EXPECT_FALSE(warnings.empty()); | 4302 EXPECT_FALSE(warnings.empty()); |
| 4309 EXPECT_EQ(Warning::kDownloadFilenameConflict, | 4303 EXPECT_EQ(Warning::kDownloadFilenameConflict, |
| 4310 warnings.begin()->warning_type()); | 4304 warnings.begin()->warning_type()); |
| 4311 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 4305 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
| 4312 } | 4306 } |
| 4313 | 4307 |
| 4314 } // namespace extensions | 4308 } // namespace extensions |
| 4315 | 4309 |
| 4316 #endif // http://crbug.com/306144 | 4310 #endif // http://crbug.com/306144 |
| OLD | NEW |