| 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 "mojo/public/cpp/application/application_test_base.h" | 5 #include "mojo/public/cpp/application/application_test_base.h" |
| 6 | 6 |
| 7 #include "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_delegate.h" |
| 8 #include "mojo/public/cpp/application/application_impl.h" | 8 #include "mojo/public/cpp/application/application_impl.h" |
| 9 #include "mojo/public/cpp/environment/environment.h" | 9 #include "mojo/public/cpp/environment/environment.h" |
| 10 #include "mojo/public/cpp/system/message_pipe.h" | 10 #include "mojo/public/cpp/system/message_pipe.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 } | 50 } |
| 51 | 51 |
| 52 ApplicationTestBase::~ApplicationTestBase() { | 52 ApplicationTestBase::~ApplicationTestBase() { |
| 53 } | 53 } |
| 54 | 54 |
| 55 ApplicationDelegate* ApplicationTestBase::GetApplicationDelegate() { | 55 ApplicationDelegate* ApplicationTestBase::GetApplicationDelegate() { |
| 56 return &default_application_delegate_; | 56 return &default_application_delegate_; |
| 57 } | 57 } |
| 58 | 58 |
| 59 void ApplicationTestBase::SetUpWithArgs(const Array<String>& args) { | 59 void ApplicationTestBase::SetUpWithArgs(const Array<String>& args) { |
| 60 // A run loop is needed for ApplicationImpl initialization and communication. | 60 // A run loop is recommended for ApplicationImpl initialization and |
| 61 Environment::InstantiateDefaultRunLoop(); | 61 // communication. |
| 62 if (ShouldCreateDefaultRunLoop()) |
| 63 Environment::InstantiateDefaultRunLoop(); |
| 62 | 64 |
| 63 // New applications are constructed for each test to avoid persisting state. | 65 // New applications are constructed for each test to avoid persisting state. |
| 64 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), | 66 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), |
| 65 PassShellHandle()); | 67 PassShellHandle()); |
| 66 | 68 |
| 67 // Fake application initialization with the given command line arguments. | 69 // Fake application initialization with the given command line arguments. |
| 68 application_impl_->Initialize(args.Clone()); | 70 application_impl_->Initialize(args.Clone()); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void ApplicationTestBase::SetUp() { | 73 void ApplicationTestBase::SetUp() { |
| 72 SetUpWithArgs(Args()); | 74 SetUpWithArgs(Args()); |
| 73 } | 75 } |
| 74 | 76 |
| 75 void ApplicationTestBase::TearDown() { | 77 void ApplicationTestBase::TearDown() { |
| 76 SetShellHandle(application_impl_->UnbindShell()); | 78 SetShellHandle(application_impl_->UnbindShell()); |
| 77 delete application_impl_; | 79 delete application_impl_; |
| 78 Environment::DestroyDefaultRunLoop(); | 80 if (ShouldCreateDefaultRunLoop()) |
| 81 Environment::DestroyDefaultRunLoop(); |
| 82 } |
| 83 |
| 84 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
| 85 return true; |
| 79 } | 86 } |
| 80 | 87 |
| 81 } // namespace test | 88 } // namespace test |
| 82 } // namespace mojo | 89 } // namespace mojo |
| OLD | NEW |