| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/test/test_timeouts.h" | 18 #include "base/test/test_timeouts.h" |
| 19 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
| 20 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" | 22 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" |
| 23 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h" | 23 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h" |
| 24 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" | 24 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" |
| 25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
| 28 #include "chrome/common/extensions/extension.h" | 28 #include "chrome/common/extensions/extension.h" |
| 29 #include "chrome/common/extensions/features/feature.h" | 29 #include "chrome/common/extensions/features/feature_channel.h" |
| 30 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/test/test_browser_thread_bundle.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 33 |
| 34 using content::BrowserThread; | 34 using content::BrowserThread; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const char kTestMessage[] = "{\"text\": \"Hello.\"}"; | 38 const char kTestMessage[] = "{\"text\": \"Hello.\"}"; |
| 39 | 39 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 base::FilePath filename = temp_dir_.path().AppendASCII("input"); | 137 base::FilePath filename = temp_dir_.path().AppendASCII("input"); |
| 138 file_util::CreateTemporaryFile(&filename); | 138 file_util::CreateTemporaryFile(&filename); |
| 139 std::string message_with_header = FormatMessage(message); | 139 std::string message_with_header = FormatMessage(message); |
| 140 EXPECT_TRUE(file_util::WriteFile( | 140 EXPECT_TRUE(file_util::WriteFile( |
| 141 filename, message_with_header.data(), message_with_header.size())); | 141 filename, message_with_header.data(), message_with_header.size())); |
| 142 return filename; | 142 return filename; |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Force the channel to be dev. | 145 // Force the channel to be dev. |
| 146 base::ScopedTempDir temp_dir_; | 146 base::ScopedTempDir temp_dir_; |
| 147 Feature::ScopedCurrentChannel current_channel_; | 147 ScopedCurrentChannel current_channel_; |
| 148 scoped_ptr<NativeMessageProcessHost> native_message_process_host_; | 148 scoped_ptr<NativeMessageProcessHost> native_message_process_host_; |
| 149 base::FilePath user_data_dir_; | 149 base::FilePath user_data_dir_; |
| 150 scoped_ptr<base::RunLoop> read_message_run_loop_; | 150 scoped_ptr<base::RunLoop> read_message_run_loop_; |
| 151 content::TestBrowserThreadBundle thread_bundle_; | 151 content::TestBrowserThreadBundle thread_bundle_; |
| 152 std::string last_message_; | 152 std::string last_message_; |
| 153 scoped_ptr<base::DictionaryValue> last_message_parsed_; | 153 scoped_ptr<base::DictionaryValue> last_message_parsed_; |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 // Read a single message from a local file. | 156 // Read a single message from a local file. |
| 157 TEST_F(NativeMessagingTest, SingleSendMessageRead) { | 157 TEST_F(NativeMessagingTest, SingleSendMessageRead) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 read_message_run_loop_->Run(); | 246 read_message_run_loop_->Run(); |
| 247 EXPECT_TRUE(last_message_parsed_->GetInteger("id", &id)); | 247 EXPECT_TRUE(last_message_parsed_->GetInteger("id", &id)); |
| 248 EXPECT_EQ(2, id); | 248 EXPECT_EQ(2, id); |
| 249 EXPECT_TRUE(last_message_parsed_->GetString("echo.foo", &text)); | 249 EXPECT_TRUE(last_message_parsed_->GetString("echo.foo", &text)); |
| 250 EXPECT_EQ("bar", text); | 250 EXPECT_EQ("bar", text); |
| 251 EXPECT_TRUE(last_message_parsed_->GetString("caller_url", &url)); | 251 EXPECT_TRUE(last_message_parsed_->GetString("caller_url", &url)); |
| 252 EXPECT_EQ(expected_url, url); | 252 EXPECT_EQ(expected_url, url); |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace extensions | 255 } // namespace extensions |
| OLD | NEW |