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, |
712 base::Unretained(context), | 710 base::Unretained(context), |
713 path, temp_file, | 711 path, temp_file, |
714 base::Unretained(&result), | 712 base::Unretained(&result), |
715 base::Unretained(&done_event))); | 713 run_loop.QuitClosure())); |
716 // Wait for that to finish. | 714 // Wait for that to finish. |
717 done_event.Wait(); | 715 run_loop.Run(); |
718 base::DeleteFile(temp_file, false); | 716 base::DeleteFile(temp_file, false); |
719 return result; | 717 return result; |
720 } | 718 } |
721 | 719 |
722 private: | 720 private: |
723 static void CopyInCompletion(bool* result, | 721 static void CopyInCompletion(bool* result, |
724 base::WaitableEvent* done_event, | 722 const base::Closure& quit_closure, |
725 base::File::Error error) { | 723 base::File::Error error) { |
726 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 724 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
727 *result = error == base::File::FILE_OK; | 725 *result = error == base::File::FILE_OK; |
728 done_event->Signal(); | 726 BrowserThread::PostTask( |
| 727 BrowserThread::UI, FROM_HERE, quit_closure); |
729 } | 728 } |
730 | 729 |
731 static void CreateFileForTestingOnIOThread( | 730 static void CreateFileForTestingOnIOThread( |
732 storage::FileSystemContext* context, | 731 storage::FileSystemContext* context, |
733 const storage::FileSystemURL& path, | 732 const storage::FileSystemURL& path, |
734 const base::FilePath& temp_file, | 733 const base::FilePath& temp_file, |
735 bool* result, | 734 bool* result, |
736 base::WaitableEvent* done_event) { | 735 const base::Closure& quit_closure) { |
737 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 736 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
738 context->operation_runner()->CopyInForeignFile( | 737 context->operation_runner()->CopyInForeignFile( |
739 temp_file, path, | 738 temp_file, path, |
740 base::Bind(&CopyInCompletion, | 739 base::Bind(&CopyInCompletion, |
741 base::Unretained(result), | 740 base::Unretained(result), |
742 base::Unretained(done_event))); | 741 quit_closure)); |
743 } | 742 } |
744 }; | 743 }; |
745 | 744 |
746 // TODO(benjhayden) Merge this with the other TestObservers. | 745 // TODO(benjhayden) Merge this with the other TestObservers. |
747 class JustInProgressDownloadObserver | 746 class JustInProgressDownloadObserver |
748 : public content::DownloadTestObserverInProgress { | 747 : public content::DownloadTestObserverInProgress { |
749 public: | 748 public: |
750 JustInProgressDownloadObserver( | 749 JustInProgressDownloadObserver( |
751 DownloadManager* download_manager, size_t wait_count) | 750 DownloadManager* download_manager, size_t wait_count) |
752 : content::DownloadTestObserverInProgress(download_manager, wait_count) { | 751 : 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); | 4302 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
4304 EXPECT_FALSE(warnings.empty()); | 4303 EXPECT_FALSE(warnings.empty()); |
4305 EXPECT_EQ(Warning::kDownloadFilenameConflict, | 4304 EXPECT_EQ(Warning::kDownloadFilenameConflict, |
4306 warnings.begin()->warning_type()); | 4305 warnings.begin()->warning_type()); |
4307 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 4306 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
4308 } | 4307 } |
4309 | 4308 |
4310 } // namespace extensions | 4309 } // namespace extensions |
4311 | 4310 |
4312 #endif // http://crbug.com/306144 | 4311 #endif // http://crbug.com/306144 |
OLD | NEW |