Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1009)

Side by Side Diff: mojo/shell/public/cpp/shell_test.h

Issue 1877753003: Move mojo\shell to services\shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@62scan
Patch Set: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/shell/public/cpp/shell_connection.h ('k') | mojo/shell/public/cpp/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_TEST_H_
6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_TEST_H_
7
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "mojo/shell/public/cpp/connector.h"
11 #include "mojo/shell/public/cpp/shell_client.h"
12 #include "mojo/shell/public/cpp/shell_connection.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace base {
16 class MessageLoop;
17 }
18
19 namespace mojo {
20 namespace shell {
21 class BackgroundShell;
22 }
23 namespace test {
24
25 class ShellTest;
26
27 // A default implementation of ShellClient for use in ShellTests. Tests wishing
28 // to customize this should subclass this class instead of ShellClient,
29 // otherwise they will have to call ShellTest::InitializeCalled() to forward
30 // metadata from Initialize() to the test.
31 class ShellTestClient : public mojo::ShellClient {
32 public:
33 explicit ShellTestClient(ShellTest* test);
34 ~ShellTestClient() override;
35
36 protected:
37 void Initialize(Connector* connector,
38 const Identity& identity,
39 uint32_t id) override;
40
41 private:
42 ShellTest* test_;
43
44 DISALLOW_COPY_AND_ASSIGN(ShellTestClient);
45 };
46
47 class ShellTest : public testing::Test {
48 public:
49 ShellTest();
50 // Initialize passing the name to use as the identity for the test itself.
51 // Once set via this constructor, it cannot be changed later by calling
52 // InitTestName(). The test executable must provide a manifest in the
53 // appropriate location that specifies this name also.
54 explicit ShellTest(const std::string& test_name);
55 ~ShellTest() override;
56
57 protected:
58 // See constructor. Can only be called once.
59 void InitTestName(const std::string& test_name);
60
61 Connector* connector() { return connector_; }
62
63 // Instance information received from the Shell during Initialize().
64 const std::string& test_name() const { return initialize_name_; }
65 const std::string& test_userid() const { return initialize_userid_; }
66 uint32_t test_instance_id() const { return initialize_instance_id_; }
67
68 // By default, creates a simple ShellClient that captures the metadata sent
69 // via Initialize(). Override to customize, but custom implementations must
70 // call InitializeCalled() to forward the metadata so test_name() etc all
71 // work.
72 virtual scoped_ptr<ShellClient> CreateShellClient();
73
74 virtual scoped_ptr<base::MessageLoop> CreateMessageLoop();
75
76 // Call to set Initialize() metadata when GetShellClient() is overridden.
77 void InitializeCalled(Connector* connector,
78 const std::string& name,
79 const std::string& userid,
80 uint32_t id);
81
82 // testing::Test:
83 void SetUp() override;
84 void TearDown() override;
85
86 private:
87 friend ShellTestClient;
88
89 scoped_ptr<ShellClient> shell_client_;
90
91 scoped_ptr<base::MessageLoop> message_loop_;
92 scoped_ptr<shell::BackgroundShell> background_shell_;
93 scoped_ptr<ShellConnection> shell_connection_;
94
95 // See constructor.
96 std::string test_name_;
97
98 Connector* connector_ = nullptr;
99 std::string initialize_name_;
100 std::string initialize_userid_ = shell::mojom::kInheritUserID;
101 uint32_t initialize_instance_id_ = shell::mojom::kInvalidInstanceID;
102
103 base::Closure initialize_called_;
104
105 DISALLOW_COPY_AND_ASSIGN(ShellTest);
106 };
107
108 } // namespace test
109 } // namespace mojo
110
111 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_TEST_H_
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/shell_connection.h ('k') | mojo/shell/public/cpp/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698