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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/window.h" 5 #include "ui/aura/window.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 private: 184 private:
185 int capture_changed_event_count_; 185 int capture_changed_event_count_;
186 int capture_lost_count_; 186 int capture_lost_count_;
187 int mouse_event_count_; 187 int mouse_event_count_;
188 int touch_event_count_; 188 int touch_event_count_;
189 int gesture_event_count_; 189 int gesture_event_count_;
190 190
191 DISALLOW_COPY_AND_ASSIGN(CaptureWindowDelegateImpl); 191 DISALLOW_COPY_AND_ASSIGN(CaptureWindowDelegateImpl);
192 }; 192 };
193 193
194 // aura::WindowDelegate that tracks the window that was reported as having the
195 // focus before us.
196 class FocusDelegate : public TestWindowDelegate {
197 public:
198 FocusDelegate() : previous_focused_window_(NULL) {
199 }
200
201 aura::Window* previous_focused_window() const {
202 return previous_focused_window_;
203 }
204
205 virtual void OnFocus(aura::Window* old_focused_window) {
206 previous_focused_window_ = old_focused_window;
207 }
208
209 private:
210 aura::Window* previous_focused_window_;
211 };
212
194 // Keeps track of the location of the gesture. 213 // Keeps track of the location of the gesture.
195 class GestureTrackPositionDelegate : public TestWindowDelegate { 214 class GestureTrackPositionDelegate : public TestWindowDelegate {
196 public: 215 public:
197 GestureTrackPositionDelegate() {} 216 GestureTrackPositionDelegate() {}
198 217
199 virtual ui::GestureStatus OnGestureEvent(GestureEvent* event) OVERRIDE { 218 virtual ui::GestureStatus OnGestureEvent(GestureEvent* event) OVERRIDE {
200 position_ = event->location(); 219 position_ = event->location();
201 return ui::GESTURE_STATUS_CONSUMED; 220 return ui::GESTURE_STATUS_CONSUMED;
202 } 221 }
203 222
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 parent->Show(); 1268 parent->Show();
1250 1269
1251 child->Focus(); 1270 child->Focus();
1252 EXPECT_TRUE(child->HasFocus()); 1271 EXPECT_TRUE(child->HasFocus());
1253 EXPECT_FALSE(parent->HasFocus()); 1272 EXPECT_FALSE(parent->HasFocus());
1254 1273
1255 child.reset(); 1274 child.reset();
1256 EXPECT_TRUE(parent->HasFocus()); 1275 EXPECT_TRUE(parent->HasFocus());
1257 } 1276 }
1258 1277
1278 // Tests that the previously-focused window is passed to
1279 // WindowDelegate::OnFocus().
1280 TEST_F(WindowTest, OldFocusedWindowTest) {
1281 const gfx::Rect kBounds(0, 0, 100, 100);
1282
1283 FocusDelegate delegate1;
1284 scoped_ptr<Window> window1(
1285 CreateTestWindowWithDelegate(&delegate1, 0, kBounds, NULL));
1286 window1->Focus();
1287 ASSERT_TRUE(window1->HasFocus());
1288 EXPECT_TRUE(delegate1.previous_focused_window() == NULL);
1289
1290 FocusDelegate delegate2;
1291 scoped_ptr<Window> window2(
1292 CreateTestWindowWithDelegate(&delegate2, 1, kBounds, NULL));
1293 window2->Focus();
1294 ASSERT_TRUE(window2->HasFocus());
1295 EXPECT_FALSE(window1->HasFocus());
1296 EXPECT_EQ(window1.get(), delegate2.previous_focused_window());
1297 }
1298
1259 namespace { 1299 namespace {
1260 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); 1300 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2);
1261 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); 1301 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish");
1262 } 1302 }
1263 1303
1264 TEST_F(WindowTest, Property) { 1304 TEST_F(WindowTest, Property) {
1265 scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL)); 1305 scoped_ptr<Window> w(CreateTestWindowWithId(0, NULL));
1266 1306
1267 static const char native_prop_key[] = "fnord"; 1307 static const char native_prop_key[] = "fnord";
1268 1308
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 2351 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
2312 2352
2313 // No bounds changed notification at the end of animation since layer 2353 // No bounds changed notification at the end of animation since layer
2314 // delegate is NULL. 2354 // delegate is NULL.
2315 EXPECT_FALSE(delegate.bounds_changed()); 2355 EXPECT_FALSE(delegate.bounds_changed());
2316 EXPECT_NE("0,0 100x100", window->bounds().ToString()); 2356 EXPECT_NE("0,0 100x100", window->bounds().ToString());
2317 } 2357 }
2318 2358
2319 } // namespace test 2359 } // namespace test
2320 } // namespace aura 2360 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698