| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/aura/test/mus/change_completion_waiter.h" |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/aura/mus/in_flight_change.h" |
| 10 #include "ui/aura/mus/window_tree_client.h" |
| 11 |
| 12 namespace aura { |
| 13 namespace test { |
| 14 |
| 15 ChangeCompletionWaiter::ChangeCompletionWaiter(WindowTreeClient* client, |
| 16 ChangeType type, |
| 17 bool success) |
| 18 : state_(WaitState::NOT_STARTED), |
| 19 client_(client), |
| 20 type_(type), |
| 21 success_(success) { |
| 22 client->AddTestObserver(this); |
| 23 } |
| 24 |
| 25 ChangeCompletionWaiter::~ChangeCompletionWaiter() { |
| 26 client_->RemoveTestObserver(this); |
| 27 } |
| 28 |
| 29 void ChangeCompletionWaiter::Wait() { |
| 30 if (state_ != WaitState::RECEIVED) { |
| 31 quit_closure_ = run_loop_.QuitClosure(); |
| 32 run_loop_.Run(); |
| 33 } |
| 34 } |
| 35 |
| 36 void ChangeCompletionWaiter::OnChangeStarted(uint32_t change_id, |
| 37 aura::ChangeType type) { |
| 38 if (state_ == WaitState::NOT_STARTED && type == type_) { |
| 39 state_ = WaitState::WAITING; |
| 40 change_id_ = change_id; |
| 41 } |
| 42 } |
| 43 |
| 44 void ChangeCompletionWaiter::OnChangeCompleted(uint32_t change_id, |
| 45 aura::ChangeType type, |
| 46 bool success) { |
| 47 if (state_ == WaitState::WAITING && change_id_ == change_id) { |
| 48 EXPECT_EQ(success_, success); |
| 49 state_ = WaitState::RECEIVED; |
| 50 if (quit_closure_) |
| 51 quit_closure_.Run(); |
| 52 } |
| 53 } |
| 54 |
| 55 } // namespace test |
| 56 } // namespace aura |
| OLD | NEW |