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

Unified Diff: ui/views/corewm/focus_controller_unittest.cc

Issue 75933005: Makes FocusdController honor focus change if no previously active window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « ui/views/corewm/focus_controller.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/corewm/focus_controller_unittest.cc
diff --git a/ui/views/corewm/focus_controller_unittest.cc b/ui/views/corewm/focus_controller_unittest.cc
index 349f517d7bd1d1bfae4c44bbd1666548b9f96487..8bea0a9727da2e22f09ae96ada2475648c290a60 100644
--- a/ui/views/corewm/focus_controller_unittest.cc
+++ b/ui/views/corewm/focus_controller_unittest.cc
@@ -305,6 +305,7 @@ class FocusControllerTestBase : public aura::test::AuraTestBase {
virtual void NoShiftActiveOnActivation() {}
virtual void NoFocusChangeOnClickOnCaptureWindow() {}
virtual void ChangeFocusWhenNothingFocusedAndCaptured() {}
+ virtual void ChangeFocusWithinActivate() {}
private:
scoped_ptr<FocusController> focus_controller_;
@@ -313,6 +314,38 @@ class FocusControllerTestBase : public aura::test::AuraTestBase {
DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase);
};
+// ActivationChangeObserver that attempts to focus another window on an
+// activation change.
+class TestActivationChangeObserver
+ : public aura::client::ActivationChangeObserver {
+ public:
+ TestActivationChangeObserver() : gained_active_(NULL), to_focus_(NULL) {}
+ virtual ~TestActivationChangeObserver() {}
+
+ // Sets the window to focus (|to_focus|) when a window is made active.
+ void SetWindows(aura::Window* gained_active, aura::Window* to_focus) {
+ gained_active_ = gained_active;
+ to_focus_ = to_focus;
+ }
+
+ // aura::client::ActivationChangeObserver:
+ virtual void OnWindowActivated(aura::Window* gained_active,
+ aura::Window* lost_active) OVERRIDE {
+ if (gained_active == gained_active_ && to_focus_) {
+ aura::Window* to_focus = to_focus_;
+ to_focus_ = NULL;
+ gained_active_ = NULL;
+ to_focus->Focus();
+ }
+ }
+
+ private:
+ aura::Window* gained_active_;
+ aura::Window* to_focus_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestActivationChangeObserver);
+};
+
// Test base for tests where focus is directly set to a target window.
class FocusControllerDirectTestBase : public FocusControllerTestBase {
protected:
@@ -618,6 +651,25 @@ class FocusControllerDirectTestBase : public FocusControllerTestBase {
aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1);
}
+ // Verifies a request to focus a window is honored if the
+ // ActivationChangeObserver changes focus.
+ virtual void ChangeFocusWithinActivate() OVERRIDE {
+ TestActivationChangeObserver test_observer;
+ aura::client::GetActivationClient(root_window())->
+ AddObserver(&test_observer);
+ // Set things such that when |w1| is made active a request is made to focus
+ // |w11|.
+ test_observer.SetWindows(root_window()->GetChildById(1),
+ root_window()->GetChildById(11));
+ // Attempt to activate |w12|. This should activate |w1| (its the child of
+ // the root
+ ActivateWindowById(12);
+ EXPECT_EQ(1, GetActiveWindowId());
+ EXPECT_EQ(12, GetFocusedWindowId());
+ aura::client::GetActivationClient(root_window())->RemoveObserver(
+ &test_observer);
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase);
};
@@ -1019,5 +1071,7 @@ DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow);
FOCUS_CONTROLLER_TEST(FocusControllerApiTest,
ChangeFocusWhenNothingFocusedAndCaptured);
+FOCUS_CONTROLLER_TEST(FocusControllerApiTest, ChangeFocusWithinActivate);
+
} // namespace corewm
} // namespace views
« no previous file with comments | « ui/views/corewm/focus_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698