Commit c124b833 authored by Katie Dektar's avatar Katie Dektar Committed by Commit Bot

Adds test to ensure Select-to-Speak gets mouse movements.

This would catch a regression that happened last week where mousemove
events were not passed properly to the background extension, should
it re-occur in the future.

Bug: 789598
Change-Id: Idd61c1e63f9dfa4f0e87603b62b0cc0a31a34902
Reviewed-on: https://chromium-review.googlesource.com/806647
Commit-Queue: Katie D <katie@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522252}
parent f3e0fc09
...@@ -100,11 +100,15 @@ void AccessibilityFocusRingController::SetFocusRing( ...@@ -100,11 +100,15 @@ void AccessibilityFocusRingController::SetFocusRing(
OnLayerChange(&focus_animation_info_); OnLayerChange(&focus_animation_info_);
focus_rects_ = rects; focus_rects_ = rects;
UpdateFocusRingsFromFocusRects(); UpdateFocusRingsFromFocusRects();
if (focus_ring_observer_for_testing_)
focus_ring_observer_for_testing_.Run();
} }
void AccessibilityFocusRingController::HideFocusRing() { void AccessibilityFocusRingController::HideFocusRing() {
focus_rects_.clear(); focus_rects_.clear();
UpdateFocusRingsFromFocusRects(); UpdateFocusRingsFromFocusRects();
if (focus_ring_observer_for_testing_)
focus_ring_observer_for_testing_.Run();
} }
void AccessibilityFocusRingController::UpdateFocusRingsFromFocusRects() { void AccessibilityFocusRingController::UpdateFocusRingsFromFocusRects() {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ash/accessibility/accessibility_focus_ring_layer.h" #include "ash/accessibility/accessibility_focus_ring_layer.h"
#include "ash/accessibility/accessibility_highlight_layer.h" #include "ash/accessibility/accessibility_highlight_layer.h"
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/optional.h" #include "base/optional.h"
...@@ -61,12 +62,26 @@ class ASH_EXPORT AccessibilityFocusRingController ...@@ -61,12 +62,26 @@ class ASH_EXPORT AccessibilityFocusRingController
// Don't fade in / out, for testing. // Don't fade in / out, for testing.
void SetNoFadeForTesting(); void SetNoFadeForTesting();
// Get accessibility layers, for testing.
AccessibilityCursorRingLayer* cursor_layer_for_testing() { AccessibilityCursorRingLayer* cursor_layer_for_testing() {
return cursor_layer_.get(); return cursor_layer_.get();
} }
AccessibilityCursorRingLayer* caret_layer_for_testing() { AccessibilityCursorRingLayer* caret_layer_for_testing() {
return caret_layer_.get(); return caret_layer_.get();
} }
const std::vector<std::unique_ptr<AccessibilityFocusRingLayer>>&
focus_ring_layers_for_testing() {
return focus_layers_;
}
AccessibilityHighlightLayer* highlight_layer_for_testing() {
return highlight_layer_.get();
}
// Sets an observer of focus ring layer changes.
void set_focus_ring_observer_for_testing(
base::RepeatingCallback<void()> observer) {
focus_ring_observer_for_testing_ = observer;
}
protected: protected:
AccessibilityFocusRingController(); AccessibilityFocusRingController();
...@@ -145,6 +160,8 @@ class ASH_EXPORT AccessibilityFocusRingController ...@@ -145,6 +160,8 @@ class ASH_EXPORT AccessibilityFocusRingController
friend struct base::DefaultSingletonTraits<AccessibilityFocusRingController>; friend struct base::DefaultSingletonTraits<AccessibilityFocusRingController>;
base::RepeatingCallback<void()> focus_ring_observer_for_testing_;
DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingController); DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingController);
}; };
......
...@@ -2,8 +2,15 @@ ...@@ -2,8 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <memory>
#include <vector>
#include "ash/accessibility/accessibility_focus_ring_controller.h"
#include "ash/accessibility/accessibility_focus_ring_layer.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray.h"
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/pattern.h" #include "base/strings/pattern.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/accessibility/speech_monitor.h" #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
...@@ -20,8 +27,15 @@ ...@@ -20,8 +27,15 @@
namespace chromeos { namespace chromeos {
class SelectToSpeakTest : public InProcessBrowserTest { class SelectToSpeakTest : public InProcessBrowserTest {
public:
void OnFocusRingChanged() {
if (loop_runner_) {
loop_runner_->Quit();
}
}
protected: protected:
SelectToSpeakTest() {} SelectToSpeakTest() : weak_ptr_factory_(this) {}
~SelectToSpeakTest() override {} ~SelectToSpeakTest() override {}
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
...@@ -56,7 +70,23 @@ class SelectToSpeakTest : public InProcessBrowserTest { ...@@ -56,7 +70,23 @@ class SelectToSpeakTest : public InProcessBrowserTest {
generator_->ReleaseKey(ui::VKEY_LWIN, 0 /* flags */); generator_->ReleaseKey(ui::VKEY_LWIN, 0 /* flags */);
} }
void PrepareToWaitForFocusRingChanged() {
loop_runner_ = new content::MessageLoopRunner();
}
// Blocks until the focus ring is changed.
void WaitForFocusRingChanged() {
loop_runner_->Run();
loop_runner_ = nullptr;
}
base::WeakPtr<SelectToSpeakTest> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
private: private:
scoped_refptr<content::MessageLoopRunner> loop_runner_;
base::WeakPtrFactory<SelectToSpeakTest> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(SelectToSpeakTest); DISALLOW_COPY_AND_ASSIGN(SelectToSpeakTest);
}; };
...@@ -129,4 +159,71 @@ IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, BreaksAtParagraphBounds) { ...@@ -129,4 +159,71 @@ IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, BreaksAtParagraphBounds) {
"Second paragraph*")); "Second paragraph*"));
} }
IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, FocusRingMovesWithMouse) {
ash::AccessibilityFocusRingController* controller =
ash::AccessibilityFocusRingController::GetInstance();
// Create a callback for the focus ring observer.
base::RepeatingCallback<void()> callback =
base::BindRepeating(&SelectToSpeakTest::OnFocusRingChanged, GetWeakPtr());
controller->set_focus_ring_observer_for_testing(callback);
std::vector<std::unique_ptr<ash::AccessibilityFocusRingLayer>> const&
focus_rings = controller->focus_ring_layers_for_testing();
// No focus rings to start.
EXPECT_EQ(focus_rings.size(), 0u);
ui_test_utils::NavigateToURL(browser(), GURL("data:text/html;charset=utf-8,"
"<p>This is some text</p>"));
gfx::Rect bounds = browser()->window()->GetBounds();
PrepareToWaitForFocusRingChanged();
generator_->PressKey(ui::VKEY_LWIN, 0 /* flags */);
generator_->MoveMouseTo(bounds.x() + 8, bounds.y() + 50);
generator_->PressLeftButton();
// Expect a focus ring to have been drawn.
WaitForFocusRingChanged();
EXPECT_EQ(focus_rings.size(), 1u);
gfx::Rect target_bounds = focus_rings.at(0)->layer()->GetTargetBounds();
// Make sure it's in a reasonable position.
EXPECT_LT(abs(target_bounds.x() - (bounds.x() + 8)), 50);
EXPECT_LT(abs(target_bounds.y() - (bounds.y() + 50)), 50);
EXPECT_LT(target_bounds.width(), 50);
EXPECT_LT(target_bounds.height(), 50);
// Move the mouse.
PrepareToWaitForFocusRingChanged();
generator_->MoveMouseTo(bounds.x() + 108, bounds.y() + 158);
// Expect focus ring to have moved with the mouse.
// The size should have grown to be over 100 (the rect is now size 100,
// and the focus ring has some buffer). Position should be unchanged.
WaitForFocusRingChanged();
target_bounds = focus_rings.at(0)->layer()->GetTargetBounds();
EXPECT_LT(abs(target_bounds.x() - (bounds.x() + 8)), 50);
EXPECT_LT(abs(target_bounds.y() - (bounds.y() + 50)), 50);
EXPECT_GT(target_bounds.width(), 100);
EXPECT_GT(target_bounds.height(), 100);
// Move the mouse smaller again, it should shrink.
PrepareToWaitForFocusRingChanged();
generator_->MoveMouseTo(bounds.x() + 18, bounds.y() + 68);
WaitForFocusRingChanged();
target_bounds = focus_rings.at(0)->layer()->GetTargetBounds();
EXPECT_LT(target_bounds.width(), 50);
EXPECT_LT(target_bounds.height(), 50);
// Cancel this by releasing the key before the mouse.
PrepareToWaitForFocusRingChanged();
generator_->ReleaseKey(ui::VKEY_LWIN, 0 /* flags */);
generator_->ReleaseLeftButton();
// Expect focus ring to have been cleared, this was canceled in STS
// by releasing the key before the button.
WaitForFocusRingChanged();
EXPECT_EQ(focus_rings.size(), 0u);
}
} // namespace chromeos } // namespace chromeos
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