Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: ui/views/mus/views_mus_test_suite.cc

Issue 2026623002: views/mus: Have explicit ownership of views::WindowManagerConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tot-merge Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 13 matching lines...) Expand all
77 // connector and identity are available at this point. This is because 79 // connector and identity are available at this point. This is because
78 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have 80 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have
79 // been installed first. So delay the creation until the necessary 81 // been installed first. So delay the creation until the necessary
80 // dependencies have been met. 82 // dependencies have been met.
81 PlatformTestHelper::set_factory(base::Bind( 83 PlatformTestHelper::set_factory(base::Bind(
82 &CreatePlatformTestHelper, shell_identity_, 84 &CreatePlatformTestHelper, shell_identity_,
83 base::Bind(&ShellConnection::GetConnector, base::Unretained(this)))); 85 base::Bind(&ShellConnection::GetConnector, base::Unretained(this))));
84 } 86 }
85 87
86 ~ShellConnection() { 88 ~ShellConnection() {
87 if (views::WindowManagerConnection::Exists())
88 views::WindowManagerConnection::Reset();
89 base::WaitableEvent wait(false, false); 89 base::WaitableEvent wait(false, false);
90 thread_.task_runner()->PostTask( 90 thread_.task_runner()->PostTask(
91 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections, 91 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections,
92 base::Unretained(this), &wait)); 92 base::Unretained(this), &wait));
93 wait.Wait(); 93 wait.Wait();
94 } 94 }
95 95
96 private: 96 private:
97 shell::Connector* GetConnector() { 97 shell::Connector* GetConnector() {
98 shell_connector_.reset(); 98 shell_connector_.reset();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 ViewsTestSuite::Initialize(); 165 ViewsTestSuite::Initialize();
166 shell_connections_.reset(new ShellConnection); 166 shell_connections_.reset(new ShellConnection);
167 } 167 }
168 168
169 void ViewsMusTestSuite::Shutdown() { 169 void ViewsMusTestSuite::Shutdown() {
170 shell_connections_.reset(); 170 shell_connections_.reset();
171 ViewsTestSuite::Shutdown(); 171 ViewsTestSuite::Shutdown();
172 } 172 }
173 173
174 } // namespace views 174 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698