| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 base::FilePath manifest_path = temp_dir_.path().AppendASCII( | 210 base::FilePath manifest_path = temp_dir_.path().AppendASCII( |
| 211 std::string(kTestNativeMessagingHostName) + ".json"); | 211 std::string(kTestNativeMessagingHostName) + ".json"); |
| 212 ASSERT_NO_FATAL_FAILURE(CreateTestNativeHostManifest(manifest_path)); | 212 ASSERT_NO_FATAL_FAILURE(CreateTestNativeHostManifest(manifest_path)); |
| 213 | 213 |
| 214 std::string hosts_option = base::StringPrintf( | 214 std::string hosts_option = base::StringPrintf( |
| 215 "%s=%s", extensions::kTestNativeMessagingHostName, | 215 "%s=%s", extensions::kTestNativeMessagingHostName, |
| 216 manifest_path.AsUTF8Unsafe().c_str()); | 216 manifest_path.AsUTF8Unsafe().c_str()); |
| 217 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 217 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 218 switches::kNativeMessagingHosts, hosts_option); | 218 switches::kNativeMessagingHosts, hosts_option); |
| 219 | 219 |
| 220 native_message_process_host_ = NativeMessageProcessHost::Create( | 220 scoped_ptr<NativeProcessLauncher> launcher = |
| 221 NativeProcessLauncher::CreateDefault(gfx::NativeView()); |
| 222 native_message_process_host_ = NativeMessageProcessHost::CreateWithLauncher( |
| 221 AsWeakPtr(), kTestNativeMessagingExtensionId, | 223 AsWeakPtr(), kTestNativeMessagingExtensionId, |
| 222 kTestNativeMessagingHostName, 0); | 224 kTestNativeMessagingHostName, 0, launcher.Pass()); |
| 223 ASSERT_TRUE(native_message_process_host_.get()); | 225 ASSERT_TRUE(native_message_process_host_.get()); |
| 224 | 226 |
| 225 native_message_process_host_->Send("{\"text\": \"Hello.\"}"); | 227 native_message_process_host_->Send("{\"text\": \"Hello.\"}"); |
| 226 read_message_run_loop_.reset(new base::RunLoop()); | 228 read_message_run_loop_.reset(new base::RunLoop()); |
| 227 read_message_run_loop_->Run(); | 229 read_message_run_loop_->Run(); |
| 228 ASSERT_FALSE(last_message_.empty()); | 230 ASSERT_FALSE(last_message_.empty()); |
| 229 ASSERT_TRUE(last_message_parsed_); | 231 ASSERT_TRUE(last_message_parsed_); |
| 230 | 232 |
| 231 std::string expected_url = std::string("chrome-extension://") + | 233 std::string expected_url = std::string("chrome-extension://") + |
| 232 kTestNativeMessagingExtensionId + "/"; | 234 kTestNativeMessagingExtensionId + "/"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 246 read_message_run_loop_->Run(); | 248 read_message_run_loop_->Run(); |
| 247 EXPECT_TRUE(last_message_parsed_->GetInteger("id", &id)); | 249 EXPECT_TRUE(last_message_parsed_->GetInteger("id", &id)); |
| 248 EXPECT_EQ(2, id); | 250 EXPECT_EQ(2, id); |
| 249 EXPECT_TRUE(last_message_parsed_->GetString("echo.foo", &text)); | 251 EXPECT_TRUE(last_message_parsed_->GetString("echo.foo", &text)); |
| 250 EXPECT_EQ("bar", text); | 252 EXPECT_EQ("bar", text); |
| 251 EXPECT_TRUE(last_message_parsed_->GetString("caller_url", &url)); | 253 EXPECT_TRUE(last_message_parsed_->GetString("caller_url", &url)); |
| 252 EXPECT_EQ(expected_url, url); | 254 EXPECT_EQ(expected_url, url); |
| 253 } | 255 } |
| 254 | 256 |
| 255 } // namespace extensions | 257 } // namespace extensions |
| OLD | NEW |