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 24 matching lines...) Expand all Loading... | |
35 public: | 35 public: |
36 DefaultShellClient() {} | 36 DefaultShellClient() {} |
37 ~DefaultShellClient() override {} | 37 ~DefaultShellClient() override {} |
38 | 38 |
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() { | 45 PlatformTestHelperMus(shell::Connector* connector, |
46 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( | 46 const shell::Identity& identity) { |
47 &WindowManagerConnection::CreateNativeWidgetMus, | 47 // It is necessary to recreate the WindowManagerConnection for each test, |
48 base::Unretained(WindowManagerConnection::Get()), | 48 // since a new MessageLoop is created for each test. |
49 std::map<std::string, std::vector<uint8_t>>())); | 49 WindowManagerConnection::Create(connector, identity); |
50 } | 50 } |
51 ~PlatformTestHelperMus() override {} | 51 ~PlatformTestHelperMus() override { WindowManagerConnection::Reset(); } |
sky
2016/05/31 18:01:27
Can you make ~WindowManagerConnection also unset i
sadrul
2016/05/31 18:08:15
Updated ~WMC to unset the native-widget factory.
| |
52 | 52 |
53 private: | 53 private: |
54 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); | 54 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); |
55 }; | 55 }; |
56 | 56 |
57 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper( | 57 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper( |
58 shell::Connector* connector, | 58 const shell::Identity& identity, |
59 const shell::Identity& identity) { | 59 const base::Callback<shell::Connector*(void)>& callback) { |
60 if (!WindowManagerConnection::Exists()) | 60 return base::WrapUnique(new PlatformTestHelperMus(callback.Run(), identity)); |
61 WindowManagerConnection::Create(connector, identity); | |
62 return base::WrapUnique(new PlatformTestHelperMus); | |
63 } | 61 } |
64 | 62 |
65 } // namespace | 63 } // namespace |
66 | 64 |
67 class ShellConnection { | 65 class ShellConnection { |
68 public: | 66 public: |
69 ShellConnection() : thread_("Persistent shell connections") { | 67 ShellConnection() : thread_("Persistent shell connections") { |
70 base::WaitableEvent wait(false, false); | 68 base::WaitableEvent wait(false, false); |
71 base::Thread::Options options; | 69 base::Thread::Options options; |
72 thread_.StartWithOptions(options); | 70 thread_.StartWithOptions(options); |
73 thread_.task_runner()->PostTask( | 71 thread_.task_runner()->PostTask( |
74 FROM_HERE, base::Bind(&ShellConnection::SetUpConnections, | 72 FROM_HERE, base::Bind(&ShellConnection::SetUpConnections, |
75 base::Unretained(this), &wait)); | 73 base::Unretained(this), &wait)); |
76 wait.Wait(); | 74 wait.Wait(); |
77 | 75 |
78 // WindowManagerConnection cannot be created from here yet, although the | 76 // WindowManagerConnection cannot be created from here yet, although the |
79 // connector and identity are available at this point. This is because | 77 // connector and identity are available at this point. This is because |
80 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have | 78 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have |
81 // been installed first. So delay the creation until the necessary | 79 // been installed first. So delay the creation until the necessary |
82 // dependencies have been met. | 80 // dependencies have been met. |
83 PlatformTestHelper::set_factory(base::Bind( | 81 PlatformTestHelper::set_factory(base::Bind( |
84 &CreatePlatformTestHelper, shell_connector_.get(), shell_identity_)); | 82 &CreatePlatformTestHelper, shell_identity_, |
83 base::Bind(&ShellConnection::GetConnector, base::Unretained(this)))); | |
85 } | 84 } |
86 | 85 |
87 ~ShellConnection() { | 86 ~ShellConnection() { |
88 if (views::WindowManagerConnection::Exists()) | 87 if (views::WindowManagerConnection::Exists()) |
89 views::WindowManagerConnection::Reset(); | 88 views::WindowManagerConnection::Reset(); |
90 base::WaitableEvent wait(false, false); | 89 base::WaitableEvent wait(false, false); |
91 thread_.task_runner()->PostTask( | 90 thread_.task_runner()->PostTask( |
92 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections, | 91 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections, |
93 base::Unretained(this), &wait)); | 92 base::Unretained(this), &wait)); |
94 wait.Wait(); | 93 wait.Wait(); |
95 } | 94 } |
96 | 95 |
97 private: | 96 private: |
97 shell::Connector* GetConnector() { | |
98 shell_connector_.reset(); | |
99 base::WaitableEvent wait(false, false); | |
100 thread_.task_runner()->PostTask(FROM_HERE, | |
101 base::Bind(&ShellConnection::CloneConnector, | |
102 base::Unretained(this), &wait)); | |
103 wait.Wait(); | |
104 DCHECK(shell_connector_); | |
105 return shell_connector_.get(); | |
106 } | |
107 | |
108 void CloneConnector(base::WaitableEvent* wait) { | |
109 shell_connector_ = shell_connection_->connector()->Clone(); | |
110 wait->Signal(); | |
111 } | |
112 | |
98 void SetUpConnections(base::WaitableEvent* wait) { | 113 void SetUpConnections(base::WaitableEvent* wait) { |
99 background_shell_.reset(new shell::BackgroundShell); | 114 background_shell_.reset(new shell::BackgroundShell); |
100 background_shell_->Init(nullptr); | 115 background_shell_->Init(nullptr); |
101 shell_client_.reset(new DefaultShellClient); | 116 shell_client_.reset(new DefaultShellClient); |
102 shell_connection_.reset(new shell::ShellConnection( | 117 shell_connection_.reset(new shell::ShellConnection( |
103 shell_client_.get(), | 118 shell_client_.get(), |
104 background_shell_->CreateShellClientRequest(GetTestName()))); | 119 background_shell_->CreateShellClientRequest(GetTestName()))); |
105 | 120 |
106 // ui/views/mus requires a WindowManager running, so launch test_wm. | 121 // ui/views/mus requires a WindowManager running, so launch test_wm. |
107 shell::Connector* connector = shell_connection_->connector(); | 122 shell::Connector* connector = shell_connection_->connector(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 ViewsTestSuite::Initialize(); | 165 ViewsTestSuite::Initialize(); |
151 shell_connections_.reset(new ShellConnection); | 166 shell_connections_.reset(new ShellConnection); |
152 } | 167 } |
153 | 168 |
154 void ViewsMusTestSuite::Shutdown() { | 169 void ViewsMusTestSuite::Shutdown() { |
155 shell_connections_.reset(); | 170 shell_connections_.reset(); |
156 ViewsTestSuite::Shutdown(); | 171 ViewsTestSuite::Shutdown(); |
157 } | 172 } |
158 | 173 |
159 } // namespace views | 174 } // namespace views |
OLD | NEW |