Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 bool TestPackExtension(const base::FilePath& path) { | 31 bool TestPackExtension(const base::FilePath& path) { |
| 32 base::ScopedTempDir temp_dir; | 32 base::ScopedTempDir temp_dir; |
| 33 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); | 33 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 34 EXPECT_TRUE(base::CopyDirectory(path, temp_dir.path(), true)); | 34 EXPECT_TRUE(base::CopyDirectory(path, temp_dir.path(), true)); |
| 35 CommandLine command_line(CommandLine::NO_PROGRAM); | 35 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 36 command_line.AppendSwitchPath(switches::kPackExtension, | 36 command_line.AppendSwitchPath(switches::kPackExtension, |
| 37 temp_dir.path().Append(path.BaseName())); | 37 temp_dir.path().Append(path.BaseName())); |
| 38 return startup_helper_.PackExtension(command_line); | 38 return startup_helper_.PackExtension(command_line); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool TestPackExtensionKey(const base::FilePath& path, | |
| 42 const base::FilePath& key_path) { | |
| 43 base::ScopedTempDir temp_dir; | |
| 44 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 45 EXPECT_TRUE(base::CopyDirectory(path, temp_dir.path(), true)); | |
| 46 CommandLine command_line(CommandLine::NO_PROGRAM); | |
| 47 command_line.AppendSwitchPath(switches::kPackExtension, | |
| 48 temp_dir.path().Append(path.BaseName())); | |
| 49 command_line.AppendSwitchPath(switches::kPackExtensionKey, | |
| 50 temp_dir.path().Append(key_path.BaseName())); | |
| 51 return startup_helper_.PackExtension(command_line); | |
| 52 } | |
| 53 | |
| 41 base::MessageLoop message_loop_; | 54 base::MessageLoop message_loop_; |
| 42 content::TestBrowserThread ui_thread_; | 55 content::TestBrowserThread ui_thread_; |
| 43 content::TestBrowserThread file_thread_; | 56 content::TestBrowserThread file_thread_; |
| 44 | 57 |
| 45 base::FilePath test_data_dir_; | 58 base::FilePath test_data_dir_; |
| 46 StartupHelper startup_helper_; | 59 StartupHelper startup_helper_; |
| 47 }; | 60 }; |
| 48 | 61 |
| 49 TEST_F(PackExtensionTest, Extension) { | 62 TEST_F(PackExtensionTest, Extension) { |
| 50 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("api_test") | 63 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("api_test") |
| 51 .AppendASCII("tabs") | 64 .AppendASCII("tabs") |
| 52 .AppendASCII("basics"))); | 65 .AppendASCII("basics"))); |
| 53 } | 66 } |
| 54 | 67 |
| 55 TEST_F(PackExtensionTest, PackagedApp) { | 68 TEST_F(PackExtensionTest, PackagedApp) { |
| 56 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("packaged_app"))); | 69 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("packaged_app"))); |
| 57 } | 70 } |
| 58 | 71 |
| 59 TEST_F(PackExtensionTest, PlatformApp) { | 72 TEST_F(PackExtensionTest, PlatformApp) { |
| 60 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("platform_apps") | 73 ASSERT_TRUE(TestPackExtension(test_data_dir_.AppendASCII("platform_apps") |
| 61 .AppendASCII("minimal"))); | 74 .AppendASCII("minimal"))); |
| 62 } | 75 } |
| 63 | 76 |
| 77 TEST_F(PackExtensionTest, ExtensionWithInvalidKey) { | |
|
zhchbin
2013/07/27 00:33:24
Why don't you put this code to the ExtensionServic
| |
| 78 ASSERT_FALSE(TestPackExtensionKey(test_data_dir_. | |
| 79 AppendASCII("bad_private_key"), | |
| 80 test_data_dir_. | |
| 81 AppendASCII("bad_private_key.pem"))); | |
| 82 } | |
| 83 | |
| 64 } // namespace extensions | 84 } // namespace extensions |
| OLD | NEW |