146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// found in the LICENSE file.
446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#ifndef MOJO_SHELL_SHELL_TEST_BASE_H_
646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#define MOJO_SHELL_SHELL_TEST_BASE_H_
746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
8f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include <string>
9f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/macros.h"
11116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/message_loop/message_loop.h"
12f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "mojo/public/cpp/system/core.h"
13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "mojo/shell/context.h"
1446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
1546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
16f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class GURL;
17f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace net {
195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace test_server {
205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class EmbeddedTestServer;
215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}  // namespace net
235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)namespace mojo {
2546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)namespace shell {
2646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)namespace test {
2746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class ShellTestBase : public testing::Test {
2946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) public:
3046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  ShellTestBase();
3146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual ~ShellTestBase();
3246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void SetUp() OVERRIDE;
345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // |application_url| should typically be a mojo: URL (the origin will be set
36116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // to an "appropriate" file: URL).
37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // TODO(tim): Should the test base be a ServiceProvider?
38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  ScopedMessagePipeHandle ConnectToService(
39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const GURL& application_url,
40116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const std::string& service_name);
41f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ScopedMessagePipeHandle ConnectToServiceViaNetwork(
435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const GURL& application_url,
445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      const std::string& service_name);
455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  template <typename Interface>
471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void ConnectToService(const GURL& application_url,
481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                        InterfacePtr<Interface>* ptr) {
491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ptr->Bind(ConnectToService(application_url, Interface::Name_).Pass());
501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  template <typename Interface>
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void ConnectToServiceViaNetwork(const GURL& application_url,
541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                        InterfacePtr<Interface>* ptr) {
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ptr->Bind(
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        ConnectToServiceViaNetwork(application_url, Interface::Name_).Pass());
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  base::MessageLoop* message_loop() { return &message_loop_; }
60116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  Context* shell_context() { return &shell_context_; }
61f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
6246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) private:
635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  scoped_ptr<net::test_server::EmbeddedTestServer> test_server_;
64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  Context shell_context_;
655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  base::MessageLoop message_loop_;
6646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
6746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ShellTestBase);
6846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)};
6946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
7046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}  // namespace test
7146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}  // namespace shell
7246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}  // namespace mojo
7346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
74f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#endif  // MOJO_SHELL_SHELL_TEST_BASE_H_
75