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

Side by Side Diff: chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc

Issue 1198313003: Fix the browser match rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use scoped_ptr<Browser> instead. Created 5 years, 5 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
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 "ash/scoped_target_root_window.h" 5 #include "ash/scoped_target_root_window.h"
6 #include "ash/screen_util.h" 6 #include "ash/screen_util.h"
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "ash/test/test_shell_delegate.h" 9 #include "ash/test/test_shell_delegate.h"
10 #include "ash/wm/window_positioner.h" 10 #include "ash/wm/window_positioner.h"
(...skipping 11 matching lines...) Expand all
22 #include "ui/aura/env.h" 22 #include "ui/aura/env.h"
23 #include "ui/aura/test/test_windows.h" 23 #include "ui/aura/test/test_windows.h"
24 #include "ui/aura/window_event_dispatcher.h" 24 #include "ui/aura/window_event_dispatcher.h"
25 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
26 #include "ui/wm/public/activation_client.h" 26 #include "ui/wm/public/activation_client.h"
27 27
28 typedef ash::test::AshTestBase WindowSizerAshTest; 28 typedef ash::test::AshTestBase WindowSizerAshTest;
29 29
30 namespace { 30 namespace {
31 31
32 // A browser window proxy which is able to associate an aura native window with 32 scoped_ptr<Browser> CreateTestBrowser(aura::Window* window,
33 // it. 33 const gfx::Rect& bounds,
34 class TestBrowserWindowAura : public TestBrowserWindow { 34 Browser::CreateParams* params) {
35 public:
36 // |native_window| will still be owned by the caller after the constructor
37 // was called.
38 explicit TestBrowserWindowAura(aura::Window* native_window)
39 : native_window_(native_window) {
40 }
41 ~TestBrowserWindowAura() override {}
42
43 // TestBrowserWindow overrides:
44 void Show() override {
45 native_window_->Show();
46 Activate();
47 }
48 void Hide() override { native_window_->Hide(); }
49 void Activate() override {
50 aura::client::GetActivationClient(
51 native_window_->GetRootWindow())->ActivateWindow(native_window_.get());
52 }
53 gfx::NativeWindow GetNativeWindow() const override {
54 return native_window_.get();
55 }
56 gfx::Rect GetBounds() const override { return native_window_->bounds(); }
57
58 Browser* browser() { return browser_.get(); }
59
60 void CreateBrowser(const Browser::CreateParams& params) {
61 Browser::CreateParams create_params = params;
62 create_params.window = this;
63 browser_.reset(new Browser(create_params));
64 if (browser_->is_type_tabbed() || browser_->is_app()) {
65 ash::wm::GetWindowState(native_window_.get())->
66 set_window_position_managed(true);
67 }
68 }
69
70 private:
71 scoped_ptr<Browser> browser_;
72 scoped_ptr<aura::Window> native_window_;
73
74 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura);
75 };
76
77 scoped_ptr<TestBrowserWindowAura> CreateTestBrowserWindow(
78 aura::Window* window,
79 const gfx::Rect& bounds,
80 const Browser::CreateParams& params) {
81 if (!bounds.IsEmpty()) 35 if (!bounds.IsEmpty())
82 window->SetBounds(bounds); 36 window->SetBounds(bounds);
83 scoped_ptr<TestBrowserWindowAura> browser_window( 37 scoped_ptr<Browser> browser =
84 new TestBrowserWindowAura(window)); 38 chrome::CreateBrowserWithAuraTestWindowForParams(make_scoped_ptr(window),
85 browser_window->CreateBrowser(params); 39 params);
86 return browser_window.Pass(); 40 if (browser->is_type_tabbed() || browser->is_app()) {
41 ash::wm::GetWindowState(browser->window()->GetNativeWindow())
42 ->set_window_position_managed(true);
43 }
44 return browser.Pass();
87 } 45 }
88 46
89 } // namespace 47 } // namespace
90 48
91 // On desktop linux aura, we currently don't use the ash frame, breaking some 49 // On desktop linux aura, we currently don't use the ash frame, breaking some
92 // tests which expect ash sizes: http://crbug.com/303862 50 // tests which expect ash sizes: http://crbug.com/303862
93 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 51 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
94 #define MAYBE_DefaultSizeCase DISABLED_DefaultSizeCase 52 #define MAYBE_DefaultSizeCase DISABLED_DefaultSizeCase
95 #else 53 #else
96 #define MAYBE_DefaultSizeCase DefaultSizeCase 54 #define MAYBE_DefaultSizeCase DefaultSizeCase
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 #endif 422 #endif
465 423
466 // Test the placement of newly created windows. 424 // Test the placement of newly created windows.
467 TEST_F(WindowSizerAshTest, MAYBE_PlaceNewWindows) { 425 TEST_F(WindowSizerAshTest, MAYBE_PlaceNewWindows) {
468 // Create a browser to pass into the GetWindowBounds function. 426 // Create a browser to pass into the GetWindowBounds function.
469 scoped_ptr<TestingProfile> profile(new TestingProfile()); 427 scoped_ptr<TestingProfile> profile(new TestingProfile());
470 // Creating a popup handler here to make sure it does not interfere with the 428 // Creating a popup handler here to make sure it does not interfere with the
471 // existing windows. 429 // existing windows.
472 Browser::CreateParams native_params(profile.get(), 430 Browser::CreateParams native_params(profile.get(),
473 chrome::HOST_DESKTOP_TYPE_ASH); 431 chrome::HOST_DESKTOP_TYPE_ASH);
474 scoped_ptr<Browser> browser( 432 scoped_ptr<Browser> browser =
475 chrome::CreateBrowserWithTestWindowForParams(&native_params)); 433 chrome::CreateBrowserWithTestWindowForParams(&native_params);
476 434
477 // Creating a popup handler here to make sure it does not interfere with the 435 // Creating a popup handler here to make sure it does not interfere with the
478 // existing windows. 436 // existing windows.
479 scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( 437 Browser::CreateParams params2(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH);
480 CreateTestWindowInShellWithId(0), 438 scoped_ptr<Browser> browser2 = CreateTestBrowser(
481 gfx::Rect(16, 32, 640, 320), 439 CreateTestWindowInShellWithId(0), gfx::Rect(16, 32, 640, 320), &params2);
482 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH))); 440 BrowserWindow* browser_window = browser2->window();
483 441
484 // Creating a popup to make sure it does not interfere with the positioning. 442 // Creating a popup to make sure it does not interfere with the positioning.
485 scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow( 443 Browser::CreateParams params_popup(Browser::TYPE_POPUP, profile.get(),
486 CreateTestWindowInShellWithId(1), 444 chrome::HOST_DESKTOP_TYPE_ASH);
487 gfx::Rect(16, 32, 128, 256), 445 scoped_ptr<Browser> browser_popup =
488 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 446 CreateTestBrowser(CreateTestWindowInShellWithId(1),
489 chrome::HOST_DESKTOP_TYPE_ASH))); 447 gfx::Rect(16, 32, 128, 256), &params_popup);
490 448
491 // Creating a panel to make sure it does not interfere with the positioning. 449 // Creating a panel to make sure it does not interfere with the positioning.
492 scoped_ptr<BrowserWindow> browser_panel(CreateTestBrowserWindow( 450 Browser::CreateParams params_panel(Browser::TYPE_POPUP, profile.get(),
493 CreateTestWindowInShellWithId(2), 451 chrome::HOST_DESKTOP_TYPE_ASH);
494 gfx::Rect(32, 48, 256, 512), 452 scoped_ptr<Browser> browser_panel =
495 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 453 CreateTestBrowser(CreateTestWindowInShellWithId(2),
496 chrome::HOST_DESKTOP_TYPE_ASH))); 454 gfx::Rect(32, 48, 256, 512), &params_panel);
455
497 browser_window->Show(); 456 browser_window->Show();
498 { // Make sure that popups do not get changed. 457 { // Make sure that popups do not get changed.
499 gfx::Rect window_bounds; 458 gfx::Rect window_bounds;
500 GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), 459 GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
501 gfx::Rect(50, 100, 300, 150), bottom_s1600x1200, 460 gfx::Rect(50, 100, 300, 150), bottom_s1600x1200, PERSISTED,
502 PERSISTED, browser_popup->browser(), 461 browser_popup.get(), gfx::Rect(), &window_bounds);
503 gfx::Rect(), &window_bounds);
504 EXPECT_EQ("50,100 300x150", window_bounds.ToString()); 462 EXPECT_EQ("50,100 300x150", window_bounds.ToString());
505 } 463 }
506 464
507 browser_window->Hide(); 465 browser_window->Hide();
508 { // If a window is there but not shown the persisted default should be used. 466 { // If a window is there but not shown the persisted default should be used.
509 gfx::Rect window_bounds; 467 gfx::Rect window_bounds;
510 GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), 468 GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
511 gfx::Rect(50, 100, 300, 150), bottom_s1600x1200, 469 gfx::Rect(50, 100, 300, 150), bottom_s1600x1200,
512 PERSISTED, browser.get(), gfx::Rect(), &window_bounds); 470 PERSISTED, browser.get(), gfx::Rect(), &window_bounds);
513 EXPECT_EQ("50,100 300x150", window_bounds.ToString()); 471 EXPECT_EQ("50,100 300x150", window_bounds.ToString());
(...skipping 27 matching lines...) Expand all
541 #endif 499 #endif
542 500
543 // Test the placement of newly created windows on an empty desktop. 501 // Test the placement of newly created windows on an empty desktop.
544 // This test supplements "PlaceNewWindows" by testing the creation of a newly 502 // This test supplements "PlaceNewWindows" by testing the creation of a newly
545 // created browser window on an empty desktop. 503 // created browser window on an empty desktop.
546 TEST_F(WindowSizerAshTest, MAYBE_PlaceNewBrowserWindowOnEmptyDesktop) { 504 TEST_F(WindowSizerAshTest, MAYBE_PlaceNewBrowserWindowOnEmptyDesktop) {
547 // Create a browser to pass into the GetWindowBoundsAndShowState function. 505 // Create a browser to pass into the GetWindowBoundsAndShowState function.
548 scoped_ptr<TestingProfile> profile(new TestingProfile()); 506 scoped_ptr<TestingProfile> profile(new TestingProfile());
549 Browser::CreateParams native_params(profile.get(), 507 Browser::CreateParams native_params(profile.get(),
550 chrome::HOST_DESKTOP_TYPE_ASH); 508 chrome::HOST_DESKTOP_TYPE_ASH);
551 scoped_ptr<Browser> browser( 509 scoped_ptr<Browser> browser =
552 chrome::CreateBrowserWithTestWindowForParams(&native_params)); 510 chrome::CreateBrowserWithTestWindowForParams(&native_params);
553 511
554 // A common screen size for Chrome OS devices where this behavior is 512 // A common screen size for Chrome OS devices where this behavior is
555 // desirable. 513 // desirable.
556 const gfx::Rect p1366x768(0, 0, 1366, 768); 514 const gfx::Rect p1366x768(0, 0, 1366, 768);
557 515
558 // If there is no previous state the window should get maximized if the 516 // If there is no previous state the window should get maximized if the
559 // screen is less than or equal to our limit (1366 pixels width). 517 // screen is less than or equal to our limit (1366 pixels width).
560 gfx::Rect window_bounds; 518 gfx::Rect window_bounds;
561 ui::WindowShowState out_show_state1 = ui::SHOW_STATE_DEFAULT; 519 ui::WindowShowState out_show_state1 = ui::SHOW_STATE_DEFAULT;
562 GetWindowBoundsAndShowState( 520 GetWindowBoundsAndShowState(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 gfx::Rect primary_bounds = ash::Shell::GetInstance()->GetScreen()-> 585 gfx::Rect primary_bounds = ash::Shell::GetInstance()->GetScreen()->
628 GetPrimaryDisplay().bounds(); 586 GetPrimaryDisplay().bounds();
629 gfx::Rect secondary_bounds = ash::ScreenUtil::GetSecondaryDisplay().bounds(); 587 gfx::Rect secondary_bounds = ash::ScreenUtil::GetSecondaryDisplay().bounds();
630 588
631 ash::Shell::GetInstance()->set_target_root_window( 589 ash::Shell::GetInstance()->set_target_root_window(
632 ash::Shell::GetPrimaryRootWindow()); 590 ash::Shell::GetPrimaryRootWindow());
633 591
634 scoped_ptr<TestingProfile> profile(new TestingProfile()); 592 scoped_ptr<TestingProfile> profile(new TestingProfile());
635 593
636 // Create browser windows that are used as reference. 594 // Create browser windows that are used as reference.
637 scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( 595 Browser::CreateParams params(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH);
638 CreateTestWindowInShellWithId(0), 596 scoped_ptr<Browser> browser = CreateTestBrowser(
639 gfx::Rect(10, 10, 200, 200), 597 CreateTestWindowInShellWithId(0), gfx::Rect(10, 10, 200, 200), &params);
640 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH))); 598 BrowserWindow* browser_window = browser->window();
599 gfx::NativeWindow native_window = browser_window->GetNativeWindow();
641 browser_window->Show(); 600 browser_window->Show();
642 EXPECT_EQ(browser_window->GetNativeWindow()->GetRootWindow(), 601 EXPECT_EQ(native_window->GetRootWindow(), ash::Shell::GetTargetRootWindow());
643 ash::Shell::GetTargetRootWindow());
644 602
645 scoped_ptr<BrowserWindow> another_browser_window(CreateTestBrowserWindow( 603 Browser::CreateParams another_params(profile.get(),
646 CreateTestWindowInShellWithId(1), 604 chrome::HOST_DESKTOP_TYPE_ASH);
647 gfx::Rect(400, 10, 300, 300), 605 scoped_ptr<Browser> another_browser =
648 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH))); 606 CreateTestBrowser(CreateTestWindowInShellWithId(1),
607 gfx::Rect(400, 10, 300, 300), &another_params);
608 BrowserWindow* another_browser_window = another_browser->window();
609 gfx::NativeWindow another_native_window =
610 another_browser_window->GetNativeWindow();
649 another_browser_window->Show(); 611 another_browser_window->Show();
650 612
651 // Creating a new window to verify the new placement. 613 // Creating a new window to verify the new placement.
652 scoped_ptr<TestBrowserWindowAura> new_browser_window(CreateTestBrowserWindow( 614 Browser::CreateParams new_params(profile.get(),
653 CreateTestWindowInShellWithId(0), 615 chrome::HOST_DESKTOP_TYPE_ASH);
654 gfx::Rect(), 616 scoped_ptr<Browser> new_browser = CreateTestBrowser(
655 Browser::CreateParams(profile.get(), 617 CreateTestWindowInShellWithId(0), gfx::Rect(), &new_params);
656 chrome::HOST_DESKTOP_TYPE_ASH)));
657 618
658 // Make sure the primary root is active. 619 // Make sure the primary root is active.
659 ASSERT_EQ(ash::Shell::GetPrimaryRootWindow(), 620 ASSERT_EQ(ash::Shell::GetPrimaryRootWindow(),
660 ash::Shell::GetTargetRootWindow()); 621 ash::Shell::GetTargetRootWindow());
661 622
662 // First new window should be in the primary. 623 // First new window should be in the primary.
663 { 624 {
664 gfx::Rect window_bounds; 625 gfx::Rect window_bounds;
665 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, 626 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, gfx::Rect(),
666 gfx::Rect(), secondary_bounds, 627 secondary_bounds, PERSISTED, new_browser.get(), gfx::Rect(),
667 PERSISTED, new_browser_window->browser(), 628 &window_bounds);
668 gfx::Rect(), &window_bounds);
669 // TODO(oshima): Use exact bounds when the window_sizer_ash is 629 // TODO(oshima): Use exact bounds when the window_sizer_ash is
670 // moved to ash and changed to include the result from 630 // moved to ash and changed to include the result from
671 // RearrangeVisibleWindowOnShow. 631 // RearrangeVisibleWindowOnShow.
672 EXPECT_TRUE(primary_bounds.Contains(window_bounds)); 632 EXPECT_TRUE(primary_bounds.Contains(window_bounds));
673 } 633 }
674 634
675 // Move the window to the right side of the secondary display and create a new 635 // Move the window to the right side of the secondary display and create a new
676 // window. It should be opened then on the secondary display. 636 // window. It should be opened then on the secondary display.
677 { 637 {
678 gfx::Display second_display = ash::Shell::GetScreen()-> 638 gfx::Display second_display = ash::Shell::GetScreen()->
679 GetDisplayNearestPoint(gfx::Point(1600 + 100,10)); 639 GetDisplayNearestPoint(gfx::Point(1600 + 100,10));
680 browser_window->GetNativeWindow()->SetBoundsInScreen( 640 browser_window->GetNativeWindow()->SetBoundsInScreen(
681 gfx::Rect(secondary_bounds.CenterPoint().x() - 100, 10, 200, 200), 641 gfx::Rect(secondary_bounds.CenterPoint().x() - 100, 10, 200, 200),
682 second_display); 642 second_display);
683 browser_window->Activate(); 643 aura::client::GetActivationClient(native_window->GetRootWindow())
644 ->ActivateWindow(native_window);
684 EXPECT_NE(ash::Shell::GetPrimaryRootWindow(), 645 EXPECT_NE(ash::Shell::GetPrimaryRootWindow(),
685 ash::Shell::GetTargetRootWindow()); 646 ash::Shell::GetTargetRootWindow());
686 gfx::Rect window_bounds; 647 gfx::Rect window_bounds;
687 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, 648 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, gfx::Rect(),
688 gfx::Rect(), secondary_bounds, 649 secondary_bounds, PERSISTED, new_browser.get(), gfx::Rect(),
689 PERSISTED, new_browser_window->browser(), 650 &window_bounds);
690 gfx::Rect(), &window_bounds);
691 // TODO(oshima): Use exact bounds when the window_sizer_ash is 651 // TODO(oshima): Use exact bounds when the window_sizer_ash is
692 // moved to ash and changed to include the result from 652 // moved to ash and changed to include the result from
693 // RearrangeVisibleWindowOnShow. 653 // RearrangeVisibleWindowOnShow.
694 EXPECT_TRUE(secondary_bounds.Contains(window_bounds)); 654 EXPECT_TRUE(secondary_bounds.Contains(window_bounds));
695 } 655 }
696 656
697 // Activate another window in the primary display and create a new window. 657 // Activate another window in the primary display and create a new window.
698 // It should be created in the primary display. 658 // It should be created in the primary display.
699 { 659 {
700 another_browser_window->Activate(); 660 aura::client::GetActivationClient(another_native_window->GetRootWindow())
661 ->ActivateWindow(another_native_window);
701 EXPECT_EQ(ash::Shell::GetPrimaryRootWindow(), 662 EXPECT_EQ(ash::Shell::GetPrimaryRootWindow(),
702 ash::Shell::GetTargetRootWindow()); 663 ash::Shell::GetTargetRootWindow());
703 664
704 gfx::Rect window_bounds; 665 gfx::Rect window_bounds;
705 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, 666 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, gfx::Rect(),
706 gfx::Rect(), secondary_bounds, 667 secondary_bounds, PERSISTED, new_browser.get(), gfx::Rect(),
707 PERSISTED, new_browser_window->browser(), 668 &window_bounds);
708 gfx::Rect(), &window_bounds);
709 // TODO(oshima): Use exact bounds when the window_sizer_ash is 669 // TODO(oshima): Use exact bounds when the window_sizer_ash is
710 // moved to ash and changed to include the result from 670 // moved to ash and changed to include the result from
711 // RearrangeVisibleWindowOnShow. 671 // RearrangeVisibleWindowOnShow.
712 EXPECT_TRUE(primary_bounds.Contains(window_bounds)); 672 EXPECT_TRUE(primary_bounds.Contains(window_bounds));
713 } 673 }
714 } 674 }
715 675
716 // On desktop linux aura, we currently don't use the ash frame, breaking some 676 // On desktop linux aura, we currently don't use the ash frame, breaking some
717 // tests which expect ash sizes: http://crbug.com/303862 677 // tests which expect ash sizes: http://crbug.com/303862
718 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 678 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
719 #define MAYBE_TestShowState DISABLED_TestShowState 679 #define MAYBE_TestShowState DISABLED_TestShowState
720 #else 680 #else
721 #define MAYBE_TestShowState TestShowState 681 #define MAYBE_TestShowState TestShowState
722 #endif 682 #endif
723 683
724 // Test that the show state is properly returned for non default cases. 684 // Test that the show state is properly returned for non default cases.
725 TEST_F(WindowSizerAshTest, MAYBE_TestShowState) { 685 TEST_F(WindowSizerAshTest, MAYBE_TestShowState) {
726 scoped_ptr<TestingProfile> profile(new TestingProfile()); 686 scoped_ptr<TestingProfile> profile(new TestingProfile());
727 687
728 // Creating a browser & window to play with. 688 // Creating a browser & window to play with.
729 scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow( 689 Browser::CreateParams params(Browser::TYPE_TABBED, profile.get(),
730 CreateTestWindowInShellWithId(0), 690 chrome::HOST_DESKTOP_TYPE_ASH);
731 gfx::Rect(16, 32, 640, 320), 691 scoped_ptr<Browser> browser = CreateTestBrowser(
732 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), 692 CreateTestWindowInShellWithId(0), gfx::Rect(16, 32, 640, 320), &params);
733 chrome::HOST_DESKTOP_TYPE_ASH)));
734 693
735 // Create also a popup browser since that behaves different. 694 // Create also a popup browser since that behaves different.
736 scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow( 695 Browser::CreateParams params_popup(Browser::TYPE_POPUP, profile.get(),
737 CreateTestWindowInShellWithId(1), 696 chrome::HOST_DESKTOP_TYPE_ASH);
738 gfx::Rect(16, 32, 640, 320), 697 scoped_ptr<Browser> browser_popup =
739 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 698 CreateTestBrowser(CreateTestWindowInShellWithId(1),
740 chrome::HOST_DESKTOP_TYPE_ASH))); 699 gfx::Rect(16, 32, 640, 320), &params_popup);
741 700
742 // Tabbed windows should retrieve the saved window state - since there is a 701 // Tabbed windows should retrieve the saved window state - since there is a
743 // top window. 702 // top window.
744 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 703 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
745 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 704 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_NORMAL,
746 ui::SHOW_STATE_NORMAL, 705 BOTH, browser.get(), p1600x1200, p1600x1200));
747 BOTH,
748 browser_window->browser(),
749 p1600x1200,
750 p1600x1200));
751 // A window that is smaller than the whole work area is set to default state. 706 // A window that is smaller than the whole work area is set to default state.
752 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 707 EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
753 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 708 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL,
754 ui::SHOW_STATE_NORMAL, 709 BOTH, browser.get(), p1280x1024, p1600x1200));
755 BOTH,
756 browser_window->browser(),
757 p1280x1024,
758 p1600x1200));
759 // A window that is sized to occupy the whole work area is maximized. 710 // A window that is sized to occupy the whole work area is maximized.
760 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 711 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
761 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 712 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL,
762 ui::SHOW_STATE_NORMAL, 713 BOTH, browser.get(), p1600x1200, p1600x1200));
763 BOTH,
764 browser_window->browser(),
765 p1600x1200,
766 p1600x1200));
767 // Non tabbed windows should always follow the window saved visibility state. 714 // Non tabbed windows should always follow the window saved visibility state.
768 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 715 EXPECT_EQ(
769 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 716 ui::SHOW_STATE_MAXIMIZED,
770 ui::SHOW_STATE_NORMAL, 717 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_NORMAL, BOTH,
771 BOTH, 718 browser_popup.get(), p1600x1200, p1600x1200));
772 browser_popup->browser(),
773 p1600x1200,
774 p1600x1200));
775 // The non tabbed window will take the status of the last active of its kind. 719 // The non tabbed window will take the status of the last active of its kind.
776 EXPECT_EQ(ui::SHOW_STATE_NORMAL, 720 EXPECT_EQ(
777 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 721 ui::SHOW_STATE_NORMAL,
778 ui::SHOW_STATE_NORMAL, 722 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL, BOTH,
779 BOTH, 723 browser_popup.get(), p1600x1200, p1600x1200));
780 browser_popup->browser(),
781 p1600x1200,
782 p1600x1200));
783 724
784 // Now create a top level window and check again for both. Only the tabbed 725 // Now create a top level window and check again for both. Only the tabbed
785 // window should follow the top level window's state. 726 // window should follow the top level window's state.
786 // Creating a browser & window to play with. 727 // Creating a browser & window to play with.
787 scoped_ptr<TestBrowserWindowAura> browser_window2(CreateTestBrowserWindow( 728 Browser::CreateParams params2(Browser::TYPE_TABBED, profile.get(),
788 CreateTestWindowInShellWithId(3), 729 chrome::HOST_DESKTOP_TYPE_ASH);
789 gfx::Rect(16, 32, 640, 320), 730 scoped_ptr<Browser> browser2 = CreateTestBrowser(
790 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), 731 CreateTestWindowInShellWithId(3), gfx::Rect(16, 32, 640, 320), &params2);
791 chrome::HOST_DESKTOP_TYPE_ASH)));
792 732
793 // A tabbed window should now take the top level window state. 733 // A tabbed window should now take the top level window state.
794 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 734 EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
795 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 735 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_DEFAULT,
796 ui::SHOW_STATE_DEFAULT, 736 BOTH, browser.get(), p1600x1200, p1600x1200));
797 BOTH,
798 browser_window->browser(),
799 p1600x1200,
800 p1600x1200));
801 // Non tabbed windows should always follow the window saved visibility state. 737 // Non tabbed windows should always follow the window saved visibility state.
802 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 738 EXPECT_EQ(
803 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 739 ui::SHOW_STATE_MAXIMIZED,
804 ui::SHOW_STATE_MINIMIZED, 740 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_MINIMIZED,
805 BOTH, 741 BOTH, browser_popup.get(), p1600x1200, p1600x1200));
806 browser_popup->browser(),
807 p1600x1200,
808 p1600x1200));
809 742
810 // In smaller screen resolutions we default to maximized if there is no other 743 // In smaller screen resolutions we default to maximized if there is no other
811 // window visible. 744 // window visible.
812 int min_size = ash::WindowPositioner::GetForceMaximizedWidthLimit() / 2; 745 int min_size = ash::WindowPositioner::GetForceMaximizedWidthLimit() / 2;
813 if (min_size > 0) { 746 if (min_size > 0) {
814 const gfx::Rect tiny_screen(0, 0, min_size, min_size); 747 const gfx::Rect tiny_screen(0, 0, min_size, min_size);
815 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 748 EXPECT_EQ(
816 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 749 ui::SHOW_STATE_DEFAULT,
817 ui::SHOW_STATE_DEFAULT, 750 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_DEFAULT,
818 BOTH, 751 BOTH, browser.get(), tiny_screen, tiny_screen));
819 browser_window->browser(), 752 browser->window()->Hide();
820 tiny_screen, 753 EXPECT_EQ(
821 tiny_screen)); 754 ui::SHOW_STATE_MAXIMIZED,
822 browser_window->Hide(); 755 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_DEFAULT,
823 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 756 BOTH, browser2.get(), tiny_screen, tiny_screen));
824 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
825 ui::SHOW_STATE_DEFAULT,
826 BOTH,
827 browser_window2->browser(),
828 tiny_screen,
829 tiny_screen));
830
831 } 757 }
832 } 758 }
833 759
834 // Test that the default show state override behavior is properly handled. 760 // Test that the default show state override behavior is properly handled.
835 TEST_F(WindowSizerAshTest, TestShowStateDefaults) { 761 TEST_F(WindowSizerAshTest, TestShowStateDefaults) {
836 // Creating a browser & window to play with. 762 // Creating a browser & window to play with.
837 scoped_ptr<TestingProfile> profile(new TestingProfile()); 763 scoped_ptr<TestingProfile> profile(new TestingProfile());
838 764
839 scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow( 765 Browser::CreateParams params(Browser::TYPE_TABBED, profile.get(),
840 CreateTestWindowInShellWithId(0), 766 chrome::HOST_DESKTOP_TYPE_ASH);
841 gfx::Rect(16, 32, 640, 320), 767 scoped_ptr<Browser> browser = CreateTestBrowser(
842 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), 768 CreateTestWindowInShellWithId(0), gfx::Rect(16, 32, 640, 320), &params);
843 chrome::HOST_DESKTOP_TYPE_ASH)));
844 769
845 // Create also a popup browser since that behaves slightly different for 770 // Create also a popup browser since that behaves slightly different for
846 // defaults. 771 // defaults.
847 scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow( 772 Browser::CreateParams params_popup(Browser::TYPE_POPUP, profile.get(),
848 CreateTestWindowInShellWithId(1), 773 chrome::HOST_DESKTOP_TYPE_ASH);
849 gfx::Rect(16, 32, 128, 256), 774 scoped_ptr<Browser> browser_popup =
850 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 775 CreateTestBrowser(CreateTestWindowInShellWithId(1),
851 chrome::HOST_DESKTOP_TYPE_ASH))); 776 gfx::Rect(16, 32, 128, 256), &params_popup);
852 777
853 // Check that a browser creation state always get used if not given as 778 // Check that a browser creation state always get used if not given as
854 // SHOW_STATE_DEFAULT. On Windows ASH it should be SHOW_STATE_MAXIMIZED. 779 // SHOW_STATE_DEFAULT. On Windows ASH it should be SHOW_STATE_MAXIMIZED.
855 ui::WindowShowState window_show_state = 780 ui::WindowShowState window_show_state =
856 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 781 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_MAXIMIZED,
857 ui::SHOW_STATE_MAXIMIZED, 782 DEFAULT, browser.get(), p1600x1200, p1600x1200);
858 DEFAULT,
859 browser_window->browser(),
860 p1600x1200,
861 p1600x1200);
862 #if defined(OS_WIN) 783 #if defined(OS_WIN)
863 EXPECT_EQ(window_show_state, ui::SHOW_STATE_MAXIMIZED); 784 EXPECT_EQ(window_show_state, ui::SHOW_STATE_MAXIMIZED);
864 #else 785 #else
865 EXPECT_EQ(window_show_state, ui::SHOW_STATE_DEFAULT); 786 EXPECT_EQ(window_show_state, ui::SHOW_STATE_DEFAULT);
866 #endif 787 #endif
867 788
868 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MINIMIZED); 789 browser->set_initial_show_state(ui::SHOW_STATE_MINIMIZED);
869 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 790 EXPECT_EQ(
870 ui::SHOW_STATE_MAXIMIZED, 791 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_MAXIMIZED,
871 BOTH, 792 BOTH, browser.get(), p1600x1200, p1600x1200),
872 browser_window->browser(), 793 ui::SHOW_STATE_MINIMIZED);
873 p1600x1200, 794 browser->set_initial_show_state(ui::SHOW_STATE_NORMAL);
874 p1600x1200), ui::SHOW_STATE_MINIMIZED); 795 EXPECT_EQ(
875 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); 796 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_MAXIMIZED,
876 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 797 BOTH, browser.get(), p1600x1200, p1600x1200),
877 ui::SHOW_STATE_MAXIMIZED, 798 ui::SHOW_STATE_NORMAL);
878 BOTH, 799 browser->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED);
879 browser_window->browser(), 800 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, ui::SHOW_STATE_NORMAL,
880 p1600x1200, 801 BOTH, browser.get(), p1600x1200, p1600x1200),
881 p1600x1200), ui::SHOW_STATE_NORMAL); 802 ui::SHOW_STATE_MAXIMIZED);
882 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED);
883 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
884 ui::SHOW_STATE_NORMAL,
885 BOTH,
886 browser_window->browser(),
887 p1600x1200,
888 p1600x1200), ui::SHOW_STATE_MAXIMIZED);
889 803
890 // Check that setting the maximized command line option is forcing the 804 // Check that setting the maximized command line option is forcing the
891 // maximized state. 805 // maximized state.
892 base::CommandLine::ForCurrentProcess()->AppendSwitch( 806 base::CommandLine::ForCurrentProcess()->AppendSwitch(
893 switches::kStartMaximized); 807 switches::kStartMaximized);
894 808
895 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); 809 browser->set_initial_show_state(ui::SHOW_STATE_NORMAL);
896 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, 810 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, ui::SHOW_STATE_NORMAL,
897 ui::SHOW_STATE_NORMAL, 811 BOTH, browser.get(), p1600x1200, p1600x1200),
898 BOTH, 812 ui::SHOW_STATE_MAXIMIZED);
899 browser_window->browser(),
900 p1600x1200,
901 p1600x1200), ui::SHOW_STATE_MAXIMIZED);
902 813
903 // The popup should favor the initial show state over the command line. 814 // The popup should favor the initial show state over the command line.
904 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, 815 EXPECT_EQ(
905 ui::SHOW_STATE_NORMAL, 816 GetWindowShowState(ui::SHOW_STATE_NORMAL, ui::SHOW_STATE_NORMAL, BOTH,
906 BOTH, 817 browser_popup.get(), p1600x1200, p1600x1200),
907 browser_popup->browser(), 818 ui::SHOW_STATE_NORMAL);
908 p1600x1200,
909 p1600x1200), ui::SHOW_STATE_NORMAL);
910 } 819 }
911 820
912 TEST_F(WindowSizerAshTest, DefaultStateBecomesMaximized) { 821 TEST_F(WindowSizerAshTest, DefaultStateBecomesMaximized) {
913 // Create a browser to pass into the GetWindowBounds function. 822 // Create a browser to pass into the GetWindowBounds function.
914 scoped_ptr<TestingProfile> profile(new TestingProfile()); 823 scoped_ptr<TestingProfile> profile(new TestingProfile());
915 Browser::CreateParams native_params(profile.get(), 824 Browser::CreateParams native_params(profile.get(),
916 chrome::HOST_DESKTOP_TYPE_ASH); 825 chrome::HOST_DESKTOP_TYPE_ASH);
917 scoped_ptr<Browser> browser( 826 scoped_ptr<Browser> browser =
918 chrome::CreateBrowserWithTestWindowForParams(&native_params)); 827 chrome::CreateBrowserWithTestWindowForParams(&native_params);
919 828
920 gfx::Rect display_bounds = ash::Shell::GetInstance()->GetScreen()-> 829 gfx::Rect display_bounds = ash::Shell::GetInstance()->GetScreen()->
921 GetPrimaryDisplay().bounds(); 830 GetPrimaryDisplay().bounds();
922 gfx::Rect specified_bounds = display_bounds; 831 gfx::Rect specified_bounds = display_bounds;
923 832
924 // Make a window bigger than the display work area. 833 // Make a window bigger than the display work area.
925 specified_bounds.Inset(-20, -20); 834 specified_bounds.Inset(-20, -20);
926 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT; 835 ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT;
927 gfx::Rect bounds; 836 gfx::Rect bounds;
928 WindowSizer::GetBrowserWindowBoundsAndShowState( 837 WindowSizer::GetBrowserWindowBoundsAndShowState(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 EXPECT_TRUE(second_root->GetBoundsInScreen().Contains(bounds)); 888 EXPECT_TRUE(second_root->GetBoundsInScreen().Contains(bounds));
980 } 889 }
981 } 890 }
982 891
983 TEST_F(WindowSizerAshTest, TrustedPopupBehavior) { 892 TEST_F(WindowSizerAshTest, TrustedPopupBehavior) {
984 scoped_ptr<TestingProfile> profile(new TestingProfile()); 893 scoped_ptr<TestingProfile> profile(new TestingProfile());
985 Browser::CreateParams trusted_popup_create_params( 894 Browser::CreateParams trusted_popup_create_params(
986 Browser::TYPE_POPUP, profile.get(), chrome::HOST_DESKTOP_TYPE_ASH); 895 Browser::TYPE_POPUP, profile.get(), chrome::HOST_DESKTOP_TYPE_ASH);
987 trusted_popup_create_params.trusted_source = true; 896 trusted_popup_create_params.trusted_source = true;
988 897
989 scoped_ptr<TestBrowserWindowAura> trusted_popup(CreateTestBrowserWindow( 898 scoped_ptr<Browser> trusted_popup = CreateTestBrowser(
990 CreateTestWindowInShellWithId(1), 899 CreateTestWindowInShellWithId(1), gfx::Rect(16, 32, 640, 320),
991 gfx::Rect(16, 32, 640, 320), 900 &trusted_popup_create_params);
992 trusted_popup_create_params));
993 // Trusted popup windows should follow the saved show state and ignore the 901 // Trusted popup windows should follow the saved show state and ignore the
994 // last show state. 902 // last show state.
995 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 903 EXPECT_EQ(
996 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 904 ui::SHOW_STATE_DEFAULT,
997 ui::SHOW_STATE_NORMAL, 905 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL, BOTH,
998 BOTH, 906 trusted_popup.get(), p1280x1024, p1600x1200));
999 trusted_popup->browser(),
1000 p1280x1024,
1001 p1600x1200));
1002 // A popup that is sized to occupy the whole work area has default state. 907 // A popup that is sized to occupy the whole work area has default state.
1003 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 908 EXPECT_EQ(
1004 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 909 ui::SHOW_STATE_DEFAULT,
1005 ui::SHOW_STATE_NORMAL, 910 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL, BOTH,
1006 BOTH, 911 trusted_popup.get(), p1600x1200, p1600x1200));
1007 trusted_popup->browser(),
1008 p1600x1200,
1009 p1600x1200));
1010 } 912 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698