15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <algorithm>
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ash/ash_switches.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/display_manager.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shelf/shelf.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_widget.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/ash_test_base.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_properties.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_util.h"
1658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "base/command_line.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h"
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/display.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/insets.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/shadow.h"
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/shadow_controller.h"
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/shadow_types.h"
28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/activation_client.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef ash::test::AshTestBase DIPTest;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test if the WM sets correct work area under different density.
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DIPTest, WorkArea) {
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UpdateDisplay("1000x900*1.0f");
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* root = Shell::GetPrimaryRootWindow();
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const gfx::Display display =
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Shell::GetScreen()->GetDisplayNearestWindow(root);
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 1000x900", display.bounds().ToString());
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect work_area = display.work_area();
4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 1000x853", work_area.ToString());
4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0,47,0", display.bounds().InsetsFrom(work_area).ToString());
4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
4758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  UpdateDisplay("2000x1800*2.0f");
4858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Screen* screen = Shell::GetScreen();
4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
5058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const gfx::Display display_2x = screen->GetDisplayNearestWindow(root);
51c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  const DisplayInfo display_info_2x =
5258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      Shell::GetInstance()->display_manager()->GetDisplayInfo(display_2x.id());
5358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
5458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // The |bounds_in_pixel()| should report bounds in pixel coordinate.
5558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("1,1 2000x1800",
5668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)            display_info_2x.bounds_in_native().ToString());
5758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
5858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Aura and views coordinates are in DIP, so they their bounds do not change.
5958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 1000x900", display_2x.bounds().ToString());
6058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  work_area = display_2x.work_area();
6158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 1000x853", work_area.ToString());
6258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0,47,0", display_2x.bounds().InsetsFrom(work_area).ToString());
6358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
6458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Sanity check if the workarea's inset hight is same as
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the shelf's height.
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shelf* shelf = Shelf::ForPrimaryDisplay();
6758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(
6858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_2x.bounds().InsetsFrom(work_area).height(),
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      shelf->shelf_widget()->GetNativeView()->layer()->bounds().height());
7058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
7158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
73