| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "extensions/browser/api/system_display/display_info_provider.h" | 13 #include "extensions/browser/api/system_display/display_info_provider.h" |
| 14 #include "extensions/browser/api/system_display/system_display_api.h" | 14 #include "extensions/browser/api/system_display/system_display_api.h" |
| 15 #include "extensions/browser/api_test_utils.h" | 15 #include "extensions/browser/api_test_utils.h" |
| 16 #include "extensions/common/api/system_display.h" | 16 #include "extensions/common/api/system_display.h" |
| 17 #include "extensions/shell/test/shell_apitest.h" | 17 #include "extensions/shell/test/shell_apitest.h" |
| 18 #include "ui/gfx/display.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/gfx/display_observer.h" | 19 #include "ui/display/screen.h" |
| 20 #include "ui/gfx/screen.h" | |
| 21 | 20 |
| 22 namespace extensions { | 21 namespace extensions { |
| 23 | 22 |
| 24 using api::system_display::Bounds; | 23 using api::system_display::Bounds; |
| 25 using api::system_display::DisplayUnitInfo; | 24 using api::system_display::DisplayUnitInfo; |
| 26 using gfx::Screen; | 25 using display::Screen; |
| 27 | 26 |
| 28 class MockScreen : public Screen { | 27 class MockScreen : public Screen { |
| 29 public: | 28 public: |
| 30 MockScreen() { | 29 MockScreen() { |
| 31 for (int i = 0; i < 4; i++) { | 30 for (int i = 0; i < 4; i++) { |
| 32 gfx::Rect bounds(0, 0, 1280, 720); | 31 gfx::Rect bounds(0, 0, 1280, 720); |
| 33 gfx::Rect work_area(0, 0, 960, 720); | 32 gfx::Rect work_area(0, 0, 960, 720); |
| 34 gfx::Display display(i, bounds); | 33 display::Display display(i, bounds); |
| 35 display.set_work_area(work_area); | 34 display.set_work_area(work_area); |
| 36 displays_.push_back(display); | 35 displays_.push_back(display); |
| 37 } | 36 } |
| 38 } | 37 } |
| 39 ~MockScreen() override {} | 38 ~MockScreen() override {} |
| 40 | 39 |
| 41 protected: | 40 protected: |
| 42 // Overridden from gfx::Screen: | 41 // Overridden from display::Screen: |
| 43 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } | 42 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } |
| 44 gfx::NativeWindow GetWindowUnderCursor() override { | 43 gfx::NativeWindow GetWindowUnderCursor() override { |
| 45 return gfx::NativeWindow(); | 44 return gfx::NativeWindow(); |
| 46 } | 45 } |
| 47 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { | 46 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { |
| 48 return gfx::NativeWindow(); | 47 return gfx::NativeWindow(); |
| 49 } | 48 } |
| 50 int GetNumDisplays() const override { | 49 int GetNumDisplays() const override { |
| 51 return static_cast<int>(displays_.size()); | 50 return static_cast<int>(displays_.size()); |
| 52 } | 51 } |
| 53 std::vector<gfx::Display> GetAllDisplays() const override { | 52 std::vector<display::Display> GetAllDisplays() const override { |
| 54 return displays_; | 53 return displays_; |
| 55 } | 54 } |
| 56 gfx::Display GetDisplayNearestWindow(gfx::NativeView window) const override { | 55 display::Display GetDisplayNearestWindow( |
| 57 return gfx::Display(0); | 56 gfx::NativeView window) const override { |
| 57 return display::Display(0); |
| 58 } | 58 } |
| 59 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { | 59 display::Display GetDisplayNearestPoint( |
| 60 return gfx::Display(0); | 60 const gfx::Point& point) const override { |
| 61 return display::Display(0); |
| 61 } | 62 } |
| 62 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override { | 63 display::Display GetDisplayMatching( |
| 63 return gfx::Display(0); | 64 const gfx::Rect& match_rect) const override { |
| 65 return display::Display(0); |
| 64 } | 66 } |
| 65 gfx::Display GetPrimaryDisplay() const override { return displays_[0]; } | 67 display::Display GetPrimaryDisplay() const override { return displays_[0]; } |
| 66 void AddObserver(gfx::DisplayObserver* observer) override {} | 68 void AddObserver(display::DisplayObserver* observer) override {} |
| 67 void RemoveObserver(gfx::DisplayObserver* observer) override {} | 69 void RemoveObserver(display::DisplayObserver* observer) override {} |
| 68 | 70 |
| 69 private: | 71 private: |
| 70 std::vector<gfx::Display> displays_; | 72 std::vector<display::Display> displays_; |
| 71 | 73 |
| 72 DISALLOW_COPY_AND_ASSIGN(MockScreen); | 74 DISALLOW_COPY_AND_ASSIGN(MockScreen); |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 class MockDisplayInfoProvider : public DisplayInfoProvider { | 77 class MockDisplayInfoProvider : public DisplayInfoProvider { |
| 76 public: | 78 public: |
| 77 MockDisplayInfoProvider() {} | 79 MockDisplayInfoProvider() {} |
| 78 | 80 |
| 79 ~MockDisplayInfoProvider() override {} | 81 ~MockDisplayInfoProvider() override {} |
| 80 | 82 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 97 } | 99 } |
| 98 | 100 |
| 99 std::string GetSetInfoDisplayId() const { return set_info_display_id_; } | 101 std::string GetSetInfoDisplayId() const { return set_info_display_id_; } |
| 100 | 102 |
| 101 bool unified_desktop_enabled() const { return unified_desktop_enabled_; } | 103 bool unified_desktop_enabled() const { return unified_desktop_enabled_; } |
| 102 | 104 |
| 103 private: | 105 private: |
| 104 // Update the content of the |unit| obtained for |display| using | 106 // Update the content of the |unit| obtained for |display| using |
| 105 // platform specific method. | 107 // platform specific method. |
| 106 void UpdateDisplayUnitInfoForPlatform( | 108 void UpdateDisplayUnitInfoForPlatform( |
| 107 const gfx::Display& display, | 109 const display::Display& display, |
| 108 extensions::api::system_display::DisplayUnitInfo* unit) override { | 110 extensions::api::system_display::DisplayUnitInfo* unit) override { |
| 109 int64_t id = display.id(); | 111 int64_t id = display.id(); |
| 110 unit->name = "DISPLAY NAME FOR " + base::Int64ToString(id); | 112 unit->name = "DISPLAY NAME FOR " + base::Int64ToString(id); |
| 111 if (id == 1) | 113 if (id == 1) |
| 112 unit->mirroring_source_id = "0"; | 114 unit->mirroring_source_id = "0"; |
| 113 unit->is_primary = id == 0 ? true : false; | 115 unit->is_primary = id == 0 ? true : false; |
| 114 unit->is_internal = id == 0 ? true : false; | 116 unit->is_internal = id == 0 ? true : false; |
| 115 unit->is_enabled = true; | 117 unit->is_enabled = true; |
| 116 unit->rotation = (90 * id) % 360; | 118 unit->rotation = (90 * id) % 360; |
| 117 unit->dpi_x = 96.0; | 119 unit->dpi_x = 96.0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 133 | 135 |
| 134 class SystemDisplayApiTest : public ShellApiTest { | 136 class SystemDisplayApiTest : public ShellApiTest { |
| 135 public: | 137 public: |
| 136 SystemDisplayApiTest() | 138 SystemDisplayApiTest() |
| 137 : provider_(new MockDisplayInfoProvider), screen_(new MockScreen) {} | 139 : provider_(new MockDisplayInfoProvider), screen_(new MockScreen) {} |
| 138 | 140 |
| 139 ~SystemDisplayApiTest() override {} | 141 ~SystemDisplayApiTest() override {} |
| 140 | 142 |
| 141 void SetUpOnMainThread() override { | 143 void SetUpOnMainThread() override { |
| 142 ShellApiTest::SetUpOnMainThread(); | 144 ShellApiTest::SetUpOnMainThread(); |
| 143 ANNOTATE_LEAKING_OBJECT_PTR(gfx::Screen::GetScreen()); | 145 ANNOTATE_LEAKING_OBJECT_PTR(display::Screen::GetScreen()); |
| 144 gfx::Screen::SetScreenInstance(screen_.get()); | 146 display::Screen::SetScreenInstance(screen_.get()); |
| 145 DisplayInfoProvider::InitializeForTesting(provider_.get()); | 147 DisplayInfoProvider::InitializeForTesting(provider_.get()); |
| 146 } | 148 } |
| 147 | 149 |
| 148 protected: | 150 protected: |
| 149 std::unique_ptr<MockDisplayInfoProvider> provider_; | 151 std::unique_ptr<MockDisplayInfoProvider> provider_; |
| 150 std::unique_ptr<gfx::Screen> screen_; | 152 std::unique_ptr<display::Screen> screen_; |
| 151 | 153 |
| 152 private: | 154 private: |
| 153 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest); | 155 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest); |
| 154 }; | 156 }; |
| 155 | 157 |
| 156 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplay) { | 158 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplay) { |
| 157 ASSERT_TRUE(RunAppTest("system/display")) << message_; | 159 ASSERT_TRUE(RunAppTest("system/display")) << message_; |
| 158 } | 160 } |
| 159 | 161 |
| 160 #if !defined(OS_CHROMEOS) | 162 #if !defined(OS_CHROMEOS) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 enable_unified_function->set_extension(test_extension.get()); | 296 enable_unified_function->set_extension(test_extension.get()); |
| 295 ASSERT_TRUE(api_test_utils::RunFunction(enable_unified_function.get(), | 297 ASSERT_TRUE(api_test_utils::RunFunction(enable_unified_function.get(), |
| 296 "[false]", browser_context())); | 298 "[false]", browser_context())); |
| 297 EXPECT_FALSE(provider_->unified_desktop_enabled()); | 299 EXPECT_FALSE(provider_->unified_desktop_enabled()); |
| 298 } | 300 } |
| 299 } | 301 } |
| 300 | 302 |
| 301 #endif // defined(OS_CHROMEOS) | 303 #endif // defined(OS_CHROMEOS) |
| 302 | 304 |
| 303 } // namespace extensions | 305 } // namespace extensions |
| OLD | NEW |