summaryrefslogtreecommitdiffstats
path: root/mojo/shell/shell_test_base.h
blob: 98e744c1870406933898bc9d4a35c5d44423bfb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2014 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.

#ifndef MOJO_SHELL_SHELL_TEST_BASE_H_
#define MOJO_SHELL_SHELL_TEST_BASE_H_

#include <string>

#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/shell/context.h"
#include "testing/gtest/include/gtest/gtest.h"

class GURL;

namespace net {
namespace test_server {
class EmbeddedTestServer;
}
}  // namespace net

namespace mojo {
namespace shell {
namespace test {

class ShellTestBase : public testing::Test {
 public:
  ShellTestBase();
  virtual ~ShellTestBase();

  virtual void SetUp() OVERRIDE;

  // |application_url| should typically be a mojo: URL (the origin will be set
  // to an "appropriate" file: URL).
  // TODO(tim): Should the test base be a ServiceProvider?
  ScopedMessagePipeHandle ConnectToService(
      const GURL& application_url,
      const std::string& service_name);

  ScopedMessagePipeHandle ConnectToServiceViaNetwork(
      const GURL& application_url,
      const std::string& service_name);

  template <typename Interface>
  void ConnectToService(const GURL& application_url,
                        InterfacePtr<Interface>* ptr) {
    ptr->Bind(ConnectToService(application_url, Interface::Name_).Pass());
  }

  template <typename Interface>
  void ConnectToServiceViaNetwork(const GURL& application_url,
                        InterfacePtr<Interface>* ptr) {
    ptr->Bind(
        ConnectToServiceViaNetwork(application_url, Interface::Name_).Pass());
  }

  base::MessageLoop* message_loop() { return &message_loop_; }
  Context* shell_context() { return &shell_context_; }

 private:
  scoped_ptr<net::test_server::EmbeddedTestServer> test_server_;
  Context shell_context_;
  base::MessageLoop message_loop_;

  DISALLOW_COPY_AND_ASSIGN(ShellTestBase);
};

}  // namespace test
}  // namespace shell
}  // namespace mojo

#endif  // MOJO_SHELL_SHELL_TEST_BASE_H_