Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / mojo / runner / shell_test_base.cc
bloba6b445e7994f7a71885fef7ba690a515de27d38e
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/runner/shell_test_base.h"
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "build/build_config.h"
14 #include "mojo/util/filename_util.h"
15 #include "url/gurl.h"
17 namespace mojo {
18 namespace runner {
19 namespace test {
21 namespace {
23 void QuitIfRunning() {
24 if (base::MessageLoop::current() &&
25 base::MessageLoop::current()->is_running()) {
26 base::MessageLoop::current()->QuitWhenIdle();
30 } // namespace
32 ShellTestBase::ShellTestBase() {
35 ShellTestBase::~ShellTestBase() {
38 void ShellTestBase::SetUp() {
39 CHECK(shell_context_.Init());
40 SetUpTestApplications();
43 void ShellTestBase::TearDown() {
44 shell_context_.Shutdown();
47 ScopedMessagePipeHandle ShellTestBase::ConnectToService(
48 const GURL& application_url,
49 const std::string& service_name) {
50 ServiceProviderPtr services;
51 mojo::URLRequestPtr request(mojo::URLRequest::New());
52 request->url = mojo::String::From(application_url.spec());
53 shell_context_.application_manager()->ConnectToApplication(
54 nullptr, request.Pass(), std::string(), GURL(), GetProxy(&services),
55 nullptr, nullptr, base::Bind(&QuitIfRunning));
56 MessagePipe pipe;
57 services->ConnectToService(service_name, pipe.handle1.Pass());
58 return pipe.handle0.Pass();
61 #if !defined(OS_ANDROID)
62 void ShellTestBase::SetUpTestApplications() {
63 // Set the URLResolver origin to be the same as the base file path for
64 // local files. This is primarily for test convenience, so that references
65 // to unknown mojo: URLs that do not have specific local file or custom
66 // mappings registered on the URL resolver are treated as shared libraries.
67 base::FilePath service_dir;
68 CHECK(PathService::Get(base::DIR_MODULE, &service_dir));
69 shell_context_.url_resolver()->SetMojoBaseURL(
70 util::FilePathToFileURL(service_dir));
72 #endif
74 } // namespace test
75 } // namespace runner
76 } // namespace mojo