jdufault | b90450d5 | 2015-07-28 22:48:07 | [diff] [blame] | 1 | // Copyright 2015 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 "ash/test/tray_cast_test_api.h" |
| 6 | |
jamescook | 05e54ed | 2016-06-29 22:11:26 | [diff] [blame] | 7 | #include "ash/common/cast_config_delegate.h" |
jamescook | 625f791 | 2016-07-14 01:00:52 | [diff] [blame] | 8 | #include "ash/common/system/tray/system_tray.h" |
jamescook | 2a4d1eb | 2016-06-09 20:10:07 | [diff] [blame] | 9 | #include "ash/common/system/tray/system_tray_delegate.h" |
jamescook | 443e42d | 2016-06-10 21:44:46 | [diff] [blame] | 10 | #include "ash/common/wm_shell.h" |
jdufault | b90450d5 | 2015-07-28 22:48:07 | [diff] [blame] | 11 | #include "ui/views/view.h" |
| 12 | |
| 13 | namespace ash { |
| 14 | |
| 15 | TrayCastTestAPI::TrayCastTestAPI(TrayCast* tray_cast) : tray_cast_(tray_cast) {} |
| 16 | |
| 17 | TrayCastTestAPI::~TrayCastTestAPI() {} |
| 18 | |
| 19 | bool TrayCastTestAPI::IsTrayInitialized() const { |
| 20 | return tray_cast_->default_ != nullptr; |
| 21 | } |
| 22 | |
| 23 | bool TrayCastTestAPI::IsTrayVisible() const { |
| 24 | return IsViewDrawn(TrayCast::TRAY_VIEW); |
| 25 | } |
| 26 | |
| 27 | bool TrayCastTestAPI::IsTrayCastViewVisible() const { |
| 28 | return IsViewDrawn(TrayCast::CAST_VIEW); |
| 29 | } |
| 30 | |
| 31 | bool TrayCastTestAPI::IsTraySelectViewVisible() const { |
| 32 | return IsViewDrawn(TrayCast::SELECT_VIEW); |
| 33 | } |
| 34 | |
jdufault | 7b1b401 | 2015-11-16 20:05:35 | [diff] [blame] | 35 | std::string TrayCastTestAPI::GetDisplayedCastId() const { |
| 36 | return tray_cast_->GetDisplayedCastId(); |
| 37 | } |
| 38 | |
jdufault | b90450d5 | 2015-07-28 22:48:07 | [diff] [blame] | 39 | void TrayCastTestAPI::StartCast(const std::string& receiver_id) { |
| 40 | return tray_cast_->StartCastForTest(receiver_id); |
| 41 | } |
| 42 | |
| 43 | void TrayCastTestAPI::StopCast() { |
| 44 | return tray_cast_->StopCastForTest(); |
| 45 | } |
| 46 | |
| 47 | void TrayCastTestAPI::OnCastingSessionStartedOrStopped(bool is_casting) { |
| 48 | tray_cast_->OnCastingSessionStartedOrStopped(is_casting); |
| 49 | } |
| 50 | |
jdufault | 7b1b401 | 2015-11-16 20:05:35 | [diff] [blame] | 51 | void TrayCastTestAPI::ReleaseConfigCallbacks() { |
jamescook | 443e42d | 2016-06-10 21:44:46 | [diff] [blame] | 52 | if (WmShell::Get() && WmShell::Get()->system_tray_delegate()) { |
| 53 | WmShell::Get() |
jdufault | 6b717bb | 2016-01-14 19:38:56 | [diff] [blame] | 54 | ->system_tray_delegate() |
| 55 | ->GetCastConfigDelegate() |
| 56 | ->RemoveObserver(tray_cast_); |
| 57 | } |
jdufault | 7b1b401 | 2015-11-16 20:05:35 | [diff] [blame] | 58 | } |
| 59 | |
jdufault | b90450d5 | 2015-07-28 22:48:07 | [diff] [blame] | 60 | bool TrayCastTestAPI::IsViewDrawn(TrayCast::ChildViewId id) const { |
| 61 | const views::View* view = tray_cast_->GetDefaultView()->GetViewByID(id); |
| 62 | return view != nullptr && view->IsDrawn(); |
| 63 | } |
| 64 | |
| 65 | } // namespace ash |