1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "ash/public/cpp/shelf_config.h"
9 #include "ash/shelf/shelf.h"
10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h"
13 #include "ash/wm/window_properties.h"
14 #include "ash/wm/window_util.h"
15 #include "base/command_line.h"
16 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/compositor/layer.h"
19 #include "ui/display/display.h"
20 #include "ui/display/manager/display_manager.h"
21 #include "ui/display/screen.h"
22 #include "ui/gfx/geometry/insets.h"
23 #include "ui/views/widget/widget.h"
27 using DIPTest = AshTestBase;
29 // Test if the WM sets correct work area under different density.
30 TEST_F(DIPTest, WorkArea) {
31 UpdateDisplay("1000x900*1.0f");
33 aura::Window* root = Shell::GetPrimaryRootWindow();
34 const display::Display display =
35 display::Screen::GetScreen()->GetDisplayNearestWindow(root);
36 const int shelf_inset = 900 - ShelfConfig::Get()->shelf_size();
38 EXPECT_EQ("0,0 1000x900", display.bounds().ToString());
39 gfx::Rect work_area = display.work_area();
40 EXPECT_EQ(gfx::Rect(0, 0, 1000, shelf_inset).ToString(),
41 work_area.ToString());
43 gfx::Insets::TLBR(0, 0, ShelfConfig::Get()->shelf_size(), 0).ToString(),
44 display.bounds().InsetsFrom(work_area).ToString());
46 UpdateDisplay("2000x1800*2.0f");
47 display::Screen* screen = display::Screen::GetScreen();
49 const display::Display display_2x = screen->GetDisplayNearestWindow(root);
50 const display::ManagedDisplayInfo display_info_2x =
51 Shell::Get()->display_manager()->GetDisplayInfo(display_2x.id());
53 // The |bounds_in_pixel()| should report bounds in pixel coordinate.
54 EXPECT_EQ("1,1 2000x1800", display_info_2x.bounds_in_native().ToString());
56 // Aura and views coordinates are in DIP, so they their bounds do not change.
57 EXPECT_EQ("0,0 1000x900", display_2x.bounds().ToString());
58 work_area = display_2x.work_area();
59 EXPECT_EQ(gfx::Rect(0, 0, 1000, shelf_inset).ToString(),
60 work_area.ToString());
62 gfx::Insets::TLBR(0, 0, ShelfConfig::Get()->shelf_size(), 0).ToString(),
63 display_2x.bounds().InsetsFrom(work_area).ToString());
65 // Sanity check if the workarea's inset hight is same as
66 // the shelf's height.
67 Shelf* shelf = GetPrimaryShelf();
68 EXPECT_EQ(display_2x.bounds().InsetsFrom(work_area).height(),
69 shelf->shelf_widget()->GetNativeView()->layer()->bounds().height());