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 // A specialized MockOperationManager that will call a quit closure when the |
| 51 // operation completes or errors. This is useful because when using other |
| 52 // processes the message queue may empty and so we need to wait for a response |
| 53 // instead of running until idle. |
| 54 class QuittingMockManager : public MockOperationManager { |
| 55 public: |
| 56 explicit QuittingMockManager(const base::Closure& quit_closure); |
| 57 |
| 58 virtual void OnComplete(const ExtensionId& extension_id); |
| 59 virtual void OnError(const ExtensionId& extension_id, |
| 60 image_writer_api::Stage stage, |
| 61 int progress, |
| 62 const std::string& error_message); |
| 63 |
| 64 private: |
| 65 base::Closure quit_closure_; |
| 66 }; |
| 67 |
49 // Base class for unit tests that manages creating image and device files. | 68 // Base class for unit tests that manages creating image and device files. |
50 class ImageWriterUnitTestBase : public testing::Test { | 69 class ImageWriterUnitTestBase : public testing::Test { |
51 public: | 70 public: |
52 ImageWriterUnitTestBase(); | 71 ImageWriterUnitTestBase(); |
53 virtual ~ImageWriterUnitTestBase(); | 72 virtual ~ImageWriterUnitTestBase(); |
54 | 73 |
55 protected: | 74 protected: |
56 virtual void SetUp() OVERRIDE; | 75 virtual void SetUp() OVERRIDE; |
57 | 76 |
58 virtual void TearDown() OVERRIDE; | 77 virtual void TearDown() OVERRIDE; |
59 | 78 |
60 // Compare the image and device files, returning true if they are the same, | 79 // Verifies that the data in image_path was written to the file at |
61 // false if different. | 80 // device_path. This is different from base::ContentsEqual because the device |
62 bool CompareImageAndDevice(); | 81 // may be larger than the image. |
| 82 bool ImageWrittenToDevice(const base::FilePath& image_path, |
| 83 const base::FilePath& device_path); |
63 | 84 |
64 base::ScopedTempDir temp_dir_; | 85 base::ScopedTempDir temp_dir_; |
65 base::FilePath test_image_path_; | 86 base::FilePath test_image_path_; |
66 base::FilePath test_device_path_; | 87 base::FilePath test_device_path_; |
67 | 88 |
68 private: | 89 private: |
69 // Fills |file| with |length| bytes of |pattern|, overwriting any existing | 90 // Fills |file| with |length| bytes of |pattern|, overwriting any existing |
70 // data. | 91 // data. |
71 bool FillFile(const base::FilePath& file, | 92 bool FillFile(const base::FilePath& file, |
72 const int pattern, | 93 const int pattern, |
73 const int length); | 94 const int length); |
74 | 95 |
75 content::TestBrowserThreadBundle thread_bundle_; | 96 content::TestBrowserThreadBundle thread_bundle_; |
| 97 content::InProcessUtilityThreadHelper utility_thread_helper_; |
76 }; | 98 }; |
77 | 99 |
78 } // namespace image_writer | 100 } // namespace image_writer |
79 } // namespace extensions | 101 } // namespace extensions |
80 | 102 |
81 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ | 103 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ |
OLD | NEW |