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 */ | |
82 | 68 |
83 private: | 69 private: |
84 DiskMap disks_; | 70 DiskMap disks_; |
85 }; | 71 }; |
86 #endif | 72 #endif |
87 | 73 |
88 class FakeImageWriterClient : public ImageWriterUtilityClient { | 74 class FakeImageWriterClient : public ImageWriterUtilityClient { |
89 public: | 75 public: |
90 FakeImageWriterClient(); | 76 FakeImageWriterClient(); |
91 | 77 |
92 virtual void Write(const ProgressCallback& progress_callback, | 78 virtual void Write(const ProgressCallback& progress_callback, |
93 const SuccessCallback& success_callback, | 79 const SuccessCallback& success_callback, |
94 const ErrorCallback& error_callback, | 80 const ErrorCallback& error_callback, |
95 const base::FilePath& source, | 81 const base::FilePath& source, |
96 const base::FilePath& target) OVERRIDE; | 82 const base::FilePath& target) OVERRIDE; |
97 | 83 |
98 virtual void Verify(const ProgressCallback& progress_callback, | 84 virtual void Verify(const ProgressCallback& progress_callback, |
99 const SuccessCallback& success_callback, | 85 const SuccessCallback& success_callback, |
100 const ErrorCallback& error_callback, | 86 const ErrorCallback& error_callback, |
101 const base::FilePath& source, | 87 const base::FilePath& source, |
102 const base::FilePath& target) OVERRIDE; | 88 const base::FilePath& target) OVERRIDE; |
103 | 89 |
104 virtual void Cancel(const CancelCallback& cancel_callback) OVERRIDE; | 90 virtual void Cancel(const CancelCallback& cancel_callback) OVERRIDE; |
105 | 91 |
106 virtual void Shutdown() OVERRIDE; | 92 virtual void Shutdown() OVERRIDE; |
107 | 93 |
| 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. |
108 void Progress(int64 progress); | 100 void Progress(int64 progress); |
| 101 // Triggers the success callback. |
109 void Success(); | 102 void Success(); |
| 103 // Triggers the error callback. |
110 void Error(const std::string& message); | 104 void Error(const std::string& message); |
| 105 // Triggers the cancel callback. |
111 void Cancel(); | 106 void Cancel(); |
112 static scoped_refptr<FakeImageWriterClient> Create(); | |
113 | 107 |
114 private: | 108 private: |
115 virtual ~FakeImageWriterClient(); | 109 virtual ~FakeImageWriterClient(); |
116 | 110 |
117 ProgressCallback progress_callback_; | 111 ProgressCallback progress_callback_; |
118 SuccessCallback success_callback_; | 112 SuccessCallback success_callback_; |
119 ErrorCallback error_callback_; | 113 ErrorCallback error_callback_; |
120 CancelCallback cancel_callback_; | 114 CancelCallback cancel_callback_; |
| 115 |
| 116 base::Closure write_callback_; |
| 117 base::Closure verify_callback_; |
121 }; | 118 }; |
122 | 119 |
123 // Base class for unit tests that manages creating image and device files. | 120 class ImageWriterTestUtils { |
124 class ImageWriterUnitTestBase : public testing::Test { | 121 public: |
125 protected: | 122 ImageWriterTestUtils(); |
126 ImageWriterUnitTestBase(); | 123 virtual ~ImageWriterTestUtils(); |
127 virtual ~ImageWriterUnitTestBase(); | |
128 | |
129 virtual void SetUp() OVERRIDE; | |
130 | |
131 virtual void TearDown() OVERRIDE; | |
132 | 124 |
133 // Verifies that the data in image_path was written to the file at | 125 // Verifies that the data in image_path was written to the file at |
134 // device_path. This is different from base::ContentsEqual because the device | 126 // device_path. This is different from base::ContentsEqual because the device |
135 // may be larger than the image. | 127 // may be larger than the image. |
136 bool ImageWrittenToDevice(const base::FilePath& image_path, | 128 bool ImageWrittenToDevice(); |
137 const base::FilePath& device_path); | |
138 | 129 |
139 // Fills |file| with |length| bytes of |pattern|, overwriting any existing | 130 // Fills |file| with |length| bytes of |pattern|, overwriting any existing |
140 // data. | 131 // data. |
141 bool FillFile(const base::FilePath& file, | 132 bool FillFile(const base::FilePath& file, |
142 const int pattern, | 133 const int pattern, |
143 const int length); | 134 const int length); |
144 | 135 |
| 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: |
145 base::ScopedTempDir temp_dir_; | 157 base::ScopedTempDir temp_dir_; |
146 base::FilePath test_image_path_; | 158 base::FilePath test_image_path_; |
147 base::FilePath test_device_path_; | 159 base::FilePath test_device_path_; |
148 | 160 |
| 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 |
149 private: | 177 private: |
150 content::TestBrowserThreadBundle thread_bundle_; | 178 content::TestBrowserThreadBundle thread_bundle_; |
151 }; | 179 }; |
152 | 180 |
153 } // namespace image_writer | 181 } // namespace image_writer |
154 } // namespace extensions | 182 } // namespace extensions |
155 | 183 |
156 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ | 184 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ |
OLD | NEW |