| OLD | NEW |
| 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/wm/maximize_mode/maximize_mode_controller.h" | 9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 11 #include "ash/display/screen_orientation_controller_chromeos.h" | 11 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "chrome/browser/extensions/display_info_provider_chromeos.h" |
| 18 #include "extensions/common/api/system_display.h" | 19 #include "extensions/common/api/system_display.h" |
| 19 #include "ui/display/display.h" | 20 #include "ui/display/display.h" |
| 20 #include "ui/display/display_layout.h" | 21 #include "ui/display/display_layout.h" |
| 21 #include "ui/display/display_switches.h" | 22 #include "ui/display/display_switches.h" |
| 22 #include "ui/display/manager/display_manager.h" | 23 #include "ui/display/manager/display_manager.h" |
| 23 #include "ui/display/test/display_manager_test_api.h" | 24 #include "ui/display/test/display_manager_test_api.h" |
| 24 #include "ui/display/types/display_constants.h" | 25 #include "ui/display/types/display_constants.h" |
| 25 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| 26 | 27 |
| 27 namespace extensions { | 28 namespace extensions { |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 bool success = false; | 1190 bool success = false; |
| 1190 std::string error; | 1191 std::string error; |
| 1191 CallSetDisplayUnitInfo(base::Int64ToString(id), info, &success, &error); | 1192 CallSetDisplayUnitInfo(base::Int64ToString(id), info, &success, &error); |
| 1192 ASSERT_TRUE(success); | 1193 ASSERT_TRUE(success); |
| 1193 | 1194 |
| 1194 // Verify that other_mode now matches the active mode. | 1195 // Verify that other_mode now matches the active mode. |
| 1195 active_mode = GetDisplayManager()->GetActiveModeForDisplayId(id); | 1196 active_mode = GetDisplayManager()->GetActiveModeForDisplayId(id); |
| 1196 EXPECT_TRUE(active_mode->IsEquivalent(other_mode_ash)); | 1197 EXPECT_TRUE(active_mode->IsEquivalent(other_mode_ash)); |
| 1197 } | 1198 } |
| 1198 | 1199 |
| 1199 TEST_F(DisplayInfoProviderChromeosTest, SetTouchCalibrationInternal) { | 1200 TEST_F(DisplayInfoProviderChromeosTest, CustomTouchCalibrationInternal) { |
| 1200 UpdateDisplay("1200x600,600x1000*2"); | 1201 UpdateDisplay("1200x600,600x1000*2"); |
| 1201 const int64_t internal_display_id = | 1202 const int64_t internal_display_id = |
| 1202 display::test::DisplayManagerTestApi( | 1203 display::test::DisplayManagerTestApi( |
| 1203 ash::Shell::GetInstance()->display_manager()) | 1204 ash::Shell::GetInstance()->display_manager()) |
| 1204 .SetFirstDisplayAsInternalDisplay(); | 1205 .SetFirstDisplayAsInternalDisplay(); |
| 1205 | 1206 |
| 1206 std::string id = base::Int64ToString(internal_display_id); | 1207 std::string id = base::Int64ToString(internal_display_id); |
| 1207 | 1208 |
| 1208 api::system_display::TouchCalibrationPairQuad pairs; | |
| 1209 api::system_display::Bounds bounds; | |
| 1210 | |
| 1211 bool success = false; | |
| 1212 std::string error; | 1209 std::string error; |
| 1213 std::string expected_err = | 1210 std::string expected_err = |
| 1214 "Display Id(" + id + ") is an internal display." + | 1211 "Display Id(" + id + ") is an internal display." + |
| 1215 " Internal displays cannot be calibrated for touch."; | 1212 " Internal displays cannot be calibrated for touch."; |
| 1216 | 1213 bool success = DisplayInfoProvider::Get()->StartCustomTouchCalibration( |
| 1217 success = DisplayInfoProvider::Get()->TouchCalibrationSet(id, pairs, bounds, | 1214 id, &error); |
| 1218 &error); | |
| 1219 | 1215 |
| 1220 ASSERT_FALSE(success); | 1216 ASSERT_FALSE(success); |
| 1221 EXPECT_EQ(expected_err, error); | 1217 EXPECT_EQ(expected_err, error); |
| 1222 } | 1218 } |
| 1223 | 1219 |
| 1224 TEST_F(DisplayInfoProviderChromeosTest, SetTouchCalibrationNonTouchDisplay) { | 1220 TEST_F(DisplayInfoProviderChromeosTest, CustomTouchCalibrationWithoutStart) { |
| 1221 UpdateDisplay("1200x600,600x1000*2"); |
| 1222 |
| 1223 api::system_display::TouchCalibrationPairQuad pairs; |
| 1224 api::system_display::Bounds bounds; |
| 1225 |
| 1226 std::string error; |
| 1227 std::string expected_err = |
| 1228 DisplayInfoProviderChromeOS::kCompleteCalibrationCalledBeforeStartError; |
| 1229 bool success = DisplayInfoProvider::Get()->CompleteCustomTouchCalibration( |
| 1230 pairs, bounds, &error); |
| 1231 |
| 1232 ASSERT_FALSE(success); |
| 1233 EXPECT_EQ(expected_err, error); |
| 1234 } |
| 1235 |
| 1236 |
| 1237 TEST_F(DisplayInfoProviderChromeosTest, CustomTouchCalibrationNonTouchDisplay) { |
| 1225 UpdateDisplay("1200x600,600x1000*2"); | 1238 UpdateDisplay("1200x600,600x1000*2"); |
| 1226 | 1239 |
| 1227 const int64_t internal_display_id = | 1240 const int64_t internal_display_id = |
| 1228 display::test::DisplayManagerTestApi( | 1241 display::test::DisplayManagerTestApi( |
| 1229 ash::Shell::GetInstance()->display_manager()) | 1242 ash::Shell::GetInstance()->display_manager()) |
| 1230 .SetFirstDisplayAsInternalDisplay(); | 1243 .SetFirstDisplayAsInternalDisplay(); |
| 1231 | 1244 |
| 1232 display::DisplayIdList display_id_list = | 1245 display::DisplayIdList display_id_list = |
| 1233 display_manager()->GetCurrentDisplayIdList(); | 1246 display_manager()->GetCurrentDisplayIdList(); |
| 1234 | 1247 |
| 1235 // Pick the non internal display Id. | 1248 // Pick the non internal display Id. |
| 1236 const int64_t display_id = display_id_list[0] == internal_display_id | 1249 const int64_t display_id = display_id_list[0] == internal_display_id |
| 1237 ? display_id_list[1] | 1250 ? display_id_list[1] |
| 1238 : display_id_list[0]; | 1251 : display_id_list[0]; |
| 1239 | 1252 |
| 1240 display::test::DisplayManagerTestApi( | 1253 display::test::DisplayManagerTestApi( |
| 1241 ash::Shell::GetInstance()->display_manager()) | 1254 ash::Shell::GetInstance()->display_manager()) |
| 1242 .SetTouchSupport(display_id, display::Display::TOUCH_SUPPORT_UNAVAILABLE); | 1255 .SetTouchSupport(display_id, display::Display::TOUCH_SUPPORT_UNAVAILABLE); |
| 1243 | 1256 |
| 1244 std::string id = base::Int64ToString(display_id); | 1257 std::string id = base::Int64ToString(display_id); |
| 1245 | 1258 |
| 1246 api::system_display::TouchCalibrationPairQuad pairs; | |
| 1247 api::system_display::Bounds bounds; | |
| 1248 | |
| 1249 bool success = false; | |
| 1250 std::string error; | 1259 std::string error; |
| 1251 std::string expected_err = "Display Id(" + id + ") does not support touch."; | 1260 std::string expected_err = "Display Id(" + id + ") does not support touch."; |
| 1252 | 1261 |
| 1253 success = DisplayInfoProvider::Get()->TouchCalibrationSet(id, pairs, bounds, | 1262 bool success = DisplayInfoProvider::Get()->StartCustomTouchCalibration( |
| 1254 &error); | 1263 id, &error); |
| 1255 | 1264 |
| 1256 ASSERT_FALSE(success); | 1265 ASSERT_FALSE(success); |
| 1257 EXPECT_EQ(expected_err, error); | 1266 EXPECT_EQ(expected_err, error); |
| 1258 } | 1267 } |
| 1259 | 1268 |
| 1260 TEST_F(DisplayInfoProviderChromeosTest, SetTouchCalibrationNegativeBounds) { | 1269 TEST_F(DisplayInfoProviderChromeosTest, CustomTouchCalibrationNegativeBounds) { |
| 1261 UpdateDisplay("1200x600,600x1000*2"); | 1270 UpdateDisplay("1200x600,600x1000*2"); |
| 1262 | 1271 |
| 1263 const int64_t internal_display_id = | 1272 const int64_t internal_display_id = |
| 1264 display::test::DisplayManagerTestApi(display_manager()) | 1273 display::test::DisplayManagerTestApi(display_manager()) |
| 1265 .SetFirstDisplayAsInternalDisplay(); | 1274 .SetFirstDisplayAsInternalDisplay(); |
| 1266 | 1275 |
| 1267 display::DisplayIdList display_id_list = | 1276 display::DisplayIdList display_id_list = |
| 1268 display_manager()->GetCurrentDisplayIdList(); | 1277 display_manager()->GetCurrentDisplayIdList(); |
| 1269 | 1278 |
| 1270 // Pick the non internal display Id. | 1279 // Pick the non internal display Id. |
| 1271 const int64_t display_id = display_id_list[0] == internal_display_id | 1280 const int64_t display_id = display_id_list[0] == internal_display_id |
| 1272 ? display_id_list[1] | 1281 ? display_id_list[1] |
| 1273 : display_id_list[0]; | 1282 : display_id_list[0]; |
| 1274 | 1283 |
| 1275 display::test::DisplayManagerTestApi(display_manager()) | 1284 display::test::DisplayManagerTestApi(display_manager()) |
| 1276 .SetTouchSupport(display_id, display::Display::TOUCH_SUPPORT_AVAILABLE); | 1285 .SetTouchSupport(display_id, display::Display::TOUCH_SUPPORT_AVAILABLE); |
| 1277 | 1286 |
| 1278 std::string id = base::Int64ToString(display_id); | 1287 std::string id = base::Int64ToString(display_id); |
| 1279 | 1288 |
| 1280 api::system_display::TouchCalibrationPairQuad pairs; | 1289 api::system_display::TouchCalibrationPairQuad pairs; |
| 1281 api::system_display::Bounds bounds; | 1290 api::system_display::Bounds bounds; |
| 1282 bounds.width = -1; | 1291 bounds.width = -1; |
| 1283 | 1292 |
| 1284 bool success = false; | |
| 1285 std::string error; | 1293 std::string error; |
| 1286 success = DisplayInfoProvider::Get()->TouchCalibrationSet(id, pairs, bounds, | 1294 DisplayInfoProvider::Get()->StartCustomTouchCalibration(id, &error); |
| 1287 &error); | 1295 error.clear(); |
| 1296 bool success = DisplayInfoProvider::Get()->CompleteCustomTouchCalibration( |
| 1297 pairs, bounds, &error); |
| 1288 | 1298 |
| 1289 std::string expected_err = "Bounds cannot have negative values."; | 1299 std::string expected_err = |
| 1300 DisplayInfoProviderChromeOS::kTouchBoundsNegativeError; |
| 1290 | 1301 |
| 1291 ASSERT_FALSE(success); | 1302 ASSERT_FALSE(success); |
| 1292 EXPECT_EQ(expected_err, error); | 1303 EXPECT_EQ(expected_err, error); |
| 1293 | 1304 |
| 1294 error.clear(); | 1305 error.clear(); |
| 1295 bounds.width = 0; | 1306 bounds.width = 0; |
| 1296 bounds.height = -1; | 1307 bounds.height = -1; |
| 1297 | 1308 |
| 1298 success = DisplayInfoProvider::Get()->TouchCalibrationSet(id, pairs, bounds, | 1309 DisplayInfoProvider::Get()->StartCustomTouchCalibration(id, &error); |
| 1299 &error); | 1310 error.clear(); |
| 1311 success = DisplayInfoProvider::Get()->CompleteCustomTouchCalibration( |
| 1312 pairs, bounds, &error); |
| 1300 ASSERT_FALSE(success); | 1313 ASSERT_FALSE(success); |
| 1301 EXPECT_EQ(expected_err, error); | 1314 EXPECT_EQ(expected_err, error); |
| 1302 } | 1315 } |
| 1303 | 1316 |
| 1304 TEST_F(DisplayInfoProviderChromeosTest, SetTouchCalibrationInvalidPoints) { | 1317 TEST_F(DisplayInfoProviderChromeosTest, CustomTouchCalibrationInvalidPoints) { |
| 1305 UpdateDisplay("1200x600,600x1000*2"); | 1318 UpdateDisplay("1200x600,600x1000*2"); |
| 1306 | 1319 |
| 1307 const int64_t internal_display_id = | 1320 const int64_t internal_display_id = |
| 1308 display::test::DisplayManagerTestApi(display_manager()) | 1321 display::test::DisplayManagerTestApi(display_manager()) |
| 1309 .SetFirstDisplayAsInternalDisplay(); | 1322 .SetFirstDisplayAsInternalDisplay(); |
| 1310 | 1323 |
| 1311 display::DisplayIdList display_id_list = | 1324 display::DisplayIdList display_id_list = |
| 1312 display_manager()->GetCurrentDisplayIdList(); | 1325 display_manager()->GetCurrentDisplayIdList(); |
| 1313 | 1326 |
| 1314 // Pick the non internal display Id. | 1327 // Pick the non internal display Id. |
| 1315 const int64_t display_id = display_id_list[0] == internal_display_id | 1328 const int64_t display_id = display_id_list[0] == internal_display_id |
| 1316 ? display_id_list[1] | 1329 ? display_id_list[1] |
| 1317 : display_id_list[0]; | 1330 : display_id_list[0]; |
| 1318 | 1331 |
| 1319 display::test::DisplayManagerTestApi(display_manager()) | 1332 display::test::DisplayManagerTestApi(display_manager()) |
| 1320 .SetTouchSupport(display_id, display::Display::TOUCH_SUPPORT_AVAILABLE); | 1333 .SetTouchSupport(display_id, display::Display::TOUCH_SUPPORT_AVAILABLE); |
| 1321 | 1334 |
| 1322 std::string id = base::Int64ToString(display_id); | 1335 std::string id = base::Int64ToString(display_id); |
| 1323 | 1336 |
| 1324 api::system_display::TouchCalibrationPairQuad pairs; | 1337 api::system_display::TouchCalibrationPairQuad pairs; |
| 1325 api::system_display::Bounds bounds; | 1338 api::system_display::Bounds bounds; |
| 1326 | 1339 |
| 1327 pairs.pair1.display_point.x = -1; | 1340 pairs.pair1.display_point.x = -1; |
| 1328 bool success = false; | |
| 1329 std::string error; | 1341 std::string error; |
| 1330 success = DisplayInfoProvider::Get()->TouchCalibrationSet(id, pairs, bounds, | 1342 DisplayInfoProvider::Get()->StartCustomTouchCalibration(id, &error); |
| 1331 &error); | 1343 error.clear(); |
| 1344 bool success = DisplayInfoProvider::Get()->CompleteCustomTouchCalibration( |
| 1345 pairs, bounds, &error); |
| 1332 | 1346 |
| 1333 std::string expected_err = "Display points and touch points cannot have " | 1347 std::string expected_err = |
| 1334 "negative coordinates"; | 1348 DisplayInfoProviderChromeOS::kTouchCalibrationPointsNegativeError; |
| 1335 | 1349 |
| 1336 ASSERT_FALSE(success); | 1350 ASSERT_FALSE(success); |
| 1337 EXPECT_EQ(expected_err, error); | 1351 EXPECT_EQ(expected_err, error); |
| 1338 | 1352 |
| 1339 error.clear(); | 1353 error.clear(); |
| 1340 bounds.width = 1; | 1354 bounds.width = 1; |
| 1341 pairs.pair1.display_point.x = 2; | 1355 pairs.pair1.display_point.x = 2; |
| 1342 expected_err = "Display point coordinates cannot be more than size of the " | 1356 expected_err = |
| 1343 "display."; | 1357 DisplayInfoProviderChromeOS::kTouchCalibrationPointsTooLargeError; |
| 1344 | 1358 |
| 1345 success = DisplayInfoProvider::Get()->TouchCalibrationSet(id, pairs, bounds, | 1359 DisplayInfoProvider::Get()->StartCustomTouchCalibration(id, &error); |
| 1346 &error); | 1360 error.clear(); |
| 1361 success = DisplayInfoProvider::Get()->CompleteCustomTouchCalibration( |
| 1362 pairs, bounds, &error); |
| 1347 ASSERT_FALSE(success); | 1363 ASSERT_FALSE(success); |
| 1348 EXPECT_EQ(expected_err, error); | 1364 EXPECT_EQ(expected_err, error); |
| 1349 } | 1365 } |
| 1350 | 1366 |
| 1351 TEST_F(DisplayInfoProviderChromeosTest, SetTouchCalibrationSuccess) { | 1367 TEST_F(DisplayInfoProviderChromeosTest, CustomTouchCalibrationSuccess) { |
| 1352 UpdateDisplay("1200x600,600x1000*2"); | 1368 UpdateDisplay("1200x600,600x1000*2"); |
| 1353 | 1369 |
| 1354 const int64_t internal_display_id = | 1370 const int64_t internal_display_id = |
| 1355 display::test::DisplayManagerTestApi(display_manager()) | 1371 display::test::DisplayManagerTestApi(display_manager()) |
| 1356 .SetFirstDisplayAsInternalDisplay(); | 1372 .SetFirstDisplayAsInternalDisplay(); |
| 1357 | 1373 |
| 1358 display::DisplayIdList display_id_list = | 1374 display::DisplayIdList display_id_list = |
| 1359 display_manager()->GetCurrentDisplayIdList(); | 1375 display_manager()->GetCurrentDisplayIdList(); |
| 1360 | 1376 |
| 1361 // Pick the non internal display Id. | 1377 // Pick the non internal display Id. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1385 pairs.pair2.touch_point.x = 22; | 1401 pairs.pair2.touch_point.x = 22; |
| 1386 pairs.pair2.touch_point.y = 23; | 1402 pairs.pair2.touch_point.y = 23; |
| 1387 pairs.pair3.touch_point.x = 24; | 1403 pairs.pair3.touch_point.x = 24; |
| 1388 pairs.pair3.touch_point.y = 25; | 1404 pairs.pair3.touch_point.y = 25; |
| 1389 pairs.pair4.touch_point.x = 26; | 1405 pairs.pair4.touch_point.x = 26; |
| 1390 pairs.pair4.touch_point.y = 27; | 1406 pairs.pair4.touch_point.y = 27; |
| 1391 | 1407 |
| 1392 bounds.width = 600; | 1408 bounds.width = 600; |
| 1393 bounds.height = 1000; | 1409 bounds.height = 1000; |
| 1394 | 1410 |
| 1395 bool success = false; | |
| 1396 std::string error; | 1411 std::string error; |
| 1397 success = DisplayInfoProvider::Get()->TouchCalibrationSet(id, pairs, bounds, | 1412 DisplayInfoProvider::Get()->StartCustomTouchCalibration(id, &error); |
| 1398 &error); | 1413 error.clear(); |
| 1414 bool success = DisplayInfoProvider::Get()->CompleteCustomTouchCalibration( |
| 1415 pairs, bounds, &error); |
| 1399 | 1416 |
| 1400 ASSERT_TRUE(success); | 1417 ASSERT_TRUE(success); |
| 1401 EXPECT_EQ(error, ""); | 1418 EXPECT_EQ(error, ""); |
| 1402 | 1419 |
| 1403 const display::ManagedDisplayInfo& info = | 1420 const display::ManagedDisplayInfo& info = |
| 1404 display_manager()->GetDisplayInfo(display_id); | 1421 display_manager()->GetDisplayInfo(display_id); |
| 1405 | 1422 |
| 1406 ASSERT_TRUE(info.has_touch_calibration_data()); | 1423 ASSERT_TRUE(info.has_touch_calibration_data()); |
| 1407 const display::TouchCalibrationData& data = info.GetTouchCalibrationData(); | 1424 const display::TouchCalibrationData& data = info.GetTouchCalibrationData(); |
| 1408 | 1425 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1424 EXPECT_EQ(pairs.pair1.touch_point.y, data.point_pairs[0].second.y()); | 1441 EXPECT_EQ(pairs.pair1.touch_point.y, data.point_pairs[0].second.y()); |
| 1425 EXPECT_EQ(pairs.pair2.touch_point.y, data.point_pairs[1].second.y()); | 1442 EXPECT_EQ(pairs.pair2.touch_point.y, data.point_pairs[1].second.y()); |
| 1426 EXPECT_EQ(pairs.pair3.touch_point.y, data.point_pairs[2].second.y()); | 1443 EXPECT_EQ(pairs.pair3.touch_point.y, data.point_pairs[2].second.y()); |
| 1427 EXPECT_EQ(pairs.pair4.touch_point.y, data.point_pairs[3].second.y()); | 1444 EXPECT_EQ(pairs.pair4.touch_point.y, data.point_pairs[3].second.y()); |
| 1428 | 1445 |
| 1429 EXPECT_EQ(bounds.width, data.bounds.width()); | 1446 EXPECT_EQ(bounds.width, data.bounds.width()); |
| 1430 EXPECT_EQ(bounds.height, data.bounds.height()); | 1447 EXPECT_EQ(bounds.height, data.bounds.height()); |
| 1431 } | 1448 } |
| 1432 } // namespace | 1449 } // namespace |
| 1433 } // namespace extensions | 1450 } // namespace extensions |
| OLD | NEW |