Index: win8/test/metro_registration_helper.cc |
diff --git a/win8/test/metro_registration_helper.cc b/win8/test/metro_registration_helper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ad2a66157c506bf6092917854bf26b707fced128 |
--- /dev/null |
+++ b/win8/test/metro_registration_helper.cc |
@@ -0,0 +1,64 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "win8/test/metro_registration_helper.h" |
+ |
+#include "base/command_line.h" |
+#include "base/file_path.h" |
+#include "base/file_util.h" |
+#include "base/logging.h" |
+#include "base/path_service.h" |
+#include "base/process.h" |
+#include "base/process_util.h" |
+#include "win8/test/test_registrar_constants.h" |
grt (UTC plus 2)
2013/02/12 15:37:43
#include "base/win/scoped_handle.h"
robertshield
2013/02/12 16:57:08
Done.
|
+ |
+namespace { |
+ |
+const int kRegistrationTimeout = 30000; |
+ |
+// Copied from util_constants.cc to avoid taking a dependency on installer_util. |
+const wchar_t kChromeExe[] = L"chrome.exe"; |
+const wchar_t kRegistrar[] = L"test_registrar.exe"; |
+ |
+} |
+ |
+namespace win8 { |
+ |
+bool RegisterTestDefaultBrowser(const string16& app_user_model_id) { |
+ FilePath dir; |
+ if (!PathService::Get(base::DIR_EXE, &dir)) |
+ return false; |
+ |
+ FilePath chrome_exe(dir.Append(kChromeExe)); |
+ FilePath registrar(dir.Append(kRegistrar)); |
+ |
+ if (!file_util::PathExists(chrome_exe) || !file_util::PathExists(registrar)) { |
+ LOG(ERROR) << "Could not locate " << kChromeExe << " and " << kRegistrar; |
grt (UTC plus 2)
2013/02/12 15:37:43
and -> and/or
robertshield
2013/02/12 16:57:08
Done.
|
+ return false; |
+ } |
+ |
+ // Perform the registration by invoking test_delegate_execute.exe with the |
grt (UTC plus 2)
2013/02/12 15:37:43
update comment
robertshield
2013/02/12 16:57:08
Done.
|
+ // necessary flags: |
+ // test_delegate_execute.exe /RegServer --appid=<appid> |
+ CommandLine register_command(registrar); |
+ register_command.AppendArg("/RegServer"); |
+ register_command.AppendSwitchNative(win8::test::kTestAppUserModelId, |
+ app_user_model_id); |
+ |
+ base::ProcessHandle register_handle; |
grt (UTC plus 2)
2013/02/12 15:37:43
base::win::ScopedHandle register_handle;
robertshield
2013/02/12 16:57:08
Done.
|
+ if (base::LaunchProcess(register_command, base::LaunchOptions(), |
+ ®ister_handle)) { |
grt (UTC plus 2)
2013/02/12 15:37:43
register_handle.Receive()
robertshield
2013/02/12 16:57:08
Done.
|
+ DWORD result = WaitForSingleObject(register_handle, kRegistrationTimeout); |
grt (UTC plus 2)
2013/02/12 15:37:43
int ret = 0;
if (base::WaitForExitCodeWithTimeout(
robertshield
2013/02/12 16:57:08
Done.
|
+ if (result == WAIT_OBJECT_0) { |
+ DWORD ret = 0; |
+ if (::GetExitCodeProcess(register_handle, &ret)) |
+ return ret == 0; |
+ } |
+ } |
+ |
+ LOG(ERROR) << "Win8 registration using " << kRegistrar << " timed out."; |
+ return false; |
+} |
+ |
+} // namespace win8 |