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

Unified Diff: ui/aura/window_unittest.cc

Issue 10562025: aura: Fix WidgetFocusChangeListener::OnNativeFocusChange(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge again Created 8 years, 6 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: ui/aura/window_unittest.cc
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 51a41f399e214b36af171731c93cc9b95c35e945..d46ddbfb0d43b1368dd83d1aada42822b0fe03ff 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -191,6 +191,25 @@ class CaptureWindowDelegateImpl : public TestWindowDelegate {
DISALLOW_COPY_AND_ASSIGN(CaptureWindowDelegateImpl);
};
+// aura::WindowDelegate that tracks the window that was reported as having the
+// focus before us.
+class FocusDelegate : public TestWindowDelegate {
+ public:
+ FocusDelegate() : previous_focused_window_(NULL) {
+ }
+
+ aura::Window* previous_focused_window() const {
+ return previous_focused_window_;
+ }
+
+ virtual void OnFocus(aura::Window* old_focused_window) {
+ previous_focused_window_ = old_focused_window;
+ }
+
+ private:
+ aura::Window* previous_focused_window_;
+};
+
// Keeps track of the location of the gesture.
class GestureTrackPositionDelegate : public TestWindowDelegate {
public:
@@ -1256,6 +1275,27 @@ TEST_F(WindowTest, FocusedWindowTest) {
EXPECT_TRUE(parent->HasFocus());
}
+// Tests that the previously-focused window is passed to
+// WindowDelegate::OnFocus().
+TEST_F(WindowTest, OldFocusedWindowTest) {
+ const gfx::Rect kBounds(0, 0, 100, 100);
+
+ FocusDelegate delegate1;
+ scoped_ptr<Window> window1(
+ CreateTestWindowWithDelegate(&delegate1, 0, kBounds, NULL));
+ window1->Focus();
+ ASSERT_TRUE(window1->HasFocus());
+ EXPECT_TRUE(delegate1.previous_focused_window() == NULL);
+
+ FocusDelegate delegate2;
+ scoped_ptr<Window> window2(
+ CreateTestWindowWithDelegate(&delegate2, 1, kBounds, NULL));
+ window2->Focus();
+ ASSERT_TRUE(window2->HasFocus());
+ EXPECT_FALSE(window1->HasFocus());
+ EXPECT_EQ(window1.get(), delegate2.previous_focused_window());
+}
+
namespace {
DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2);
DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish");

Powered by Google App Engine
This is Rietveld 408576698