| 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 #include "ui/views/mus/views_mus_test_suite.h" | 5 #include "ui/views/mus/views_mus_test_suite.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 private: | 39 private: |
| 40 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient); | 40 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient); |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 class PlatformTestHelperMus : public PlatformTestHelper { | 43 class PlatformTestHelperMus : public PlatformTestHelper { |
| 44 public: | 44 public: |
| 45 PlatformTestHelperMus(shell::Connector* connector, | 45 PlatformTestHelperMus(shell::Connector* connector, |
| 46 const shell::Identity& identity) { | 46 const shell::Identity& identity) { |
| 47 // It is necessary to recreate the WindowManagerConnection for each test, | 47 // It is necessary to recreate the WindowManagerConnection for each test, |
| 48 // since a new MessageLoop is created for each test. | 48 // since a new MessageLoop is created for each test. |
| 49 WindowManagerConnection::Create(connector, identity); | 49 connection_ = WindowManagerConnection::Create(connector, identity); |
| 50 } | 50 } |
| 51 ~PlatformTestHelperMus() override { WindowManagerConnection::Reset(); } | 51 ~PlatformTestHelperMus() override {} |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 std::unique_ptr<WindowManagerConnection> connection_; |
| 55 |
| 54 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); | 56 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); |
| 55 }; | 57 }; |
| 56 | 58 |
| 57 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper( | 59 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper( |
| 58 const shell::Identity& identity, | 60 const shell::Identity& identity, |
| 59 const base::Callback<shell::Connector*(void)>& callback) { | 61 const base::Callback<shell::Connector*(void)>& callback) { |
| 60 return base::WrapUnique(new PlatformTestHelperMus(callback.Run(), identity)); | 62 return base::WrapUnique(new PlatformTestHelperMus(callback.Run(), identity)); |
| 61 } | 63 } |
| 62 | 64 |
| 63 } // namespace | 65 } // namespace |
| (...skipping 14 matching lines...) Expand all Loading... |
| 78 // connector and identity are available at this point. This is because | 80 // connector and identity are available at this point. This is because |
| 79 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have | 81 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have |
| 80 // been installed first. So delay the creation until the necessary | 82 // been installed first. So delay the creation until the necessary |
| 81 // dependencies have been met. | 83 // dependencies have been met. |
| 82 PlatformTestHelper::set_factory(base::Bind( | 84 PlatformTestHelper::set_factory(base::Bind( |
| 83 &CreatePlatformTestHelper, shell_identity_, | 85 &CreatePlatformTestHelper, shell_identity_, |
| 84 base::Bind(&ShellConnection::GetConnector, base::Unretained(this)))); | 86 base::Bind(&ShellConnection::GetConnector, base::Unretained(this)))); |
| 85 } | 87 } |
| 86 | 88 |
| 87 ~ShellConnection() { | 89 ~ShellConnection() { |
| 88 if (views::WindowManagerConnection::Exists()) | |
| 89 views::WindowManagerConnection::Reset(); | |
| 90 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 90 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 91 base::WaitableEvent::InitialState::NOT_SIGNALED); | 91 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 92 thread_.task_runner()->PostTask( | 92 thread_.task_runner()->PostTask( |
| 93 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections, | 93 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections, |
| 94 base::Unretained(this), &wait)); | 94 base::Unretained(this), &wait)); |
| 95 wait.Wait(); | 95 wait.Wait(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 shell::Connector* GetConnector() { | 99 shell::Connector* GetConnector() { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 ViewsTestSuite::Initialize(); | 167 ViewsTestSuite::Initialize(); |
| 168 shell_connections_.reset(new ShellConnection); | 168 shell_connections_.reset(new ShellConnection); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void ViewsMusTestSuite::Shutdown() { | 171 void ViewsMusTestSuite::Shutdown() { |
| 172 shell_connections_.reset(); | 172 shell_connections_.reset(); |
| 173 ViewsTestSuite::Shutdown(); | 173 ViewsTestSuite::Shutdown(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace views | 176 } // namespace views |
| OLD | NEW |