Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2579883002: Scale bounds in aura-mus client-lib and NativeWidgetMus in hdpi mode. (Closed)
Patch Set: sadrul@'s comments Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/mus/window_tree_host_mus.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "mojo/common/common_type_converters.h" 13 #include "mojo/common/common_type_converters.h"
13 #include "services/ui/public/cpp/property_type_converters.h" 14 #include "services/ui/public/cpp/property_type_converters.h"
14 #include "services/ui/public/interfaces/window_manager.mojom.h" 15 #include "services/ui/public/interfaces/window_manager.mojom.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/aura/client/aura_constants.h" 17 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/client/capture_client.h" 18 #include "ui/aura/client/capture_client.h"
18 #include "ui/aura/client/capture_client_observer.h" 19 #include "ui/aura/client/capture_client_observer.h"
19 #include "ui/aura/client/focus_client.h" 20 #include "ui/aura/client/focus_client.h"
20 #include "ui/aura/client/transient_window_client.h" 21 #include "ui/aura/client/transient_window_client.h"
21 #include "ui/aura/mus/property_converter.h" 22 #include "ui/aura/mus/property_converter.h"
22 #include "ui/aura/mus/window_mus.h" 23 #include "ui/aura/mus/window_mus.h"
23 #include "ui/aura/mus/window_tree_client_delegate.h" 24 #include "ui/aura/mus/window_tree_client_delegate.h"
24 #include "ui/aura/mus/window_tree_client_observer.h" 25 #include "ui/aura/mus/window_tree_client_observer.h"
25 #include "ui/aura/mus/window_tree_host_mus.h" 26 #include "ui/aura/mus/window_tree_host_mus.h"
26 #include "ui/aura/test/aura_mus_test_base.h" 27 #include "ui/aura/test/aura_mus_test_base.h"
27 #include "ui/aura/test/mus/test_window_tree.h" 28 #include "ui/aura/test/mus/test_window_tree.h"
28 #include "ui/aura/test/mus/window_tree_client_private.h" 29 #include "ui/aura/test/mus/window_tree_client_private.h"
29 #include "ui/aura/test/test_window_delegate.h" 30 #include "ui/aura/test/test_window_delegate.h"
30 #include "ui/aura/window.h" 31 #include "ui/aura/window.h"
31 #include "ui/aura/window_property.h" 32 #include "ui/aura/window_property.h"
32 #include "ui/aura/window_tracker.h" 33 #include "ui/aura/window_tracker.h"
33 #include "ui/compositor/compositor.h" 34 #include "ui/compositor/compositor.h"
35 #include "ui/display/display_switches.h"
34 #include "ui/events/event.h" 36 #include "ui/events/event.h"
35 #include "ui/events/event_utils.h" 37 #include "ui/events/event_utils.h"
36 #include "ui/gfx/geometry/rect.h" 38 #include "ui/gfx/geometry/rect.h"
37 39
38 namespace aura { 40 namespace aura {
39 41
40 namespace { 42 namespace {
41 43
42 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); 44 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0);
43 DEFINE_WINDOW_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0); 45 DEFINE_WINDOW_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0);
(...skipping 29 matching lines...) Expand all
73 // Note that this implicitly casts arguments to the aura storage type, int64_t. 75 // Note that this implicitly casts arguments to the aura storage type, int64_t.
74 std::vector<uint8_t> ConvertToPropertyTransportValue(int64_t value) { 76 std::vector<uint8_t> ConvertToPropertyTransportValue(int64_t value) {
75 return mojo::ConvertTo<std::vector<uint8_t>>(value); 77 return mojo::ConvertTo<std::vector<uint8_t>>(value);
76 } 78 }
77 79
78 } // namespace 80 } // namespace
79 81
80 using WindowTreeClientWmTest = test::AuraMusWmTestBase; 82 using WindowTreeClientWmTest = test::AuraMusWmTestBase;
81 using WindowTreeClientClientTest = test::AuraMusClientTestBase; 83 using WindowTreeClientClientTest = test::AuraMusClientTestBase;
82 84
85 // WindowTreeClientWmTest with --force-device-scale-factor=2.
86 class WindowTreeClientWmTestHighDPI : public WindowTreeClientWmTest {
87 public:
88 WindowTreeClientWmTestHighDPI() {}
89 ~WindowTreeClientWmTestHighDPI() override {}
90
91 // WindowTreeClientWmTest:
92 void SetUp() override {
93 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
94 switches::kForceDeviceScaleFactor, "2");
95 WindowTreeClientWmTest::SetUp();
96 }
97
98 private:
99 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientWmTestHighDPI);
100 };
101
102 // WindowTreeClientClientTest with --force-device-scale-factor=2.
103 class WindowTreeClientClientTestHighDPI : public WindowTreeClientClientTest {
104 public:
105 WindowTreeClientClientTestHighDPI() {}
106 ~WindowTreeClientClientTestHighDPI() override {}
107
108 // WindowTreeClientClientTest:
109 void SetUp() override {
110 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
111 switches::kForceDeviceScaleFactor, "2");
112 WindowTreeClientClientTest::SetUp();
113 }
114
115 private:
116 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientClientTestHighDPI);
117 };
118
83 // Verifies bounds are reverted if the server replied that the change failed. 119 // Verifies bounds are reverted if the server replied that the change failed.
84 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) { 120 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) {
85 Window window(nullptr); 121 Window window(nullptr);
86 window.Init(ui::LAYER_NOT_DRAWN); 122 window.Init(ui::LAYER_NOT_DRAWN);
87 const gfx::Rect original_bounds(window.bounds()); 123 const gfx::Rect original_bounds(window.bounds());
88 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); 124 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
89 ASSERT_NE(new_bounds, window.bounds()); 125 ASSERT_NE(new_bounds, window.bounds());
90 window.SetBounds(new_bounds); 126 window.SetBounds(new_bounds);
91 EXPECT_EQ(new_bounds, window.bounds()); 127 EXPECT_EQ(new_bounds, window.bounds());
92 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, 128 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS,
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 WindowTreeClientPrivate(window_tree_client_impl()) 1420 WindowTreeClientPrivate(window_tree_client_impl())
1385 .CallWmNewDisplayAdded(display, std::move(root_data), parent_drawn); 1421 .CallWmNewDisplayAdded(display, std::move(root_data), parent_drawn);
1386 EXPECT_EQ(display.bounds(), window_tree_host->GetBoundsInPixels()); 1422 EXPECT_EQ(display.bounds(), window_tree_host->GetBoundsInPixels());
1387 // The root window of the WindowTreeHost always has an origin of 0,0. 1423 // The root window of the WindowTreeHost always has an origin of 0,0.
1388 EXPECT_EQ(gfx::Rect(display.bounds().size()), 1424 EXPECT_EQ(gfx::Rect(display.bounds().size()),
1389 window_tree_host->window()->bounds()); 1425 window_tree_host->window()->bounds());
1390 EXPECT_TRUE(window_tree_host->window()->IsVisible()); 1426 EXPECT_TRUE(window_tree_host->window()->IsVisible());
1391 EXPECT_EQ(display.id(), window_tree_host->display_id()); 1427 EXPECT_EQ(display.id(), window_tree_host->display_id());
1392 } 1428 }
1393 1429
1430 TEST_F(WindowTreeClientWmTestHighDPI, SetBounds) {
1431 const gfx::Rect original_bounds(root_window()->bounds());
1432 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
1433 ASSERT_NE(new_bounds, root_window()->bounds());
1434 root_window()->SetBounds(new_bounds);
1435 EXPECT_EQ(new_bounds, root_window()->bounds());
1436
1437 // Simulate the server responding with a bounds change. Server should operate
1438 // in pixels.
1439 const gfx::Rect server_changed_bounds(gfx::Rect(0, 0, 200, 200));
1440 window_tree_client()->OnWindowBoundsChanged(
1441 server_id(root_window()), original_bounds, server_changed_bounds);
1442 EXPECT_EQ(new_bounds, root_window()->bounds());
1443 }
1444
1445 TEST_F(WindowTreeClientClientTestHighDPI, NewTopLevelWindowBounds) {
1446 WindowTreeHostMus window_tree_host(window_tree_client_impl());
1447 Window* top_level = window_tree_host.window();
1448 window_tree_host.InitHost();
1449
1450 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
1451 data->window_id = server_id(top_level);
1452 data->bounds.SetRect(2, 4, 6, 8);
1453 const int64_t display_id = 10;
1454 uint32_t change_id;
1455 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
1456 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
1457 window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
1458 display_id, true);
1459
1460 // aura::Window should operate in DIP and aura::WindowTreeHost should operate
1461 // in pixels.
1462 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds());
1463 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels());
1464 }
1465
1394 } // namespace aura 1466 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/mus/window_tree_host_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698