Commit 5939e063 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

capture_mode: Add testapi and remove button listener.

Move 4 CaptureSession test only functions to test file api. Use callback
instead of overriding ButtonListener, seems to be new style [1].

[1] https://bugs.chromium.org/p/chromium/issues/detail?id=772945

Test: existing tests
Bug: none
Change-Id: Ic61bd06419e1c9f348fa35d62e648d42ab1ec9e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2480812
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818652}
parent 48b908f2
...@@ -146,8 +146,10 @@ CaptureLabelView::CaptureLabelView(CaptureModeSession* capture_mode_session) ...@@ -146,8 +146,10 @@ CaptureLabelView::CaptureLabelView(CaptureModeSession* capture_mode_session)
SkColor text_color = color_provider->GetContentLayerColor( SkColor text_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary); AshColorProvider::ContentLayerType::kTextColorPrimary);
label_button_ = AddChildView( label_button_ = AddChildView(std::make_unique<views::LabelButton>(
std::make_unique<views::LabelButton>(this, base::string16())); base::BindRepeating(&CaptureLabelView::OnButtonPressed,
base::Unretained(this)),
base::string16()));
label_button_->SetPaintToLayer(); label_button_->SetPaintToLayer();
label_button_->layer()->SetFillsBoundsOpaquely(false); label_button_->layer()->SetFillsBoundsOpaquely(false);
label_button_->SetEnabledTextColors(text_color); label_button_->SetEnabledTextColors(text_color);
...@@ -307,12 +309,6 @@ gfx::Size CaptureLabelView::CalculatePreferredSize() const { ...@@ -307,12 +309,6 @@ gfx::Size CaptureLabelView::CalculatePreferredSize() const {
kCaptureLabelRadius * 2); kCaptureLabelRadius * 2);
} }
void CaptureLabelView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK_EQ(static_cast<views::Button*>(label_button_), sender);
CaptureModeController::Get()->PerformCapture();
}
void CaptureLabelView::ScheduleCountDownAnimation() { void CaptureLabelView::ScheduleCountDownAnimation() {
label_->SetVisible(true); label_->SetVisible(true);
label_->SetText(base::FormatNumber(timeout_count_down_)); label_->SetText(base::FormatNumber(timeout_count_down_));
...@@ -438,6 +434,10 @@ void CaptureLabelView::StartWidgetLayerAnimationSequences() { ...@@ -438,6 +434,10 @@ void CaptureLabelView::StartWidgetLayerAnimationSequences() {
{widget_opacity_sequence.release(), widget_transform_sequence.release()}); {widget_opacity_sequence.release(), widget_transform_sequence.release()});
} }
void CaptureLabelView::OnButtonPressed() {
CaptureModeController::Get()->PerformCapture();
}
BEGIN_METADATA(CaptureLabelView, views::View) BEGIN_METADATA(CaptureLabelView, views::View)
END_METADATA END_METADATA
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace views { namespace views {
...@@ -28,8 +27,7 @@ class CaptureModeSession; ...@@ -28,8 +27,7 @@ class CaptureModeSession;
// A view that displays (optional) icon and text message to the user depending // A view that displays (optional) icon and text message to the user depending
// on current capture source and type. In video capture mode, it will later // on current capture source and type. In video capture mode, it will later
// transform into a 3 second countdown timer. // transform into a 3 second countdown timer.
class ASH_EXPORT CaptureLabelView : public views::View, class ASH_EXPORT CaptureLabelView : public views::View {
public views::ButtonListener {
public: public:
METADATA_HEADER(CaptureLabelView); METADATA_HEADER(CaptureLabelView);
...@@ -56,9 +54,6 @@ class ASH_EXPORT CaptureLabelView : public views::View, ...@@ -56,9 +54,6 @@ class ASH_EXPORT CaptureLabelView : public views::View,
void Layout() override; void Layout() override;
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: private:
// Start performing countdown to number |timout_count_down_| animation. // Start performing countdown to number |timout_count_down_| animation.
void ScheduleCountDownAnimation(); void ScheduleCountDownAnimation();
...@@ -71,6 +66,9 @@ class ASH_EXPORT CaptureLabelView : public views::View, ...@@ -71,6 +66,9 @@ class ASH_EXPORT CaptureLabelView : public views::View,
// Starts the layer animation sequences for the entire widget if applicable. // Starts the layer animation sequences for the entire widget if applicable.
void StartWidgetLayerAnimationSequences(); void StartWidgetLayerAnimationSequences();
// Called when |label_button_| is pressed.
void OnButtonPressed();
// The label button that displays an icon and a text message. Can be user // The label button that displays an icon and a text message. Can be user
// interactable. When clicking/tapping on the button, start perform image or // interactable. When clicking/tapping on the button, start perform image or
// video capture. // video capture.
......
...@@ -59,9 +59,6 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner, ...@@ -59,9 +59,6 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
static constexpr int kCaptureButtonDistanceFromRegionDp = 24; static constexpr int kCaptureButtonDistanceFromRegionDp = 24;
aura::Window* current_root() const { return current_root_; } aura::Window* current_root() const { return current_root_; }
CaptureModeBarView* capture_mode_bar_view() const {
return capture_mode_bar_view_;
}
bool is_selecting_region() const { return is_selecting_region_; } bool is_selecting_region() const { return is_selecting_region_; }
// Gets the current window selected for |kWindow| capture source. Returns // Gets the current window selected for |kWindow| capture source. Returns
...@@ -92,17 +89,8 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner, ...@@ -92,17 +89,8 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
// aura::WindowObserver: // aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override; void OnWindowDestroying(aura::Window* window) override;
views::Widget* capture_label_widget_for_testing() const {
return capture_label_widget_.get();
}
views::Widget* dimensions_label_widget_for_testing() const {
return dimensions_label_widget_.get();
}
const MagnifierGlass& magnifier_glass_for_testing() const {
return magnifier_glass_;
}
private: private:
friend class CaptureModeSessionTestApi;
class ScopedCursorSetter; class ScopedCursorSetter;
// Gets the bounds of current window selected for |kWindow| capture source. // Gets the bounds of current window selected for |kWindow| capture source.
......
...@@ -73,6 +73,36 @@ void MoveMouseToAndUpdateCursorDisplay( ...@@ -73,6 +73,36 @@ void MoveMouseToAndUpdateCursorDisplay(
} // namespace } // namespace
// Wrapper for CaptureModeSession that exposes internal state to test functions.
class CaptureModeSessionTestApi {
public:
explicit CaptureModeSessionTestApi(CaptureModeSession* session)
: session_(session) {}
CaptureModeSessionTestApi(const CaptureModeSessionTestApi&) = delete;
CaptureModeSessionTestApi& operator=(const CaptureModeSessionTestApi&) =
delete;
~CaptureModeSessionTestApi() = default;
CaptureModeBarView* capture_mode_bar_view() const {
return session_->capture_mode_bar_view_;
}
views::Widget* capture_label_widget() const {
return session_->capture_label_widget_.get();
}
views::Widget* dimensions_label_widget() const {
return session_->dimensions_label_widget_.get();
}
const MagnifierGlass& magnifier_glass() const {
return session_->magnifier_glass_;
}
private:
const CaptureModeSession* const session_;
};
class CaptureModeTest : public AshTestBase { class CaptureModeTest : public AshTestBase {
public: public:
CaptureModeTest() = default; CaptureModeTest() = default;
...@@ -86,29 +116,28 @@ class CaptureModeTest : public AshTestBase { ...@@ -86,29 +116,28 @@ class CaptureModeTest : public AshTestBase {
AshTestBase::SetUp(); AshTestBase::SetUp();
} }
CaptureModeBarView* GetCaptureModeBarView() const {
auto* session = CaptureModeController::Get()->capture_mode_session();
DCHECK(session);
return CaptureModeSessionTestApi(session).capture_mode_bar_view();
}
CaptureModeToggleButton* GetImageToggleButton() const { CaptureModeToggleButton* GetImageToggleButton() const {
auto* controller = CaptureModeController::Get(); auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive()); DCHECK(controller->IsActive());
return controller->capture_mode_session() return GetCaptureModeBarView()->capture_type_view()->image_toggle_button();
->capture_mode_bar_view()
->capture_type_view()
->image_toggle_button();
} }
CaptureModeToggleButton* GetVideoToggleButton() const { CaptureModeToggleButton* GetVideoToggleButton() const {
auto* controller = CaptureModeController::Get(); auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive()); DCHECK(controller->IsActive());
return controller->capture_mode_session() return GetCaptureModeBarView()->capture_type_view()->video_toggle_button();
->capture_mode_bar_view()
->capture_type_view()
->video_toggle_button();
} }
CaptureModeToggleButton* GetFullscreenToggleButton() const { CaptureModeToggleButton* GetFullscreenToggleButton() const {
auto* controller = CaptureModeController::Get(); auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive()); DCHECK(controller->IsActive());
return controller->capture_mode_session() return GetCaptureModeBarView()
->capture_mode_bar_view()
->capture_source_view() ->capture_source_view()
->fullscreen_toggle_button(); ->fullscreen_toggle_button();
} }
...@@ -116,8 +145,7 @@ class CaptureModeTest : public AshTestBase { ...@@ -116,8 +145,7 @@ class CaptureModeTest : public AshTestBase {
CaptureModeToggleButton* GetRegionToggleButton() const { CaptureModeToggleButton* GetRegionToggleButton() const {
auto* controller = CaptureModeController::Get(); auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive()); DCHECK(controller->IsActive());
return controller->capture_mode_session() return GetCaptureModeBarView()
->capture_mode_bar_view()
->capture_source_view() ->capture_source_view()
->region_toggle_button(); ->region_toggle_button();
} }
...@@ -125,8 +153,7 @@ class CaptureModeTest : public AshTestBase { ...@@ -125,8 +153,7 @@ class CaptureModeTest : public AshTestBase {
CaptureModeToggleButton* GetWindowToggleButton() const { CaptureModeToggleButton* GetWindowToggleButton() const {
auto* controller = CaptureModeController::Get(); auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive()); DCHECK(controller->IsActive());
return controller->capture_mode_session() return GetCaptureModeBarView()
->capture_mode_bar_view()
->capture_source_view() ->capture_source_view()
->window_toggle_button(); ->window_toggle_button();
} }
...@@ -134,16 +161,14 @@ class CaptureModeTest : public AshTestBase { ...@@ -134,16 +161,14 @@ class CaptureModeTest : public AshTestBase {
CaptureModeCloseButton* GetCloseButton() const { CaptureModeCloseButton* GetCloseButton() const {
auto* controller = CaptureModeController::Get(); auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive()); DCHECK(controller->IsActive());
return controller->capture_mode_session() return GetCaptureModeBarView()->close_button();
->capture_mode_bar_view()
->close_button();
} }
aura::Window* GetDimensionsLabelWindow() const { aura::Window* GetDimensionsLabelWindow() const {
auto* controller = CaptureModeController::Get(); auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive()); DCHECK(controller->IsActive());
auto* widget = controller->capture_mode_session() auto* widget = CaptureModeSessionTestApi(controller->capture_mode_session())
->dimensions_label_widget_for_testing(); .dimensions_label_widget();
return widget ? widget->GetNativeWindow() : nullptr; return widget ? widget->GetNativeWindow() : nullptr;
} }
...@@ -151,7 +176,8 @@ class CaptureModeTest : public AshTestBase { ...@@ -151,7 +176,8 @@ class CaptureModeTest : public AshTestBase {
auto* controller = CaptureModeController::Get(); auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive()); DCHECK(controller->IsActive());
auto& magnifier = auto& magnifier =
controller->capture_mode_session()->magnifier_glass_for_testing(); CaptureModeSessionTestApi(controller->capture_mode_session())
.magnifier_glass();
if (magnifier.host_widget_for_testing()) { if (magnifier.host_widget_for_testing()) {
return magnifier.host_widget_for_testing() return magnifier.host_widget_for_testing()
->GetWindowBoundsInScreen() ->GetWindowBoundsInScreen()
...@@ -491,9 +517,7 @@ TEST_F(CaptureModeTest, CaptureRegionCoversCaptureModeBar) { ...@@ -491,9 +517,7 @@ TEST_F(CaptureModeTest, CaptureRegionCoversCaptureModeBar) {
// Select a region such that the capture mode bar is covered. // Select a region such that the capture mode bar is covered.
SelectRegion(gfx::Rect(5, 5, 795, 795)); SelectRegion(gfx::Rect(5, 5, 795, 795));
EXPECT_TRUE(controller->user_capture_region().Contains( EXPECT_TRUE(controller->user_capture_region().Contains(
controller->capture_mode_session() GetCaptureModeBarView()->GetBoundsInScreen()));
->capture_mode_bar_view()
->GetBoundsInScreen()));
// Click on the fullscreen toggle button to verify that we enter fullscreen // Click on the fullscreen toggle button to verify that we enter fullscreen
// capture mode. Then click on the region toggle button to verify that we // capture mode. Then click on the region toggle button to verify that we
...@@ -505,9 +529,7 @@ TEST_F(CaptureModeTest, CaptureRegionCoversCaptureModeBar) { ...@@ -505,9 +529,7 @@ TEST_F(CaptureModeTest, CaptureRegionCoversCaptureModeBar) {
ClickOnView(GetRegionToggleButton(), GetEventGenerator()); ClickOnView(GetRegionToggleButton(), GetEventGenerator());
ASSERT_EQ(CaptureModeSource::kRegion, controller->source()); ASSERT_EQ(CaptureModeSource::kRegion, controller->source());
ASSERT_TRUE(controller->user_capture_region().Contains( ASSERT_TRUE(controller->user_capture_region().Contains(
controller->capture_mode_session() GetCaptureModeBarView()->GetBoundsInScreen()));
->capture_mode_bar_view()
->GetBoundsInScreen()));
ClickOnView(GetCloseButton(), event_generator); ClickOnView(GetCloseButton(), event_generator);
EXPECT_FALSE(controller->IsActive()); EXPECT_FALSE(controller->IsActive());
...@@ -652,7 +674,8 @@ TEST_F(CaptureModeTest, CaptureRegionCaptureButtonLocation) { ...@@ -652,7 +674,8 @@ TEST_F(CaptureModeTest, CaptureRegionCaptureButtonLocation) {
SelectRegion(gfx::Rect(100, 100, 600, 600)); SelectRegion(gfx::Rect(100, 100, 600, 600));
views::Widget* capture_button_widget = views::Widget* capture_button_widget =
controller->capture_mode_session()->capture_label_widget_for_testing(); CaptureModeSessionTestApi(controller->capture_mode_session())
.capture_label_widget();
ASSERT_TRUE(capture_button_widget); ASSERT_TRUE(capture_button_widget);
aura::Window* capture_button_window = aura::Window* capture_button_window =
capture_button_widget->GetNativeWindow(); capture_button_widget->GetNativeWindow();
...@@ -729,16 +752,13 @@ TEST_F(CaptureModeTest, MultiDisplayCaptureBarInitialLocation) { ...@@ -729,16 +752,13 @@ TEST_F(CaptureModeTest, MultiDisplayCaptureBarInitialLocation) {
auto* controller = StartImageRegionCapture(); auto* controller = StartImageRegionCapture();
EXPECT_TRUE(gfx::Rect(801, 0, 800, 800) EXPECT_TRUE(gfx::Rect(801, 0, 800, 800)
.Contains(controller->capture_mode_session() .Contains(GetCaptureModeBarView()->GetBoundsInScreen()));
->capture_mode_bar_view()
->GetBoundsInScreen()));
controller->Stop(); controller->Stop();
MoveMouseToAndUpdateCursorDisplay(gfx::Point(100, 500), event_generator); MoveMouseToAndUpdateCursorDisplay(gfx::Point(100, 500), event_generator);
StartImageRegionCapture(); StartImageRegionCapture();
EXPECT_TRUE(gfx::Rect(800, 800).Contains(controller->capture_mode_session() EXPECT_TRUE(gfx::Rect(800, 800).Contains(
->capture_mode_bar_view() GetCaptureModeBarView()->GetBoundsInScreen()));
->GetBoundsInScreen()));
} }
// Tests behavior of a capture mode session if the active display is removed. // Tests behavior of a capture mode session if the active display is removed.
...@@ -749,9 +769,8 @@ TEST_F(CaptureModeTest, DisplayRemoval) { ...@@ -749,9 +769,8 @@ TEST_F(CaptureModeTest, DisplayRemoval) {
MoveMouseToAndUpdateCursorDisplay(gfx::Point(1000, 500), GetEventGenerator()); MoveMouseToAndUpdateCursorDisplay(gfx::Point(1000, 500), GetEventGenerator());
auto* controller = StartImageRegionCapture(); auto* controller = StartImageRegionCapture();
auto* session = controller->capture_mode_session(); auto* session = controller->capture_mode_session();
EXPECT_TRUE( EXPECT_TRUE(gfx::Rect(801, 0, 800, 800)
gfx::Rect(801, 0, 800, 800) .Contains(GetCaptureModeBarView()->GetBoundsInScreen()));
.Contains(session->capture_mode_bar_view()->GetBoundsInScreen()));
ASSERT_EQ(Shell::GetAllRootWindows()[1], session->current_root()); ASSERT_EQ(Shell::GetAllRootWindows()[1], session->current_root());
// Remove secondary display. // Remove secondary display.
...@@ -768,7 +787,7 @@ TEST_F(CaptureModeTest, DisplayRemoval) { ...@@ -768,7 +787,7 @@ TEST_F(CaptureModeTest, DisplayRemoval) {
// Tests that the capture mode bar is now on the primary display. // Tests that the capture mode bar is now on the primary display.
EXPECT_TRUE(gfx::Rect(800, 800).Contains( EXPECT_TRUE(gfx::Rect(800, 800).Contains(
session->capture_mode_bar_view()->GetBoundsInScreen())); GetCaptureModeBarView()->GetBoundsInScreen()));
ASSERT_EQ(Shell::GetAllRootWindows()[0], session->current_root()); ASSERT_EQ(Shell::GetAllRootWindows()[0], session->current_root());
} }
...@@ -823,16 +842,13 @@ TEST_F(CaptureModeTest, MultiDisplayRegionSourceRootWindow) { ...@@ -823,16 +842,13 @@ TEST_F(CaptureModeTest, MultiDisplayRegionSourceRootWindow) {
// the primary display until the mouse is released. // the primary display until the mouse is released.
event_generator->PressLeftButton(); event_generator->PressLeftButton();
EXPECT_EQ(Shell::GetAllRootWindows()[1], session->current_root()); EXPECT_EQ(Shell::GetAllRootWindows()[1], session->current_root());
EXPECT_TRUE(gfx::Rect(800, 800).Contains(controller->capture_mode_session() EXPECT_TRUE(gfx::Rect(800, 800).Contains(
->capture_mode_bar_view() GetCaptureModeBarView()->GetBoundsInScreen()));
->GetBoundsInScreen()));
event_generator->ReleaseLeftButton(); event_generator->ReleaseLeftButton();
EXPECT_EQ(Shell::GetAllRootWindows()[1], session->current_root()); EXPECT_EQ(Shell::GetAllRootWindows()[1], session->current_root());
EXPECT_TRUE(gfx::Rect(801, 0, 800, 800) EXPECT_TRUE(gfx::Rect(801, 0, 800, 800)
.Contains(controller->capture_mode_session() .Contains(GetCaptureModeBarView()->GetBoundsInScreen()));
->capture_mode_bar_view()
->GetBoundsInScreen()));
} }
TEST_F(CaptureModeTest, RegionCursorStates) { TEST_F(CaptureModeTest, RegionCursorStates) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment