| OLD | NEW |
| 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 MOJO_SHELL_PUBLIC_CPP_SHELL_TEST_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_TEST_H_ |
| 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_TEST_H_ | 6 #define MOJO_SHELL_PUBLIC_CPP_SHELL_TEST_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "mojo/public/cpp/system/macros.h" | 9 #include "mojo/public/cpp/system/macros.h" |
| 10 #include "mojo/shell/public/cpp/connector.h" | 10 #include "mojo/shell/public/cpp/connector.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // otherwise they will have to call ShellTest::InitializeCalled() to forward | 29 // otherwise they will have to call ShellTest::InitializeCalled() to forward |
| 30 // metadata from Initialize() to the test. | 30 // metadata from Initialize() to the test. |
| 31 class ShellTestClient : public mojo::ShellClient { | 31 class ShellTestClient : public mojo::ShellClient { |
| 32 public: | 32 public: |
| 33 explicit ShellTestClient(ShellTest* test); | 33 explicit ShellTestClient(ShellTest* test); |
| 34 ~ShellTestClient() override; | 34 ~ShellTestClient() override; |
| 35 | 35 |
| 36 protected: | 36 protected: |
| 37 void Initialize(Connector* connector, | 37 void Initialize(Connector* connector, |
| 38 const std::string& name, | 38 const std::string& name, |
| 39 uint32_t id, | 39 const std::string& user_id, |
| 40 uint32_t user_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 Initialize(). |
| 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 uint32_t test_instance_id() const { return initialize_instance_id_; } | 67 uint32_t test_instance_id() const { return initialize_instance_id_; } |
| 67 uint32_t test_userid() const { return initialize_userid_; } | |
| 68 | 68 |
| 69 // By default, creates a simple ShellClient that captures the metadata sent | 69 // By default, creates a simple ShellClient that captures the metadata sent |
| 70 // via Initialize(). Override to customize, but custom implementations must | 70 // via Initialize(). Override to customize, but custom implementations must |
| 71 // call InitializeCalled() to forward the metadata so test_name() etc all | 71 // call InitializeCalled() to forward the metadata so test_name() etc all |
| 72 // work. | 72 // work. |
| 73 virtual scoped_ptr<ShellClient> CreateShellClient(); | 73 virtual scoped_ptr<ShellClient> CreateShellClient(); |
| 74 | 74 |
| 75 // Call to set Initialize() metadata when GetShellClient() is overridden. | 75 // Call to set Initialize() metadata when GetShellClient() is overridden. |
| 76 void InitializeCalled(Connector* connector, | 76 void InitializeCalled(Connector* connector, |
| 77 const std::string& name, | 77 const std::string& name, |
| 78 uint32_t id, | 78 const std::string& userid, |
| 79 uint32_t userid); | 79 uint32_t id); |
| 80 | 80 |
| 81 // testing::Test: | 81 // testing::Test: |
| 82 void SetUp() override; | 82 void SetUp() override; |
| 83 void TearDown() override; | 83 void TearDown() override; |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 friend ShellTestClient; | 86 friend ShellTestClient; |
| 87 | 87 |
| 88 scoped_ptr<ShellClient> shell_client_; | 88 scoped_ptr<ShellClient> shell_client_; |
| 89 | 89 |
| 90 scoped_ptr<base::MessageLoop> message_loop_; | 90 scoped_ptr<base::MessageLoop> message_loop_; |
| 91 scoped_ptr<shell::BackgroundShell> background_shell_; | 91 scoped_ptr<shell::BackgroundShell> background_shell_; |
| 92 scoped_ptr<ShellConnection> shell_connection_; | 92 scoped_ptr<ShellConnection> shell_connection_; |
| 93 | 93 |
| 94 // See constructor. | 94 // See constructor. |
| 95 std::string test_name_; | 95 std::string test_name_; |
| 96 | 96 |
| 97 Connector* connector_ = nullptr; | 97 Connector* connector_ = nullptr; |
| 98 std::string initialize_name_; | 98 std::string initialize_name_; |
| 99 std::string initialize_userid_ = shell::mojom::kInheritUserID; |
| 99 uint32_t initialize_instance_id_ = | 100 uint32_t initialize_instance_id_ = |
| 100 shell::mojom::Connector::kInvalidApplicationID; | 101 shell::mojom::Connector::kInvalidApplicationID; |
| 101 uint32_t initialize_userid_ = shell::mojom::Connector::kUserInherit; | |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(ShellTest); | 103 DISALLOW_COPY_AND_ASSIGN(ShellTest); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 } // namespace test | 106 } // namespace test |
| 107 } // namespace mojo | 107 } // namespace mojo |
| 108 | 108 |
| 109 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_TEST_H_ | 109 #endif // MOJO_SHELL_PUBLIC_CPP_SHELL_TEST_H_ |
| OLD | NEW |