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 GetWindowAtCursorScreenPoint() OVERRIDE { | |
| 41 return gfx::NativeWindow(); | |
| 42 } | |
| 43 virtual int GetNumDisplays() const OVERRIDE { | |
| 44 return displays_.size(); | |
| 45 } | |
| 46 virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE { | |
| 47 return displays_; | |
| 48 } | |
| 49 virtual gfx::Display GetDisplayNearestWindow( | |
| 50 gfx::NativeView window) const OVERRIDE { | |
| 51 return gfx::Display(); | |
| 52 } | |
| 53 virtual gfx::Display GetDisplayNearestPoint( | |
| 54 const gfx::Point& point) const OVERRIDE { | |
| 55 return gfx::Display(); | |
| 56 } | |
| 57 virtual gfx::Display GetDisplayMatching( | |
| 58 const gfx::Rect& match_rect) const OVERRIDE { | |
| 59 return gfx::Display(); | |
| 60 } | |
| 61 virtual gfx::Display GetPrimaryDisplay() const OVERRIDE { | |
| 62 return displays_[0]; | |
| 63 } | |
| 64 virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE {} | |
| 65 virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE {} | |
| 66 | |
| 67 private: | |
| 68 std::vector<gfx::Display> displays_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(MockScreen); | |
| 71 }; | |
| 72 | |
| 18 | 73 |
| 19 class MockDisplayInfoProvider : public DisplayInfoProvider { | 74 class MockDisplayInfoProvider : public DisplayInfoProvider { |
| 20 public: | 75 public: |
| 21 MockDisplayInfoProvider() {} | 76 MockDisplayInfoProvider() {} |
| 22 | 77 |
| 23 virtual bool QueryInfo() OVERRIDE { | 78 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 | 79 |
| 56 virtual void SetInfo( | 80 virtual bool SetInfo( |
| 57 const std::string& display_id, | 81 const std::string& display_id, |
| 58 const api::system_display::DisplayProperties& params, | 82 const api::system_display::DisplayProperties& params, |
| 59 const SetInfoCallback& callback) OVERRIDE { | 83 std::string* error) OVERRIDE { |
| 60 // Should get called only once per test case. | 84 // Should get called only once per test case. |
| 61 EXPECT_FALSE(set_info_value_); | 85 EXPECT_FALSE(set_info_value_); |
| 62 set_info_value_ = params.ToValue(); | 86 set_info_value_ = params.ToValue(); |
| 63 set_info_display_id_ = display_id; | 87 set_info_display_id_ = display_id; |
| 64 callback.Run(true, std::string()); | 88 return true; |
| 65 } | 89 } |
| 66 | 90 |
| 67 scoped_ptr<base::DictionaryValue> GetSetInfoValue() { | 91 scoped_ptr<base::DictionaryValue> GetSetInfoValue() { |
| 68 return set_info_value_.Pass(); | 92 return set_info_value_.Pass(); |
| 69 } | 93 } |
| 70 | 94 |
| 71 std::string GetSetInfoDisplayId() const { | 95 std::string GetSetInfoDisplayId() const { |
| 72 return set_info_display_id_; | 96 return set_info_display_id_; |
| 73 } | 97 } |
| 74 | 98 |
| 75 private: | 99 private: |
| 76 virtual ~MockDisplayInfoProvider() {} | 100 // Update the content of the |unit| obtained for |display| using |
| 101 // platform specific method. | |
| 102 virtual void UpdateDisplayUnitInfoForPlatform( | |
| 103 const gfx::Display& display, | |
| 104 extensions::api::system_display::DisplayUnitInfo* unit) OVERRIDE { | |
| 105 int64 id = display.id(); | |
| 106 unit->name = "DISPLAY NAME FOR " + base::Int64ToString(id); | |
| 107 if (id == 1) | |
| 108 unit->mirroring_source_id = "0"; | |
| 109 unit->is_primary = id == 0 ? true : false; | |
| 110 unit->is_internal = id == 0 ? true : false; | |
| 111 unit->is_enabled = true; | |
| 112 unit->rotation = (90 * id) % 360; | |
| 113 unit->dpi_x = 96.0; | |
| 114 unit->dpi_y = 96.0; | |
| 115 unit->bounds.left = 0; | |
| 116 unit->bounds.top = 0; | |
| 117 unit->bounds.width = 1280; | |
| 118 unit->bounds.height = 720; | |
| 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 unit->work_area.left = 0; | |
| 126 unit->work_area.top = 0; | |
| 127 unit->work_area.width = 960; | |
| 128 unit->work_area.height = 720; | |
|
oshima
2013/09/03 23:14:46
Some of these must be already done in DisplayInfoP
Haojian Wu
2013/09/04 12:11:33
Yes. Remove it now.
| |
| 129 } | |
| 77 | 130 |
| 78 scoped_ptr<base::DictionaryValue> set_info_value_; | 131 scoped_ptr<base::DictionaryValue> set_info_value_; |
| 79 std::string set_info_display_id_; | 132 std::string set_info_display_id_; |
| 80 | 133 |
| 81 DISALLOW_COPY_AND_ASSIGN(MockDisplayInfoProvider); | 134 DISALLOW_COPY_AND_ASSIGN(MockDisplayInfoProvider); |
| 82 }; | 135 }; |
| 83 | 136 |
| 84 class SystemDisplayApiTest: public ExtensionApiTest { | 137 class SystemDisplayApiTest: public ExtensionApiTest { |
| 85 public: | 138 public: |
| 86 SystemDisplayApiTest() {} | 139 SystemDisplayApiTest() : screen_(new MockScreen) { |
| 140 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | |
| 141 } | |
| 87 virtual ~SystemDisplayApiTest() {} | 142 virtual ~SystemDisplayApiTest() {} |
| 88 | 143 |
| 89 virtual void SetUpOnMainThread() OVERRIDE { | 144 virtual void SetUpOnMainThread() OVERRIDE { |
| 90 ExtensionApiTest::SetUpOnMainThread(); | 145 ExtensionApiTest::SetUpOnMainThread(); |
| 91 provider_ = new MockDisplayInfoProvider(); | 146 provider_ = new MockDisplayInfoProvider(); |
| 92 // The |provider| will be co-owned by the singleton instance. | 147 // The |provider_| will be co-owned by the DisplayInfoProvider instance. |
| 93 DisplayInfoProvider::InitializeForTesting(provider_); | 148 DisplayInfoProvider::InitializeForTesting(provider_); |
| 94 } | 149 } |
| 95 | 150 |
| 96 virtual void CleanUpOnMainThread() OVERRIDE { | 151 virtual void CleanUpOnMainThread() OVERRIDE { |
| 97 // Has to be released before the main thread is gone. | |
| 98 provider_ = NULL; | |
| 99 ExtensionApiTest::CleanUpOnMainThread(); | 152 ExtensionApiTest::CleanUpOnMainThread(); |
| 100 } | 153 } |
| 101 | 154 |
| 102 protected: | 155 protected: |
| 103 scoped_refptr<MockDisplayInfoProvider> provider_; | 156 MockDisplayInfoProvider* provider_; |
| 157 scoped_ptr<gfx::Screen> screen_; | |
| 104 | 158 |
| 105 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest); | 159 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest); |
| 106 }; | 160 }; |
| 107 | 161 |
| 108 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplay) { | 162 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplay) { |
| 109 ASSERT_TRUE(RunPlatformAppTest("system/display")) << message_; | 163 ASSERT_TRUE(RunPlatformAppTest("system/display")) << message_; |
| 110 } | 164 } |
| 111 | 165 |
| 112 #if !defined(OS_CHROMEOS) | 166 #if !defined(OS_CHROMEOS) |
| 113 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { | 167 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")); | 257 EXPECT_EQ(1, utils::GetInteger(overscan, "left")); |
| 204 EXPECT_EQ(2, utils::GetInteger(overscan, "top")); | 258 EXPECT_EQ(2, utils::GetInteger(overscan, "top")); |
| 205 EXPECT_EQ(3, utils::GetInteger(overscan, "right")); | 259 EXPECT_EQ(3, utils::GetInteger(overscan, "right")); |
| 206 EXPECT_EQ(4, utils::GetInteger(overscan, "bottom")); | 260 EXPECT_EQ(4, utils::GetInteger(overscan, "bottom")); |
| 207 | 261 |
| 208 EXPECT_EQ("display_id", provider_->GetSetInfoDisplayId()); | 262 EXPECT_EQ("display_id", provider_->GetSetInfoDisplayId()); |
| 209 } | 263 } |
| 210 #endif // defined(OS_CHROMEOS) | 264 #endif // defined(OS_CHROMEOS) |
| 211 | 265 |
| 212 } // namespace extensions | 266 } // namespace extensions |
| OLD | NEW |