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

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: Move testing API into ash/test 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..59140c021eb287864941a772e0a1b34b38f6e14a 100644
--- a/ash/system/cast/tray_cast.cc
+++ b/ash/system/cast/tray_cast.cc
@@ -16,17 +16,13 @@
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/throbber_view.h"
#include "ash/system/tray/tray_constants.h"
-#include "ash/system/tray/tray_details_view.h"
-#include "ash/system/tray/tray_item_more.h"
#include "ash/system/tray/tray_item_view.h"
-#include "ash/system/tray/tray_popup_label_button.h"
#include "base/bind.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
-#include "ui/views/controls/button/button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
@@ -40,30 +36,6 @@ const int kStopButtonRightPadding = 18;
namespace tray {
-// This view is displayed in the system tray when the cast extension is active.
-// It asks the user if they want to cast the desktop. If they click on the
-// chevron, then a detail view will replace this view where the user will
-// actually pick the cast receiver.
-class CastSelectDefaultView : public TrayItemMore {
- public:
- CastSelectDefaultView(SystemTrayItem* owner,
- CastConfigDelegate* cast_config_delegate,
- bool show_more);
- ~CastSelectDefaultView() override;
-
- // Updates the label based on the current set of receivers (if there are or
- // are not any available receivers).
- void UpdateLabel();
-
- private:
- void UpdateLabelCallback(
- const CastConfigDelegate::ReceiversAndActivites& receivers_activities);
-
- CastConfigDelegate* cast_config_delegate_;
- base::WeakPtrFactory<CastSelectDefaultView> weak_ptr_factory_;
- DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView);
-};
-
CastSelectDefaultView::CastSelectDefaultView(
SystemTrayItem* owner,
CastConfigDelegate* cast_config_delegate,
@@ -106,38 +78,6 @@ void CastSelectDefaultView::UpdateLabel() {
weak_ptr_factory_.GetWeakPtr()));
}
-// This view is displayed when the screen is actively being casted; it allows
-// the user to easily stop casting. It fully replaces the
-// |CastSelectDefaultView| view inside of the |CastDuplexView|.
-class CastCastView : public views::View, public views::ButtonListener {
- public:
- explicit CastCastView(CastConfigDelegate* cast_config_delegate);
- ~CastCastView() override;
-
- // Updates the label for the stop view to include information about the
- // current device that is being casted.
- void UpdateLabel();
-
- private:
- void UpdateLabelCallback(
- const CastConfigDelegate::ReceiversAndActivites& receivers_activities);
-
- // Overridden from views::View.
- int GetHeightForWidth(int width) const override;
- void Layout() override;
-
- // Overridden from views::ButtonListener.
- void ButtonPressed(views::Button* sender, const ui::Event& event) override;
-
- CastConfigDelegate* cast_config_delegate_;
- views::ImageView* icon_;
- views::Label* label_;
- TrayPopupLabelButton* stop_button_;
- base::WeakPtrFactory<CastCastView> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(CastCastView);
-};
-
CastCastView::CastCastView(CastConfigDelegate* cast_config_delegate)
: cast_config_delegate_(cast_config_delegate), weak_ptr_factory_(this) {
// We will initialize the primary tray view which shows a stop button here.
@@ -206,6 +146,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,43 +191,9 @@ 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
-// which of the two child views (|CastSelectDefaultView| and |CastCastView|)
-// is active.
-class CastDuplexView : public views::View {
- public:
- CastDuplexView(SystemTrayItem* owner,
- CastConfigDelegate* config_delegate,
- bool show_more);
- ~CastDuplexView() override;
-
- // Activate either the casting or select view.
- void ActivateCastView();
- void ActivateSelectView();
-
- CastSelectDefaultView* select_view() { return select_view_; }
- CastCastView* cast_view() { return cast_view_; }
-
- 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_;
-
- DISALLOW_COPY_AND_ASSIGN(CastDuplexView);
-};
-
CastDuplexView::CastDuplexView(SystemTrayItem* owner,
CastConfigDelegate* config_delegate,
bool show_more) {
@@ -378,44 +290,6 @@ void CastTrayView::UpdateAlignment(ShelfAlignment alignment) {
Layout();
}
-// This view displays a list of cast receivers that can be clicked on and casted
-// to. It is activated by clicking on the chevron inside of
-// |CastSelectDefaultView|.
-class CastDetailedView : public TrayDetailsView, public ViewClickListener {
- public:
- CastDetailedView(SystemTrayItem* owner,
- CastConfigDelegate* cast_config_delegate,
- user::LoginStatus login);
- ~CastDetailedView() override;
-
- private:
- void CreateItems();
-
- void UpdateReceiverList();
- void UpdateReceiverListCallback(
- const CastConfigDelegate::ReceiversAndActivites&
- new_receivers_and_activities);
- void UpdateReceiverListFromCachedData();
- views::View* AddToReceiverList(
- const CastConfigDelegate::ReceiverAndActivity& receiverActivity);
-
- void AppendSettingsEntries();
- void AppendHeaderEntry();
-
- // Overridden from ViewClickListener.
- void OnViewClicked(views::View* sender) override;
-
- CastConfigDelegate* cast_config_delegate_;
- user::LoginStatus login_;
- views::View* options_ = nullptr;
- CastConfigDelegate::ReceiversAndActivites receivers_and_activities_;
- // A mapping from the view pointer to the associated activity id
- std::map<views::View*, std::string> receiver_activity_map_;
- base::WeakPtrFactory<CastDetailedView> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(CastDetailedView);
-};
-
CastDetailedView::CastDetailedView(SystemTrayItem* owner,
CastConfigDelegate* cast_config_delegate,
user::LoginStatus login)
@@ -430,6 +304,16 @@ CastDetailedView::CastDetailedView(SystemTrayItem* owner,
CastDetailedView::~CastDetailedView() {
}
+void CastDetailedView::SimulateViewClickedForTest(
+ const std::string& receiver_id) {
+ for (auto& it : receiver_activity_map_) {
+ if (it.second == receiver_id) {
+ OnViewClicked(it.first);
+ break;
+ }
+ }
+}
+
void CastDetailedView::CreateItems() {
CreateScrollableList();
AppendSettingsEntries();

Powered by Google App Engine
This is Rietveld 408576698