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

Unified Diff: chrome/app/chrome_watcher_command_line_unittest_win.cc

Issue 1538923004: [win] Change Chrome Watcher configuration API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unittests. Created 5 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/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().
« no previous file with comments | « no previous file | chrome/app/chrome_watcher_command_line_win.h » ('j') | chrome/app/chrome_watcher_command_line_win.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698