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

Side by Side Diff: services/ui/ws/window_tree_client_unittest.cc

Issue 2365753003: mus ws: Move 'reset(new' to base::MakeUnique. (Closed)
Patch Set: Merge with tot Created 4 years, 2 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
« no previous file with comments | « services/ui/ws/window_tree.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 track_root_bounds_changes_ = value; 144 track_root_bounds_changes_ = value;
145 } 145 }
146 146
147 // Runs a nested MessageLoop until |count| changes (calls to 147 // Runs a nested MessageLoop until |count| changes (calls to
148 // WindowTreeClient functions) have been received. 148 // WindowTreeClient functions) have been received.
149 void WaitForChangeCount(size_t count) { 149 void WaitForChangeCount(size_t count) {
150 if (tracker_.changes()->size() >= count) 150 if (tracker_.changes()->size() >= count)
151 return; 151 return;
152 152
153 ASSERT_TRUE(wait_state_.get() == nullptr); 153 ASSERT_TRUE(wait_state_.get() == nullptr);
154 wait_state_.reset(new WaitState); 154 wait_state_ = base::MakeUnique<WaitState>();
155 wait_state_->change_count = count; 155 wait_state_->change_count = count;
156 wait_state_->run_loop.Run(); 156 wait_state_->run_loop.Run();
157 wait_state_.reset(); 157 wait_state_.reset();
158 } 158 }
159 159
160 uint32_t GetAndAdvanceChangeId() { return next_change_id_++; } 160 uint32_t GetAndAdvanceChangeId() { return next_change_id_++; }
161 161
162 // Runs a nested MessageLoop until OnEmbed() has been encountered. 162 // Runs a nested MessageLoop until OnEmbed() has been encountered.
163 void WaitForOnEmbed() { 163 void WaitForOnEmbed() {
164 if (tree_) 164 if (tree_)
165 return; 165 return;
166 embed_run_loop_.reset(new base::RunLoop); 166 embed_run_loop_ = base::MakeUnique<base::RunLoop>();
167 embed_run_loop_->Run(); 167 embed_run_loop_->Run();
168 embed_run_loop_.reset(); 168 embed_run_loop_.reset();
169 } 169 }
170 170
171 bool WaitForChangeCompleted(uint32_t id) { 171 bool WaitForChangeCompleted(uint32_t id) {
172 waiting_change_id_ = id; 172 waiting_change_id_ = id;
173 change_completed_run_loop_.reset(new base::RunLoop); 173 change_completed_run_loop_ = base::MakeUnique<base::RunLoop>();
174 change_completed_run_loop_->Run(); 174 change_completed_run_loop_->Run();
175 return on_change_completed_result_; 175 return on_change_completed_result_;
176 } 176 }
177 177
178 bool DeleteWindow(Id id) { 178 bool DeleteWindow(Id id) {
179 const uint32_t change_id = GetAndAdvanceChangeId(); 179 const uint32_t change_id = GetAndAdvanceChangeId();
180 tree()->DeleteWindow(change_id, id); 180 tree()->DeleteWindow(change_id, id);
181 return WaitForChangeCompleted(change_id); 181 return WaitForChangeCompleted(change_id);
182 } 182 }
183 183
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 410
411 void OnChangeCompleted(uint32_t change_id, bool success) override { 411 void OnChangeCompleted(uint32_t change_id, bool success) override {
412 if (waiting_change_id_ == change_id && change_completed_run_loop_) { 412 if (waiting_change_id_ == change_id && change_completed_run_loop_) {
413 on_change_completed_result_ = success; 413 on_change_completed_result_ = success;
414 change_completed_run_loop_->Quit(); 414 change_completed_run_loop_->Quit();
415 } 415 }
416 } 416 }
417 void RequestClose(uint32_t window_id) override {} 417 void RequestClose(uint32_t window_id) override {}
418 void GetWindowManager(mojo::AssociatedInterfaceRequest<mojom::WindowManager> 418 void GetWindowManager(mojo::AssociatedInterfaceRequest<mojom::WindowManager>
419 internal) override { 419 internal) override {
420 window_manager_binding_.reset( 420 window_manager_binding_ =
421 new mojo::AssociatedBinding<mojom::WindowManager>(this, 421 base::MakeUnique<mojo::AssociatedBinding<mojom::WindowManager>>(
422 std::move(internal))); 422 this, std::move(internal));
423 tree_->GetWindowManagerClient( 423 tree_->GetWindowManagerClient(
424 GetProxy(&window_manager_client_, tree_.associated_group())); 424 GetProxy(&window_manager_client_, tree_.associated_group()));
425 } 425 }
426 426
427 // mojom::WindowManager: 427 // mojom::WindowManager:
428 void OnConnect(uint16_t client_id) override {} 428 void OnConnect(uint16_t client_id) override {}
429 void WmNewDisplayAdded(const display::Display& display, 429 void WmNewDisplayAdded(const display::Display& display,
430 mojom::WindowDataPtr root_data, 430 mojom::WindowDataPtr root_data,
431 bool drawn) override { 431 bool drawn) override {
432 NOTIMPLEMENTED(); 432 NOTIMPLEMENTED();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 class WindowTreeClientFactory 499 class WindowTreeClientFactory
500 : public shell::InterfaceFactory<WindowTreeClient> { 500 : public shell::InterfaceFactory<WindowTreeClient> {
501 public: 501 public:
502 WindowTreeClientFactory() {} 502 WindowTreeClientFactory() {}
503 ~WindowTreeClientFactory() override {} 503 ~WindowTreeClientFactory() override {}
504 504
505 // Runs a nested MessageLoop until a new instance has been created. 505 // Runs a nested MessageLoop until a new instance has been created.
506 std::unique_ptr<TestWindowTreeClient> WaitForInstance() { 506 std::unique_ptr<TestWindowTreeClient> WaitForInstance() {
507 if (!client_impl_.get()) { 507 if (!client_impl_.get()) {
508 DCHECK(!run_loop_); 508 DCHECK(!run_loop_);
509 run_loop_.reset(new base::RunLoop); 509 run_loop_ = base::MakeUnique<base::RunLoop>();
510 run_loop_->Run(); 510 run_loop_->Run();
511 run_loop_.reset(); 511 run_loop_.reset();
512 } 512 }
513 return std::move(client_impl_); 513 return std::move(client_impl_);
514 } 514 }
515 515
516 private: 516 private:
517 // InterfaceFactory<WindowTreeClient>: 517 // InterfaceFactory<WindowTreeClient>:
518 void Create(const shell::Identity& remote_identity, 518 void Create(const shell::Identity& remote_identity,
519 InterfaceRequest<WindowTreeClient> request) override { 519 InterfaceRequest<WindowTreeClient> request) override {
520 client_impl_.reset(new TestWindowTreeClient()); 520 client_impl_ = base::MakeUnique<TestWindowTreeClient>();
521 client_impl_->Bind(std::move(request)); 521 client_impl_->Bind(std::move(request));
522 if (run_loop_.get()) 522 if (run_loop_.get())
523 run_loop_->Quit(); 523 run_loop_->Quit();
524 } 524 }
525 525
526 std::unique_ptr<TestWindowTreeClient> client_impl_; 526 std::unique_ptr<TestWindowTreeClient> client_impl_;
527 std::unique_ptr<base::RunLoop> run_loop_; 527 std::unique_ptr<base::RunLoop> run_loop_;
528 528
529 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientFactory); 529 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientFactory);
530 }; 530 };
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 } 624 }
625 625
626 // WindowServerServiceTestBase: 626 // WindowServerServiceTestBase:
627 bool OnConnect(const shell::Identity& remote_identity, 627 bool OnConnect(const shell::Identity& remote_identity,
628 shell::InterfaceRegistry* registry) override { 628 shell::InterfaceRegistry* registry) override {
629 registry->AddInterface(client_factory_.get()); 629 registry->AddInterface(client_factory_.get());
630 return true; 630 return true;
631 } 631 }
632 632
633 void SetUp() override { 633 void SetUp() override {
634 client_factory_.reset(new WindowTreeClientFactory()); 634 client_factory_ = base::MakeUnique<WindowTreeClientFactory>();
635 635
636 WindowServerServiceTestBase::SetUp(); 636 WindowServerServiceTestBase::SetUp();
637 637
638 mojom::WindowTreeHostFactoryPtr factory; 638 mojom::WindowTreeHostFactoryPtr factory;
639 connector()->ConnectToInterface("mojo:ui", &factory); 639 connector()->ConnectToInterface("mojo:ui", &factory);
640 640
641 mojom::WindowTreeClientPtr tree_client_ptr; 641 mojom::WindowTreeClientPtr tree_client_ptr;
642 wt_client1_.reset(new TestWindowTreeClient()); 642 wt_client1_ = base::MakeUnique<TestWindowTreeClient>();
643 wt_client1_->Bind(GetProxy(&tree_client_ptr)); 643 wt_client1_->Bind(GetProxy(&tree_client_ptr));
644 644
645 factory->CreateWindowTreeHost(GetProxy(&host_), 645 factory->CreateWindowTreeHost(GetProxy(&host_),
646 std::move(tree_client_ptr)); 646 std::move(tree_client_ptr));
647 647
648 // Next we should get an embed call on the "window manager" client. 648 // Next we should get an embed call on the "window manager" client.
649 wt_client1_->WaitForOnEmbed(); 649 wt_client1_->WaitForOnEmbed();
650 650
651 ASSERT_EQ(1u, changes1()->size()); 651 ASSERT_EQ(1u, changes1()->size());
652 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); 652 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type);
(...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after
2118 2118
2119 // TODO(sky): make sure coverage of what was 2119 // TODO(sky): make sure coverage of what was
2120 // WindowManagerTest.SecondEmbedRoot_InitService and 2120 // WindowManagerTest.SecondEmbedRoot_InitService and
2121 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window 2121 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window
2122 // manager 2122 // manager
2123 // tests. 2123 // tests.
2124 2124
2125 } // namespace test 2125 } // namespace test
2126 } // namespace ws 2126 } // namespace ws
2127 } // namespace ui 2127 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/window_tree.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698