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 <set> | |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/stl_util.h" | |
11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
13 #include "extensions/browser/api/system_display/display_info_provider.h" | 15 #include "extensions/browser/api/system_display/display_info_provider.h" |
14 #include "extensions/browser/api/system_display/system_display_api.h" | 16 #include "extensions/browser/api/system_display/system_display_api.h" |
15 #include "extensions/browser/api_test_utils.h" | 17 #include "extensions/browser/api_test_utils.h" |
16 #include "extensions/common/api/system_display.h" | 18 #include "extensions/common/api/system_display.h" |
17 #include "extensions/shell/test/shell_apitest.h" | 19 #include "extensions/shell/test/shell_apitest.h" |
20 #include "extensions/test/result_catcher.h" | |
18 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
19 #include "ui/display/screen.h" | 22 #include "ui/display/screen.h" |
20 | 23 |
21 namespace extensions { | 24 namespace extensions { |
22 | 25 |
23 using api::system_display::Bounds; | 26 using api::system_display::Bounds; |
24 using api::system_display::DisplayUnitInfo; | 27 using api::system_display::DisplayUnitInfo; |
25 using display::Screen; | 28 using display::Screen; |
26 | 29 |
27 class MockScreen : public Screen { | 30 class MockScreen : public Screen { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 EXPECT_FALSE(set_info_value_); | 88 EXPECT_FALSE(set_info_value_); |
86 set_info_value_ = params.ToValue(); | 89 set_info_value_ = params.ToValue(); |
87 set_info_display_id_ = display_id; | 90 set_info_display_id_ = display_id; |
88 return true; | 91 return true; |
89 } | 92 } |
90 | 93 |
91 void EnableUnifiedDesktop(bool enable) override { | 94 void EnableUnifiedDesktop(bool enable) override { |
92 unified_desktop_enabled_ = enable; | 95 unified_desktop_enabled_ = enable; |
93 } | 96 } |
94 | 97 |
98 bool OverscanCalibrationStart(const std::string& id) override { | |
99 if (base::ContainsKey(overscan_started_, id)) | |
100 return false; | |
101 overscan_started_.insert(id); | |
102 return true; | |
103 } | |
104 | |
105 bool OverscanCalibrationAdjust( | |
106 const std::string& id, | |
107 const api::system_display::Insets& delta) override { | |
108 if (!base::ContainsKey(overscan_started_, id)) | |
109 return false; | |
110 overscan_adjusted_.insert(id); | |
111 return true; | |
112 } | |
113 | |
114 bool OverscanCalibrationReset(const std::string& id) override { | |
115 if (!base::ContainsKey(overscan_started_, id)) | |
116 return false; | |
117 overscan_adjusted_.erase(id); | |
118 return true; | |
119 } | |
120 | |
121 bool OverscanCalibrationComplete(const std::string& id) override { | |
122 if (!base::ContainsKey(overscan_started_, id)) | |
123 return false; | |
124 overscan_started_.erase(id); | |
125 return true; | |
126 } | |
127 | |
95 std::unique_ptr<base::DictionaryValue> GetSetInfoValue() { | 128 std::unique_ptr<base::DictionaryValue> GetSetInfoValue() { |
96 return std::move(set_info_value_); | 129 return std::move(set_info_value_); |
97 } | 130 } |
98 | 131 |
99 std::string GetSetInfoDisplayId() const { return set_info_display_id_; } | 132 std::string GetSetInfoDisplayId() const { return set_info_display_id_; } |
100 | 133 |
101 bool unified_desktop_enabled() const { return unified_desktop_enabled_; } | 134 bool unified_desktop_enabled() const { return unified_desktop_enabled_; } |
102 | 135 |
136 bool calibration_started(const std::string& id) { | |
xiyuan
2016/12/07 21:32:40
nit: const method?
stevenjb
2016/12/07 21:54:42
Done.
| |
137 return base::ContainsKey(overscan_started_, id); | |
138 } | |
139 | |
140 bool calibration_changed(const std::string& id) { | |
xiyuan
2016/12/07 21:32:40
nit: const method?
stevenjb
2016/12/07 21:54:42
Done.
| |
141 return base::ContainsKey(overscan_adjusted_, id); | |
142 } | |
143 | |
103 private: | 144 private: |
104 // Update the content of the |unit| obtained for |display| using | 145 // Update the content of the |unit| obtained for |display| using |
105 // platform specific method. | 146 // platform specific method. |
106 void UpdateDisplayUnitInfoForPlatform( | 147 void UpdateDisplayUnitInfoForPlatform( |
107 const display::Display& display, | 148 const display::Display& display, |
108 extensions::api::system_display::DisplayUnitInfo* unit) override { | 149 extensions::api::system_display::DisplayUnitInfo* unit) override { |
109 int64_t id = display.id(); | 150 int64_t id = display.id(); |
110 unit->name = "DISPLAY NAME FOR " + base::Int64ToString(id); | 151 unit->name = "DISPLAY NAME FOR " + base::Int64ToString(id); |
111 if (id == 1) | 152 if (id == 1) |
112 unit->mirroring_source_id = "0"; | 153 unit->mirroring_source_id = "0"; |
113 unit->is_primary = id == 0 ? true : false; | 154 unit->is_primary = id == 0 ? true : false; |
114 unit->is_internal = id == 0 ? true : false; | 155 unit->is_internal = id == 0 ? true : false; |
115 unit->is_enabled = true; | 156 unit->is_enabled = true; |
116 unit->rotation = (90 * id) % 360; | 157 unit->rotation = (90 * id) % 360; |
117 unit->dpi_x = 96.0; | 158 unit->dpi_x = 96.0; |
118 unit->dpi_y = 96.0; | 159 unit->dpi_y = 96.0; |
119 if (id == 0) { | 160 if (id == 0) { |
120 unit->overscan.left = 20; | 161 unit->overscan.left = 20; |
121 unit->overscan.top = 40; | 162 unit->overscan.top = 40; |
122 unit->overscan.right = 60; | 163 unit->overscan.right = 60; |
123 unit->overscan.bottom = 80; | 164 unit->overscan.bottom = 80; |
124 } | 165 } |
125 } | 166 } |
126 | 167 |
127 std::unique_ptr<base::DictionaryValue> set_info_value_; | 168 std::unique_ptr<base::DictionaryValue> set_info_value_; |
128 std::string set_info_display_id_; | 169 std::string set_info_display_id_; |
129 bool unified_desktop_enabled_ = false; | 170 bool unified_desktop_enabled_ = false; |
171 std::set<std::string> overscan_started_; | |
172 std::set<std::string> overscan_adjusted_; | |
130 | 173 |
131 DISALLOW_COPY_AND_ASSIGN(MockDisplayInfoProvider); | 174 DISALLOW_COPY_AND_ASSIGN(MockDisplayInfoProvider); |
132 }; | 175 }; |
133 | 176 |
134 class SystemDisplayApiTest : public ShellApiTest { | 177 class SystemDisplayApiTest : public ShellApiTest { |
135 public: | 178 public: |
136 SystemDisplayApiTest() | 179 SystemDisplayApiTest() |
137 : provider_(new MockDisplayInfoProvider), screen_(new MockScreen) {} | 180 : provider_(new MockDisplayInfoProvider), screen_(new MockScreen) {} |
138 | 181 |
139 ~SystemDisplayApiTest() override {} | 182 ~SystemDisplayApiTest() override {} |
(...skipping 10 matching lines...) Expand all Loading... | |
150 std::unique_ptr<display::Screen> screen_; | 193 std::unique_ptr<display::Screen> screen_; |
151 | 194 |
152 private: | 195 private: |
153 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest); | 196 DISALLOW_COPY_AND_ASSIGN(SystemDisplayApiTest); |
154 }; | 197 }; |
155 | 198 |
156 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplayInfo) { | 199 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, GetDisplayInfo) { |
157 ASSERT_TRUE(RunAppTest("system/display/info")) << message_; | 200 ASSERT_TRUE(RunAppTest("system/display/info")) << message_; |
158 } | 201 } |
159 | 202 |
203 const char test_manifest[] = | |
xiyuan
2016/12/07 21:32:40
nit: const -> constexpr, test_manifest -> kTestMan
stevenjb
2016/12/07 21:54:42
Done.
| |
204 "{\n" | |
205 " \"name\": \"Test\",\n" | |
206 " \"version\": \"1.0\",\n" | |
207 " \"app\": {\n" | |
208 " \"background\": {\n" | |
209 " \"scripts\": [\"background.js\"]\n" | |
210 " }\n" | |
211 " }\n" | |
212 "}"; | |
213 | |
214 const char test_manifest_kiosk[] = | |
xiyuan
2016/12/07 21:32:40
nit: const -> constexpr, test_manifest_kiosk -> kT
stevenjb
2016/12/07 21:54:42
Done.
| |
215 "{\n" | |
216 " \"name\": \"Test\",\n" | |
217 " \"version\": \"1.0\",\n" | |
218 " \"app\": {\n" | |
219 " \"background\": {\n" | |
220 " \"scripts\": [\"background.js\"]\n" | |
221 " }\n" | |
222 " },\n" | |
223 " \"kiosk_enabled\": true\n" | |
224 "}"; | |
225 | |
160 #if !defined(OS_CHROMEOS) | 226 #if !defined(OS_CHROMEOS) |
161 | 227 |
162 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { | 228 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { |
163 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function( | 229 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function( |
164 new SystemDisplaySetDisplayPropertiesFunction()); | 230 new SystemDisplaySetDisplayPropertiesFunction()); |
165 | 231 |
166 set_info_function->set_has_callback(true); | 232 set_info_function->set_has_callback(true); |
167 | 233 |
168 EXPECT_EQ( | 234 EXPECT_EQ( |
169 SystemDisplayFunction::kCrosOnlyError, | 235 SystemDisplayFunction::kCrosOnlyError, |
170 api_test_utils::RunFunctionAndReturnError( | 236 api_test_utils::RunFunctionAndReturnError( |
171 set_info_function.get(), "[\"display_id\", {}]", browser_context())); | 237 set_info_function.get(), "[\"display_id\", {}]", browser_context())); |
172 | 238 |
173 std::unique_ptr<base::DictionaryValue> set_info = | 239 std::unique_ptr<base::DictionaryValue> set_info = |
174 provider_->GetSetInfoValue(); | 240 provider_->GetSetInfoValue(); |
175 EXPECT_FALSE(set_info); | 241 EXPECT_FALSE(set_info); |
176 } | 242 } |
177 | 243 |
178 #else // !defined(OS_CHROMEOS) | 244 #else // !defined(OS_CHROMEOS) |
179 | 245 |
180 // TODO(stevenjb): Add API tests for {GS}etDisplayLayout. That code currently | 246 // TODO(stevenjb): Add API tests for {GS}etDisplayLayout. That code currently |
181 // lives in src/chrome but should be getting moved soon. | 247 // lives in src/chrome but should be getting moved soon. |
182 | 248 |
183 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayNotKioskEnabled) { | 249 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayNotKioskEnabled) { |
184 std::unique_ptr<base::DictionaryValue> test_extension_value( | 250 std::unique_ptr<base::DictionaryValue> test_extension_value( |
185 api_test_utils::ParseDictionary("{\n" | 251 api_test_utils::ParseDictionary(test_manifest)); |
186 " \"name\": \"Test\",\n" | |
187 " \"version\": \"1.0\",\n" | |
188 " \"app\": {\n" | |
189 " \"background\": {\n" | |
190 " \"scripts\": [\"background.js\"]\n" | |
191 " }\n" | |
192 " }\n" | |
193 "}")); | |
194 scoped_refptr<Extension> test_extension( | 252 scoped_refptr<Extension> test_extension( |
195 api_test_utils::CreateExtension(test_extension_value.get())); | 253 api_test_utils::CreateExtension(test_extension_value.get())); |
196 | 254 |
197 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function( | 255 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function( |
198 new SystemDisplaySetDisplayPropertiesFunction()); | 256 new SystemDisplaySetDisplayPropertiesFunction()); |
199 | 257 |
200 set_info_function->set_extension(test_extension.get()); | 258 set_info_function->set_extension(test_extension.get()); |
201 set_info_function->set_has_callback(true); | 259 set_info_function->set_has_callback(true); |
202 | 260 |
203 EXPECT_EQ( | 261 EXPECT_EQ( |
204 SystemDisplayFunction::kKioskOnlyError, | 262 SystemDisplayFunction::kKioskOnlyError, |
205 api_test_utils::RunFunctionAndReturnError( | 263 api_test_utils::RunFunctionAndReturnError( |
206 set_info_function.get(), "[\"display_id\", {}]", browser_context())); | 264 set_info_function.get(), "[\"display_id\", {}]", browser_context())); |
207 | 265 |
208 std::unique_ptr<base::DictionaryValue> set_info = | 266 std::unique_ptr<base::DictionaryValue> set_info = |
209 provider_->GetSetInfoValue(); | 267 provider_->GetSetInfoValue(); |
210 EXPECT_FALSE(set_info); | 268 EXPECT_FALSE(set_info); |
211 } | 269 } |
212 | 270 |
213 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayKioskEnabled) { | 271 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayKioskEnabled) { |
214 std::unique_ptr<base::DictionaryValue> test_extension_value( | 272 std::unique_ptr<base::DictionaryValue> test_extension_value( |
215 api_test_utils::ParseDictionary("{\n" | 273 api_test_utils::ParseDictionary(test_manifest_kiosk)); |
216 " \"name\": \"Test\",\n" | |
217 " \"version\": \"1.0\",\n" | |
218 " \"app\": {\n" | |
219 " \"background\": {\n" | |
220 " \"scripts\": [\"background.js\"]\n" | |
221 " }\n" | |
222 " },\n" | |
223 " \"kiosk_enabled\": true\n" | |
224 "}")); | |
225 scoped_refptr<Extension> test_extension( | 274 scoped_refptr<Extension> test_extension( |
226 api_test_utils::CreateExtension(test_extension_value.get())); | 275 api_test_utils::CreateExtension(test_extension_value.get())); |
227 | 276 |
228 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function( | 277 scoped_refptr<SystemDisplaySetDisplayPropertiesFunction> set_info_function( |
229 new SystemDisplaySetDisplayPropertiesFunction()); | 278 new SystemDisplaySetDisplayPropertiesFunction()); |
230 | 279 |
231 set_info_function->set_has_callback(true); | 280 set_info_function->set_has_callback(true); |
232 set_info_function->set_extension(test_extension.get()); | 281 set_info_function->set_extension(test_extension.get()); |
233 | 282 |
234 ASSERT_TRUE(api_test_utils::RunFunction( | 283 ASSERT_TRUE(api_test_utils::RunFunction( |
(...skipping 22 matching lines...) Expand all Loading... | |
257 EXPECT_EQ(1, api_test_utils::GetInteger(overscan, "left")); | 306 EXPECT_EQ(1, api_test_utils::GetInteger(overscan, "left")); |
258 EXPECT_EQ(2, api_test_utils::GetInteger(overscan, "top")); | 307 EXPECT_EQ(2, api_test_utils::GetInteger(overscan, "top")); |
259 EXPECT_EQ(3, api_test_utils::GetInteger(overscan, "right")); | 308 EXPECT_EQ(3, api_test_utils::GetInteger(overscan, "right")); |
260 EXPECT_EQ(4, api_test_utils::GetInteger(overscan, "bottom")); | 309 EXPECT_EQ(4, api_test_utils::GetInteger(overscan, "bottom")); |
261 | 310 |
262 EXPECT_EQ("display_id", provider_->GetSetInfoDisplayId()); | 311 EXPECT_EQ("display_id", provider_->GetSetInfoDisplayId()); |
263 } | 312 } |
264 | 313 |
265 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, EnableUnifiedDesktop) { | 314 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, EnableUnifiedDesktop) { |
266 std::unique_ptr<base::DictionaryValue> test_extension_value( | 315 std::unique_ptr<base::DictionaryValue> test_extension_value( |
267 api_test_utils::ParseDictionary("{\n" | 316 api_test_utils::ParseDictionary(test_manifest_kiosk)); |
268 " \"name\": \"Test\",\n" | |
269 " \"version\": \"1.0\",\n" | |
270 " \"app\": {\n" | |
271 " \"background\": {\n" | |
272 " \"scripts\": [\"background.js\"]\n" | |
273 " }\n" | |
274 " },\n" | |
275 " \"kiosk_enabled\": true\n" | |
276 "}")); | |
277 scoped_refptr<Extension> test_extension( | 317 scoped_refptr<Extension> test_extension( |
278 api_test_utils::CreateExtension(test_extension_value.get())); | 318 api_test_utils::CreateExtension(test_extension_value.get())); |
279 { | 319 { |
280 scoped_refptr<SystemDisplayEnableUnifiedDesktopFunction> | 320 scoped_refptr<SystemDisplayEnableUnifiedDesktopFunction> |
281 enable_unified_function( | 321 enable_unified_function( |
282 new SystemDisplayEnableUnifiedDesktopFunction()); | 322 new SystemDisplayEnableUnifiedDesktopFunction()); |
283 | 323 |
284 enable_unified_function->set_has_callback(true); | 324 enable_unified_function->set_has_callback(true); |
285 enable_unified_function->set_extension(test_extension.get()); | 325 enable_unified_function->set_extension(test_extension.get()); |
286 | 326 |
287 EXPECT_FALSE(provider_->unified_desktop_enabled()); | 327 EXPECT_FALSE(provider_->unified_desktop_enabled()); |
288 | 328 |
289 ASSERT_TRUE(api_test_utils::RunFunction(enable_unified_function.get(), | 329 ASSERT_TRUE(api_test_utils::RunFunction(enable_unified_function.get(), |
290 "[true]", browser_context())); | 330 "[true]", browser_context())); |
291 EXPECT_TRUE(provider_->unified_desktop_enabled()); | 331 EXPECT_TRUE(provider_->unified_desktop_enabled()); |
292 } | 332 } |
293 { | 333 { |
294 scoped_refptr<SystemDisplayEnableUnifiedDesktopFunction> | 334 scoped_refptr<SystemDisplayEnableUnifiedDesktopFunction> |
295 enable_unified_function( | 335 enable_unified_function( |
296 new SystemDisplayEnableUnifiedDesktopFunction()); | 336 new SystemDisplayEnableUnifiedDesktopFunction()); |
297 | 337 |
298 enable_unified_function->set_has_callback(true); | 338 enable_unified_function->set_has_callback(true); |
299 enable_unified_function->set_extension(test_extension.get()); | 339 enable_unified_function->set_extension(test_extension.get()); |
300 ASSERT_TRUE(api_test_utils::RunFunction(enable_unified_function.get(), | 340 ASSERT_TRUE(api_test_utils::RunFunction(enable_unified_function.get(), |
301 "[false]", browser_context())); | 341 "[false]", browser_context())); |
302 EXPECT_FALSE(provider_->unified_desktop_enabled()); | 342 EXPECT_FALSE(provider_->unified_desktop_enabled()); |
303 } | 343 } |
304 } | 344 } |
305 | 345 |
346 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, OverscanCalibrationStart) { | |
347 const std::string id = "display0"; | |
348 std::unique_ptr<base::DictionaryValue> test_extension_value( | |
349 api_test_utils::ParseDictionary(test_manifest_kiosk)); | |
350 scoped_refptr<Extension> test_extension( | |
351 api_test_utils::CreateExtension(test_extension_value.get())); | |
352 | |
353 // Setup MockDisplayInfoProvider. | |
354 api::system_display::DisplayProperties params; | |
355 provider_->SetInfo(id, params, nullptr); | |
356 | |
357 // Call OverscanCalibrationStart. | |
358 scoped_refptr<SystemDisplayOverscanCalibrationStartFunction> start_function( | |
359 new SystemDisplayOverscanCalibrationStartFunction()); | |
360 start_function->set_extension(test_extension.get()); | |
361 start_function->set_has_callback(true); | |
362 ASSERT_TRUE(api_test_utils::RunFunction( | |
363 start_function.get(), "[\"" + id + "\"]", browser_context())); | |
364 | |
365 ASSERT_TRUE(provider_->calibration_started(id)); | |
366 | |
367 // Call OverscanCalibrationComplete. | |
368 scoped_refptr<SystemDisplayOverscanCalibrationCompleteFunction> | |
369 complete_function(new SystemDisplayOverscanCalibrationCompleteFunction()); | |
370 complete_function->set_extension(test_extension.get()); | |
371 complete_function->set_has_callback(true); | |
372 ASSERT_TRUE(api_test_utils::RunFunction( | |
373 complete_function.get(), "[\"" + id + "\"]", browser_context())); | |
374 | |
375 ASSERT_FALSE(provider_->calibration_started(id)); | |
376 } | |
377 | |
378 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, OverscanCalibrationApp) { | |
379 // Setup MockDisplayInfoProvider. | |
380 const std::string id = "display0"; | |
381 api::system_display::DisplayProperties params; | |
382 provider_->SetInfo(id, params, nullptr); | |
383 | |
384 ASSERT_TRUE(RunAppTest("system/display/overscan")) << message_; | |
385 | |
386 ASSERT_FALSE(provider_->calibration_started(id)); | |
387 ASSERT_TRUE(provider_->calibration_changed(id)); | |
388 } | |
389 | |
390 IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, OverscanCalibrationAppNoComplete) { | |
391 // Setup MockDisplayInfoProvider. | |
392 const std::string id = "display0"; | |
393 api::system_display::DisplayProperties params; | |
394 provider_->SetInfo(id, params, nullptr); | |
395 | |
396 ResultCatcher catcher; | |
397 const Extension* extension = LoadApp("system/display/overscan_no_complete"); | |
398 ASSERT_TRUE(extension); | |
399 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
400 | |
401 // Calibration was started by the app but not completed. | |
402 ASSERT_TRUE(provider_->calibration_started(id)); | |
403 | |
404 // Unloading the app should complete the calibraiton (and hide the overlay). | |
405 UnloadApp(extension); | |
406 ASSERT_FALSE(provider_->calibration_changed(id)); | |
407 ASSERT_FALSE(provider_->calibration_started(id)); | |
408 } | |
409 | |
306 #endif // !defined(OS_CHROMEOS) | 410 #endif // !defined(OS_CHROMEOS) |
307 | 411 |
308 } // namespace extensions | 412 } // namespace extensions |
OLD | NEW |