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

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: Address msw@'s comments. 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 const 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 = chrome::CreateBrowserForAuraTestWindowAndParams(
84 new TestBrowserWindowAura(window)); 38 make_scoped_ptr(window), params);
85 browser_window->CreateBrowser(params); 39 if (browser->is_type_tabbed() || browser->is_app()) {
86 return browser_window.Pass(); 40 ash::wm::GetWindowState(browser->window()->GetNativeWindow())
41 ->set_window_position_managed(true);
42 }
43 return browser.Pass();
87 } 44 }
88 45
89 } // namespace 46 } // namespace
90 47
91 // On desktop linux aura, we currently don't use the ash frame, breaking some 48 // On desktop linux aura, we currently don't use the ash frame, breaking some
92 // tests which expect ash sizes: http://crbug.com/303862 49 // tests which expect ash sizes: http://crbug.com/303862
93 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 50 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
94 #define MAYBE_DefaultSizeCase DISABLED_DefaultSizeCase 51 #define MAYBE_DefaultSizeCase DISABLED_DefaultSizeCase
95 #else 52 #else
96 #define MAYBE_DefaultSizeCase DefaultSizeCase 53 #define MAYBE_DefaultSizeCase DefaultSizeCase
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 scoped_ptr<TestingProfile> profile(new TestingProfile()); 426 scoped_ptr<TestingProfile> profile(new TestingProfile());
470 // Creating a popup handler here to make sure it does not interfere with the 427 // Creating a popup handler here to make sure it does not interfere with the
471 // existing windows. 428 // existing windows.
472 Browser::CreateParams native_params(profile.get(), 429 Browser::CreateParams native_params(profile.get(),
473 chrome::HOST_DESKTOP_TYPE_ASH); 430 chrome::HOST_DESKTOP_TYPE_ASH);
474 scoped_ptr<Browser> browser( 431 scoped_ptr<Browser> browser(
475 chrome::CreateBrowserWithTestWindowForParams(&native_params)); 432 chrome::CreateBrowserWithTestWindowForParams(&native_params));
476 433
477 // Creating a popup handler here to make sure it does not interfere with the 434 // Creating a popup handler here to make sure it does not interfere with the
478 // existing windows. 435 // existing windows.
479 scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( 436 scoped_ptr<Browser> browser2 = CreateTestBrowser(
480 CreateTestWindowInShellWithId(0), 437 CreateTestWindowInShellWithId(0), gfx::Rect(16, 32, 640, 320),
481 gfx::Rect(16, 32, 640, 320), 438 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH));
482 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH))); 439 BrowserWindow* browser_window = browser2->window();
483 440
484 // Creating a popup to make sure it does not interfere with the positioning. 441 // Creating a popup to make sure it does not interfere with the positioning.
485 scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow( 442 scoped_ptr<Browser> browser_popup = CreateTestBrowser(
486 CreateTestWindowInShellWithId(1), 443 CreateTestWindowInShellWithId(1), gfx::Rect(16, 32, 128, 256),
487 gfx::Rect(16, 32, 128, 256),
488 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 444 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
489 chrome::HOST_DESKTOP_TYPE_ASH))); 445 chrome::HOST_DESKTOP_TYPE_ASH));
490 446
491 // Creating a panel to make sure it does not interfere with the positioning. 447 // Creating a panel to make sure it does not interfere with the positioning.
492 scoped_ptr<BrowserWindow> browser_panel(CreateTestBrowserWindow( 448 scoped_ptr<Browser> browser_panel = CreateTestBrowser(
493 CreateTestWindowInShellWithId(2), 449 CreateTestWindowInShellWithId(2), gfx::Rect(32, 48, 256, 512),
494 gfx::Rect(32, 48, 256, 512),
495 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 450 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
496 chrome::HOST_DESKTOP_TYPE_ASH))); 451 chrome::HOST_DESKTOP_TYPE_ASH));
452
497 browser_window->Show(); 453 browser_window->Show();
498 { // Make sure that popups do not get changed. 454 { // Make sure that popups do not get changed.
499 gfx::Rect window_bounds; 455 gfx::Rect window_bounds;
500 GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), 456 GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
501 gfx::Rect(50, 100, 300, 150), bottom_s1600x1200, 457 gfx::Rect(50, 100, 300, 150), bottom_s1600x1200, PERSISTED,
502 PERSISTED, browser_popup->browser(), 458 browser_popup.get(), gfx::Rect(), &window_bounds);
503 gfx::Rect(), &window_bounds);
504 EXPECT_EQ("50,100 300x150", window_bounds.ToString()); 459 EXPECT_EQ("50,100 300x150", window_bounds.ToString());
505 } 460 }
506 461
507 browser_window->Hide(); 462 browser_window->Hide();
508 { // If a window is there but not shown the persisted default should be used. 463 { // If a window is there but not shown the persisted default should be used.
509 gfx::Rect window_bounds; 464 gfx::Rect window_bounds;
510 GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), 465 GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
511 gfx::Rect(50, 100, 300, 150), bottom_s1600x1200, 466 gfx::Rect(50, 100, 300, 150), bottom_s1600x1200,
512 PERSISTED, browser.get(), gfx::Rect(), &window_bounds); 467 PERSISTED, browser.get(), gfx::Rect(), &window_bounds);
513 EXPECT_EQ("50,100 300x150", window_bounds.ToString()); 468 EXPECT_EQ("50,100 300x150", window_bounds.ToString());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 gfx::Rect primary_bounds = ash::Shell::GetInstance()->GetScreen()-> 582 gfx::Rect primary_bounds = ash::Shell::GetInstance()->GetScreen()->
628 GetPrimaryDisplay().bounds(); 583 GetPrimaryDisplay().bounds();
629 gfx::Rect secondary_bounds = ash::ScreenUtil::GetSecondaryDisplay().bounds(); 584 gfx::Rect secondary_bounds = ash::ScreenUtil::GetSecondaryDisplay().bounds();
630 585
631 ash::Shell::GetInstance()->set_target_root_window( 586 ash::Shell::GetInstance()->set_target_root_window(
632 ash::Shell::GetPrimaryRootWindow()); 587 ash::Shell::GetPrimaryRootWindow());
633 588
634 scoped_ptr<TestingProfile> profile(new TestingProfile()); 589 scoped_ptr<TestingProfile> profile(new TestingProfile());
635 590
636 // Create browser windows that are used as reference. 591 // Create browser windows that are used as reference.
637 scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( 592 scoped_ptr<Browser> browser = CreateTestBrowser(
638 CreateTestWindowInShellWithId(0), 593 CreateTestWindowInShellWithId(0), gfx::Rect(10, 10, 200, 200),
639 gfx::Rect(10, 10, 200, 200), 594 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH));
640 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH))); 595 BrowserWindow* browser_window = browser->window();
596 gfx::NativeWindow native_window = browser_window->GetNativeWindow();
641 browser_window->Show(); 597 browser_window->Show();
642 EXPECT_EQ(browser_window->GetNativeWindow()->GetRootWindow(), 598 EXPECT_EQ(native_window->GetRootWindow(), ash::Shell::GetTargetRootWindow());
643 ash::Shell::GetTargetRootWindow());
644 599
645 scoped_ptr<BrowserWindow> another_browser_window(CreateTestBrowserWindow( 600 scoped_ptr<Browser> another_browser = CreateTestBrowser(
646 CreateTestWindowInShellWithId(1), 601 CreateTestWindowInShellWithId(1), gfx::Rect(400, 10, 300, 300),
647 gfx::Rect(400, 10, 300, 300), 602 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH));
648 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH))); 603 BrowserWindow* another_browser_window = another_browser->window();
604 gfx::NativeWindow another_native_window =
605 another_browser_window->GetNativeWindow();
649 another_browser_window->Show(); 606 another_browser_window->Show();
650 607
651 // Creating a new window to verify the new placement. 608 // Creating a new window to verify the new placement.
652 scoped_ptr<TestBrowserWindowAura> new_browser_window(CreateTestBrowserWindow( 609 scoped_ptr<Browser> new_browser = CreateTestBrowser(
653 CreateTestWindowInShellWithId(0), 610 CreateTestWindowInShellWithId(0), gfx::Rect(),
654 gfx::Rect(), 611 Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH));
655 Browser::CreateParams(profile.get(),
656 chrome::HOST_DESKTOP_TYPE_ASH)));
657 612
658 // Make sure the primary root is active. 613 // Make sure the primary root is active.
659 ASSERT_EQ(ash::Shell::GetPrimaryRootWindow(), 614 ASSERT_EQ(ash::Shell::GetPrimaryRootWindow(),
660 ash::Shell::GetTargetRootWindow()); 615 ash::Shell::GetTargetRootWindow());
661 616
662 // First new window should be in the primary. 617 // First new window should be in the primary.
663 { 618 {
664 gfx::Rect window_bounds; 619 gfx::Rect window_bounds;
665 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, 620 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, gfx::Rect(),
666 gfx::Rect(), secondary_bounds, 621 secondary_bounds, PERSISTED, new_browser.get(), gfx::Rect(),
667 PERSISTED, new_browser_window->browser(), 622 &window_bounds);
668 gfx::Rect(), &window_bounds);
669 // TODO(oshima): Use exact bounds when the window_sizer_ash is 623 // TODO(oshima): Use exact bounds when the window_sizer_ash is
670 // moved to ash and changed to include the result from 624 // moved to ash and changed to include the result from
671 // RearrangeVisibleWindowOnShow. 625 // RearrangeVisibleWindowOnShow.
672 EXPECT_TRUE(primary_bounds.Contains(window_bounds)); 626 EXPECT_TRUE(primary_bounds.Contains(window_bounds));
673 } 627 }
674 628
675 // Move the window to the right side of the secondary display and create a new 629 // 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. 630 // window. It should be opened then on the secondary display.
677 { 631 {
678 gfx::Display second_display = ash::Shell::GetScreen()-> 632 gfx::Display second_display = ash::Shell::GetScreen()->
679 GetDisplayNearestPoint(gfx::Point(1600 + 100,10)); 633 GetDisplayNearestPoint(gfx::Point(1600 + 100,10));
680 browser_window->GetNativeWindow()->SetBoundsInScreen( 634 browser_window->GetNativeWindow()->SetBoundsInScreen(
681 gfx::Rect(secondary_bounds.CenterPoint().x() - 100, 10, 200, 200), 635 gfx::Rect(secondary_bounds.CenterPoint().x() - 100, 10, 200, 200),
682 second_display); 636 second_display);
683 browser_window->Activate(); 637 aura::client::GetActivationClient(native_window->GetRootWindow())
638 ->ActivateWindow(native_window);
684 EXPECT_NE(ash::Shell::GetPrimaryRootWindow(), 639 EXPECT_NE(ash::Shell::GetPrimaryRootWindow(),
685 ash::Shell::GetTargetRootWindow()); 640 ash::Shell::GetTargetRootWindow());
686 gfx::Rect window_bounds; 641 gfx::Rect window_bounds;
687 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, 642 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, gfx::Rect(),
688 gfx::Rect(), secondary_bounds, 643 secondary_bounds, PERSISTED, new_browser.get(), gfx::Rect(),
689 PERSISTED, new_browser_window->browser(), 644 &window_bounds);
690 gfx::Rect(), &window_bounds);
691 // TODO(oshima): Use exact bounds when the window_sizer_ash is 645 // TODO(oshima): Use exact bounds when the window_sizer_ash is
692 // moved to ash and changed to include the result from 646 // moved to ash and changed to include the result from
693 // RearrangeVisibleWindowOnShow. 647 // RearrangeVisibleWindowOnShow.
694 EXPECT_TRUE(secondary_bounds.Contains(window_bounds)); 648 EXPECT_TRUE(secondary_bounds.Contains(window_bounds));
695 } 649 }
696 650
697 // Activate another window in the primary display and create a new window. 651 // Activate another window in the primary display and create a new window.
698 // It should be created in the primary display. 652 // It should be created in the primary display.
699 { 653 {
700 another_browser_window->Activate(); 654 aura::client::GetActivationClient(another_native_window->GetRootWindow())
655 ->ActivateWindow(another_native_window);
701 EXPECT_EQ(ash::Shell::GetPrimaryRootWindow(), 656 EXPECT_EQ(ash::Shell::GetPrimaryRootWindow(),
702 ash::Shell::GetTargetRootWindow()); 657 ash::Shell::GetTargetRootWindow());
703 658
704 gfx::Rect window_bounds; 659 gfx::Rect window_bounds;
705 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, 660 GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds, gfx::Rect(),
706 gfx::Rect(), secondary_bounds, 661 secondary_bounds, PERSISTED, new_browser.get(), gfx::Rect(),
707 PERSISTED, new_browser_window->browser(), 662 &window_bounds);
708 gfx::Rect(), &window_bounds);
709 // TODO(oshima): Use exact bounds when the window_sizer_ash is 663 // TODO(oshima): Use exact bounds when the window_sizer_ash is
710 // moved to ash and changed to include the result from 664 // moved to ash and changed to include the result from
711 // RearrangeVisibleWindowOnShow. 665 // RearrangeVisibleWindowOnShow.
712 EXPECT_TRUE(primary_bounds.Contains(window_bounds)); 666 EXPECT_TRUE(primary_bounds.Contains(window_bounds));
713 } 667 }
714 } 668 }
715 669
716 // On desktop linux aura, we currently don't use the ash frame, breaking some 670 // On desktop linux aura, we currently don't use the ash frame, breaking some
717 // tests which expect ash sizes: http://crbug.com/303862 671 // tests which expect ash sizes: http://crbug.com/303862
718 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 672 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
719 #define MAYBE_TestShowState DISABLED_TestShowState 673 #define MAYBE_TestShowState DISABLED_TestShowState
720 #else 674 #else
721 #define MAYBE_TestShowState TestShowState 675 #define MAYBE_TestShowState TestShowState
722 #endif 676 #endif
723 677
724 // Test that the show state is properly returned for non default cases. 678 // Test that the show state is properly returned for non default cases.
725 TEST_F(WindowSizerAshTest, MAYBE_TestShowState) { 679 TEST_F(WindowSizerAshTest, MAYBE_TestShowState) {
726 scoped_ptr<TestingProfile> profile(new TestingProfile()); 680 scoped_ptr<TestingProfile> profile(new TestingProfile());
727 681
728 // Creating a browser & window to play with. 682 // Creating a browser & window to play with.
729 scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow( 683 scoped_ptr<Browser> browser = CreateTestBrowser(
730 CreateTestWindowInShellWithId(0), 684 CreateTestWindowInShellWithId(0), gfx::Rect(16, 32, 640, 320),
731 gfx::Rect(16, 32, 640, 320),
732 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), 685 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(),
733 chrome::HOST_DESKTOP_TYPE_ASH))); 686 chrome::HOST_DESKTOP_TYPE_ASH));
734 687
735 // Create also a popup browser since that behaves different. 688 // Create also a popup browser since that behaves different.
736 scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow( 689 scoped_ptr<Browser> browser_popup = CreateTestBrowser(
737 CreateTestWindowInShellWithId(1), 690 CreateTestWindowInShellWithId(1), gfx::Rect(16, 32, 640, 320),
738 gfx::Rect(16, 32, 640, 320),
739 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 691 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
740 chrome::HOST_DESKTOP_TYPE_ASH))); 692 chrome::HOST_DESKTOP_TYPE_ASH));
741 693
742 // Tabbed windows should retrieve the saved window state - since there is a 694 // Tabbed windows should retrieve the saved window state - since there is a
743 // top window. 695 // top window.
744 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 696 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
745 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 697 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_NORMAL,
746 ui::SHOW_STATE_NORMAL, 698 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. 699 // A window that is smaller than the whole work area is set to default state.
752 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 700 EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
753 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 701 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL,
754 ui::SHOW_STATE_NORMAL, 702 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. 703 // A window that is sized to occupy the whole work area is maximized.
760 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 704 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
761 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 705 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL,
762 ui::SHOW_STATE_NORMAL, 706 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. 707 // Non tabbed windows should always follow the window saved visibility state.
768 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 708 EXPECT_EQ(
769 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 709 ui::SHOW_STATE_MAXIMIZED,
770 ui::SHOW_STATE_NORMAL, 710 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_NORMAL, BOTH,
771 BOTH, 711 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. 712 // The non tabbed window will take the status of the last active of its kind.
776 EXPECT_EQ(ui::SHOW_STATE_NORMAL, 713 EXPECT_EQ(
777 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 714 ui::SHOW_STATE_NORMAL,
778 ui::SHOW_STATE_NORMAL, 715 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL, BOTH,
779 BOTH, 716 browser_popup.get(), p1600x1200, p1600x1200));
780 browser_popup->browser(),
781 p1600x1200,
782 p1600x1200));
783 717
784 // Now create a top level window and check again for both. Only the tabbed 718 // Now create a top level window and check again for both. Only the tabbed
785 // window should follow the top level window's state. 719 // window should follow the top level window's state.
786 // Creating a browser & window to play with. 720 // Creating a browser & window to play with.
787 scoped_ptr<TestBrowserWindowAura> browser_window2(CreateTestBrowserWindow( 721 scoped_ptr<Browser> browser2 = CreateTestBrowser(
788 CreateTestWindowInShellWithId(3), 722 CreateTestWindowInShellWithId(3), gfx::Rect(16, 32, 640, 320),
789 gfx::Rect(16, 32, 640, 320),
790 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), 723 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(),
791 chrome::HOST_DESKTOP_TYPE_ASH))); 724 chrome::HOST_DESKTOP_TYPE_ASH));
792 725
793 // A tabbed window should now take the top level window state. 726 // A tabbed window should now take the top level window state.
794 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 727 EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
795 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 728 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_DEFAULT,
796 ui::SHOW_STATE_DEFAULT, 729 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. 730 // Non tabbed windows should always follow the window saved visibility state.
802 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 731 EXPECT_EQ(
803 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 732 ui::SHOW_STATE_MAXIMIZED,
804 ui::SHOW_STATE_MINIMIZED, 733 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_MINIMIZED,
805 BOTH, 734 BOTH, browser_popup.get(), p1600x1200, p1600x1200));
806 browser_popup->browser(),
807 p1600x1200,
808 p1600x1200));
809 735
810 // In smaller screen resolutions we default to maximized if there is no other 736 // In smaller screen resolutions we default to maximized if there is no other
811 // window visible. 737 // window visible.
812 int min_size = ash::WindowPositioner::GetForceMaximizedWidthLimit() / 2; 738 int min_size = ash::WindowPositioner::GetForceMaximizedWidthLimit() / 2;
813 if (min_size > 0) { 739 if (min_size > 0) {
814 const gfx::Rect tiny_screen(0, 0, min_size, min_size); 740 const gfx::Rect tiny_screen(0, 0, min_size, min_size);
815 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 741 EXPECT_EQ(
816 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 742 ui::SHOW_STATE_DEFAULT,
817 ui::SHOW_STATE_DEFAULT, 743 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_DEFAULT,
818 BOTH, 744 BOTH, browser.get(), tiny_screen, tiny_screen));
819 browser_window->browser(), 745 browser->window()->Hide();
820 tiny_screen, 746 EXPECT_EQ(
821 tiny_screen)); 747 ui::SHOW_STATE_MAXIMIZED,
822 browser_window->Hide(); 748 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_DEFAULT,
823 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, 749 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 } 750 }
832 } 751 }
833 752
834 // Test that the default show state override behavior is properly handled. 753 // Test that the default show state override behavior is properly handled.
835 TEST_F(WindowSizerAshTest, TestShowStateDefaults) { 754 TEST_F(WindowSizerAshTest, TestShowStateDefaults) {
836 // Creating a browser & window to play with. 755 // Creating a browser & window to play with.
837 scoped_ptr<TestingProfile> profile(new TestingProfile()); 756 scoped_ptr<TestingProfile> profile(new TestingProfile());
838 757
839 scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow( 758 scoped_ptr<Browser> browser = CreateTestBrowser(
840 CreateTestWindowInShellWithId(0), 759 CreateTestWindowInShellWithId(0), gfx::Rect(16, 32, 640, 320),
841 gfx::Rect(16, 32, 640, 320),
842 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(), 760 Browser::CreateParams(Browser::TYPE_TABBED, profile.get(),
843 chrome::HOST_DESKTOP_TYPE_ASH))); 761 chrome::HOST_DESKTOP_TYPE_ASH));
844 762
845 // Create also a popup browser since that behaves slightly different for 763 // Create also a popup browser since that behaves slightly different for
846 // defaults. 764 // defaults.
847 scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow( 765 scoped_ptr<Browser> browser_popup = CreateTestBrowser(
848 CreateTestWindowInShellWithId(1), 766 CreateTestWindowInShellWithId(1), gfx::Rect(16, 32, 128, 256),
849 gfx::Rect(16, 32, 128, 256),
850 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(), 767 Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
851 chrome::HOST_DESKTOP_TYPE_ASH))); 768 chrome::HOST_DESKTOP_TYPE_ASH));
852 769
853 // Check that a browser creation state always get used if not given as 770 // 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. 771 // SHOW_STATE_DEFAULT. On Windows ASH it should be SHOW_STATE_MAXIMIZED.
855 ui::WindowShowState window_show_state = 772 ui::WindowShowState window_show_state =
856 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 773 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_MAXIMIZED,
857 ui::SHOW_STATE_MAXIMIZED, 774 DEFAULT, browser.get(), p1600x1200, p1600x1200);
858 DEFAULT,
859 browser_window->browser(),
860 p1600x1200,
861 p1600x1200);
862 #if defined(OS_WIN) 775 #if defined(OS_WIN)
863 EXPECT_EQ(window_show_state, ui::SHOW_STATE_MAXIMIZED); 776 EXPECT_EQ(window_show_state, ui::SHOW_STATE_MAXIMIZED);
864 #else 777 #else
865 EXPECT_EQ(window_show_state, ui::SHOW_STATE_DEFAULT); 778 EXPECT_EQ(window_show_state, ui::SHOW_STATE_DEFAULT);
866 #endif 779 #endif
867 780
868 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MINIMIZED); 781 browser->set_initial_show_state(ui::SHOW_STATE_MINIMIZED);
869 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 782 EXPECT_EQ(
870 ui::SHOW_STATE_MAXIMIZED, 783 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_MAXIMIZED,
871 BOTH, 784 BOTH, browser.get(), p1600x1200, p1600x1200),
872 browser_window->browser(), 785 ui::SHOW_STATE_MINIMIZED);
873 p1600x1200, 786 browser->set_initial_show_state(ui::SHOW_STATE_NORMAL);
874 p1600x1200), ui::SHOW_STATE_MINIMIZED); 787 EXPECT_EQ(
875 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); 788 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, ui::SHOW_STATE_MAXIMIZED,
876 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, 789 BOTH, browser.get(), p1600x1200, p1600x1200),
877 ui::SHOW_STATE_MAXIMIZED, 790 ui::SHOW_STATE_NORMAL);
878 BOTH, 791 browser->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED);
879 browser_window->browser(), 792 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, ui::SHOW_STATE_NORMAL,
880 p1600x1200, 793 BOTH, browser.get(), p1600x1200, p1600x1200),
881 p1600x1200), ui::SHOW_STATE_NORMAL); 794 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 795
890 // Check that setting the maximized command line option is forcing the 796 // Check that setting the maximized command line option is forcing the
891 // maximized state. 797 // maximized state.
892 base::CommandLine::ForCurrentProcess()->AppendSwitch( 798 base::CommandLine::ForCurrentProcess()->AppendSwitch(
893 switches::kStartMaximized); 799 switches::kStartMaximized);
894 800
895 browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL); 801 browser->set_initial_show_state(ui::SHOW_STATE_NORMAL);
896 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, 802 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, ui::SHOW_STATE_NORMAL,
897 ui::SHOW_STATE_NORMAL, 803 BOTH, browser.get(), p1600x1200, p1600x1200),
898 BOTH, 804 ui::SHOW_STATE_MAXIMIZED);
899 browser_window->browser(),
900 p1600x1200,
901 p1600x1200), ui::SHOW_STATE_MAXIMIZED);
902 805
903 // The popup should favor the initial show state over the command line. 806 // The popup should favor the initial show state over the command line.
904 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, 807 EXPECT_EQ(
905 ui::SHOW_STATE_NORMAL, 808 GetWindowShowState(ui::SHOW_STATE_NORMAL, ui::SHOW_STATE_NORMAL, BOTH,
906 BOTH, 809 browser_popup.get(), p1600x1200, p1600x1200),
907 browser_popup->browser(), 810 ui::SHOW_STATE_NORMAL);
908 p1600x1200,
909 p1600x1200), ui::SHOW_STATE_NORMAL);
910 } 811 }
911 812
912 TEST_F(WindowSizerAshTest, DefaultStateBecomesMaximized) { 813 TEST_F(WindowSizerAshTest, DefaultStateBecomesMaximized) {
913 // Create a browser to pass into the GetWindowBounds function. 814 // Create a browser to pass into the GetWindowBounds function.
914 scoped_ptr<TestingProfile> profile(new TestingProfile()); 815 scoped_ptr<TestingProfile> profile(new TestingProfile());
915 Browser::CreateParams native_params(profile.get(), 816 Browser::CreateParams native_params(profile.get(),
916 chrome::HOST_DESKTOP_TYPE_ASH); 817 chrome::HOST_DESKTOP_TYPE_ASH);
917 scoped_ptr<Browser> browser( 818 scoped_ptr<Browser> browser(
918 chrome::CreateBrowserWithTestWindowForParams(&native_params)); 819 chrome::CreateBrowserWithTestWindowForParams(&native_params));
919 820
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 EXPECT_TRUE(second_root->GetBoundsInScreen().Contains(bounds)); 880 EXPECT_TRUE(second_root->GetBoundsInScreen().Contains(bounds));
980 } 881 }
981 } 882 }
982 883
983 TEST_F(WindowSizerAshTest, TrustedPopupBehavior) { 884 TEST_F(WindowSizerAshTest, TrustedPopupBehavior) {
984 scoped_ptr<TestingProfile> profile(new TestingProfile()); 885 scoped_ptr<TestingProfile> profile(new TestingProfile());
985 Browser::CreateParams trusted_popup_create_params( 886 Browser::CreateParams trusted_popup_create_params(
986 Browser::TYPE_POPUP, profile.get(), chrome::HOST_DESKTOP_TYPE_ASH); 887 Browser::TYPE_POPUP, profile.get(), chrome::HOST_DESKTOP_TYPE_ASH);
987 trusted_popup_create_params.trusted_source = true; 888 trusted_popup_create_params.trusted_source = true;
988 889
989 scoped_ptr<TestBrowserWindowAura> trusted_popup(CreateTestBrowserWindow( 890 scoped_ptr<Browser> trusted_popup = CreateTestBrowser(
990 CreateTestWindowInShellWithId(1), 891 CreateTestWindowInShellWithId(1), gfx::Rect(16, 32, 640, 320),
991 gfx::Rect(16, 32, 640, 320), 892 trusted_popup_create_params);
992 trusted_popup_create_params));
993 // Trusted popup windows should follow the saved show state and ignore the 893 // Trusted popup windows should follow the saved show state and ignore the
994 // last show state. 894 // last show state.
995 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 895 EXPECT_EQ(
996 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 896 ui::SHOW_STATE_DEFAULT,
997 ui::SHOW_STATE_NORMAL, 897 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL, BOTH,
998 BOTH, 898 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. 899 // A popup that is sized to occupy the whole work area has default state.
1003 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, 900 EXPECT_EQ(
1004 GetWindowShowState(ui::SHOW_STATE_DEFAULT, 901 ui::SHOW_STATE_DEFAULT,
1005 ui::SHOW_STATE_NORMAL, 902 GetWindowShowState(ui::SHOW_STATE_DEFAULT, ui::SHOW_STATE_NORMAL, BOTH,
1006 BOTH, 903 trusted_popup.get(), p1600x1200, p1600x1200));
1007 trusted_popup->browser(),
1008 p1600x1200,
1009 p1600x1200));
1010 } 904 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698