| OLD | NEW |
| 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 "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" | 5 #include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h" |
| 6 | 6 |
| 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_resizer.h" | 10 #include "ash/wm/window_resizer.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 gfx::Rect TestBrowserWindowAura::GetBounds() const { | 69 gfx::Rect TestBrowserWindowAura::GetBounds() const { |
| 70 return native_window_->bounds(); | 70 return native_window_->bounds(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 int AlignToGridRoundDown(int location, int grid_size) { | 73 int AlignToGridRoundDown(int location, int grid_size) { |
| 74 if (grid_size <= 1 || location % grid_size == 0) | 74 if (grid_size <= 1 || location % grid_size == 0) |
| 75 return location; | 75 return location; |
| 76 return location / grid_size * grid_size; | 76 return location / grid_size * grid_size; |
| 77 } | 77 } |
| 78 | 78 |
| 79 // A special test class for use with browser creation - it will create a | 79 } // namespace |
| 80 // browser thread and deletes it after all other things have been destroyed. | |
| 81 class WindowSizerTestWithBrowser : public WindowSizerTest { | |
| 82 public: | |
| 83 WindowSizerTestWithBrowser(); | |
| 84 virtual ~WindowSizerTestWithBrowser(); | |
| 85 | 80 |
| 86 private: | |
| 87 // Note: It is important to delete the thread after the browser instances got | |
| 88 // deleted. For this we transfer the thread here. | |
| 89 scoped_ptr<content::TestBrowserThread> ui_thread_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(WindowSizerTestWithBrowser); | |
| 92 }; | |
| 93 | |
| 94 // The class function definitions from window_sizer_common_unittest.h | |
| 95 WindowSizerTestWithBrowser::WindowSizerTestWithBrowser() { | |
| 96 // Set up a UI message thread. | |
| 97 base::MessageLoopForUI* ui_loop = message_loop(); | |
| 98 ui_thread_.reset( | |
| 99 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); | |
| 100 } | |
| 101 | |
| 102 WindowSizerTestWithBrowser::~WindowSizerTestWithBrowser() { | |
| 103 } | |
| 104 | |
| 105 } | |
| 106 // Test that the window is sized appropriately for the first run experience | 81 // Test that the window is sized appropriately for the first run experience |
| 107 // where the default window bounds calculation is invoked. | 82 // where the default window bounds calculation is invoked. |
| 108 TEST_F(WindowSizerTest, DefaultSizeCase) { | 83 TEST_F(WindowSizerTest, DefaultSizeCase) { |
| 109 int grid = WindowSizer::kDesktopBorderSize; | 84 int grid = WindowSizer::kDesktopBorderSize; |
| 110 { // 4:3 monitor case, 1024x768, no taskbar | 85 { // 4:3 monitor case, 1024x768, no taskbar |
| 111 gfx::Rect window_bounds; | 86 gfx::Rect window_bounds; |
| 112 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), | 87 GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(), |
| 113 gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds); | 88 gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds); |
| 114 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 89 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
| 115 WindowSizer::kDesktopBorderSize, | 90 WindowSizer::kDesktopBorderSize, |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 NULL, gfx::Rect(), &window_bounds); | 423 NULL, gfx::Rect(), &window_bounds); |
| 449 EXPECT_EQ(gfx::Rect(994 /* not 995 */, | 424 EXPECT_EQ(gfx::Rect(994 /* not 995 */, |
| 450 738 /* not 739 */, | 425 738 /* not 739 */, |
| 451 500, | 426 500, |
| 452 400).ToString(), | 427 400).ToString(), |
| 453 window_bounds.ToString()); | 428 window_bounds.ToString()); |
| 454 } | 429 } |
| 455 } | 430 } |
| 456 | 431 |
| 457 // Test the placement of newly created windows. | 432 // Test the placement of newly created windows. |
| 458 TEST_F(WindowSizerTestWithBrowser, PlaceNewWindows) { | 433 TEST_F(WindowSizerTest, PlaceNewWindows) { |
| 459 // Create a dummy window. | 434 // Create a dummy window. |
| 460 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 435 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 461 window->SetBounds(gfx::Rect(16, 32, 640, 320)); | 436 window->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 462 | 437 |
| 463 scoped_ptr<aura::Window> popup(CreateTestWindowInShellWithId(1)); | 438 scoped_ptr<aura::Window> popup(CreateTestWindowInShellWithId(1)); |
| 464 popup->SetBounds(gfx::Rect(16, 32, 128, 256)); | 439 popup->SetBounds(gfx::Rect(16, 32, 128, 256)); |
| 465 | 440 |
| 466 scoped_ptr<aura::Window> panel(CreateTestWindowInShellWithId(2)); | 441 scoped_ptr<aura::Window> panel(CreateTestWindowInShellWithId(2)); |
| 467 panel->SetBounds(gfx::Rect(32, 48, 256, 512)); | 442 panel->SetBounds(gfx::Rect(32, 48, 256, 512)); |
| 468 | 443 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 std::min(WindowSizer::kMaximumWindowWidth, | 543 std::min(WindowSizer::kMaximumWindowWidth, |
| 569 1600 - 2 * WindowSizer::kDesktopBorderSize), | 544 1600 - 2 * WindowSizer::kDesktopBorderSize), |
| 570 1200 - WindowSizer::kDesktopBorderSize).ToString(), | 545 1200 - WindowSizer::kDesktopBorderSize).ToString(), |
| 571 window_bounds.ToString()); | 546 window_bounds.ToString()); |
| 572 } | 547 } |
| 573 } | 548 } |
| 574 | 549 |
| 575 // Test the placement of newly created windows on an empty desktop. | 550 // Test the placement of newly created windows on an empty desktop. |
| 576 // This test supplements "PlaceNewWindows" by testing the creation of a newly | 551 // This test supplements "PlaceNewWindows" by testing the creation of a newly |
| 577 // created browser window on an empty desktop. | 552 // created browser window on an empty desktop. |
| 578 TEST_F(WindowSizerTestWithBrowser, PlaceNewBrowserWindowOnEmptyDesktop) { | 553 TEST_F(WindowSizerTest, PlaceNewBrowserWindowOnEmptyDesktop) { |
| 579 // Create a browser which we can use to pass into the GetWindowBounds | 554 // Create a browser which we can use to pass into the GetWindowBounds |
| 580 // function. | 555 // function. |
| 581 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 556 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
| 582 Browser::CreateParams native_params(profile.get(), | 557 Browser::CreateParams native_params(profile.get(), |
| 583 chrome::HOST_DESKTOP_TYPE_ASH); | 558 chrome::HOST_DESKTOP_TYPE_ASH); |
| 584 scoped_ptr<Browser> browser( | 559 scoped_ptr<Browser> browser( |
| 585 chrome::CreateBrowserWithTestWindowForParams(&native_params)); | 560 chrome::CreateBrowserWithTestWindowForParams(&native_params)); |
| 586 | 561 |
| 587 // If there is no previous state the window should get maximized if the | 562 // If there is no previous state the window should get maximized if the |
| 588 // screen is smaller than our limit (1350 pixels width). | 563 // screen is smaller than our limit (1350 pixels width). |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 600 |
| 626 | 601 |
| 627 #if defined(OS_CHROMEOS) | 602 #if defined(OS_CHROMEOS) |
| 628 #define MAYBE_PlaceNewWindowsOnMultipleDisplays PlaceNewWindowsOnMultipleDisplay
s | 603 #define MAYBE_PlaceNewWindowsOnMultipleDisplays PlaceNewWindowsOnMultipleDisplay
s |
| 629 #else | 604 #else |
| 630 // No multiple displays on windows ash. | 605 // No multiple displays on windows ash. |
| 631 #define MAYBE_PlaceNewWindowsOnMultipleDisplays DISABLED_PlaceNewWindowsOnMultip
leDisplays | 606 #define MAYBE_PlaceNewWindowsOnMultipleDisplays DISABLED_PlaceNewWindowsOnMultip
leDisplays |
| 632 #endif | 607 #endif |
| 633 | 608 |
| 634 // Test the placement of newly created windows on multiple dislays. | 609 // Test the placement of newly created windows on multiple dislays. |
| 635 TEST_F(WindowSizerTestWithBrowser, MAYBE_PlaceNewWindowsOnMultipleDisplays) { | 610 TEST_F(WindowSizerTest, MAYBE_PlaceNewWindowsOnMultipleDisplays) { |
| 636 UpdateDisplay("1600x1200,1600x1200"); | 611 UpdateDisplay("1600x1200,1600x1200"); |
| 637 const gfx::Rect secondary(1600, 0, 1600, 1200); | 612 const gfx::Rect secondary(1600, 0, 1600, 1200); |
| 638 | 613 |
| 639 ash::Shell::GetInstance()->set_active_root_window( | 614 ash::Shell::GetInstance()->set_active_root_window( |
| 640 ash::Shell::GetPrimaryRootWindow()); | 615 ash::Shell::GetPrimaryRootWindow()); |
| 641 | 616 |
| 642 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 617 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
| 643 | 618 |
| 644 // Create browser windows that are used as reference. | 619 // Create browser windows that are used as reference. |
| 645 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 620 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 689 |
| 715 gfx::Rect window_bounds; | 690 gfx::Rect window_bounds; |
| 716 GetWindowBounds(p1600x1200, p1600x1200, secondary, | 691 GetWindowBounds(p1600x1200, p1600x1200, secondary, |
| 717 gfx::Rect(), secondary, | 692 gfx::Rect(), secondary, |
| 718 PERSISTED, new_browser.get(), gfx::Rect(), &window_bounds); | 693 PERSISTED, new_browser.get(), gfx::Rect(), &window_bounds); |
| 719 EXPECT_EQ("0,10 300x300", window_bounds.ToString()); | 694 EXPECT_EQ("0,10 300x300", window_bounds.ToString()); |
| 720 } | 695 } |
| 721 } | 696 } |
| 722 | 697 |
| 723 // Test that the show state is properly returned for non default cases. | 698 // Test that the show state is properly returned for non default cases. |
| 724 TEST_F(WindowSizerTestWithBrowser, TestShowState) { | 699 TEST_F(WindowSizerTest, TestShowState) { |
| 725 // Creating a browser & window to play with. | 700 // Creating a browser & window to play with. |
| 726 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 701 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 727 window->SetBounds(gfx::Rect(16, 32, 640, 320)); | 702 window->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 728 | 703 |
| 729 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 704 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
| 730 | 705 |
| 731 scoped_ptr<BrowserWindow> browser_window( | 706 scoped_ptr<BrowserWindow> browser_window( |
| 732 new TestBrowserWindowAura(window.get())); | 707 new TestBrowserWindowAura(window.get())); |
| 733 Browser::CreateParams window_params(Browser::TYPE_TABBED, profile.get(), | 708 Browser::CreateParams window_params(Browser::TYPE_TABBED, profile.get(), |
| 734 chrome::HOST_DESKTOP_TYPE_ASH); | 709 chrome::HOST_DESKTOP_TYPE_ASH); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, | 794 GetWindowShowState(ui::SHOW_STATE_MAXIMIZED, |
| 820 ui::SHOW_STATE_DEFAULT, | 795 ui::SHOW_STATE_DEFAULT, |
| 821 BOTH, | 796 BOTH, |
| 822 browser2.get(), | 797 browser2.get(), |
| 823 tiny_screen)); | 798 tiny_screen)); |
| 824 | 799 |
| 825 } | 800 } |
| 826 } | 801 } |
| 827 | 802 |
| 828 // Test that the default show state override behavior is properly handled. | 803 // Test that the default show state override behavior is properly handled. |
| 829 TEST_F(WindowSizerTestWithBrowser, TestShowStateDefaults) { | 804 TEST_F(WindowSizerTest, TestShowStateDefaults) { |
| 830 // Creating a browser & window to play with. | 805 // Creating a browser & window to play with. |
| 831 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 806 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 832 window->SetBounds(gfx::Rect(16, 32, 640, 320)); | 807 window->SetBounds(gfx::Rect(16, 32, 640, 320)); |
| 833 | 808 |
| 834 scoped_ptr<TestingProfile> profile(new TestingProfile()); | 809 scoped_ptr<TestingProfile> profile(new TestingProfile()); |
| 835 | 810 |
| 836 scoped_ptr<BrowserWindow> browser_window( | 811 scoped_ptr<BrowserWindow> browser_window( |
| 837 new TestBrowserWindowAura(window.get())); | 812 new TestBrowserWindowAura(window.get())); |
| 838 Browser::CreateParams window_params(Browser::TYPE_TABBED, profile.get(), | 813 Browser::CreateParams window_params(Browser::TYPE_TABBED, profile.get(), |
| 839 chrome::HOST_DESKTOP_TYPE_ASH); | 814 chrome::HOST_DESKTOP_TYPE_ASH); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 browser.get(), | 864 browser.get(), |
| 890 p1600x1200), ui::SHOW_STATE_MAXIMIZED); | 865 p1600x1200), ui::SHOW_STATE_MAXIMIZED); |
| 891 | 866 |
| 892 // The popup should favor the initial show state over the command line. | 867 // The popup should favor the initial show state over the command line. |
| 893 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, | 868 EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL, |
| 894 ui::SHOW_STATE_NORMAL, | 869 ui::SHOW_STATE_NORMAL, |
| 895 BOTH, | 870 BOTH, |
| 896 popup_browser.get(), | 871 popup_browser.get(), |
| 897 p1600x1200), ui::SHOW_STATE_NORMAL); | 872 p1600x1200), ui::SHOW_STATE_NORMAL); |
| 898 } | 873 } |
| OLD | NEW |