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" |
12 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" | 13 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "content/public/test/test_utils.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 | 18 |
17 namespace extensions { | 19 namespace extensions { |
18 namespace image_writer { | 20 namespace image_writer { |
19 | 21 |
20 const char kDummyExtensionId[] = "DummyExtension"; | 22 const char kDummyExtensionId[] = "DummyExtension"; |
21 | 23 |
22 // Default file size to use in tests. Currently 32kB. | 24 // Default file size to use in tests. Currently 32kB. |
23 const int kTestFileSize = 32 * 1024; | 25 const int kTestFileSize = 32 * 1024; |
(...skipping 16 matching lines...) Expand all Loading... |
40 // Callback for completion events. | 42 // Callback for completion events. |
41 MOCK_METHOD1(OnComplete, void(const std::string& extension_id)); | 43 MOCK_METHOD1(OnComplete, void(const std::string& extension_id)); |
42 | 44 |
43 // Callback for error events. | 45 // Callback for error events. |
44 MOCK_METHOD4(OnError, void(const ExtensionId& extension_id, | 46 MOCK_METHOD4(OnError, void(const ExtensionId& extension_id, |
45 image_writer_api::Stage stage, | 47 image_writer_api::Stage stage, |
46 int progress, | 48 int progress, |
47 const std::string& error_message)); | 49 const std::string& error_message)); |
48 }; | 50 }; |
49 | 51 |
| 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 |
50 // Base class for unit tests that manages creating image and device files. | 87 // Base class for unit tests that manages creating image and device files. |
51 class ImageWriterUnitTestBase : public testing::Test { | 88 class ImageWriterUnitTestBase : public testing::Test { |
52 public: | 89 protected: |
53 ImageWriterUnitTestBase(); | 90 ImageWriterUnitTestBase(); |
54 virtual ~ImageWriterUnitTestBase(); | 91 virtual ~ImageWriterUnitTestBase(); |
55 | 92 |
56 protected: | |
57 virtual void SetUp() OVERRIDE; | 93 virtual void SetUp() OVERRIDE; |
58 | 94 |
59 virtual void TearDown() OVERRIDE; | 95 virtual void TearDown() OVERRIDE; |
60 | 96 |
| 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 |
61 // Fills |file| with |length| bytes of |pattern|, overwriting any existing | 103 // Fills |file| with |length| bytes of |pattern|, overwriting any existing |
62 // data. | 104 // data. |
63 bool FillFile(const base::FilePath& file, | 105 bool FillFile(const base::FilePath& file, |
64 const int pattern, | 106 const int pattern, |
65 const int length); | 107 const int length); |
66 | 108 |
67 base::ScopedTempDir temp_dir_; | 109 base::ScopedTempDir temp_dir_; |
68 base::FilePath test_image_path_; | 110 base::FilePath test_image_path_; |
69 base::FilePath test_device_path_; | 111 base::FilePath test_device_path_; |
70 | 112 |
71 private: | 113 private: |
72 content::TestBrowserThreadBundle thread_bundle_; | 114 content::TestBrowserThreadBundle thread_bundle_; |
73 }; | 115 }; |
74 | 116 |
75 } // namespace image_writer | 117 } // namespace image_writer |
76 } // namespace extensions | 118 } // namespace extensions |
77 | 119 |
78 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ | 120 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ |
OLD | NEW |