OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ |
7 | 7 |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // A fake for the DiskMountManager that will successfully call the unmount | 58 // A fake for the DiskMountManager that will successfully call the unmount |
59 // callback. | 59 // callback. |
60 class FakeDiskMountManager : public chromeos::disks::MockDiskMountManager { | 60 class FakeDiskMountManager : public chromeos::disks::MockDiskMountManager { |
61 public: | 61 public: |
62 FakeDiskMountManager(); | 62 FakeDiskMountManager(); |
63 virtual ~FakeDiskMountManager(); | 63 virtual ~FakeDiskMountManager(); |
64 | 64 |
65 virtual void UnmountDeviceRecursively( | 65 virtual void UnmountDeviceRecursively( |
66 const std::string& device_path, | 66 const std::string& device_path, |
67 const UnmountDeviceRecursivelyCallbackType& callback) OVERRIDE; | 67 const UnmountDeviceRecursivelyCallbackType& callback) OVERRIDE; |
| 68 /* |
| 69 MOCK_METHOD1(AddObserver, void(chromeos::disks::DiskMountManager::Observer*)); |
| 70 MOCK_METHOD1(RemoveObserver, |
| 71 void(chromeos::disks::DiskMountManager::Observer*)); |
| 72 MOCK_CONST_METHOD0(disks, const DiskMap&()); |
| 73 MOCK_CONST_METHOD1(FindDiskBySourcePath, const Disk*(const std::string&)); |
| 74 MOCK_CONST_METHOD0(mount_points, const MountPointMap&()); |
| 75 MOCK_METHOD0(RequestMountInfoRefresh, void()); |
| 76 MOCK_METHOD4(MountPath, void(const std::string&, const std::string&, const |
| 77 std::string&, chromeos::MountType)); |
| 78 MOCK_METHOD3(UnmountPath, void(const std::string&, chromeos::UnmountOptions, |
| 79 const UnmountPathCallback&)); |
| 80 MOCK_METHOD1(FormatMountedDevice, void(const std::string&)); |
| 81 */ |
68 | 82 |
69 private: | 83 private: |
70 DiskMap disks_; | 84 DiskMap disks_; |
71 }; | 85 }; |
72 #endif | 86 #endif |
73 | 87 |
74 class FakeImageWriterClient : public ImageWriterUtilityClient { | 88 class FakeImageWriterClient : public ImageWriterUtilityClient { |
75 public: | 89 public: |
76 FakeImageWriterClient(); | 90 FakeImageWriterClient(); |
77 | 91 |
78 virtual void Write(const ProgressCallback& progress_callback, | 92 virtual void Write(const ProgressCallback& progress_callback, |
79 const SuccessCallback& success_callback, | 93 const SuccessCallback& success_callback, |
80 const ErrorCallback& error_callback, | 94 const ErrorCallback& error_callback, |
81 const base::FilePath& source, | 95 const base::FilePath& source, |
82 const base::FilePath& target) OVERRIDE; | 96 const base::FilePath& target) OVERRIDE; |
83 | 97 |
84 virtual void Verify(const ProgressCallback& progress_callback, | 98 virtual void Verify(const ProgressCallback& progress_callback, |
85 const SuccessCallback& success_callback, | 99 const SuccessCallback& success_callback, |
86 const ErrorCallback& error_callback, | 100 const ErrorCallback& error_callback, |
87 const base::FilePath& source, | 101 const base::FilePath& source, |
88 const base::FilePath& target) OVERRIDE; | 102 const base::FilePath& target) OVERRIDE; |
89 | 103 |
90 virtual void Cancel(const CancelCallback& cancel_callback) OVERRIDE; | 104 virtual void Cancel(const CancelCallback& cancel_callback) OVERRIDE; |
91 | 105 |
92 virtual void Shutdown() OVERRIDE; | 106 virtual void Shutdown() OVERRIDE; |
93 | 107 |
94 // Sets a callback for when a Write call is made. | |
95 void SetWriteCallback(const base::Closure& write_callback); | |
96 // Sets a callback for when a Verify call is made. | |
97 void SetVerifyCallback(const base::Closure& verify_callback); | |
98 | |
99 // Triggers the progress callback. | |
100 void Progress(int64 progress); | 108 void Progress(int64 progress); |
101 // Triggers the success callback. | |
102 void Success(); | 109 void Success(); |
103 // Triggers the error callback. | |
104 void Error(const std::string& message); | 110 void Error(const std::string& message); |
105 // Triggers the cancel callback. | |
106 void Cancel(); | 111 void Cancel(); |
| 112 static scoped_refptr<FakeImageWriterClient> Create(); |
107 | 113 |
108 private: | 114 private: |
109 virtual ~FakeImageWriterClient(); | 115 virtual ~FakeImageWriterClient(); |
110 | 116 |
111 ProgressCallback progress_callback_; | 117 ProgressCallback progress_callback_; |
112 SuccessCallback success_callback_; | 118 SuccessCallback success_callback_; |
113 ErrorCallback error_callback_; | 119 ErrorCallback error_callback_; |
114 CancelCallback cancel_callback_; | 120 CancelCallback cancel_callback_; |
115 | |
116 base::Closure write_callback_; | |
117 base::Closure verify_callback_; | |
118 }; | 121 }; |
119 | 122 |
120 class ImageWriterTestUtils { | 123 // Base class for unit tests that manages creating image and device files. |
121 public: | 124 class ImageWriterUnitTestBase : public testing::Test { |
122 ImageWriterTestUtils(); | 125 protected: |
123 virtual ~ImageWriterTestUtils(); | 126 ImageWriterUnitTestBase(); |
| 127 virtual ~ImageWriterUnitTestBase(); |
| 128 |
| 129 virtual void SetUp() OVERRIDE; |
| 130 |
| 131 virtual void TearDown() OVERRIDE; |
124 | 132 |
125 // Verifies that the data in image_path was written to the file at | 133 // Verifies that the data in image_path was written to the file at |
126 // device_path. This is different from base::ContentsEqual because the device | 134 // device_path. This is different from base::ContentsEqual because the device |
127 // may be larger than the image. | 135 // may be larger than the image. |
128 bool ImageWrittenToDevice(); | 136 bool ImageWrittenToDevice(const base::FilePath& image_path, |
| 137 const base::FilePath& device_path); |
129 | 138 |
130 // Fills |file| with |length| bytes of |pattern|, overwriting any existing | 139 // Fills |file| with |length| bytes of |pattern|, overwriting any existing |
131 // data. | 140 // data. |
132 bool FillFile(const base::FilePath& file, | 141 bool FillFile(const base::FilePath& file, |
133 const int pattern, | 142 const int pattern, |
134 const int length); | 143 const int length); |
135 | 144 |
136 // Set up the test utils, creating temporary folders and such. | |
137 // Note that browser tests should use the alternate form and pass "true" as an | |
138 // argument. | |
139 virtual void SetUp(); | |
140 // Set up the test utils, creating temporary folders and such. If | |
141 // |is_browser_test| is true then it will use alternate initialization | |
142 // appropriate for a browser test. This should be run in | |
143 // |SetUpInProcessBrowserTestFixture|. | |
144 virtual void SetUp(bool is_browser_test); | |
145 | |
146 virtual void TearDown(); | |
147 | |
148 const base::FilePath& GetTempDir(); | |
149 const base::FilePath& GetImagePath(); | |
150 const base::FilePath& GetDevicePath(); | |
151 | |
152 #if !defined(OS_CHROMEOS) | |
153 FakeImageWriterClient* GetUtilityClient(); | |
154 #endif | |
155 | |
156 protected: | |
157 base::ScopedTempDir temp_dir_; | 145 base::ScopedTempDir temp_dir_; |
158 base::FilePath test_image_path_; | 146 base::FilePath test_image_path_; |
159 base::FilePath test_device_path_; | 147 base::FilePath test_device_path_; |
160 | 148 |
161 #if !defined(OS_CHROMEOS) | |
162 scoped_refptr<FakeImageWriterClient> client_; | |
163 #endif | |
164 }; | |
165 | |
166 // Base class for unit tests that manages creating image and device files. | |
167 class ImageWriterUnitTestBase : public testing::Test { | |
168 protected: | |
169 ImageWriterUnitTestBase(); | |
170 virtual ~ImageWriterUnitTestBase(); | |
171 | |
172 virtual void SetUp() OVERRIDE; | |
173 virtual void TearDown() OVERRIDE; | |
174 | |
175 ImageWriterTestUtils test_utils_; | |
176 | |
177 private: | 149 private: |
178 content::TestBrowserThreadBundle thread_bundle_; | 150 content::TestBrowserThreadBundle thread_bundle_; |
179 }; | 151 }; |
180 | 152 |
181 } // namespace image_writer | 153 } // namespace image_writer |
182 } // namespace extensions | 154 } // namespace extensions |
183 | 155 |
184 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ | 156 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ |
OLD | NEW |