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

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..572af7e53090605f12aaab9eba1a099f8ef658a6
--- /dev/null
+++ b/win8/test/metro_registration_helper.cc
@@ -0,0 +1,68 @@
+// 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 kRegistrationTimeoutMs = 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,
+ 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,
grt (UTC plus 2) 2013/02/12 18:17:27 i like this change.
robertshield 2013/02/12 18:35:34 thank you.
+ 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::FromMilliseconds(kRegistrationTimeoutMs))) {
grt (UTC plus 2) 2013/02/12 18:17:27 how about using seconds rather than milliseconds?
robertshield 2013/02/12 18:35:34 Done.
+ return ret == 0;
+ }
+ }
+
+ LOG(ERROR) << "Win8 registration using " << kRegistrar << " timed out.";
grt (UTC plus 2) 2013/02/12 18:17:27 consider logging register_command.GetCommandLineSt
robertshield 2013/02/12 18:35:34 Done.
+ return false;
+}
+
+} // namespace win8

Powered by Google App Engine
This is Rietveld 408576698