summaryrefslogtreecommitdiffstats
path: root/win8/test
diff options
context:
space:
mode:
authorgab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-28 17:56:09 +0000
committergab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-28 17:56:09 +0000
commitb84f821c145a0fd9b247a1d3800affb1fbb9a3ba (patch)
tree3ade3cdb94ee2bd34204d5b06eea9277c6a5639e /win8/test
parent0f253da52ef4fdb2dde29f3cf5f8ca660e5067ea (diff)
downloadchromium_src-b84f821c145a0fd9b247a1d3800affb1fbb9a3ba.zip
chromium_src-b84f821c145a0fd9b247a1d3800affb1fbb9a3ba.tar.gz
chromium_src-b84f821c145a0fd9b247a1d3800affb1fbb9a3ba.tar.bz2
Introduce a single call to grab default browser on Win8 for tests.
Required to avoid duplicating code for upcoming Ash browser_tests on Windows. Also avoids calling into OpenWithDialogController if the test is already default browser. BUG=179830 Review URL: https://chromiumcodereview.appspot.com/15755016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202599 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'win8/test')
-rw-r--r--win8/test/metro_registration_helper.cc79
-rw-r--r--win8/test/metro_registration_helper.h20
2 files changed, 74 insertions, 25 deletions
diff --git a/win8/test/metro_registration_helper.cc b/win8/test/metro_registration_helper.cc
index bfcfb29..1d665dc 100644
--- a/win8/test/metro_registration_helper.cc
+++ b/win8/test/metro_registration_helper.cc
@@ -4,6 +4,10 @@
#include "win8/test/metro_registration_helper.h"
+#include <shlobj.h>
+
+#include <vector>
+
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
@@ -11,7 +15,11 @@
#include "base/path_service.h"
#include "base/process.h"
#include "base/process_util.h"
+#include "base/string16.h"
+#include "base/win/scoped_co_mem.h"
+#include "base/win/scoped_comptr.h"
#include "base/win/scoped_handle.h"
+#include "win8/test/open_with_dialog_controller.h"
#include "win8/test/test_registrar_constants.h"
namespace {
@@ -22,12 +30,12 @@ const int kRegistrationTimeoutSeconds = 30;
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) {
+// Registers chrome.exe as a potential Win8 default browser. It will then show
+// up in the default browser selection dialog as kDefaultTestExeName. Intended
+// to be used by a test binary in the build output directory and assumes the
+// presence of test_registrar.exe, a viewer process, and all needed DLLs in the
+// same directory as the calling module.
+bool RegisterTestDefaultBrowser() {
base::FilePath dir;
if (!PathService::Get(base::DIR_EXE, &dir))
return false;
@@ -40,15 +48,9 @@ bool RegisterTestDefaultBrowser(const string16& app_user_model_id,
return false;
}
- // Perform the registration by invoking test_registrar.exe with the
- // necessary flags:
- // test_registrar.exe /RegServer --appid=<appid> --exe-name=<name>
+ // Perform the registration by invoking test_registrar.exe.
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(),
@@ -75,4 +77,55 @@ bool RegisterTestDefaultBrowser(const string16& app_user_model_id,
return false;
}
+// Returns true if the test viewer's progid is the default handler for
+// |protocol|.
+bool IsTestDefaultForProtocol(const wchar_t* protocol) {
+ base::win::ScopedComPtr<IApplicationAssociationRegistration> registration;
+ HRESULT hr = registration.CreateInstance(
+ CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC);
+ if (FAILED(hr)) {
+ LOG(ERROR) << std::hex << hr;
+ return false;
+ }
+
+ base::win::ScopedCoMem<wchar_t> current_app;
+ hr = registration->QueryCurrentDefault(protocol, AT_URLPROTOCOL,
+ AL_EFFECTIVE, &current_app);
+ if (FAILED(hr)) {
+ LOG(ERROR) << std::hex << hr;
+ return false;
+ }
+
+ return string16(win8::test::kDefaultTestProgId).compare(current_app) == 0;
+}
+
+} // namespace
+
+namespace win8 {
+
+bool MakeTestDefaultBrowserSynchronously() {
+ static const wchar_t kDefaultBrowserProtocol[] = L"http";
+
+ if (!RegisterTestDefaultBrowser())
+ return false;
+
+ // Make sure the registration changes have been acknowledged by the shell
+ // before querying for the current default.
+ SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSH, NULL, NULL);
+
+ // OpenWithDialogController will fail if the Test Runner is already default
+ // since it will not show up verbatim in the dialog (e.g., in EN-US, it will
+ // be prefixed by "Keep using ").
+ if (IsTestDefaultForProtocol(kDefaultBrowserProtocol))
+ return true;
+
+ std::vector<base::string16> choices;
+ OpenWithDialogController controller;
+ HRESULT hr = controller.RunSynchronously(
+ NULL, kDefaultBrowserProtocol, win8::test::kDefaultTestExeName, &choices);
+ LOG_IF(ERROR, FAILED(hr)) << std::hex << hr;
+ DCHECK(IsTestDefaultForProtocol(kDefaultBrowserProtocol));
+ return SUCCEEDED(hr);
+}
+
} // namespace win8
diff --git a/win8/test/metro_registration_helper.h b/win8/test/metro_registration_helper.h
index 86f0015..754c87b1 100644
--- a/win8/test/metro_registration_helper.h
+++ b/win8/test/metro_registration_helper.h
@@ -9,18 +9,14 @@
namespace win8 {
-// Registers a viewer process as a potential Win8 default browser. Intended to
-// be used by a test binary in the build output directory and assumes the
-// presence of test_registrar.exe, a viewer process and all needed DLLs in the
-// same directory as the calling module. The viewer process is then subsequently
-// set as THE default Win8 browser, is activatable using the AppUserModelId in
-// |app_user_model_id| and will show up in the default browser selection dialog
-// as |viewer_process_name|.
-//
-// See also open_with_dialog_controller.h for a mechanism for setting THE
-// default Win8 browser.
-bool RegisterTestDefaultBrowser(const string16& app_user_model_id,
- const string16& viewer_process_name);
+// Synchronously makes chrome.exe THE default Win8 browser after which it is
+// activatable into a Metro viewer process using
+// win8::test::kDefaultTestAppUserModelId. Intended to be used by a test binary
+// in the output directory and assumes the presence of test_registrar.exe,
+// chrome.exe (the viewer process), and all needed DLLs in the same directory
+// as the calling module.
+// NOTE: COM must be initialized prior to calling this method.
+bool MakeTestDefaultBrowserSynchronously();
} // namespace win8