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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "chrome/browser/extensions/api/image_writer_private/image_writer_utilit
y_client.h" | |
13 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" | 12 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" |
14 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
15 #include "content/public/test/test_utils.h" | |
16 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
18 | 16 |
19 namespace extensions { | 17 namespace extensions { |
20 namespace image_writer { | 18 namespace image_writer { |
21 | 19 |
22 const char kDummyExtensionId[] = "DummyExtension"; | 20 const char kDummyExtensionId[] = "DummyExtension"; |
23 | 21 |
24 // Default file size to use in tests. Currently 32kB. | 22 // Default file size to use in tests. Currently 32kB. |
25 const int kTestFileSize = 32 * 1024; | 23 const int kTestFileSize = 32 * 1024; |
(...skipping 16 matching lines...) Expand all Loading... |
42 // Callback for completion events. | 40 // Callback for completion events. |
43 MOCK_METHOD1(OnComplete, void(const std::string& extension_id)); | 41 MOCK_METHOD1(OnComplete, void(const std::string& extension_id)); |
44 | 42 |
45 // Callback for error events. | 43 // Callback for error events. |
46 MOCK_METHOD4(OnError, void(const ExtensionId& extension_id, | 44 MOCK_METHOD4(OnError, void(const ExtensionId& extension_id, |
47 image_writer_api::Stage stage, | 45 image_writer_api::Stage stage, |
48 int progress, | 46 int progress, |
49 const std::string& error_message)); | 47 const std::string& error_message)); |
50 }; | 48 }; |
51 | 49 |
52 class FakeImageWriterClient : public ImageWriterUtilityClient { | |
53 public: | |
54 FakeImageWriterClient(); | |
55 | |
56 virtual void Write(const ProgressCallback& progress_callback, | |
57 const SuccessCallback& success_callback, | |
58 const ErrorCallback& error_callback, | |
59 const base::FilePath& source, | |
60 const base::FilePath& target) OVERRIDE; | |
61 | |
62 virtual void Verify(const ProgressCallback& progress_callback, | |
63 const SuccessCallback& success_callback, | |
64 const ErrorCallback& error_callback, | |
65 const base::FilePath& source, | |
66 const base::FilePath& target) OVERRIDE; | |
67 | |
68 virtual void Cancel(const CancelCallback& cancel_callback) OVERRIDE; | |
69 | |
70 virtual void Shutdown() OVERRIDE; | |
71 | |
72 void Progress(int64 progress); | |
73 void Success(); | |
74 void Error(const std::string& message); | |
75 void Cancel(); | |
76 static scoped_refptr<FakeImageWriterClient> Create(); | |
77 | |
78 private: | |
79 virtual ~FakeImageWriterClient(); | |
80 | |
81 ProgressCallback progress_callback_; | |
82 SuccessCallback success_callback_; | |
83 ErrorCallback error_callback_; | |
84 CancelCallback cancel_callback_; | |
85 }; | |
86 | |
87 // Base class for unit tests that manages creating image and device files. | 50 // Base class for unit tests that manages creating image and device files. |
88 class ImageWriterUnitTestBase : public testing::Test { | 51 class ImageWriterUnitTestBase : public testing::Test { |
89 protected: | 52 public: |
90 ImageWriterUnitTestBase(); | 53 ImageWriterUnitTestBase(); |
91 virtual ~ImageWriterUnitTestBase(); | 54 virtual ~ImageWriterUnitTestBase(); |
92 | 55 |
| 56 protected: |
93 virtual void SetUp() OVERRIDE; | 57 virtual void SetUp() OVERRIDE; |
94 | 58 |
95 virtual void TearDown() OVERRIDE; | 59 virtual void TearDown() OVERRIDE; |
96 | 60 |
97 // Verifies that the data in image_path was written to the file at | |
98 // device_path. This is different from base::ContentsEqual because the device | |
99 // may be larger than the image. | |
100 bool ImageWrittenToDevice(const base::FilePath& image_path, | |
101 const base::FilePath& device_path); | |
102 | |
103 // Fills |file| with |length| bytes of |pattern|, overwriting any existing | 61 // Fills |file| with |length| bytes of |pattern|, overwriting any existing |
104 // data. | 62 // data. |
105 bool FillFile(const base::FilePath& file, | 63 bool FillFile(const base::FilePath& file, |
106 const int pattern, | 64 const int pattern, |
107 const int length); | 65 const int length); |
108 | 66 |
109 base::ScopedTempDir temp_dir_; | 67 base::ScopedTempDir temp_dir_; |
110 base::FilePath test_image_path_; | 68 base::FilePath test_image_path_; |
111 base::FilePath test_device_path_; | 69 base::FilePath test_device_path_; |
112 | 70 |
113 private: | 71 private: |
114 content::TestBrowserThreadBundle thread_bundle_; | 72 content::TestBrowserThreadBundle thread_bundle_; |
115 }; | 73 }; |
116 | 74 |
117 } // namespace image_writer | 75 } // namespace image_writer |
118 } // namespace extensions | 76 } // namespace extensions |
119 | 77 |
120 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ | 78 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ |
OLD | NEW |