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

Side by Side Diff: chrome/browser/extensions/display_info_provider_chromeos_unittest.cc

Issue 2072633002: Add Get/SetDisplayLayout to chrome.system.display extension API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win Created 4 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/system_display/display_info_provider.h" 5 #include "extensions/browser/api/system_display/display_info_provider.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "ash/common/ash_switches.h" 9 #include "ash/common/ash_switches.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/display/screen_orientation_controller_chromeos.h" 11 #include "ash/display/screen_orientation_controller_chromeos.h"
12 #include "ash/screen_util.h" 12 #include "ash/screen_util.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/display_manager_test_api.h" 15 #include "ash/test/display_manager_test_api.h"
16 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 16 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "extensions/common/api/system_display.h" 21 #include "extensions/common/api/system_display.h"
22 #include "ui/display/display.h" 22 #include "ui/display/display.h"
23 #include "ui/display/manager/display_layout.h" 23 #include "ui/display/manager/display_layout.h"
24 #include "ui/gfx/geometry/rect.h" 24 #include "ui/gfx/geometry/rect.h"
25 25
26 namespace extensions { 26 namespace extensions {
27 namespace { 27 namespace {
28 28
29 using DisplayUnitInfoList = DisplayInfoProvider::DisplayUnitInfoList;
30 using DisplayLayoutList = DisplayInfoProvider::DisplayLayoutList;
31
29 class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase { 32 class DisplayInfoProviderChromeosTest : public ash::test::AshTestBase {
30 public: 33 public:
31 DisplayInfoProviderChromeosTest() {} 34 DisplayInfoProviderChromeosTest() {}
32 35
33 ~DisplayInfoProviderChromeosTest() override {} 36 ~DisplayInfoProviderChromeosTest() override {}
34 37
35 void SetUp() override { 38 void SetUp() override {
36 base::CommandLine::ForCurrentProcess()->AppendSwitch( 39 base::CommandLine::ForCurrentProcess()->AppendSwitch(
37 ash::switches::kAshUseFirstDisplayAsInternal); 40 ash::switches::kAshUseFirstDisplayAsInternal);
38 ash::test::AshTestBase::SetUp(); 41 ash::test::AshTestBase::SetUp();
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 GetDisplayManager()->SetLayoutForCurrentDisplays( 430 GetDisplayManager()->SetLayoutForCurrentDisplays(
428 ash::test::CreateDisplayLayout(display::DisplayPlacement::BOTTOM, 80)); 431 ash::test::CreateDisplayLayout(display::DisplayPlacement::BOTTOM, 80));
429 432
430 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo(); 433 result = DisplayInfoProvider::Get()->GetAllDisplaysInfo();
431 ASSERT_EQ(2u, result.size()); 434 ASSERT_EQ(2u, result.size());
432 EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result[0].bounds)); 435 EXPECT_EQ("0,0 600x600", SystemInfoDisplayBoundsToString(result[0].bounds));
433 EXPECT_EQ("80,600 400x520", 436 EXPECT_EQ("80,600 400x520",
434 SystemInfoDisplayBoundsToString(result[1].bounds)); 437 SystemInfoDisplayBoundsToString(result[1].bounds));
435 } 438 }
436 439
440 TEST_F(DisplayInfoProviderChromeosTest, Layout) {
441 UpdateDisplay("500x400,500x400,500x400");
442
443 DisplayUnitInfoList displays =
444 DisplayInfoProvider::Get()->GetAllDisplaysInfo();
445 std::string primary_id = displays[0].id;
446 ASSERT_EQ(3u, displays.size());
447
448 DisplayLayoutList layout = DisplayInfoProvider::Get()->GetDisplayLayout();
449
450 ASSERT_EQ(2u, layout.size());
451
452 // Confirm layout.
453 EXPECT_EQ(displays[1].id, layout[0].id);
454 EXPECT_EQ(primary_id, layout[0].parent_id);
455 EXPECT_EQ(api::system_display::LAYOUT_POSITION_RIGHT, layout[0].position);
456 EXPECT_EQ(0, layout[0].offset);
457
458 EXPECT_EQ(displays[2].id, layout[1].id);
459 EXPECT_EQ(layout[0].id, layout[1].parent_id);
460 EXPECT_EQ(api::system_display::LAYOUT_POSITION_RIGHT, layout[1].position);
461 EXPECT_EQ(0, layout[1].offset);
462
463 // Modify layout.
464 layout[0].offset = 100;
465 layout[1].parent_id = primary_id;
466 layout[1].position = api::system_display::LAYOUT_POSITION_BOTTOM;
467 layout[1].offset = -100;
468
469 // Update with modified layout.
470 ASSERT_TRUE(DisplayInfoProvider::Get()->SetDisplayLayout(layout));
471
472 // Get updated layout.
473 layout = DisplayInfoProvider::Get()->GetDisplayLayout();
474
475 // Confirm modified layout.
476 EXPECT_EQ(displays[1].id, layout[0].id);
477 EXPECT_EQ(primary_id, layout[0].parent_id);
478 EXPECT_EQ(api::system_display::LAYOUT_POSITION_RIGHT, layout[0].position);
479 EXPECT_EQ(100, layout[0].offset);
480
481 EXPECT_EQ(displays[2].id, layout[1].id);
482 EXPECT_EQ(primary_id, layout[1].parent_id);
483 EXPECT_EQ(api::system_display::LAYOUT_POSITION_BOTTOM, layout[1].position);
484 EXPECT_EQ(-100, layout[1].offset);
485
486 // TODO(stevenjb/oshima): Implement and test illegal layout prevention.
487
488 // Test setting invalid layout fails.
489 layout[0].parent_id = displays[2].id;
490 layout[1].parent_id = displays[1].id;
491 EXPECT_FALSE(DisplayInfoProvider::Get()->SetDisplayLayout(layout));
492 }
493
437 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftExact) { 494 TEST_F(DisplayInfoProviderChromeosTest, SetBoundsOriginLeftExact) {
438 UpdateDisplay("1200x600,520x400"); 495 UpdateDisplay("1200x600,520x400");
439 496
440 const display::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay(); 497 const display::Display& secondary = ash::ScreenUtil::GetSecondaryDisplay();
441 api::system_display::DisplayProperties info; 498 api::system_display::DisplayProperties info;
442 info.bounds_origin_x.reset(new int(-520)); 499 info.bounds_origin_x.reset(new int(-520));
443 info.bounds_origin_y.reset(new int(50)); 500 info.bounds_origin_y.reset(new int(50));
444 501
445 bool success = false; 502 bool success = false;
446 std::string error; 503 std::string error;
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 CallSetDisplayUnitInfo(base::Int64ToString(id), info, &success, &error); 1183 CallSetDisplayUnitInfo(base::Int64ToString(id), info, &success, &error);
1127 ASSERT_TRUE(success); 1184 ASSERT_TRUE(success);
1128 1185
1129 // Verify that other_mode now matches the active mode. 1186 // Verify that other_mode now matches the active mode.
1130 active_mode = GetDisplayManager()->GetActiveModeForDisplayId(id); 1187 active_mode = GetDisplayManager()->GetActiveModeForDisplayId(id);
1131 EXPECT_TRUE(active_mode.IsEquivalent(other_mode_ash)); 1188 EXPECT_TRUE(active_mode.IsEquivalent(other_mode_ash));
1132 } 1189 }
1133 1190
1134 } // namespace 1191 } // namespace
1135 } // namespace extensions 1192 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/display_info_provider_chromeos.cc ('k') | chrome/browser/extensions/display_info_provider_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698