Index: chrome/app/chrome_watcher_command_line_unittest_win.cc |
diff --git a/chrome/app/chrome_watcher_command_line_unittest_win.cc b/chrome/app/chrome_watcher_command_line_unittest_win.cc |
index b7c6be34463f526673649e0c7700cff02040270e..0c2ce0c56707b6451d6c97212e2056c86c538e89 100644 |
--- a/chrome/app/chrome_watcher_command_line_unittest_win.cc |
+++ b/chrome/app/chrome_watcher_command_line_unittest_win.cc |
@@ -12,6 +12,61 @@ |
#include "base/win/scoped_handle.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+class TestChromeWatcherCommandLineGenerator |
+ : public ChromeWatcherCommandLineGenerator { |
+ public: |
+ explicit TestChromeWatcherCommandLineGenerator( |
+ const base::FilePath& chrome_exe) |
+ : ChromeWatcherCommandLineGenerator(chrome_exe) { |
+ } |
+ |
+ void ReleaseHandlesWithoutClosing() { |
+ on_initialized_event_handle_.Take(); |
+ parent_process_handle_.Take(); |
+ } |
+}; |
+ |
+TEST(ChromeWatcherCommandLineTest, EndToEnd) { |
+ base::win::ScopedHandle process(::OpenProcess( |
+ PROCESS_QUERY_INFORMATION | SYNCHRONIZE, |
+ FALSE, // Not inheritable. |
+ ::GetCurrentProcessId())); |
+ ASSERT_TRUE(process.Get()); |
+ |
+ base::win::ScopedHandle event(::CreateEvent(nullptr, FALSE, FALSE, nullptr)); |
+ ASSERT_TRUE(event.Get()); |
+ |
+ // The above handles are duplicated by the generator. |
+ TestChromeWatcherCommandLineGenerator generator( |
+ base::FilePath(L"example.exe")); |
+ generator.SetOnInitializedEventHandle(event.Get()); |
+ generator.SetParentProcessHandle(process.Get()); |
+ |
+ // Expect there to be two inherited handles created by the generator. |
+ std::vector<HANDLE> handles; |
+ generator.GetInheritedHandles(&handles); |
+ EXPECT_EQ(2u, handles.size()); |
+ |
+ base::CommandLine cmd_line = generator.GenerateCommandLine(); |
+ |
+ // Release the handles from the generator. Ownership will be picked up by the |
+ // interpreter, and this prevents the handle tracking from complaining about |
+ // there being two owners of the same handle. |
+ generator.ReleaseHandlesWithoutClosing(); |
+ |
+ // Parse the command line. This creates scoped vectors around the same handles |
+ // that are currently owned by the generator. |
+ ChromeWatcherCommandLineInterpreter interpreter; |
+ EXPECT_TRUE(interpreter.InterpretCommandLine(cmd_line)); |
+ |
+ EXPECT_EQ(::GetCurrentThreadId(), interpreter.main_thread_id()); |
+ |
+ // Explicitly take the handles from the interpreter. |
+ base::win::ScopedHandle on_init, proc; |
+ EXPECT_TRUE(interpreter.TakeOnInitializedEventHandle(&on_init)); |
+ EXPECT_TRUE(interpreter.TakeParentProcessHandle(&proc)); |
+} |
+ |
TEST(ChromeWatcherCommandLineTest, BasicTest) { |
// Ownership of these handles is passed to the ScopedHandles below via |
// InterpretChromeWatcherCommandLine(). |