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

Unified Diff: ash/system/cast/tray_cast.cc

Issue 1218653006: Add support code to test the cast system tray item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: ash/system/cast/tray_cast.cc
diff --git a/ash/system/cast/tray_cast.cc b/ash/system/cast/tray_cast.cc
index 33ff8f191127472045eb2586a09c9960f7550c3f..2b6ab56f19dd3170037ba7b8db950b2100d402e3 100644
--- a/ash/system/cast/tray_cast.cc
+++ b/ash/system/cast/tray_cast.cc
@@ -114,6 +114,8 @@ class CastCastView : public views::View, public views::ButtonListener {
explicit CastCastView(CastConfigDelegate* cast_config_delegate);
~CastCastView() override;
+ void StopCasting();
+
// Updates the label for the stop view to include information about the
// current device that is being casted.
void UpdateLabel();
@@ -206,6 +208,12 @@ void CastCastView::Layout() {
}
}
+void CastCastView::StopCasting() {
+ cast_config_delegate_->StopCasting();
+ Shell::GetInstance()->metrics()->RecordUserMetricsAction(
+ ash::UMA_STATUS_AREA_CAST_STOP_CAST);
+}
+
void CastCastView::UpdateLabel() {
if (cast_config_delegate_ == nullptr ||
cast_config_delegate_->HasCastExtension() == false)
@@ -245,9 +253,7 @@ void CastCastView::UpdateLabelCallback(
void CastCastView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK(sender == stop_button_);
- cast_config_delegate_->StopCasting();
- Shell::GetInstance()->metrics()->RecordUserMetricsAction(
- ash::UMA_STATUS_AREA_CAST_STOP_CAST);
+ StopCasting();
}
// This view by itself does very little. It acts as a front-end for managing
@@ -267,15 +273,15 @@ class CastDuplexView : public views::View {
CastSelectDefaultView* select_view() { return select_view_; }
CastCastView* cast_view() { return cast_view_; }
+ // Only one of |select_view_| or |cast_view_| will be displayed at any given
+ // time. This will return the view is being displayed.
+ views::View* ActiveChildView();
+
private:
// Overridden from views::View.
void ChildPreferredSizeChanged(views::View* child) override;
void Layout() override;
- // Only one of |select_view_| or |cast_view_| will be displayed at any given
- // time. This will return the view is being displayed.
- views::View* ActiveChildView();
-
CastSelectDefaultView* select_view_;
CastCastView* cast_view_;
@@ -388,6 +394,8 @@ class CastDetailedView : public TrayDetailsView, public ViewClickListener {
user::LoginStatus login);
~CastDetailedView() override;
+ void SimulateViewClickedForTest(const std::string& id);
achuithb 2015/07/14 18:06:39 I think it's worthwhile to add a function comment
jdufault 2015/07/15 17:35:01 Done.
+
private:
void CreateItems();
@@ -430,6 +438,15 @@ CastDetailedView::CastDetailedView(SystemTrayItem* owner,
CastDetailedView::~CastDetailedView() {
}
+void CastDetailedView::SimulateViewClickedForTest(const std::string& id) {
+ for (auto& it : receiver_activity_map_) {
+ if (it.second == id) {
+ OnViewClicked(it.first);
+ break;
+ }
+ }
+}
+
void CastDetailedView::CreateItems() {
CreateScrollableList();
AppendSettingsEntries();
@@ -548,6 +565,33 @@ TrayCast::~TrayCast() {
Shell::GetInstance()->RemoveShellObserver(this);
}
+bool TrayCast::IsTrayInitializedForTest() const {
+ return default_ != nullptr;
+}
+
+bool TrayCast::IsTrayVisibleForTest() const {
+ return default_ != nullptr && default_->IsDrawn();
+}
+
+bool TrayCast::IsTrayCastViewVisibleForTest() const {
+ return default_ != nullptr &&
+ default_->ActiveChildView() == default_->cast_view();
+}
+
+bool TrayCast::IsTraySelectViewVisibleForTest() const {
+ return default_ != nullptr &&
+ default_->ActiveChildView() == default_->select_view();
+}
+
+void TrayCast::StartCastForTest(const std::string& id) {
+ if (detailed_ != nullptr)
+ detailed_->SimulateViewClickedForTest(id);
+}
+
+void TrayCast::StopCastForTest() {
+ default_->cast_view()->StopCasting();
+}
+
views::View* TrayCast::CreateTrayView(user::LoginStatus status) {
CHECK(tray_ == nullptr);
tray_ = new tray::CastTrayView(this);

Powered by Google App Engine
This is Rietveld 408576698