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