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

Unified Diff: win8/test/metro_registration_helper.cc

Issue 12096064: Automatic Win8 default browser registration for the ash unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Dear Greg Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
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..79e19d44b589c1f7660861d3a874f157bdae8dca
--- /dev/null
+++ b/win8/test/metro_registration_helper.cc
@@ -0,0 +1,78 @@
+// 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 "base/win/scoped_handle.h"
+#include "win8/test/test_registrar_constants.h"
+
+namespace {
+
+const int kRegistrationTimeoutSeconds = 30;
+
+// 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,
+ const string16& viewer_process_name) {
+ 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 << " or " << kRegistrar;
+ return false;
+ }
+
+ // Perform the registration by invoking test_registrar.exe with the
+ // necessary flags:
+ // test_registrar.exe /RegServer --appid=<appid> --exe-name=<name>
+ CommandLine register_command(registrar);
+ register_command.AppendArg("/RegServer");
+ register_command.AppendSwitchNative(win8::test::kTestAppUserModelId,
+ app_user_model_id);
+ register_command.AppendSwitchNative(win8::test::kTestExeName,
+ viewer_process_name);
+
+ base::win::ScopedHandle register_handle;
+ if (base::LaunchProcess(register_command, base::LaunchOptions(),
+ register_handle.Receive())) {
+ int ret = 0;
+ if (base::WaitForExitCodeWithTimeout(
+ register_handle, &ret,
+ base::TimeDelta::FromSeconds(kRegistrationTimeoutSeconds))) {
+ if (ret == 0) {
+ return true;
+ } else {
+ LOG(ERROR) << "Win8 registration using "
+ << register_command.GetCommandLineString()
+ << " failed with error code " << ret;
+ }
+ } else {
+ LOG(ERROR) << "Win8 registration using "
+ << register_command.GetCommandLineString() << " timed out.";
+ }
+ }
+
+ PLOG(ERROR) << "Failed to launch Win8 registration utility using "
+ << register_command.GetCommandLineString();
+ return false;
+}
+
+} // namespace win8

Powered by Google App Engine
This is Rietveld 408576698