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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h " | 12 #include "chrome/browser/extensions/api/image_writer_private/operation_manager.h " |
12 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace extensions { | 17 namespace extensions { |
17 namespace image_writer { | 18 namespace image_writer { |
18 | 19 |
19 const char kDummyExtensionId[] = "DummyExtension"; | 20 const char kDummyExtensionId[] = "DummyExtension"; |
20 const char kTestData[] = "This is some test data, padded. "; | |
21 | 21 |
22 // Default file size to use in tests. Currently 1MB. | |
23 const int kTestFileSize = 1024 * 1024; | |
tbarzic
2013/12/14 01:01:04
can't you use a bit smaller numbers :)
I'm not sur
Drew Haven
2013/12/16 20:15:33
I want to make sure we get a few cycles through.
tbarzic
2013/12/16 20:33:45
Another option would be to set different values in
Drew Haven
2013/12/16 22:05:25
That's a good idea. I figured it was more depende
| |
24 // Pattern to use in the image file. | |
25 const char kImagePattern = 0x55; // 01010101 | |
26 // Pattern to use in the device file. | |
27 const char kDevicePattern = 0xAA; // 10101010 | |
28 | |
29 // A mock around the operation manager for tracking callbacks. Note that there | |
30 // are non-virtual methods on this class that should not be called in tests. | |
22 class MockOperationManager : public OperationManager { | 31 class MockOperationManager : public OperationManager { |
23 public: | 32 public: |
24 MockOperationManager(); | 33 MockOperationManager(); |
25 virtual ~MockOperationManager(); | 34 virtual ~MockOperationManager(); |
26 | 35 |
27 MOCK_METHOD3(OnProgress, void(const ExtensionId& extension_id, | 36 MOCK_METHOD3(OnProgress, void(const ExtensionId& extension_id, |
28 image_writer_api::Stage stage, | 37 image_writer_api::Stage stage, |
29 int progress)); | 38 int progress)); |
30 // Callback for completion events. | 39 // Callback for completion events. |
31 MOCK_METHOD1(OnComplete, void(const std::string& extension_id)); | 40 MOCK_METHOD1(OnComplete, void(const std::string& extension_id)); |
32 | 41 |
33 // Callback for error events. | 42 // Callback for error events. |
34 MOCK_METHOD4(OnError, void(const ExtensionId& extension_id, | 43 MOCK_METHOD4(OnError, void(const ExtensionId& extension_id, |
35 image_writer_api::Stage stage, | 44 image_writer_api::Stage stage, |
36 int progress, | 45 int progress, |
37 const std::string& error_message)); | 46 const std::string& error_message)); |
38 }; | 47 }; |
39 | 48 |
49 // Base class for unit tests that manages creating image and device files. | |
40 class ImageWriterUnitTestBase : public testing::Test { | 50 class ImageWriterUnitTestBase : public testing::Test { |
41 public: | 51 protected: |
42 virtual void SetUp() OVERRIDE; | 52 virtual void SetUp() OVERRIDE; |
43 | 53 |
44 virtual void TearDown() OVERRIDE; | 54 virtual void TearDown() OVERRIDE; |
45 | 55 |
46 base::FilePath test_image_; | 56 // Compare the image and device files, returning true if they are the same, |
47 base::FilePath test_device_; | 57 // false if different. |
58 bool CompareImageAndDevice(); | |
59 | |
60 base::ScopedTempDir temp_dir_; | |
61 base::FilePath test_image_path_; | |
62 base::FilePath test_device_path_; | |
63 | |
48 private: | 64 private: |
65 // Fills |file| with |length| bytes of |pattern|, overwriting any existing | |
66 // data. | |
67 bool FillFile(const base::FilePath& file, | |
68 const char pattern, | |
69 const int length); | |
70 | |
49 content::TestBrowserThreadBundle thread_bundle_; | 71 content::TestBrowserThreadBundle thread_bundle_; |
50 }; | 72 }; |
51 | 73 |
52 } // namespace image_writer | 74 } // namespace image_writer |
53 } // namespace extensions | 75 } // namespace extensions |
54 | 76 |
55 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ | 77 #endif // CHROME_BROWSER_EXTENSIONS_API_IMAGE_WRITER_PRIVATE_TEST_UTILS_H_ |
OLD | NEW |