Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / shell / shell_test_base.h
blob98e744c1870406933898bc9d4a35c5d44423bfb4
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 #ifndef MOJO_SHELL_SHELL_TEST_BASE_H_
6 #define MOJO_SHELL_SHELL_TEST_BASE_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/message_loop/message_loop.h"
12 #include "mojo/public/cpp/system/core.h"
13 #include "mojo/shell/context.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 class GURL;
18 namespace net {
19 namespace test_server {
20 class EmbeddedTestServer;
22 } // namespace net
24 namespace mojo {
25 namespace shell {
26 namespace test {
28 class ShellTestBase : public testing::Test {
29 public:
30 ShellTestBase();
31 virtual ~ShellTestBase();
33 virtual void SetUp() OVERRIDE;
35 // |application_url| should typically be a mojo: URL (the origin will be set
36 // to an "appropriate" file: URL).
37 // TODO(tim): Should the test base be a ServiceProvider?
38 ScopedMessagePipeHandle ConnectToService(
39 const GURL& application_url,
40 const std::string& service_name);
42 ScopedMessagePipeHandle ConnectToServiceViaNetwork(
43 const GURL& application_url,
44 const std::string& service_name);
46 template <typename Interface>
47 void ConnectToService(const GURL& application_url,
48 InterfacePtr<Interface>* ptr) {
49 ptr->Bind(ConnectToService(application_url, Interface::Name_).Pass());
52 template <typename Interface>
53 void ConnectToServiceViaNetwork(const GURL& application_url,
54 InterfacePtr<Interface>* ptr) {
55 ptr->Bind(
56 ConnectToServiceViaNetwork(application_url, Interface::Name_).Pass());
59 base::MessageLoop* message_loop() { return &message_loop_; }
60 Context* shell_context() { return &shell_context_; }
62 private:
63 scoped_ptr<net::test_server::EmbeddedTestServer> test_server_;
64 Context shell_context_;
65 base::MessageLoop message_loop_;
67 DISALLOW_COPY_AND_ASSIGN(ShellTestBase);
70 } // namespace test
71 } // namespace shell
72 } // namespace mojo
74 #endif // MOJO_SHELL_SHELL_TEST_BASE_H_