| 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // bound as that parameter. | 56 // bound as that parameter. |
| 57 // Example: | 57 // Example: |
| 58 // class FooClass { | 58 // class FooClass { |
| 59 // public: | 59 // public: |
| 60 // virtual void Foo(base::Callback<void(bool)> callback); | 60 // virtual void Foo(base::Callback<void(bool)> callback); |
| 61 // }; | 61 // }; |
| 62 // ... | 62 // ... |
| 63 // EXPECT_CALL(mock_fooclass_instance, Foo(callback)) | 63 // EXPECT_CALL(mock_fooclass_instance, Foo(callback)) |
| 64 // .WillOnce(ScheduleCallback(false)); | 64 // .WillOnce(ScheduleCallback(false)); |
| 65 ACTION_P(ScheduleCallback, result) { | 65 ACTION_P(ScheduleCallback, result) { |
| 66 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(arg0, result)); | 66 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(arg0, result)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Used with DownloadTestCase. Indicates the type of test case. The expectations | 69 // Used with DownloadTestCase. Indicates the type of test case. The expectations |
| 70 // for the test is set based on the type. | 70 // for the test is set based on the type. |
| 71 enum TestCaseType { | 71 enum TestCaseType { |
| 72 SAVE_AS, | 72 SAVE_AS, |
| 73 AUTOMATIC, | 73 AUTOMATIC, |
| 74 FORCED // Requires that forced_file_path be non-empty. | 74 FORCED // Requires that forced_file_path be non-empty. |
| 75 }; | 75 }; |
| 76 | 76 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 186 |
| 187 virtual void GetReservedPath( | 187 virtual void GetReservedPath( |
| 188 content::DownloadItem& download, | 188 content::DownloadItem& download, |
| 189 const base::FilePath& target_path, | 189 const base::FilePath& target_path, |
| 190 const base::FilePath& default_download_path, | 190 const base::FilePath& default_download_path, |
| 191 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | 191 DownloadPathReservationTracker::FilenameConflictAction conflict_action, |
| 192 const DownloadPathReservationTracker::ReservedPathCallback& callback) | 192 const DownloadPathReservationTracker::ReservedPathCallback& callback) |
| 193 OVERRIDE { | 193 OVERRIDE { |
| 194 // Pretend the path reservation succeeded without any change to | 194 // Pretend the path reservation succeeded without any change to |
| 195 // |target_path|. | 195 // |target_path|. |
| 196 MessageLoop::current()->PostTask(FROM_HERE, | 196 base::MessageLoop::current()->PostTask( |
| 197 base::Bind(callback, target_path, true)); | 197 FROM_HERE, base::Bind(callback, target_path, true)); |
| 198 } | 198 } |
| 199 | 199 |
| 200 // During tests, we want to mock the behavior of this method. | 200 // During tests, we want to mock the behavior of this method. |
| 201 MOCK_METHOD3(ChooseDownloadPath, | 201 MOCK_METHOD3(ChooseDownloadPath, |
| 202 void(content::DownloadItem*, | 202 void(content::DownloadItem*, |
| 203 const base::FilePath&, | 203 const base::FilePath&, |
| 204 const FileSelectedCallback&)); | 204 const FileSelectedCallback&)); |
| 205 | 205 |
| 206 #if defined(FULL_SAFE_BROWSING) | 206 #if defined(FULL_SAFE_BROWSING) |
| 207 // A TestDownloadProtectionService* is convenient for setting up mocks. | 207 // A TestDownloadProtectionService* is convenient for setting up mocks. |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 // Run the first test case again. Since the last download path was cleared, | 917 // Run the first test case again. Since the last download path was cleared, |
| 918 // this test case should behave identically to the first time it was run. | 918 // this test case should behave identically to the first time it was run. |
| 919 RunTestCases(kLastSavePathTestCases, 1); | 919 RunTestCases(kLastSavePathTestCases, 1); |
| 920 } | 920 } |
| 921 | 921 |
| 922 // TODO(asanka): Add more tests. | 922 // TODO(asanka): Add more tests. |
| 923 // * Default download path is not writable. | 923 // * Default download path is not writable. |
| 924 // * Download path doesn't exist. | 924 // * Download path doesn't exist. |
| 925 // * IsDangerousFile(). | 925 // * IsDangerousFile(). |
| 926 // * Filename generation. | 926 // * Filename generation. |
| OLD | NEW |