OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/browser_window_state.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "chrome/common/chrome_switches.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/base/ui_base_types.h" |
| 11 #include "ui/gfx/geometry/rect.h" |
| 12 |
| 13 namespace chrome { |
| 14 |
| 15 namespace internal { |
| 16 |
| 17 namespace { |
| 18 |
| 19 constexpr int kDefaultWidth = 1920; |
| 20 constexpr int kDefaultHeight = 1200; |
| 21 constexpr int kDefaultOffsetX = 0; |
| 22 constexpr int kDefaultOffsetY = 0; |
| 23 constexpr ui::WindowShowState kDefaultShowState = ui::SHOW_STATE_MAXIMIZED; |
| 24 |
| 25 class BrowserWindowStateTest : public testing::Test { |
| 26 public: |
| 27 BrowserWindowStateTest() |
| 28 : bounds_(gfx::Point(kDefaultOffsetX, kDefaultOffsetY), |
| 29 gfx::Size(kDefaultWidth, kDefaultHeight)), |
| 30 show_state_(kDefaultShowState), |
| 31 command_line_(base::CommandLine::NO_PROGRAM) {} |
| 32 |
| 33 gfx::Rect bounds_; |
| 34 ui::WindowShowState show_state_; |
| 35 base::CommandLine command_line_; |
| 36 }; |
| 37 |
| 38 } // namespace |
| 39 |
| 40 TEST_F(BrowserWindowStateTest, NoCommandLineLeavesParamsIntact) { |
| 41 UpdateWindowBoundsAndShowStateFromCommandLine(command_line_, &bounds_, |
| 42 &show_state_); |
| 43 EXPECT_EQ(bounds_.x(), kDefaultOffsetX); |
| 44 EXPECT_EQ(bounds_.y(), kDefaultOffsetY); |
| 45 EXPECT_EQ(bounds_.width(), kDefaultWidth); |
| 46 EXPECT_EQ(bounds_.height(), kDefaultHeight); |
| 47 EXPECT_EQ(show_state_, kDefaultShowState); |
| 48 } |
| 49 |
| 50 TEST_F(BrowserWindowStateTest, InvalidCommandLineLeavesParamsIntact) { |
| 51 command_line_.AppendSwitchASCII(switches::kWindowSize, "0,abc"); |
| 52 command_line_.AppendSwitchASCII(switches::kWindowPosition, "invalid"); |
| 53 |
| 54 UpdateWindowBoundsAndShowStateFromCommandLine(command_line_, &bounds_, |
| 55 &show_state_); |
| 56 EXPECT_EQ(bounds_.x(), kDefaultOffsetX); |
| 57 EXPECT_EQ(bounds_.y(), kDefaultOffsetY); |
| 58 EXPECT_EQ(bounds_.width(), kDefaultWidth); |
| 59 EXPECT_EQ(bounds_.height(), kDefaultHeight); |
| 60 EXPECT_EQ(show_state_, kDefaultShowState); |
| 61 } |
| 62 |
| 63 TEST_F(BrowserWindowStateTest, WindowSizeOverridesShowState) { |
| 64 command_line_.AppendSwitchASCII(switches::kWindowSize, "100,200"); |
| 65 |
| 66 UpdateWindowBoundsAndShowStateFromCommandLine(command_line_, &bounds_, |
| 67 &show_state_); |
| 68 EXPECT_EQ(bounds_.x(), kDefaultOffsetX); |
| 69 EXPECT_EQ(bounds_.y(), kDefaultOffsetY); |
| 70 EXPECT_EQ(bounds_.width(), 100); |
| 71 EXPECT_EQ(bounds_.height(), 200); |
| 72 EXPECT_EQ(show_state_, ui::SHOW_STATE_NORMAL); |
| 73 } |
| 74 |
| 75 TEST_F(BrowserWindowStateTest, WindowPositionOverridesShowState) { |
| 76 command_line_.AppendSwitchASCII(switches::kWindowPosition, "100,200"); |
| 77 |
| 78 UpdateWindowBoundsAndShowStateFromCommandLine(command_line_, &bounds_, |
| 79 &show_state_); |
| 80 EXPECT_EQ(bounds_.x(), 100); |
| 81 EXPECT_EQ(bounds_.y(), 200); |
| 82 EXPECT_EQ(bounds_.width(), kDefaultWidth); |
| 83 EXPECT_EQ(bounds_.height(), kDefaultHeight); |
| 84 EXPECT_EQ(show_state_, ui::SHOW_STATE_NORMAL); |
| 85 } |
| 86 |
| 87 } // namespace internal |
| 88 |
| 89 } // namespace chrome |
OLD | NEW |