| 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 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" | 9 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" |
| 10 #include "chrome/browser/extensions/api/image_writer_private/operation.h" | 10 #include "chrome/browser/extensions/api/image_writer_private/operation.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 &image_file_)); | 71 &image_file_)); |
| 72 ASSERT_TRUE(base::CreateTemporaryFile(&zip_file_)); | 72 ASSERT_TRUE(base::CreateTemporaryFile(&zip_file_)); |
| 73 | 73 |
| 74 scoped_ptr<char[]> buffer(new char[kTestFileSize]); | 74 scoped_ptr<char[]> buffer(new char[kTestFileSize]); |
| 75 memset(buffer.get(), kImagePattern, kTestFileSize); | 75 memset(buffer.get(), kImagePattern, kTestFileSize); |
| 76 file_util::WriteFile(image_file_, buffer.get(), kTestFileSize); | 76 file_util::WriteFile(image_file_, buffer.get(), kTestFileSize); |
| 77 | 77 |
| 78 zip::Zip(temp_dir_.path(), zip_file_, true); | 78 zip::Zip(temp_dir_.path(), zip_file_, true); |
| 79 } | 79 } |
| 80 | 80 |
| 81 virtual void TearDown() OVERRIDE { | |
| 82 ImageWriterUnitTestBase::TearDown(); | |
| 83 } | |
| 84 | |
| 85 base::ScopedTempDir temp_dir_; | 81 base::ScopedTempDir temp_dir_; |
| 86 base::FilePath image_file_; | 82 base::FilePath image_file_; |
| 87 base::FilePath zip_file_; | 83 base::FilePath zip_file_; |
| 88 }; | 84 }; |
| 89 | 85 |
| 90 } // namespace | 86 } // namespace |
| 91 | 87 |
| 92 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 88 #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_WIN) |
| 93 // Tests a successful unzip. | 89 // Tests a successful unzip. |
| 94 TEST_F(ImageWriterOperationTest, Unzip) { | 90 TEST_F(ImageWriterOperationTest, Unzip) { |
| 95 MockOperationManager manager; | 91 base::RunLoop loop; |
| 92 QuittingMockManager manager(loop.QuitClosure()); |
| 96 | 93 |
| 97 scoped_refptr<OperationForTest> operation( | 94 scoped_refptr<OperationForTest> operation( |
| 98 new OperationForTest(manager.AsWeakPtr(), | 95 new OperationForTest(manager.AsWeakPtr(), |
| 99 kDummyExtensionId, | 96 kDummyExtensionId, |
| 100 test_device_path_.AsUTF8Unsafe())); | 97 test_device_path_.AsUTF8Unsafe())); |
| 101 | 98 |
| 102 scoped_ptr<base::FilePath> zip_file(new base::FilePath(zip_file_)); | 99 scoped_ptr<base::FilePath> zip_file(new base::FilePath(zip_file_)); |
| 103 | 100 |
| 104 // At least one progress report > 0% and < 100%. | 101 // At least one progress report > 0% and < 100%. |
| 105 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, | 102 EXPECT_CALL(manager, OnProgress(kDummyExtensionId, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 121 EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(1); | 118 EXPECT_CALL(manager, OnComplete(kDummyExtensionId)).Times(1); |
| 122 // No errors | 119 // No errors |
| 123 EXPECT_CALL(manager, OnError(_, _, _, _)).Times(0); | 120 EXPECT_CALL(manager, OnError(_, _, _, _)).Times(0); |
| 124 | 121 |
| 125 content::BrowserThread::PostTask(content::BrowserThread::FILE, | 122 content::BrowserThread::PostTask(content::BrowserThread::FILE, |
| 126 FROM_HERE, | 123 FROM_HERE, |
| 127 base::Bind(&OperationForTest::UnzipStart, | 124 base::Bind(&OperationForTest::UnzipStart, |
| 128 operation, | 125 operation, |
| 129 base::Passed(&zip_file))); | 126 base::Passed(&zip_file))); |
| 130 | 127 |
| 131 base::RunLoop().RunUntilIdle(); | 128 loop.Run(); |
| 132 | 129 |
| 133 EXPECT_TRUE(base::ContentsEqual(image_file_, test_device_path_)); | 130 EXPECT_TRUE(ImageWrittenToDevice(image_file_, test_device_path_)); |
| 134 } | 131 } |
| 135 #endif | 132 #endif |
| 136 | 133 |
| 137 TEST_F(ImageWriterOperationTest, Creation) { | 134 TEST_F(ImageWriterOperationTest, Creation) { |
| 138 MockOperationManager manager; | 135 MockOperationManager manager; |
| 139 scoped_refptr<Operation> op( | 136 scoped_refptr<Operation> op( |
| 140 new OperationForTest(manager.AsWeakPtr(), | 137 new OperationForTest(manager.AsWeakPtr(), |
| 141 kDummyExtensionId, | 138 kDummyExtensionId, |
| 142 test_device_path_.AsUTF8Unsafe())); | 139 test_device_path_.AsUTF8Unsafe())); |
| 143 | 140 |
| 144 EXPECT_EQ(0, op->GetProgress()); | 141 EXPECT_EQ(0, op->GetProgress()); |
| 145 EXPECT_EQ(image_writer_api::STAGE_UNKNOWN, op->GetStage()); | 142 EXPECT_EQ(image_writer_api::STAGE_UNKNOWN, op->GetStage()); |
| 146 } | 143 } |
| 147 | 144 |
| 148 } // namespace image_writer | 145 } // namespace image_writer |
| 149 } // namespace extensions | 146 } // namespace extensions |
| OLD | NEW |