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/operation_manager.h
" | 12 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h
" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "content/public/test/test_utils.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace extensions { | 18 namespace extensions { |
18 namespace image_writer { | 19 namespace image_writer { |
19 | 20 |
20 const char kDummyExtensionId[] = "DummyExtension"; | 21 const char kDummyExtensionId[] = "DummyExtension"; |
21 | 22 |
22 // Default file size to use in tests. Currently 32kB. | 23 // Default file size to use in tests. Currently 32kB. |
23 const int kTestFileSize = 32 * 1024; | 24 const int kTestFileSize = 32 * 1024; |
(...skipping 15 matching lines...) Expand all Loading... |
39 // Callback for completion events. | 40 // Callback for completion events. |
40 MOCK_METHOD1(OnComplete, void(const std::string& extension_id)); | 41 MOCK_METHOD1(OnComplete, void(const std::string& extension_id)); |
41 | 42 |
42 // Callback for error events. | 43 // Callback for error events. |
43 MOCK_METHOD4(OnError, void(const ExtensionId& extension_id, | 44 MOCK_METHOD4(OnError, void(const ExtensionId& extension_id, |
44 image_writer_api::Stage stage, | 45 image_writer_api::Stage stage, |
45 int progress, | 46 int progress, |
46 const std::string& error_message)); | 47 const std::string& error_message)); |
47 }; | 48 }; |
48 | 49 |
| 50 class QuittingMockManager : public MockOperationManager { |
| 51 public: |
| 52 explicit QuittingMockManager(const base::Closure& quit_closure); |
| 53 |
| 54 virtual void OnComplete(const ExtensionId& extension_id); |
| 55 virtual void OnError(const ExtensionId& extension_id, |
| 56 image_writer_api::Stage stage, |
| 57 int progress, |
| 58 const std::string& error_message); |
| 59 |
| 60 private: |
| 61 base::Closure quit_closure_; |
| 62 }; |
| 63 |
49 // Base class for unit tests that manages creating image and device files. | 64 // Base class for unit tests that manages creating image and device files. |
50 class ImageWriterUnitTestBase : public testing::Test { | 65 class ImageWriterUnitTestBase : public testing::Test { |
51 public: | 66 public: |
52 ImageWriterUnitTestBase(); | 67 ImageWriterUnitTestBase(); |
53 virtual ~ImageWriterUnitTestBase(); | 68 virtual ~ImageWriterUnitTestBase(); |
54 | 69 |
55 protected: | 70 protected: |
56 virtual void SetUp() OVERRIDE; | 71 virtual void SetUp() OVERRIDE; |
57 | 72 |
58 virtual void TearDown() OVERRIDE; | 73 virtual void TearDown() OVERRIDE; |
59 | 74 |
60 // Compare the image and device files, returning true if they are the same, | 75 // Verifies that the data in image_path was written to the file at |
61 // false if different. | 76 // device_path. This is different from base::ContentsEqual because the device |
62 bool CompareImageAndDevice(); | 77 // may be larger than the image. |
| 78 bool ImageWrittenToDevice(const base::FilePath& image_path, |
| 79 const base::FilePath& device_path); |
63 | 80 |
64 base::ScopedTempDir temp_dir_; | 81 base::ScopedTempDir temp_dir_; |
65 base::FilePath test_image_path_; | 82 base::FilePath test_image_path_; |
66 base::FilePath test_device_path_; | 83 base::FilePath test_device_path_; |
67 | 84 |
| 85 content::TestBrowserThreadBundle thread_bundle_; |
| 86 content::InProcessUtilityThreadHelper utility_thread_helper_; |
| 87 |
68 private: | 88 private: |
69 // Fills |file| with |length| bytes of |pattern|, overwriting any existing | 89 // Fills |file| with |length| bytes of |pattern|, overwriting any existing |
70 // data. | 90 // data. |
71 bool FillFile(const base::FilePath& file, | 91 bool FillFile(const base::FilePath& file, |
72 const int pattern, | 92 const int pattern, |
73 const int length); | 93 const int length); |
74 | |
75 content::TestBrowserThreadBundle thread_bundle_; | |
76 }; | 94 }; |
77 | 95 |
78 } // namespace image_writer | 96 } // namespace image_writer |
79 } // namespace extensions | 97 } // namespace extensions |
80 | 98 |
81 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ | 99 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ |
OLD | NEW |