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

Side by Side Diff: ui/aura/window_unittest.cc

Issue 8771015: Rename Desktop->RootWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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
« no previous file with comments | « ui/aura/window.cc ('k') | ui/aura_shell/app_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/aura/client/stacking_client.h" 11 #include "ui/aura/client/stacking_client.h"
12 #include "ui/aura/desktop.h"
13 #include "ui/aura/desktop_observer.h"
14 #include "ui/aura/event.h" 12 #include "ui/aura/event.h"
15 #include "ui/aura/focus_manager.h" 13 #include "ui/aura/focus_manager.h"
14 #include "ui/aura/root_window.h"
15 #include "ui/aura/root_window_observer.h"
16 #include "ui/aura/test/aura_test_base.h" 16 #include "ui/aura/test/aura_test_base.h"
17 #include "ui/aura/test/event_generator.h" 17 #include "ui/aura/test/event_generator.h"
18 #include "ui/aura/test/test_windows.h" 18 #include "ui/aura/test/test_windows.h"
19 #include "ui/aura/test/test_window_delegate.h" 19 #include "ui/aura/test/test_window_delegate.h"
20 #include "ui/aura/window_delegate.h" 20 #include "ui/aura/window_delegate.h"
21 #include "ui/aura/window_observer.h" 21 #include "ui/aura/window_observer.h"
22 #include "ui/base/hit_test.h" 22 #include "ui/base/hit_test.h"
23 #include "ui/base/keycodes/keyboard_codes.h" 23 #include "ui/base/keycodes/keyboard_codes.h"
24 #include "ui/gfx/canvas_skia.h" 24 #include "ui/gfx/canvas_skia.h"
25 #include "ui/gfx/compositor/layer.h" 25 #include "ui/gfx/compositor/layer.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 scoped_ptr<Window> w1111( 195 scoped_ptr<Window> w1111(
196 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); 196 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get()));
197 scoped_ptr<Window> w12( 197 scoped_ptr<Window> w12(
198 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), 198 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25),
199 w1.get())); 199 w1.get()));
200 scoped_ptr<Window> w121( 200 scoped_ptr<Window> w121(
201 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get())); 201 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get()));
202 scoped_ptr<Window> w13( 202 scoped_ptr<Window> w13(
203 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get())); 203 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get()));
204 204
205 Window* root = Desktop::GetInstance(); 205 Window* root = RootWindow::GetInstance();
206 w1->parent()->SetBounds(gfx::Rect(500, 500)); 206 w1->parent()->SetBounds(gfx::Rect(500, 500));
207 EXPECT_EQ(NULL, root->GetEventHandlerForPoint(gfx::Point(5, 5))); 207 EXPECT_EQ(NULL, root->GetEventHandlerForPoint(gfx::Point(5, 5)));
208 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint(gfx::Point(11, 11))); 208 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint(gfx::Point(11, 11)));
209 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint(gfx::Point(16, 16))); 209 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint(gfx::Point(16, 16)));
210 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint(gfx::Point(21, 21))); 210 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint(gfx::Point(21, 21)));
211 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); 211 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26)));
212 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); 212 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431)));
213 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); 213 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436)));
214 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); 214 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481)));
215 } 215 }
216 216
217 TEST_F(WindowTest, GetTopWindowContainingPoint) { 217 TEST_F(WindowTest, GetTopWindowContainingPoint) {
218 Window* root = Desktop::GetInstance(); 218 Window* root = RootWindow::GetInstance();
219 root->SetBounds(gfx::Rect(0, 0, 300, 300)); 219 root->SetBounds(gfx::Rect(0, 0, 300, 300));
220 220
221 scoped_ptr<Window> w1( 221 scoped_ptr<Window> w1(
222 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL)); 222 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL));
223 scoped_ptr<Window> w11( 223 scoped_ptr<Window> w11(
224 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); 224 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get()));
225 225
226 scoped_ptr<Window> w2( 226 scoped_ptr<Window> w2(
227 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), NULL)); 227 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(5, 5, 55, 55), NULL));
228 228
(...skipping 18 matching lines...) Expand all
247 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(110, 110))); 247 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(110, 110)));
248 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(200, 200))); 248 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(200, 200)));
249 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(220, 220))); 249 EXPECT_EQ(w31.get(), root->GetTopWindowContainingPoint(gfx::Point(220, 220)));
250 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(260, 260))); 250 EXPECT_EQ(NULL, root->GetTopWindowContainingPoint(gfx::Point(260, 260)));
251 } 251 }
252 252
253 TEST_F(WindowTest, GetToplevelWindow) { 253 TEST_F(WindowTest, GetToplevelWindow) {
254 const gfx::Rect kBounds(0, 0, 10, 10); 254 const gfx::Rect kBounds(0, 0, 10, 10);
255 TestWindowDelegate delegate; 255 TestWindowDelegate delegate;
256 256
257 Window* root = aura::Desktop::GetInstance(); 257 Window* root = aura::RootWindow::GetInstance();
258 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root)); 258 scoped_ptr<Window> w1(CreateTestWindowWithId(1, root));
259 scoped_ptr<Window> w11( 259 scoped_ptr<Window> w11(
260 CreateTestWindowWithDelegate(&delegate, 11, kBounds, w1.get())); 260 CreateTestWindowWithDelegate(&delegate, 11, kBounds, w1.get()));
261 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); 261 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get()));
262 scoped_ptr<Window> w1111( 262 scoped_ptr<Window> w1111(
263 CreateTestWindowWithDelegate(&delegate, 1111, kBounds, w111.get())); 263 CreateTestWindowWithDelegate(&delegate, 1111, kBounds, w111.get()));
264 264
265 EXPECT_TRUE(root->GetToplevelWindow() == NULL); 265 EXPECT_TRUE(root->GetToplevelWindow() == NULL);
266 EXPECT_TRUE(w1->GetToplevelWindow() == NULL); 266 EXPECT_TRUE(w1->GetToplevelWindow() == NULL);
267 EXPECT_EQ(w11.get(), w11->GetToplevelWindow()); 267 EXPECT_EQ(w11.get(), w11->GetToplevelWindow());
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 EXPECT_EQ(&child1, parent.children()[1]); 366 EXPECT_EQ(&child1, parent.children()[1]);
367 EXPECT_EQ(&child3, parent.children()[2]); 367 EXPECT_EQ(&child3, parent.children()[2]);
368 ASSERT_EQ(3u, parent.layer()->children().size()); 368 ASSERT_EQ(3u, parent.layer()->children().size());
369 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); 369 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]);
370 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); 370 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]);
371 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]); 371 EXPECT_EQ(child3.layer(), parent.layer()->children()[2]);
372 } 372 }
373 373
374 // Various destruction assertions. 374 // Various destruction assertions.
375 TEST_F(WindowTest, CaptureTests) { 375 TEST_F(WindowTest, CaptureTests) {
376 aura::Desktop* desktop = aura::Desktop::GetInstance(); 376 aura::RootWindow* root_window = aura::RootWindow::GetInstance();
377 CaptureWindowDelegateImpl delegate; 377 CaptureWindowDelegateImpl delegate;
378 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 378 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
379 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); 379 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
380 EXPECT_FALSE(window->HasCapture()); 380 EXPECT_FALSE(window->HasCapture());
381 381
382 // Do a capture. 382 // Do a capture.
383 window->SetCapture(); 383 window->SetCapture();
384 EXPECT_TRUE(window->HasCapture()); 384 EXPECT_TRUE(window->HasCapture());
385 EXPECT_EQ(0, delegate.capture_lost_count()); 385 EXPECT_EQ(0, delegate.capture_lost_count());
386 EventGenerator generator(gfx::Point(50, 50)); 386 EventGenerator generator(gfx::Point(50, 50));
387 generator.PressLeftButton(); 387 generator.PressLeftButton();
388 EXPECT_EQ(1, delegate.mouse_event_count()); 388 EXPECT_EQ(1, delegate.mouse_event_count());
389 generator.ReleaseLeftButton(); 389 generator.ReleaseLeftButton();
390 390
391 EXPECT_EQ(2, delegate.mouse_event_count()); 391 EXPECT_EQ(2, delegate.mouse_event_count());
392 delegate.set_mouse_event_count(0); 392 delegate.set_mouse_event_count(0);
393 393
394 TouchEvent touchev(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 0); 394 TouchEvent touchev(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 0);
395 desktop->DispatchTouchEvent(&touchev); 395 root_window->DispatchTouchEvent(&touchev);
396 EXPECT_EQ(1, delegate.touch_event_count()); 396 EXPECT_EQ(1, delegate.touch_event_count());
397 delegate.set_touch_event_count(0); 397 delegate.set_touch_event_count(0);
398 398
399 window->ReleaseCapture(); 399 window->ReleaseCapture();
400 EXPECT_FALSE(window->HasCapture()); 400 EXPECT_FALSE(window->HasCapture());
401 EXPECT_EQ(1, delegate.capture_lost_count()); 401 EXPECT_EQ(1, delegate.capture_lost_count());
402 402
403 generator.PressLeftButton(); 403 generator.PressLeftButton();
404 EXPECT_EQ(0, delegate.mouse_event_count()); 404 EXPECT_EQ(0, delegate.mouse_event_count());
405 405
406 desktop->DispatchTouchEvent(&touchev); 406 root_window->DispatchTouchEvent(&touchev);
407 EXPECT_EQ(0, delegate.touch_event_count()); 407 EXPECT_EQ(0, delegate.touch_event_count());
408 408
409 // Removing the capture window from parent should reset the capture window 409 // Removing the capture window from parent should reset the capture window
410 // in the desktop. 410 // in the root window.
411 window->SetCapture(); 411 window->SetCapture();
412 EXPECT_EQ(window.get(), desktop->capture_window()); 412 EXPECT_EQ(window.get(), root_window->capture_window());
413 window->parent()->RemoveChild(window.get()); 413 window->parent()->RemoveChild(window.get());
414 EXPECT_FALSE(window->HasCapture()); 414 EXPECT_FALSE(window->HasCapture());
415 EXPECT_EQ(NULL, desktop->capture_window()); 415 EXPECT_EQ(NULL, root_window->capture_window());
416 } 416 }
417 417
418 // Verifies capture is reset when a window is destroyed. 418 // Verifies capture is reset when a window is destroyed.
419 TEST_F(WindowTest, ReleaseCaptureOnDestroy) { 419 TEST_F(WindowTest, ReleaseCaptureOnDestroy) {
420 Desktop* desktop = Desktop::GetInstance(); 420 RootWindow* root_window = RootWindow::GetInstance();
421 CaptureWindowDelegateImpl delegate; 421 CaptureWindowDelegateImpl delegate;
422 scoped_ptr<Window> window(CreateTestWindowWithDelegate( 422 scoped_ptr<Window> window(CreateTestWindowWithDelegate(
423 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL)); 423 &delegate, 0, gfx::Rect(0, 0, 20, 20), NULL));
424 EXPECT_FALSE(window->HasCapture()); 424 EXPECT_FALSE(window->HasCapture());
425 425
426 // Do a capture. 426 // Do a capture.
427 window->SetCapture(); 427 window->SetCapture();
428 EXPECT_TRUE(window->HasCapture()); 428 EXPECT_TRUE(window->HasCapture());
429 429
430 // Destroy the window. 430 // Destroy the window.
431 window.reset(); 431 window.reset();
432 432
433 // Make sure the desktop doesn't reference the window anymore. 433 // Make sure the root window doesn't reference the window anymore.
434 EXPECT_EQ(NULL, desktop->mouse_pressed_handler()); 434 EXPECT_EQ(NULL, root_window->mouse_pressed_handler());
435 EXPECT_EQ(NULL, desktop->capture_window()); 435 EXPECT_EQ(NULL, root_window->capture_window());
436 } 436 }
437 437
438 TEST_F(WindowTest, GetScreenBounds) { 438 TEST_F(WindowTest, GetScreenBounds) {
439 scoped_ptr<Window> viewport(CreateTestWindowWithBounds( 439 scoped_ptr<Window> viewport(CreateTestWindowWithBounds(
440 gfx::Rect(0, 0, 300, 300), NULL)); 440 gfx::Rect(0, 0, 300, 300), NULL));
441 scoped_ptr<Window> child(CreateTestWindowWithBounds( 441 scoped_ptr<Window> child(CreateTestWindowWithBounds(
442 gfx::Rect(0, 0, 100, 100), viewport.get())); 442 gfx::Rect(0, 0, 100, 100), viewport.get()));
443 // Sanity check. 443 // Sanity check.
444 EXPECT_EQ("0,0 100x100", child->GetScreenBounds().ToString()); 444 EXPECT_EQ("0,0 100x100", child->GetScreenBounds().ToString());
445 445
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 bool entered_; 478 bool entered_;
479 bool exited_; 479 bool exited_;
480 480
481 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate); 481 DISALLOW_COPY_AND_ASSIGN(MouseEnterExitWindowDelegate);
482 }; 482 };
483 483
484 484
485 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for 485 // Verifies that the WindowDelegate receives MouseExit and MouseEnter events for
486 // mouse transitions from window to window. 486 // mouse transitions from window to window.
487 TEST_F(WindowTest, MouseEnterExit) { 487 TEST_F(WindowTest, MouseEnterExit) {
488 Desktop* desktop = Desktop::GetInstance(); 488 RootWindow* root_window = RootWindow::GetInstance();
489 489
490 MouseEnterExitWindowDelegate d1; 490 MouseEnterExitWindowDelegate d1;
491 scoped_ptr<Window> w1( 491 scoped_ptr<Window> w1(
492 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); 492 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL));
493 MouseEnterExitWindowDelegate d2; 493 MouseEnterExitWindowDelegate d2;
494 scoped_ptr<Window> w2( 494 scoped_ptr<Window> w2(
495 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL)); 495 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50), NULL));
496 496
497 gfx::Point move_point = w1->bounds().CenterPoint(); 497 gfx::Point move_point = w1->bounds().CenterPoint();
498 Window::ConvertPointToWindow(w1->parent(), desktop, &move_point); 498 Window::ConvertPointToWindow(w1->parent(), root_window, &move_point);
499 MouseEvent mouseev1(ui::ET_MOUSE_MOVED, move_point, 0); 499 MouseEvent mouseev1(ui::ET_MOUSE_MOVED, move_point, 0);
500 desktop->DispatchMouseEvent(&mouseev1); 500 root_window->DispatchMouseEvent(&mouseev1);
501 501
502 EXPECT_TRUE(d1.entered()); 502 EXPECT_TRUE(d1.entered());
503 EXPECT_FALSE(d1.exited()); 503 EXPECT_FALSE(d1.exited());
504 EXPECT_FALSE(d2.entered()); 504 EXPECT_FALSE(d2.entered());
505 EXPECT_FALSE(d2.exited()); 505 EXPECT_FALSE(d2.exited());
506 506
507 move_point = w2->bounds().CenterPoint(); 507 move_point = w2->bounds().CenterPoint();
508 Window::ConvertPointToWindow(w2->parent(), desktop, &move_point); 508 Window::ConvertPointToWindow(w2->parent(), root_window, &move_point);
509 MouseEvent mouseev2(ui::ET_MOUSE_MOVED, move_point, 0); 509 MouseEvent mouseev2(ui::ET_MOUSE_MOVED, move_point, 0);
510 desktop->DispatchMouseEvent(&mouseev2); 510 root_window->DispatchMouseEvent(&mouseev2);
511 511
512 EXPECT_TRUE(d1.entered()); 512 EXPECT_TRUE(d1.entered());
513 EXPECT_TRUE(d1.exited()); 513 EXPECT_TRUE(d1.exited());
514 EXPECT_TRUE(d2.entered()); 514 EXPECT_TRUE(d2.entered());
515 EXPECT_FALSE(d2.exited()); 515 EXPECT_FALSE(d2.exited());
516 } 516 }
517 517
518 namespace { 518 namespace {
519 519
520 class ActiveWindowDelegate : public TestWindowDelegate { 520 class ActiveWindowDelegate : public TestWindowDelegate {
(...skipping 22 matching lines...) Expand all
543 int hit_count_; 543 int hit_count_;
544 544
545 DISALLOW_COPY_AND_ASSIGN(ActiveWindowDelegate); 545 DISALLOW_COPY_AND_ASSIGN(ActiveWindowDelegate);
546 }; 546 };
547 547
548 } // namespace 548 } // namespace
549 549
550 // Verifies that when WindowDelegate::OnLostActive is invoked the window is not 550 // Verifies that when WindowDelegate::OnLostActive is invoked the window is not
551 // active. 551 // active.
552 TEST_F(WindowTest, NotActiveInLostActive) { 552 TEST_F(WindowTest, NotActiveInLostActive) {
553 Desktop* desktop = Desktop::GetInstance(); 553 RootWindow* root_window = RootWindow::GetInstance();
554 554
555 ActiveWindowDelegate d1; 555 ActiveWindowDelegate d1;
556 scoped_ptr<Window> w1( 556 scoped_ptr<Window> w1(
557 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL)); 557 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL));
558 d1.set_window(w1.get()); 558 d1.set_window(w1.get());
559 scoped_ptr<Window> w2( 559 scoped_ptr<Window> w2(
560 CreateTestWindowWithDelegate(NULL, 1, gfx::Rect(10, 10, 50, 50), NULL)); 560 CreateTestWindowWithDelegate(NULL, 1, gfx::Rect(10, 10, 50, 50), NULL));
561 561
562 // Activate w1. 562 // Activate w1.
563 desktop->SetActiveWindow(w1.get(), NULL); 563 root_window->SetActiveWindow(w1.get(), NULL);
564 EXPECT_EQ(w1.get(), desktop->active_window()); 564 EXPECT_EQ(w1.get(), root_window->active_window());
565 565
566 // Should not have gotten a OnLostActive yet. 566 // Should not have gotten a OnLostActive yet.
567 EXPECT_EQ(0, d1.hit_count()); 567 EXPECT_EQ(0, d1.hit_count());
568 568
569 // SetActiveWindow(NULL) should not change the active window. 569 // SetActiveWindow(NULL) should not change the active window.
570 desktop->SetActiveWindow(NULL, NULL); 570 root_window->SetActiveWindow(NULL, NULL);
571 EXPECT_TRUE(desktop->active_window() == w1.get()); 571 EXPECT_TRUE(root_window->active_window() == w1.get());
572 572
573 // Now activate another window. 573 // Now activate another window.
574 desktop->SetActiveWindow(w2.get(), NULL); 574 root_window->SetActiveWindow(w2.get(), NULL);
575 575
576 // Should have gotten OnLostActive and w1 should not have been active at that 576 // Should have gotten OnLostActive and w1 should not have been active at that
577 // time. 577 // time.
578 EXPECT_EQ(1, d1.hit_count()); 578 EXPECT_EQ(1, d1.hit_count());
579 EXPECT_FALSE(d1.was_active()); 579 EXPECT_FALSE(d1.was_active());
580 } 580 }
581 581
582 // Creates a window with a delegate (w111) that can handle events at a lower 582 // Creates a window with a delegate (w111) that can handle events at a lower
583 // z-index than a window without a delegate (w12). w12 is sized to fill the 583 // z-index than a window without a delegate (w12). w12 is sized to fill the
584 // entire bounds of the container. This test verifies that 584 // entire bounds of the container. This test verifies that
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 EXPECT_FALSE(w2->IsActive()); 770 EXPECT_FALSE(w2->IsActive());
771 EXPECT_EQ(w1.get(), parent->children()[1]); 771 EXPECT_EQ(w1.get(), parent->children()[1]);
772 772
773 // Deactivate w1 and make sure w2 becomes active and frontmost. 773 // Deactivate w1 and make sure w2 becomes active and frontmost.
774 w1->Deactivate(); 774 w1->Deactivate();
775 EXPECT_FALSE(w1->IsActive()); 775 EXPECT_FALSE(w1->IsActive());
776 EXPECT_TRUE(w2->IsActive()); 776 EXPECT_TRUE(w2->IsActive());
777 EXPECT_EQ(w2.get(), parent->children()[1]); 777 EXPECT_EQ(w2.get(), parent->children()[1]);
778 } 778 }
779 779
780 // Tests transformation on the desktop. 780 // Tests transformation on the root window.
781 TEST_F(WindowTest, Transform) { 781 TEST_F(WindowTest, Transform) {
782 Desktop* desktop = Desktop::GetInstance(); 782 RootWindow* root_window = RootWindow::GetInstance();
783 gfx::Size size = desktop->GetHostSize(); 783 gfx::Size size = root_window->GetHostSize();
784 EXPECT_EQ(gfx::Rect(size), 784 EXPECT_EQ(gfx::Rect(size),
785 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point())); 785 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()));
786 786
787 // Rotate it clock-wise 90 degrees. 787 // Rotate it clock-wise 90 degrees.
788 ui::Transform transform; 788 ui::Transform transform;
789 transform.SetRotate(90.0f); 789 transform.SetRotate(90.0f);
790 transform.ConcatTranslate(size.width(), 0); 790 transform.ConcatTranslate(size.width(), 0);
791 desktop->SetTransform(transform); 791 root_window->SetTransform(transform);
792 792
793 // The size should be the transformed size. 793 // The size should be the transformed size.
794 gfx::Size transformed_size(size.height(), size.width()); 794 gfx::Size transformed_size(size.height(), size.width());
795 EXPECT_EQ(transformed_size.ToString(), desktop->GetHostSize().ToString()); 795 EXPECT_EQ(transformed_size.ToString(), root_window->GetHostSize().ToString());
796 EXPECT_EQ(gfx::Rect(transformed_size).ToString(), 796 EXPECT_EQ(gfx::Rect(transformed_size).ToString(),
797 desktop->bounds().ToString()); 797 root_window->bounds().ToString());
798 EXPECT_EQ(gfx::Rect(transformed_size).ToString(), 798 EXPECT_EQ(gfx::Rect(transformed_size).ToString(),
799 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()).ToString()); 799 gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point()).ToString());
800 } 800 }
801 801
802 // Various assertions for transient children. 802 // Various assertions for transient children.
803 TEST_F(WindowTest, TransientChildren) { 803 TEST_F(WindowTest, TransientChildren) {
804 scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL)); 804 scoped_ptr<Window> parent(CreateTestWindowWithId(0, NULL));
805 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); 805 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
806 scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get())); 806 scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get()));
807 Window* w2 = CreateTestWindowWithId(2, parent.get()); 807 Window* w2 = CreateTestWindowWithId(2, parent.get());
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 EXPECT_EQ(2, w1->GetIntProperty(key)); 1085 EXPECT_EQ(2, w1->GetIntProperty(key));
1086 EXPECT_EQ(reinterpret_cast<void*>(2), w1->GetProperty(key)); 1086 EXPECT_EQ(reinterpret_cast<void*>(2), w1->GetProperty(key));
1087 EXPECT_EQ("name=test old=1 new=2", PropertyChangeInfoAndClear()); 1087 EXPECT_EQ("name=test old=1 new=2", PropertyChangeInfoAndClear());
1088 w1->SetProperty(key, NULL); 1088 w1->SetProperty(key, NULL);
1089 EXPECT_EQ("name=test old=2 new=0", PropertyChangeInfoAndClear()); 1089 EXPECT_EQ("name=test old=2 new=0", PropertyChangeInfoAndClear());
1090 1090
1091 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. 1091 // Sanity check to see if |PropertyChangeInfoAndClear| really clears.
1092 EXPECT_EQ("name= old=0 new=0", PropertyChangeInfoAndClear()); 1092 EXPECT_EQ("name= old=0 new=0", PropertyChangeInfoAndClear());
1093 } 1093 }
1094 1094
1095 class DesktopObserverTest : public WindowTest, 1095 class RootWindowObserverTest : public WindowTest,
1096 public DesktopObserver { 1096 public RootWindowObserver {
1097 public: 1097 public:
1098 DesktopObserverTest() : active_(NULL) { 1098 RootWindowObserverTest() : active_(NULL) {
1099 } 1099 }
1100 1100
1101 virtual ~DesktopObserverTest() {} 1101 virtual ~RootWindowObserverTest() {}
1102 1102
1103 Window* active() const { return active_; } 1103 Window* active() const { return active_; }
1104 1104
1105 void Reset() { 1105 void Reset() {
1106 active_ = NULL; 1106 active_ = NULL;
1107 } 1107 }
1108 1108
1109 private: 1109 private:
1110 virtual void SetUp() OVERRIDE { 1110 virtual void SetUp() OVERRIDE {
1111 WindowTest::SetUp(); 1111 WindowTest::SetUp();
1112 Desktop::GetInstance()->AddObserver(this); 1112 RootWindow::GetInstance()->AddObserver(this);
1113 } 1113 }
1114 1114
1115 virtual void TearDown() OVERRIDE { 1115 virtual void TearDown() OVERRIDE {
1116 Desktop::GetInstance()->RemoveObserver(this); 1116 RootWindow::GetInstance()->RemoveObserver(this);
1117 WindowTest::TearDown(); 1117 WindowTest::TearDown();
1118 } 1118 }
1119 1119
1120 virtual void OnActiveWindowChanged(Window* active) OVERRIDE { 1120 virtual void OnActiveWindowChanged(Window* active) OVERRIDE {
1121 active_ = active; 1121 active_ = active;
1122 } 1122 }
1123 1123
1124 Window* active_; 1124 Window* active_;
1125 1125
1126 DISALLOW_COPY_AND_ASSIGN(DesktopObserverTest); 1126 DISALLOW_COPY_AND_ASSIGN(RootWindowObserverTest);
1127 }; 1127 };
1128 1128
1129 TEST_F(DesktopObserverTest, WindowActivationObserve) { 1129 TEST_F(RootWindowObserverTest, WindowActivationObserve) {
1130 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); 1130 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
1131 scoped_ptr<Window> w2(CreateTestWindowWithId(2, NULL)); 1131 scoped_ptr<Window> w2(CreateTestWindowWithId(2, NULL));
1132 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get())); 1132 scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get()));
1133 1133
1134 EXPECT_EQ(NULL, active()); 1134 EXPECT_EQ(NULL, active());
1135 1135
1136 w2->Activate(); 1136 w2->Activate();
1137 EXPECT_EQ(w2.get(), active()); 1137 EXPECT_EQ(w2.get(), active());
1138 1138
1139 w3->Activate(); 1139 w3->Activate();
1140 EXPECT_EQ(w2.get(), active()); 1140 EXPECT_EQ(w2.get(), active());
1141 1141
1142 w1->Activate(); 1142 w1->Activate();
1143 EXPECT_EQ(w1.get(), active()); 1143 EXPECT_EQ(w1.get(), active());
1144 } 1144 }
1145 1145
1146 } // namespace test 1146 } // namespace test
1147 } // namespace aura 1147 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.cc ('k') | ui/aura_shell/app_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698