| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "mojo/public/cpp/bindings/binding.h" | 11 #include "mojo/public/cpp/bindings/binding.h" |
| 11 #include "mojo/public/cpp/environment/environment.h" | |
| 12 #include "mojo/public/cpp/system/message_pipe.h" | 12 #include "mojo/public/cpp/system/message_pipe.h" |
| 13 #include "mojo/shell/public/cpp/application_test_base.h" | 13 #include "mojo/shell/public/cpp/application_test_base.h" |
| 14 #include "mojo/shell/public/cpp/shell_connection.h" | 14 #include "mojo/shell/public/cpp/shell_connection.h" |
| 15 #include "mojo/shell/public/interfaces/shell_client.mojom.h" | 15 #include "mojo/shell/public/interfaces/shell_client.mojom.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace test { | 18 namespace test { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 // Share the application name with multiple application tests. | 21 // Share the application name with multiple application tests. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 Binding<ShellClient> binding_; | 65 Binding<ShellClient> binding_; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 MojoResult RunAllTests(MojoHandle shell_client_request_handle) { | 70 MojoResult RunAllTests(MojoHandle shell_client_request_handle) { |
| 71 { | 71 { |
| 72 // This loop is used for init, and then destroyed before running tests. | 72 // This loop is used for init, and then destroyed before running tests. |
| 73 Environment::InstantiateDefaultRunLoop(); | 73 base::MessageLoop message_loop; |
| 74 | 74 |
| 75 // Grab the shell handle. | 75 // Grab the shell handle. |
| 76 ShellGrabber grabber( | 76 ShellGrabber grabber( |
| 77 MakeRequest<shell::mojom::ShellClient>(MakeScopedHandle( | 77 MakeRequest<shell::mojom::ShellClient>(MakeScopedHandle( |
| 78 MessagePipeHandle(shell_client_request_handle)))); | 78 MessagePipeHandle(shell_client_request_handle)))); |
| 79 grabber.WaitForInitialize(); | 79 grabber.WaitForInitialize(); |
| 80 CHECK(g_connector); | 80 CHECK(g_connector); |
| 81 CHECK(g_shell_client_request.is_pending()); | 81 CHECK(g_shell_client_request.is_pending()); |
| 82 | 82 |
| 83 int argc = 0; | 83 int argc = 0; |
| 84 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 84 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 85 const char** argv = new const char* [cmd_line->argv().size() + 1]; | 85 const char** argv = new const char* [cmd_line->argv().size() + 1]; |
| 86 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
| 87 std::vector<std::string> local_strings; | 87 std::vector<std::string> local_strings; |
| 88 #endif | 88 #endif |
| 89 for (auto& arg : cmd_line->argv()) { | 89 for (auto& arg : cmd_line->argv()) { |
| 90 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
| 91 local_strings.push_back(base::WideToUTF8(arg)); | 91 local_strings.push_back(base::WideToUTF8(arg)); |
| 92 argv[argc++] = local_strings.back().c_str(); | 92 argv[argc++] = local_strings.back().c_str(); |
| 93 #else | 93 #else |
| 94 argv[argc++] = arg.c_str(); | 94 argv[argc++] = arg.c_str(); |
| 95 #endif | 95 #endif |
| 96 } | 96 } |
| 97 argv[argc] = nullptr; | 97 argv[argc] = nullptr; |
| 98 | 98 |
| 99 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); | 99 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); |
| 100 | |
| 101 Environment::DestroyDefaultRunLoop(); | |
| 102 } | 100 } |
| 103 | 101 |
| 104 int result = RUN_ALL_TESTS(); | 102 int result = RUN_ALL_TESTS(); |
| 105 | 103 |
| 106 // Shut down our message pipes before exiting. | 104 // Shut down our message pipes before exiting. |
| 107 (void)g_shell_client_request.PassMessagePipe(); | 105 (void)g_shell_client_request.PassMessagePipe(); |
| 108 g_connector.reset(); | 106 g_connector.reset(); |
| 109 | 107 |
| 110 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; | 108 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; |
| 111 } | 109 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 133 ApplicationTestBase::~ApplicationTestBase() { | 131 ApplicationTestBase::~ApplicationTestBase() { |
| 134 } | 132 } |
| 135 | 133 |
| 136 ShellClient* ApplicationTestBase::GetShellClient() { | 134 ShellClient* ApplicationTestBase::GetShellClient() { |
| 137 return nullptr; | 135 return nullptr; |
| 138 } | 136 } |
| 139 | 137 |
| 140 void ApplicationTestBase::SetUp() { | 138 void ApplicationTestBase::SetUp() { |
| 141 // A run loop is recommended for ShellConnection initialization and | 139 // A run loop is recommended for ShellConnection initialization and |
| 142 // communication. | 140 // communication. |
| 143 if (ShouldCreateDefaultRunLoop()) | 141 if (ShouldCreateDefaultRunLoop()) { |
| 144 Environment::InstantiateDefaultRunLoop(); | 142 CHECK(!base::MessageLoop::current()); |
| 143 // Not leaked: accessible from |base::MessageLoop::current()|. |
| 144 base::MessageLoop* message_loop = new base::MessageLoop(); |
| 145 CHECK_EQ(message_loop, base::MessageLoop::current()); |
| 146 } |
| 145 | 147 |
| 146 CHECK(g_shell_client_request.is_pending()); | 148 CHECK(g_shell_client_request.is_pending()); |
| 147 CHECK(g_connector); | 149 CHECK(g_connector); |
| 148 | 150 |
| 149 // New applications are constructed for each test to avoid persisting state. | 151 // New applications are constructed for each test to avoid persisting state. |
| 150 test_helper_.reset(new TestHelper(GetShellClient())); | 152 test_helper_.reset(new TestHelper(GetShellClient())); |
| 151 } | 153 } |
| 152 | 154 |
| 153 void ApplicationTestBase::TearDown() { | 155 void ApplicationTestBase::TearDown() { |
| 154 CHECK(!g_shell_client_request.is_pending()); | 156 CHECK(!g_shell_client_request.is_pending()); |
| 155 CHECK(!g_connector); | 157 CHECK(!g_connector); |
| 156 | 158 |
| 157 test_helper_.reset(); | 159 test_helper_.reset(); |
| 158 | 160 |
| 159 if (ShouldCreateDefaultRunLoop()) | 161 if (ShouldCreateDefaultRunLoop()) { |
| 160 Environment::DestroyDefaultRunLoop(); | 162 CHECK(base::MessageLoop::current()); |
| 163 delete base::MessageLoop::current(); |
| 164 CHECK(!base::MessageLoop::current()); |
| 165 } |
| 161 } | 166 } |
| 162 | 167 |
| 163 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 168 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
| 164 return true; | 169 return true; |
| 165 } | 170 } |
| 166 | 171 |
| 167 } // namespace test | 172 } // namespace test |
| 168 } // namespace mojo | 173 } // namespace mojo |
| OLD | NEW |