Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Unified Diff: chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc

Issue 10918255: The Windows portion of Native Messagaing (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_posix.cc b/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
similarity index 75%
rename from chrome/browser/extensions/api/messaging/native_message_process_host_unittest_posix.cc
rename to chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
index c45fbfff417bce7f9883ade60de69e89aef39f2e..a8036dbd6f6b89ce4464cae9d4af33bbc699f68d 100644
--- a/chrome/browser/extensions/api/messaging/native_message_process_host_unittest_posix.cc
+++ b/chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc
@@ -11,6 +11,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/platform_file.h"
+#include "base/run_loop.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
#include "chrome/browser/extensions/api/messaging/native_process_launcher.h"
@@ -26,6 +27,14 @@ using content::BrowserThread;
namespace {
+#if defined(OS_WIN)
+const char kEmptyAppName[] = "empty_app.bat";
+const char kEchoAppName[] = "echo.bat";
+#else
+const char kEmptyAppName[] = "empty_app.py";
+const char kEchoAppName[] = "echo.py";
+#endif // defined(OS_WIN)
+
FilePath GetTestDir() {
FilePath test_dir;
PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
@@ -40,13 +49,14 @@ namespace extensions {
class FakeLauncher : public NativeProcessLauncher {
public:
FakeLauncher(FilePath read_file, FilePath write_file) {
+ int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_ASYNC;
read_file_ = base::CreatePlatformFile(
read_file,
- base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
+ flags | base::PLATFORM_FILE_READ,
NULL, NULL);
write_file_ = base::CreatePlatformFile(
write_file,
- base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE,
+ flags | base::PLATFORM_FILE_WRITE,
NULL, NULL);
}
@@ -70,7 +80,8 @@ class NativeMessagingTest : public ::testing::Test,
public NativeMessageProcessHost::Client,
public base::SupportsWeakPtr<NativeMessagingTest> {
public:
- NativeMessagingTest() : current_channel_(chrome::VersionInfo::CHANNEL_DEV) {
+ NativeMessagingTest() : current_channel_(chrome::VersionInfo::CHANNEL_DEV),
+ run_loop_(NULL) {
}
virtual void SetUp() {
@@ -84,51 +95,57 @@ class NativeMessagingTest : public ::testing::Test,
&message_loop_));
file_thread_.reset(new content::TestBrowserThread(BrowserThread::FILE,
&message_loop_));
+ io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO,
+ &message_loop_));
}
virtual void TearDown() {
// Change the user data dir back for other tests.
ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA, user_data_dir_));
- BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE,
- native_message_process_host_);
+ native_message_process_host_.reset();
message_loop_.RunUntilIdle();
}
void PostMessageFromNativeProcess(int port_id, const std::string& message) {
last_posted_message_ = message;
+ if (run_loop_)
+ run_loop_->Quit();
}
void CloseChannel(int port_id, bool error) {
}
void AcquireProcess(NativeMessageProcessHost::ScopedHost process) {
- native_message_process_host_ = process.release();
+ native_message_process_host_.swap(process);
}
protected:
// Force the channel to be dev.
Feature::ScopedCurrentChannel current_channel_;
- NativeMessageProcessHost* native_message_process_host_;
+ NativeMessageProcessHost::ScopedHost native_message_process_host_;
FilePath user_data_dir_;
MessageLoopForIO message_loop_;
scoped_ptr<content::TestBrowserThread> ui_thread_;
scoped_ptr<content::TestBrowserThread> file_thread_;
+ scoped_ptr<content::TestBrowserThread> io_thread_;
std::string last_posted_message_;
+ base::RunLoop* run_loop_;
};
// Read a single message from a local file (single_message_response.msg).
TEST_F(NativeMessagingTest, SingleSendMessageRead) {
FilePath temp_file;
file_util::CreateTemporaryFile(&temp_file);
- FakeLauncher launcher(GetTestDir().AppendASCII("single_message_response.msg"),
- temp_file);
NativeMessageProcessHost::CreateWithLauncher(
- AsWeakPtr(), "empty_app.py", "{}", 0,
+ AsWeakPtr(), kEmptyAppName, "{}", 0,
NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST, base::Bind(
&NativeMessagingTest::AcquireProcess, AsWeakPtr()),
- launcher);
+ scoped_ptr<NativeProcessLauncher>(new FakeLauncher(
+ GetTestDir().AppendASCII("single_message_response.msg"), temp_file)));
message_loop_.RunUntilIdle();
- ASSERT_TRUE(native_message_process_host_);
+ ASSERT_TRUE(native_message_process_host_.get());
+ // The process host is directly connected to files, there is no need to wait
+ // for the message.
native_message_process_host_->ReadNowForTesting();
message_loop_.RunUntilIdle();
EXPECT_EQ(last_posted_message_, "{\"text\": \"Hi There!.\"}");
@@ -140,42 +157,40 @@ TEST_F(NativeMessagingTest, SingleSendMessageRead) {
TEST_F(NativeMessagingTest, SingleSendMessageWrite) {
FilePath temp_file;
file_util::CreateTemporaryFile(&temp_file);
- FakeLauncher launcher(GetTestDir().AppendASCII("single_message_response.msg"),
- temp_file);
NativeMessageProcessHost::CreateWithLauncher(
- AsWeakPtr(), "empty_app.py", "{\"text\": \"Hello.\"}", 0,
+ AsWeakPtr(), kEmptyAppName, "{\"text\": \"Hello.\"}", 0,
NativeMessageProcessHost::TYPE_SEND_MESSAGE_REQUEST, base::Bind(
&NativeMessagingTest::AcquireProcess, AsWeakPtr()),
- launcher);
+ scoped_ptr<NativeProcessLauncher>(new FakeLauncher(
+ GetTestDir().AppendASCII("single_message_response.msg"), temp_file)));
message_loop_.RunUntilIdle();
- ASSERT_TRUE(native_message_process_host_);
-
+ ASSERT_TRUE(native_message_process_host_.get());
EXPECT_TRUE(file_util::ContentsEqual(
temp_file, GetTestDir().AppendASCII("single_message_request.msg")));
-
file_util::Delete(temp_file, false /* non-recursive */);
}
// Disabled, see http://crbug.com/159754.
-// Test send message with a real client. The client just echo's back the text
-// it recieved.
+// Test connecting with a real client. The client just echo's back the text
+// it recieves.
TEST_F(NativeMessagingTest, DISABLED_EchoConnect) {
NativeMessageProcessHost::Create(
- AsWeakPtr(), "echo.py", "{\"text\": \"Hello.\"}", 0,
+ AsWeakPtr(), kEchoAppName, "{\"text\": \"Hello.\"}", 0,
NativeMessageProcessHost::TYPE_CONNECT, base::Bind(
&NativeMessagingTest::AcquireProcess, AsWeakPtr()));
message_loop_.RunUntilIdle();
- ASSERT_TRUE(native_message_process_host_);
+ ASSERT_TRUE(native_message_process_host_.get());
- native_message_process_host_->ReadNowForTesting();
- message_loop_.RunUntilIdle();
+ base::RunLoop run_loop_1;
+ run_loop_ = &run_loop_1;
+ run_loop_1.Run();
EXPECT_EQ(last_posted_message_,
"{\"id\": 1, \"echo\": {\"text\": \"Hello.\"}}");
native_message_process_host_->Send("{\"foo\": \"bar\"}");
- message_loop_.RunUntilIdle();
- native_message_process_host_->ReadNowForTesting();
- message_loop_.RunUntilIdle();
+ base::RunLoop run_loop_2;
+ run_loop_ = &run_loop_2;
+ run_loop_2.Run();
EXPECT_EQ(last_posted_message_, "{\"id\": 2, \"echo\": {\"foo\": \"bar\"}}");
}

Powered by Google App Engine
This is Rietveld 408576698