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)
SkColor text_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary);
label_button_ = AddChildView(
std::make_unique<views::LabelButton>(this, base::string16()));
label_button_ = AddChildView(std::make_unique<views::LabelButton>(
base::BindRepeating(&CaptureLabelView::OnButtonPressed,
base::Unretained(this)),
base::string16()));
label_button_->SetPaintToLayer();
label_button_->layer()->SetFillsBoundsOpaquely(false);
label_button_->SetEnabledTextColors(text_color);
......@@ -307,12 +309,6 @@ gfx::Size CaptureLabelView::CalculatePreferredSize() const {
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() {
label_->SetVisible(true);
label_->SetText(base::FormatNumber(timeout_count_down_));
......@@ -438,6 +434,10 @@ void CaptureLabelView::StartWidgetLayerAnimationSequences() {
{widget_opacity_sequence.release(), widget_transform_sequence.release()});
}
void CaptureLabelView::OnButtonPressed() {
CaptureModeController::Get()->PerformCapture();
}
BEGIN_METADATA(CaptureLabelView, views::View)
END_METADATA
......
......@@ -9,7 +9,6 @@
#include "ash/ash_export.h"
#include "base/memory/weak_ptr.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"
namespace views {
......@@ -28,8 +27,7 @@ class CaptureModeSession;
// 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
// transform into a 3 second countdown timer.
class ASH_EXPORT CaptureLabelView : public views::View,
public views::ButtonListener {
class ASH_EXPORT CaptureLabelView : public views::View {
public:
METADATA_HEADER(CaptureLabelView);
......@@ -56,9 +54,6 @@ class ASH_EXPORT CaptureLabelView : public views::View,
void Layout() override;
gfx::Size CalculatePreferredSize() const override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
// Start performing countdown to number |timout_count_down_| animation.
void ScheduleCountDownAnimation();
......@@ -71,6 +66,9 @@ class ASH_EXPORT CaptureLabelView : public views::View,
// Starts the layer animation sequences for the entire widget if applicable.
void StartWidgetLayerAnimationSequences();
// Called when |label_button_| is pressed.
void OnButtonPressed();
// 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
// video capture.
......
......@@ -59,9 +59,6 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
static constexpr int kCaptureButtonDistanceFromRegionDp = 24;
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_; }
// Gets the current window selected for |kWindow| capture source. Returns
......@@ -92,17 +89,8 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
// aura::WindowObserver:
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:
friend class CaptureModeSessionTestApi;
class ScopedCursorSetter;
// Gets the bounds of current window selected for |kWindow| capture source.
......
......@@ -73,6 +73,36 @@ void MoveMouseToAndUpdateCursorDisplay(
} // 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 {
public:
CaptureModeTest() = default;
......@@ -86,29 +116,28 @@ class CaptureModeTest : public AshTestBase {
AshTestBase::SetUp();
}
CaptureModeBarView* GetCaptureModeBarView() const {
auto* session = CaptureModeController::Get()->capture_mode_session();
DCHECK(session);
return CaptureModeSessionTestApi(session).capture_mode_bar_view();
}
CaptureModeToggleButton* GetImageToggleButton() const {
auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive());
return controller->capture_mode_session()
->capture_mode_bar_view()
->capture_type_view()
->image_toggle_button();
return GetCaptureModeBarView()->capture_type_view()->image_toggle_button();
}
CaptureModeToggleButton* GetVideoToggleButton() const {
auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive());
return controller->capture_mode_session()
->capture_mode_bar_view()
->capture_type_view()
->video_toggle_button();
return GetCaptureModeBarView()->capture_type_view()->video_toggle_button();
}
CaptureModeToggleButton* GetFullscreenToggleButton() const {
auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive());
return controller->capture_mode_session()
->capture_mode_bar_view()
return GetCaptureModeBarView()
->capture_source_view()
->fullscreen_toggle_button();
}
......@@ -116,8 +145,7 @@ class CaptureModeTest : public AshTestBase {
CaptureModeToggleButton* GetRegionToggleButton() const {
auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive());
return controller->capture_mode_session()
->capture_mode_bar_view()
return GetCaptureModeBarView()
->capture_source_view()
->region_toggle_button();
}
......@@ -125,8 +153,7 @@ class CaptureModeTest : public AshTestBase {
CaptureModeToggleButton* GetWindowToggleButton() const {
auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive());
return controller->capture_mode_session()
->capture_mode_bar_view()
return GetCaptureModeBarView()
->capture_source_view()
->window_toggle_button();
}
......@@ -134,16 +161,14 @@ class CaptureModeTest : public AshTestBase {
CaptureModeCloseButton* GetCloseButton() const {
auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive());
return controller->capture_mode_session()
->capture_mode_bar_view()
->close_button();
return GetCaptureModeBarView()->close_button();
}
aura::Window* GetDimensionsLabelWindow() const {
auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive());
auto* widget = controller->capture_mode_session()
->dimensions_label_widget_for_testing();
auto* widget = CaptureModeSessionTestApi(controller->capture_mode_session())
.dimensions_label_widget();
return widget ? widget->GetNativeWindow() : nullptr;
}
......@@ -151,7 +176,8 @@ class CaptureModeTest : public AshTestBase {
auto* controller = CaptureModeController::Get();
DCHECK(controller->IsActive());
auto& magnifier =
controller->capture_mode_session()->magnifier_glass_for_testing();
CaptureModeSessionTestApi(controller->capture_mode_session())
.magnifier_glass();
if (magnifier.host_widget_for_testing()) {
return magnifier.host_widget_for_testing()
->GetWindowBoundsInScreen()
......@@ -491,9 +517,7 @@ TEST_F(CaptureModeTest, CaptureRegionCoversCaptureModeBar) {
// Select a region such that the capture mode bar is covered.
SelectRegion(gfx::Rect(5, 5, 795, 795));
EXPECT_TRUE(controller->user_capture_region().Contains(
controller->capture_mode_session()
->capture_mode_bar_view()
->GetBoundsInScreen()));
GetCaptureModeBarView()->GetBoundsInScreen()));
// 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
......@@ -505,9 +529,7 @@ TEST_F(CaptureModeTest, CaptureRegionCoversCaptureModeBar) {
ClickOnView(GetRegionToggleButton(), GetEventGenerator());
ASSERT_EQ(CaptureModeSource::kRegion, controller->source());
ASSERT_TRUE(controller->user_capture_region().Contains(
controller->capture_mode_session()
->capture_mode_bar_view()
->GetBoundsInScreen()));
GetCaptureModeBarView()->GetBoundsInScreen()));
ClickOnView(GetCloseButton(), event_generator);
EXPECT_FALSE(controller->IsActive());
......@@ -652,7 +674,8 @@ TEST_F(CaptureModeTest, CaptureRegionCaptureButtonLocation) {
SelectRegion(gfx::Rect(100, 100, 600, 600));
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);
aura::Window* capture_button_window =
capture_button_widget->GetNativeWindow();
......@@ -729,16 +752,13 @@ TEST_F(CaptureModeTest, MultiDisplayCaptureBarInitialLocation) {
auto* controller = StartImageRegionCapture();
EXPECT_TRUE(gfx::Rect(801, 0, 800, 800)
.Contains(controller->capture_mode_session()
->capture_mode_bar_view()
->GetBoundsInScreen()));
.Contains(GetCaptureModeBarView()->GetBoundsInScreen()));
controller->Stop();
MoveMouseToAndUpdateCursorDisplay(gfx::Point(100, 500), event_generator);
StartImageRegionCapture();
EXPECT_TRUE(gfx::Rect(800, 800).Contains(controller->capture_mode_session()
->capture_mode_bar_view()
->GetBoundsInScreen()));
EXPECT_TRUE(gfx::Rect(800, 800).Contains(
GetCaptureModeBarView()->GetBoundsInScreen()));
}
// Tests behavior of a capture mode session if the active display is removed.
......@@ -749,9 +769,8 @@ TEST_F(CaptureModeTest, DisplayRemoval) {
MoveMouseToAndUpdateCursorDisplay(gfx::Point(1000, 500), GetEventGenerator());
auto* controller = StartImageRegionCapture();
auto* session = controller->capture_mode_session();
EXPECT_TRUE(
gfx::Rect(801, 0, 800, 800)
.Contains(session->capture_mode_bar_view()->GetBoundsInScreen()));
EXPECT_TRUE(gfx::Rect(801, 0, 800, 800)
.Contains(GetCaptureModeBarView()->GetBoundsInScreen()));
ASSERT_EQ(Shell::GetAllRootWindows()[1], session->current_root());
// Remove secondary display.
......@@ -768,7 +787,7 @@ TEST_F(CaptureModeTest, DisplayRemoval) {
// Tests that the capture mode bar is now on the primary display.
EXPECT_TRUE(gfx::Rect(800, 800).Contains(
session->capture_mode_bar_view()->GetBoundsInScreen()));
GetCaptureModeBarView()->GetBoundsInScreen()));
ASSERT_EQ(Shell::GetAllRootWindows()[0], session->current_root());
}
......@@ -823,16 +842,13 @@ TEST_F(CaptureModeTest, MultiDisplayRegionSourceRootWindow) {
// the primary display until the mouse is released.
event_generator->PressLeftButton();
EXPECT_EQ(Shell::GetAllRootWindows()[1], session->current_root());
EXPECT_TRUE(gfx::Rect(800, 800).Contains(controller->capture_mode_session()
->capture_mode_bar_view()
->GetBoundsInScreen()));
EXPECT_TRUE(gfx::Rect(800, 800).Contains(
GetCaptureModeBarView()->GetBoundsInScreen()));
event_generator->ReleaseLeftButton();
EXPECT_EQ(Shell::GetAllRootWindows()[1], session->current_root());
EXPECT_TRUE(gfx::Rect(801, 0, 800, 800)
.Contains(controller->capture_mode_session()
->capture_mode_bar_view()
->GetBoundsInScreen()));
.Contains(GetCaptureModeBarView()->GetBoundsInScreen()));
}
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