Chromium Code Reviews| 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 "chrome/browser/extensions/api/system_display/system_display_api.h" | 5 #include "chrome/browser/extensions/api/system_display/system_display_api.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "chrome/browser/extensions/api/system_display/display_info_provider.h" | 8 #include "chrome/browser/extensions/api/system_display/display_info_provider.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/extensions/extension_function_test_utils.h" | 10 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 11 #include "ui/gfx/display.h" | |
| 12 #include "ui/gfx/display_observer.h" | |
| 13 #include "ui/gfx/screen.h" | |
| 11 | 14 |
| 12 namespace utils = extension_function_test_utils; | 15 namespace utils = extension_function_test_utils; |
| 13 | 16 |
| 14 namespace extensions { | 17 namespace extensions { |
| 15 | 18 |
| 16 using api::system_display::Bounds; | 19 using api::system_display::Bounds; |
| 17 using api::system_display::DisplayUnitInfo; | 20 using api::system_display::DisplayUnitInfo; |
| 21 using gfx::Screen; | |
| 22 | |
| 23 class MockScreen : public Screen { | |
| 24 public: | |
| 25 MockScreen() { | |
| 26 for (int i = 0; i < 4; i++) { | |
| 27 gfx::Rect bounds(0, 0, 1280, 720); | |
| 28 gfx::Rect work_area(0, 0, 960, 720); | |
| 29 gfx::Display display(i, bounds); | |
| 30 display.set_work_area(work_area); | |
| 31 displays_.push_back(display); | |
| 32 } | |
| 33 } | |
| 34 virtual ~MockScreen() {} | |
| 35 | |
| 36 protected: | |
| 37 // Overridden from gfx::Screen: | |
| 38 virtual bool IsDIPEnabled() OVERRIDE { return true; } | |
| 39 virtual gfx::Point GetCursorScreenPoint() OVERRIDE { return gfx::Point(); } | |
| 40 virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE { | |
| 41 return gfx::NativeWindow(); | |
| 42 } | |
| 43 virtual gfx::NativeWindow GetWindowAtScreenPoint( | |
| 44 const gfx::Point& point) OVERRIDE { | |
| 45 return gfx::NativeWindow(); | |
| 46 } | |
| 47 virtual int GetNumDisplays() const OVERRIDE { | |
| 48 return displays_.size(); | |
| 49 } | |
| 50 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { | |
| 51 return displays_; | |
| 52 } | |
| 53 virtual gfx::Display GetDisplayNearestWindow( | |
| 54 gfx::NativeView window) const OVERRIDE { | |
| 55 return gfx::Display(0); | |
| 56 } | |
| 57 virtual gfx::Display GetDisplayNearestPoint( | |
| 58 const gfx::Point& point) const OVERRIDE { | |
| 59 return gfx::Display(0); | |
| 60 } | |
| 61 virtual gfx::Display GetDisplayMatching( | |
| 62 const gfx::Rect& match_rect) const OVERRIDE { | |
| 63 return gfx::Display(0); | |
| 64 } | |
| 65 virtual gfx::Display GetPrimaryDisplay() const OVERRIDE { | |
| 66 return displays_[0]; | |
| 67 } | |
| 68 virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE {} | |
| 69 virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE {} | |
| 70 | |
| 71 private: | |
| 72 std::vector<gfx::Display> displays_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(MockScreen); | |
| 75 }; | |
| 76 | |
| 18 | 77 |
| 19 class MockDisplayInfoProvider : public DisplayInfoProvider { | 78 class MockDisplayInfoProvider : public DisplayInfoProvider { |
| 20 public: | 79 public: |
| 21 MockDisplayInfoProvider() {} | 80 MockDisplayInfoProvider() {} |
| 22 | 81 |
| 23 virtual bool QueryInfo() OVERRIDE { | 82 virtual ~MockDisplayInfoProvider() {} |
| 24 info_.clear(); | |
| 25 for (int i = 0; i < 4; i++) { | |
| 26 linked_ptr<DisplayUnitInfo> unit(new DisplayUnitInfo()); | |
| 27 unit->id = base::IntToString(i); | |
| 28 unit->name = "DISPLAY NAME FOR " + unit->id; | |
| 29 if (i == 1) | |
| 30 unit->mirroring_source_id = "0"; | |
| 31 unit->is_primary = i == 0 ? true : false; | |
| 32 unit->is_internal = i == 0 ? true : false; | |
| 33 unit->is_enabled = true; | |
| 34 unit->rotation = (90 * i) % 360; | |
| 35 unit->dpi_x = 96.0; | |
| 36 unit->dpi_y = 96.0; | |
| 37 unit->bounds.left = 0; | |
| 38 unit->bounds.top = 0; | |
| 39 unit->bounds.width = 1280; | |
| 40 unit->bounds.height = 720; | |
| 41 if (i == 0) { | |
| 42 unit->overscan.left = 20; | |
| 43 unit->overscan.top = 40; | |
| 44 unit->overscan.right = 60; | |
| 45 unit->overscan.bottom = 80; | |
| 46 } | |
| 47 unit->work_area.left = 0; | |
| 48 unit->work_area.top = 0; | |
| 49 unit->work_area.width = 960; | |
| 50 unit->work_area.height = 720; | |
| 51 info_.push_back(unit); | |
| 52 } | |
| 53 return true; | |
| 54 } | |
| 55 | 83 |
| 56 virtual void SetInfo( | 84 virtual bool SetInfo( |
| 57 const std::string& display_id, | 85 const std::string& display_id, |
| 58 const api::system_display::DisplayProperties& params, | 86 const api::system_display::DisplayProperties& params, |
| 59 const SetInfoCallback& callback) OVERRIDE { | 87 std::string* error) OVERRIDE { |
| 60 // Should get called only once per test case. | 88 // Should get called only once per test case. |
| 61 EXPECT_FALSE(set_info_value_); | 89 EXPECT_FALSE(set_info_value_); |
| 62 set_info_value_ = params.ToValue(); | 90 set_info_value_ = params.ToValue(); |
| 63 set_info_display_id_ = display_id; | 91 set_info_display_id_ = display_id; |
| 64 callback.Run(true, std::string()); | 92 return true; |
| 65 } | 93 } |
| 66 | 94 |
| 67 scoped_ptr<base::DictionaryValue> GetSetInfoValue() { | 95 scoped_ptr<base::DictionaryValue> GetSetInfoValue() { |
| 68 return set_info_value_.Pass(); | 96 return set_info_value_.Pass(); |
| 69 } | 97 } |
| 70 | 98 |
| 71 std::string GetSetInfoDisplayId() const { | 99 std::string GetSetInfoDisplayId() const { |
| 72 return set_info_display_id_; | 100 return set_info_display_id_; |
| 73 } | 101 } |
| 74 | 102 |
| 75 private: | 103 private: |
| 76 virtual ~MockDisplayInfoProvider() {} | 104 // Update the content of the |unit| obtained for |display| using |
| 105 // platform specific method. | |
| 106 virtual void UpdateDisplayUnitInfoForPlatform( | |
| 107 const gfx::Display& display, | |
| 108 extensions::api::system_display::DisplayUnitInfo* unit) OVERRIDE { | |
| 109 int64 id = display.id(); | |
| 110 unit->name = "DISPLAY NAME FOR " + base::Int64ToString(id); | |
| 111 if (id == 1) | |
| 112 unit->mirroring_source_id = "0"; | |
| 113 unit->is_primary = id == 0 ? true : false; | |
| 114 unit->is_internal = id == 0 ? true : false; | |
| 115 unit->is_enabled = true; | |
| 116 unit->rotation = (90 * id) % 360; | |
| 117 unit->dpi_x = 96.0; | |
| 118 unit->dpi_y = 96.0; | |
| 119 if (id == 0) { | |
| 120 unit->overscan.left = 20; | |
| 121 unit->overscan.top = 40; | |
| 122 unit->overscan.right = 60; | |
| 123 unit->overscan.bottom = 80; | |
| 124 } | |
| 125 } | |
| 77 | 126 |
| 78 scoped_ptr<base::DictionaryValue> set_info_value_; | 127 scoped_ptr<base::DictionaryValue> set_info_value_; |
| 79 std::string set_info_display_id_; | 128 std::string set_info_display_id_; |
| 80 | 129 |
| 81 DISALLOW_COPY_AND_ASSIGN(MockDisplayInfoProvider); | 130 DISALLOW_COPY_AND_ASSIGN(MockDisplayInfoProvider); |
| 82 }; | 131 }; |
| 83 | 132 |
| 84 class SystemDisplayApiTest: public ExtensionApiTest { | 133 class SystemDisplayApiTest: public ExtensionApiTest { |
| 85 public: | 134 public: |
| 86 SystemDisplayApiTest() {} | 135 SystemDisplayApiTest() : provider_(new MockDisplayInfoProvider), |
| 136 screen_(new MockScreen) {} | |
| 137 | |
| 87 virtual ~SystemDisplayApiTest() {} | 138 virtual ~SystemDisplayApiTest() {} |
| 88 | 139 |
| 89 virtual void SetUpOnMainThread() OVERRIDE { | 140 virtual void SetUpOnMainThread() OVERRIDE { |
| 90 ExtensionApiTest::SetUpOnMainThread(); | 141 ExtensionApiTest::SetUpOnMainThread(); |
| 91 provider_ = new MockDisplayInfoProvider(); | 142 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
|
Haojian Wu
2013/09/18 13:03:55
oshima@, Is this reset-screen usage available?
I
| |
| 92 // The |provider| will be co-owned by the singleton instance. | 143 DisplayInfoProvider::InitializeForTesting(provider_.get()); |
| 93 DisplayInfoProvider::InitializeForTesting(provider_); | |
| 94 } | 144 } |
| 95 | 145 |
| 96 virtual void CleanUpOnMainThread() OVERRIDE { | 146 virtual void CleanUpOnMainThread() OVERRIDE { |
| 97 // Has to be released before the main thread is gone. | |
| 98 provider_ = NULL; | |
| 99 ExtensionApiTest::CleanUpOnMainThread(); | 147 ExtensionApiTest::CleanUpOnMainThread(); |
| 100 } | 148 } |
| 101 | 149 |
| 102 protected: | 150 protected: |
| 103 scoped_refptr<MockDisplayInfoProvider> provider_; | 151 scoped_ptr<MockDisplayInfoProvider> provider_; |
| 152 scoped_ptr<gfx::Screen> screen_; | |
| 104 | 153 |
| 105 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest); | 154 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest); |
| 106 }; | 155 }; |
| 107 | 156 |
| 108 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplay) { | 157 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplay) { |
| 109 ASSERT_TRUE(RunPlatformAppTest("system/display")) << message_; | 158 ASSERT_TRUE(RunPlatformAppTest("system/display")) << message_; |
| 110 } | 159 } |
| 111 | 160 |
| 112 #if !defined(OS_CHROMEOS) | 161 #if !defined(OS_CHROMEOS) |
| 113 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { | 162 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 EXPECT_EQ(1, utils::GetInteger(overscan, "left")); | 252 EXPECT_EQ(1, utils::GetInteger(overscan, "left")); |
| 204 EXPECT_EQ(2, utils::GetInteger(overscan, "top")); | 253 EXPECT_EQ(2, utils::GetInteger(overscan, "top")); |
| 205 EXPECT_EQ(3, utils::GetInteger(overscan, "right")); | 254 EXPECT_EQ(3, utils::GetInteger(overscan, "right")); |
| 206 EXPECT_EQ(4, utils::GetInteger(overscan, "bottom")); | 255 EXPECT_EQ(4, utils::GetInteger(overscan, "bottom")); |
| 207 | 256 |
| 208 EXPECT_EQ("display_id", provider_->GetSetInfoDisplayId()); | 257 EXPECT_EQ("display_id", provider_->GetSetInfoDisplayId()); |
| 209 } | 258 } |
| 210 #endif // defined(OS_CHROMEOS) | 259 #endif // defined(OS_CHROMEOS) |
| 211 | 260 |
| 212 } // namespace extensions | 261 } // namespace extensions |
| OLD | NEW |