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

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

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

Powered by Google App Engine
This is Rietveld 408576698