| Index: chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc b/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
|
| index bb9c7a030e7fe70f109eeea02d6042295126378b..958c9c5eeff8229216aaf72b0c752b33da305d9d 100644
|
| --- a/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
|
| +++ b/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
|
| @@ -10,7 +10,6 @@
|
| #include "base/files/scoped_temp_dir.h"
|
| #include "base/json/json_reader.h"
|
| #include "base/memory/scoped_ptr.h"
|
| -#include "base/memory/weak_ptr.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/rand_util.h"
|
| #include "base/run_loop.h"
|
| @@ -93,7 +92,7 @@ class FakeLauncher : public NativeProcessLauncher {
|
| };
|
|
|
| class NativeMessagingTest : public ::testing::Test,
|
| - public NativeMessageProcessHost::Client,
|
| + public NativeMessageHost::Client,
|
| public base::SupportsWeakPtr<NativeMessagingTest> {
|
| protected:
|
| NativeMessagingTest()
|
| @@ -106,16 +105,14 @@ class NativeMessagingTest : public ::testing::Test,
|
| }
|
|
|
| virtual void TearDown() override {
|
| - if (native_message_process_host_.get()) {
|
| - BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
|
| - native_message_process_host_.release());
|
| + if (native_message_host_.get()) {
|
| + BrowserThread::DeleteSoon(
|
| + BrowserThread::IO, FROM_HERE, native_message_host_.release());
|
| }
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| - virtual void PostMessageFromNativeProcess(
|
| - int port_id,
|
| - const std::string& message) override {
|
| + virtual void PostMessageFromNativeHost(const std::string& message) override {
|
| last_message_ = message;
|
|
|
| // Parse the message.
|
| @@ -133,8 +130,7 @@ class NativeMessagingTest : public ::testing::Test,
|
| run_loop_->Quit();
|
| }
|
|
|
| - virtual void CloseChannel(int port_id,
|
| - const std::string& error_message) override {
|
| + virtual void CloseChannel(const std::string& error_message) override {
|
| channel_closed_ = true;
|
| if (run_loop_)
|
| run_loop_->Quit();
|
| @@ -164,7 +160,7 @@ class NativeMessagingTest : public ::testing::Test,
|
| base::ScopedTempDir temp_dir_;
|
| // Force the channel to be dev.
|
| ScopedCurrentChannel current_channel_;
|
| - scoped_ptr<NativeMessageProcessHost> native_message_process_host_;
|
| + scoped_ptr<NativeMessageHost> native_message_host_;
|
| scoped_ptr<base::RunLoop> run_loop_;
|
| content::TestBrowserThreadBundle thread_bundle_;
|
| std::string last_message_;
|
| @@ -180,15 +176,19 @@ TEST_F(NativeMessagingTest, SingleSendMessageRead) {
|
|
|
| scoped_ptr<NativeProcessLauncher> launcher =
|
| FakeLauncher::Create(temp_input_file, temp_output_file).Pass();
|
| - native_message_process_host_ = NativeMessageProcessHost::CreateWithLauncher(
|
| - AsWeakPtr(), ScopedTestNativeMessagingHost::kExtensionId, "empty_app.py",
|
| - 0, launcher.Pass());
|
| - ASSERT_TRUE(native_message_process_host_.get());
|
| + native_message_host_ = NativeMessageProcessHost::CreateWithLauncher(
|
| + ScopedTestNativeMessagingHost::kExtensionId,
|
| + "empty_app.py",
|
| + launcher.Pass());
|
| + native_message_host_->Start(this);
|
| + ASSERT_TRUE(native_message_host_.get());
|
| run_loop_.reset(new base::RunLoop());
|
| run_loop_->RunUntilIdle();
|
|
|
| if (last_message_.empty()) {
|
| run_loop_.reset(new base::RunLoop());
|
| + scoped_ptr<NativeMessageProcessHost> native_message_process_host_(
|
| + static_cast<NativeMessageProcessHost*>(native_message_host_.release()));
|
| native_message_process_host_->ReadNowForTesting();
|
| run_loop_->Run();
|
| }
|
| @@ -226,13 +226,15 @@ TEST_F(NativeMessagingTest, SingleSendMessageWrite) {
|
| scoped_ptr<NativeProcessLauncher> launcher =
|
| FakeLauncher::CreateWithPipeInput(read_file.Pass(),
|
| temp_output_file).Pass();
|
| - native_message_process_host_ = NativeMessageProcessHost::CreateWithLauncher(
|
| - AsWeakPtr(), ScopedTestNativeMessagingHost::kExtensionId, "empty_app.py",
|
| - 0, launcher.Pass());
|
| - ASSERT_TRUE(native_message_process_host_.get());
|
| + native_message_host_ = NativeMessageProcessHost::CreateWithLauncher(
|
| + ScopedTestNativeMessagingHost::kExtensionId,
|
| + "empty_app.py",
|
| + launcher.Pass());
|
| + native_message_host_->Start(this);
|
| + ASSERT_TRUE(native_message_host_.get());
|
| base::RunLoop().RunUntilIdle();
|
|
|
| - native_message_process_host_->Send(kTestMessage);
|
| + native_message_host_->OnMessage(kTestMessage);
|
| base::RunLoop().RunUntilIdle();
|
|
|
| std::string output;
|
| @@ -252,13 +254,17 @@ TEST_F(NativeMessagingTest, SingleSendMessageWrite) {
|
| TEST_F(NativeMessagingTest, EchoConnect) {
|
| ScopedTestNativeMessagingHost test_host;
|
| ASSERT_NO_FATAL_FAILURE(test_host.RegisterTestHost(false));
|
| -
|
| - native_message_process_host_ = NativeMessageProcessHost::Create(
|
| - NULL, AsWeakPtr(), ScopedTestNativeMessagingHost::kExtensionId,
|
| - ScopedTestNativeMessagingHost::kHostName, 0, false);
|
| - ASSERT_TRUE(native_message_process_host_.get());
|
| -
|
| - native_message_process_host_->Send("{\"text\": \"Hello.\"}");
|
| + std::string error_message;
|
| + native_message_host_ = NativeMessageProcessHost::Create(
|
| + NULL,
|
| + ScopedTestNativeMessagingHost::kExtensionId,
|
| + ScopedTestNativeMessagingHost::kHostName,
|
| + false,
|
| + &error_message);
|
| + native_message_host_->Start(this);
|
| + ASSERT_TRUE(native_message_host_.get());
|
| +
|
| + native_message_host_->OnMessage("{\"text\": \"Hello.\"}");
|
| run_loop_.reset(new base::RunLoop());
|
| run_loop_->Run();
|
| ASSERT_FALSE(last_message_.empty());
|
| @@ -276,7 +282,7 @@ TEST_F(NativeMessagingTest, EchoConnect) {
|
| EXPECT_TRUE(last_message_parsed_->GetString("caller_url", &url));
|
| EXPECT_EQ(expected_url, url);
|
|
|
| - native_message_process_host_->Send("{\"foo\": \"bar\"}");
|
| + native_message_host_->OnMessage("{\"foo\": \"bar\"}");
|
| run_loop_.reset(new base::RunLoop());
|
| run_loop_->Run();
|
| EXPECT_TRUE(last_message_parsed_->GetInteger("id", &id));
|
| @@ -291,12 +297,17 @@ TEST_F(NativeMessagingTest, UserLevel) {
|
| ScopedTestNativeMessagingHost test_host;
|
| ASSERT_NO_FATAL_FAILURE(test_host.RegisterTestHost(true));
|
|
|
| - native_message_process_host_ = NativeMessageProcessHost::Create(
|
| - NULL, AsWeakPtr(), ScopedTestNativeMessagingHost::kExtensionId,
|
| - ScopedTestNativeMessagingHost::kHostName, 0, true);
|
| - ASSERT_TRUE(native_message_process_host_.get());
|
| -
|
| - native_message_process_host_->Send("{\"text\": \"Hello.\"}");
|
| + std::string error_message;
|
| + native_message_host_ = NativeMessageProcessHost::Create(
|
| + NULL,
|
| + ScopedTestNativeMessagingHost::kExtensionId,
|
| + ScopedTestNativeMessagingHost::kHostName,
|
| + true,
|
| + &error_message);
|
| + native_message_host_->Start(this);
|
| + ASSERT_TRUE(native_message_host_.get());
|
| +
|
| + native_message_host_->OnMessage("{\"text\": \"Hello.\"}");
|
| run_loop_.reset(new base::RunLoop());
|
| run_loop_->Run();
|
| ASSERT_FALSE(last_message_.empty());
|
| @@ -307,10 +318,15 @@ TEST_F(NativeMessagingTest, DisallowUserLevel) {
|
| ScopedTestNativeMessagingHost test_host;
|
| ASSERT_NO_FATAL_FAILURE(test_host.RegisterTestHost(true));
|
|
|
| - native_message_process_host_ = NativeMessageProcessHost::Create(
|
| - NULL, AsWeakPtr(), ScopedTestNativeMessagingHost::kExtensionId,
|
| - ScopedTestNativeMessagingHost::kHostName, 0, false);
|
| - ASSERT_TRUE(native_message_process_host_.get());
|
| + std::string error_message;
|
| + native_message_host_ = NativeMessageProcessHost::Create(
|
| + NULL,
|
| + ScopedTestNativeMessagingHost::kExtensionId,
|
| + ScopedTestNativeMessagingHost::kHostName,
|
| + false,
|
| + &error_message);
|
| + native_message_host_->Start(this);
|
| + ASSERT_TRUE(native_message_host_.get());
|
| run_loop_.reset(new base::RunLoop());
|
| run_loop_->Run();
|
|
|
|
|