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