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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc

Issue 2384163003: Use FileDescriptorWatcher in NativeMessageProcessHost. (Closed)
Patch Set: fix test error Created 4 years, 2 months 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/api/messaging/native_message_process_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/extensions/api/messaging/native_message_process_host.h" 5 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 17 matching lines...) Expand all
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h" 29 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h"
30 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" 30 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h"
31 #include "components/version_info/version_info.h" 31 #include "components/version_info/version_info.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/test/test_browser_thread_bundle.h" 33 #include "content/public/test/test_browser_thread_bundle.h"
34 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
35 #include "extensions/common/features/feature_channel.h" 35 #include "extensions/common/features/feature_channel.h"
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 37
38 #if defined(OS_POSIX)
39 #include "base/files/file_descriptor_watcher_posix.h"
40 #endif
41
38 #if defined(OS_WIN) 42 #if defined(OS_WIN)
39 #include <windows.h> 43 #include <windows.h>
40 #include "base/win/scoped_handle.h" 44 #include "base/win/scoped_handle.h"
41 #else 45 #else
42 #include <unistd.h> 46 #include <unistd.h>
43 #endif 47 #endif
44 48
45 using content::BrowserThread; 49 using content::BrowserThread;
46 50
47 namespace { 51 namespace {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 mutable base::File write_file_; 99 mutable base::File write_file_;
96 }; 100 };
97 101
98 class NativeMessagingTest : public ::testing::Test, 102 class NativeMessagingTest : public ::testing::Test,
99 public NativeMessageHost::Client, 103 public NativeMessageHost::Client,
100 public base::SupportsWeakPtr<NativeMessagingTest> { 104 public base::SupportsWeakPtr<NativeMessagingTest> {
101 protected: 105 protected:
102 NativeMessagingTest() 106 NativeMessagingTest()
103 : current_channel_(version_info::Channel::DEV), 107 : current_channel_(version_info::Channel::DEV),
104 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 108 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
109 #if defined(OS_POSIX)
110 file_descriptor_watcher_(base::MessageLoopForIO::current()),
111 #endif
105 channel_closed_(false) {} 112 channel_closed_(false) {}
106 113
107 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } 114 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); }
108 115
109 void TearDown() override { 116 void TearDown() override {
110 if (native_message_host_.get()) { 117 if (native_message_host_.get()) {
111 BrowserThread::DeleteSoon( 118 BrowserThread::DeleteSoon(
112 BrowserThread::IO, FROM_HERE, native_message_host_.release()); 119 BrowserThread::IO, FROM_HERE, native_message_host_.release());
113 } 120 }
114 base::RunLoop().RunUntilIdle(); 121 base::RunLoop().RunUntilIdle();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 164 }
158 return filename; 165 return filename;
159 } 166 }
160 167
161 base::ScopedTempDir temp_dir_; 168 base::ScopedTempDir temp_dir_;
162 // Force the channel to be dev. 169 // Force the channel to be dev.
163 ScopedCurrentChannel current_channel_; 170 ScopedCurrentChannel current_channel_;
164 std::unique_ptr<NativeMessageHost> native_message_host_; 171 std::unique_ptr<NativeMessageHost> native_message_host_;
165 std::unique_ptr<base::RunLoop> run_loop_; 172 std::unique_ptr<base::RunLoop> run_loop_;
166 content::TestBrowserThreadBundle thread_bundle_; 173 content::TestBrowserThreadBundle thread_bundle_;
174 #if defined(OS_POSIX)
175 // Required to watch a file descriptor from NativeMessageProcessHost.
176 base::FileDescriptorWatcher file_descriptor_watcher_;
177 #endif
178
167 std::string last_message_; 179 std::string last_message_;
168 std::unique_ptr<base::DictionaryValue> last_message_parsed_; 180 std::unique_ptr<base::DictionaryValue> last_message_parsed_;
169 bool channel_closed_; 181 bool channel_closed_;
170 }; 182 };
171 183
172 // Read a single message from a local file. 184 // Read a single message from a local file.
173 TEST_F(NativeMessagingTest, SingleSendMessageRead) { 185 TEST_F(NativeMessagingTest, SingleSendMessageRead) {
174 base::FilePath temp_output_file = temp_dir_.GetPath().AppendASCII("output"); 186 base::FilePath temp_output_file = temp_dir_.GetPath().AppendASCII("output");
175 base::FilePath temp_input_file = CreateTempFileWithMessage(kTestMessage); 187 base::FilePath temp_input_file = CreateTempFileWithMessage(kTestMessage);
176 ASSERT_FALSE(temp_input_file.empty()); 188 ASSERT_FALSE(temp_input_file.empty());
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 native_message_host_->Start(this); 338 native_message_host_->Start(this);
327 ASSERT_TRUE(native_message_host_.get()); 339 ASSERT_TRUE(native_message_host_.get());
328 run_loop_.reset(new base::RunLoop()); 340 run_loop_.reset(new base::RunLoop());
329 run_loop_->Run(); 341 run_loop_->Run();
330 342
331 // The host should fail to start. 343 // The host should fail to start.
332 ASSERT_TRUE(channel_closed_); 344 ASSERT_TRUE(channel_closed_);
333 } 345 }
334 346
335 } // namespace extensions 347 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/messaging/native_message_process_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698