| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/utility_process_host.h" | 5 #include "chrome/browser/utility_process_host.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 14 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/notification_registrar.h" | 17 #include "chrome/common/notification_registrar.h" |
| 18 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class UtilityProcessHostTest : public testing::Test { | 23 class UtilityProcessHostTest : public testing::Test { |
| 24 public: | 24 public: |
| 25 UtilityProcessHostTest() { | 25 UtilityProcessHostTest() : io_thread_(ChromeThread::IO, &message_loop_) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 MessageLoopForIO message_loop_; | 29 MessageLoopForIO message_loop_; |
| 30 ChromeThread io_thread_; |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 class TestUtilityProcessHostClient : public UtilityProcessHost::Client { | 33 class TestUtilityProcessHostClient : public UtilityProcessHost::Client { |
| 33 public: | 34 public: |
| 34 explicit TestUtilityProcessHostClient(MessageLoop* message_loop) | 35 explicit TestUtilityProcessHostClient() : success_(false) { |
| 35 : message_loop_(message_loop), success_(false) { | |
| 36 } | 36 } |
| 37 | 37 |
| 38 // UtilityProcessHost::Client methods. | 38 // UtilityProcessHost::Client methods. |
| 39 virtual void OnProcessCrashed() { | 39 virtual void OnProcessCrashed() { |
| 40 NOTREACHED(); | 40 NOTREACHED(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual void OnUnpackExtensionSucceeded(const DictionaryValue& manifest) { | 43 virtual void OnUnpackExtensionSucceeded(const DictionaryValue& manifest) { |
| 44 success_ = true; | 44 success_ = true; |
| 45 } | 45 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 56 virtual void OnUnpackWebResourceFailed( | 56 virtual void OnUnpackWebResourceFailed( |
| 57 const std::string& error_message) { | 57 const std::string& error_message) { |
| 58 NOTREACHED(); | 58 NOTREACHED(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool success() { | 61 bool success() { |
| 62 return success_; | 62 return success_; |
| 63 } | 63 } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 MessageLoop* message_loop_; | |
| 67 bool success_; | 66 bool success_; |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 class TestUtilityProcessHost : public UtilityProcessHost { | 69 class TestUtilityProcessHost : public UtilityProcessHost { |
| 71 public: | 70 public: |
| 72 TestUtilityProcessHost(TestUtilityProcessHostClient* client, | 71 TestUtilityProcessHost(TestUtilityProcessHostClient* client, |
| 73 MessageLoop* loop_io, | |
| 74 ResourceDispatcherHost* rdh) | 72 ResourceDispatcherHost* rdh) |
| 75 : UtilityProcessHost(rdh, client, loop_io) { | 73 : UtilityProcessHost(rdh, client, ChromeThread::IO) { |
| 76 } | 74 } |
| 77 | 75 |
| 78 protected: | 76 protected: |
| 79 virtual FilePath GetUtilityProcessCmd() { | 77 virtual FilePath GetUtilityProcessCmd() { |
| 80 FilePath exe_path; | 78 FilePath exe_path; |
| 81 PathService::Get(base::DIR_EXE, &exe_path); | 79 PathService::Get(base::DIR_EXE, &exe_path); |
| 82 exe_path = exe_path.Append(chrome::kHelperProcessExecutablePath); | 80 exe_path = exe_path.Append(chrome::kHelperProcessExecutablePath); |
| 83 return exe_path; | 81 return exe_path; |
| 84 } | 82 } |
| 85 | 83 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 extension_file = extension_file.AppendASCII("extensions") | 131 extension_file = extension_file.AppendASCII("extensions") |
| 134 .AppendASCII("theme.crx"); | 132 .AppendASCII("theme.crx"); |
| 135 FilePath temp_extension_dir; | 133 FilePath temp_extension_dir; |
| 136 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &temp_extension_dir)); | 134 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &temp_extension_dir)); |
| 137 temp_extension_dir = temp_extension_dir.AppendASCII("extension_test"); | 135 temp_extension_dir = temp_extension_dir.AppendASCII("extension_test"); |
| 138 ASSERT_TRUE(file_util::CreateDirectory(temp_extension_dir)); | 136 ASSERT_TRUE(file_util::CreateDirectory(temp_extension_dir)); |
| 139 ASSERT_TRUE(file_util::CopyFile(extension_file, | 137 ASSERT_TRUE(file_util::CopyFile(extension_file, |
| 140 temp_extension_dir.AppendASCII("theme.crx"))); | 138 temp_extension_dir.AppendASCII("theme.crx"))); |
| 141 | 139 |
| 142 scoped_refptr<TestUtilityProcessHostClient> client( | 140 scoped_refptr<TestUtilityProcessHostClient> client( |
| 143 new TestUtilityProcessHostClient(&message_loop_)); | 141 new TestUtilityProcessHostClient()); |
| 144 ResourceDispatcherHost rdh(NULL); | 142 ResourceDispatcherHost rdh(NULL); |
| 145 TestUtilityProcessHost* process_host = | 143 TestUtilityProcessHost* process_host = |
| 146 new TestUtilityProcessHost(client.get(), &message_loop_, &rdh); | 144 new TestUtilityProcessHost(client.get(), &rdh); |
| 147 // process_host will delete itself when it's done. | 145 // process_host will delete itself when it's done. |
| 148 ProcessClosedObserver observer(&message_loop_); | 146 ProcessClosedObserver observer(&message_loop_); |
| 149 process_host->StartExtensionUnpacker( | 147 process_host->StartExtensionUnpacker( |
| 150 temp_extension_dir.AppendASCII("theme.crx")); | 148 temp_extension_dir.AppendASCII("theme.crx")); |
| 151 observer.RunUntilClose(process_host->id()); | 149 observer.RunUntilClose(process_host->id()); |
| 152 EXPECT_TRUE(client->success()); | 150 EXPECT_TRUE(client->success()); |
| 153 | 151 |
| 154 // Clean up the temp dir. | 152 // Clean up the temp dir. |
| 155 file_util::Delete(temp_extension_dir, true); | 153 file_util::Delete(temp_extension_dir, true); |
| 156 } | 154 } |
| 157 #endif | 155 #endif |
| 158 | 156 |
| 159 } // namespace | 157 } // namespace |
| OLD | NEW |