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

Side by Side Diff: mojo/shell/public/cpp/application_test_base.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/application_runner.h ('k') | mojo/shell/public/cpp/capabilities.h » ('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 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.
4
5 #ifndef MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_
6 #define MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_
7
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "mojo/public/cpp/bindings/array.h"
11 #include "mojo/public/cpp/bindings/string.h"
12 #include "mojo/shell/public/cpp/connector.h"
13 #include "mojo/shell/public/cpp/shell_client.h"
14 #include "mojo/shell/public/cpp/shell_connection.h"
15 #include "mojo/shell/public/interfaces/shell_client.mojom.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace mojo {
19
20 class ShellConnection;
21
22 namespace test {
23
24 // Run all application tests. This must be called after the environment is
25 // initialized, to support construction of a default run loop.
26 MojoResult RunAllTests(MojoHandle shell_client_request_handle);
27
28 // Used to configure the ShellConnection. This is used internally by
29 // ApplicationTestBase, but useful if you do not want to subclass
30 // ApplicationTestBase.
31 class TestHelper {
32 public:
33 explicit TestHelper(ShellClient* client);
34 ~TestHelper();
35
36 Connector* connector() { return shell_connection_->connector(); }
37 const std::string& test_name() { return name_; }
38 const std::string& test_userid() { return userid_; }
39 uint32_t test_instance_id() { return instance_id_; }
40
41 private:
42 // The application delegate used if GetShellClient is not overridden.
43 ShellClient default_shell_client_;
44
45 // The application implementation instance, reconstructed for each test.
46 scoped_ptr<ShellConnection> shell_connection_;
47
48 std::string name_;
49 std::string userid_;
50 uint32_t instance_id_;
51
52 DISALLOW_COPY_AND_ASSIGN(TestHelper);
53 };
54
55 // A GTEST base class for application testing executed in mojo_shell.
56 class ApplicationTestBase : public testing::Test {
57 public:
58 ApplicationTestBase();
59 ~ApplicationTestBase() override;
60
61 protected:
62 Connector* connector() {
63 return test_helper_ ? test_helper_->connector() : nullptr;
64 }
65 const std::string& test_name() const {
66 return test_helper_ ? test_helper_->test_name() : empty_;
67 }
68 const std::string& test_userid() const {
69 return test_helper_ ? test_helper_->test_userid() : inherit_user_id_;
70 }
71 uint32_t test_instance_id() const {
72 return test_helper_ ? test_helper_->test_instance_id() :
73 shell::mojom::kInvalidInstanceID;
74 }
75
76 // Get the ShellClient for the application to be tested.
77 virtual ShellClient* GetShellClient();
78
79 // testing::Test:
80 void SetUp() override;
81 void TearDown() override;
82
83 // True by default, which indicates a MessageLoop will automatically be
84 // created for the application. Tests may override this function to prevent
85 // a default loop from being created.
86 virtual bool ShouldCreateDefaultRunLoop();
87
88 private:
89 scoped_ptr<TestHelper> test_helper_;
90 std::string empty_;
91 std::string inherit_user_id_ = shell::mojom::kInheritUserID;
92
93 DISALLOW_COPY_AND_ASSIGN(ApplicationTestBase);
94 };
95
96 } // namespace test
97
98 } // namespace mojo
99
100 #endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/application_runner.h ('k') | mojo/shell/public/cpp/capabilities.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698