Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/android/vr_shell/ui_scene.h" | 5 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 6 | 6 |
| 7 #define _USE_MATH_DEFINES // For M_PI in MSVC. | 7 #define _USE_MATH_DEFINES // For M_PI in MSVC. |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 EXPECT_EQ(scene.GetUiElements().size(), 0u); | 68 EXPECT_EQ(scene.GetUiElements().size(), 0u); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST(UiScene, AddRemoveContentQuad) { | 71 TEST(UiScene, AddRemoveContentQuad) { |
| 72 UiScene scene; | 72 UiScene scene; |
| 73 | 73 |
| 74 EXPECT_EQ(scene.GetContentQuad(), nullptr); | 74 EXPECT_EQ(scene.GetContentQuad(), nullptr); |
| 75 | 75 |
| 76 base::DictionaryValue dict; | 76 base::DictionaryValue dict; |
| 77 dict.SetInteger("id", 0); | 77 dict.SetInteger("id", 0); |
| 78 dict.SetBoolean("contentQuad", true); | 78 dict.SetInteger("fillType", Fill::CONTENT); |
| 79 scene.AddUiElementFromDict(dict); | 79 scene.AddUiElementFromDict(dict); |
| 80 EXPECT_NE(scene.GetContentQuad(), nullptr); | 80 EXPECT_NE(scene.GetContentQuad(), nullptr); |
| 81 | 81 |
| 82 dict.SetBoolean("contentQuad", false); | 82 dict.SetInteger("fillType", Fill::SPRITE); |
| 83 scene.UpdateUiElementFromDict(dict); | 83 scene.UpdateUiElementFromDict(dict); |
| 84 EXPECT_EQ(scene.GetContentQuad(), nullptr); | 84 EXPECT_EQ(scene.GetContentQuad(), nullptr); |
| 85 | 85 |
| 86 dict.SetBoolean("contentQuad", true); | 86 dict.SetInteger("fillType", Fill::CONTENT); |
| 87 scene.UpdateUiElementFromDict(dict); | 87 scene.UpdateUiElementFromDict(dict); |
| 88 EXPECT_NE(scene.GetContentQuad(), nullptr); | 88 EXPECT_NE(scene.GetContentQuad(), nullptr); |
| 89 | 89 |
| 90 scene.RemoveUiElement(0); | 90 scene.RemoveUiElement(0); |
| 91 EXPECT_EQ(scene.GetContentQuad(), nullptr); | 91 EXPECT_EQ(scene.GetContentQuad(), nullptr); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST(UiScene, AddRemoveAnimations) { | 94 TEST(UiScene, AddRemoveAnimations) { |
| 95 UiScene scene; | 95 UiScene scene; |
| 96 addElement(&scene, 0); | 96 addElement(&scene, 0); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 UiScene scene; | 229 UiScene scene; |
| 230 addElement(&scene, 11); | 230 addElement(&scene, 11); |
| 231 | 231 |
| 232 base::DictionaryValue dict; | 232 base::DictionaryValue dict; |
| 233 | 233 |
| 234 dict.SetInteger("id", 10); | 234 dict.SetInteger("id", 10); |
| 235 dict.SetInteger("parentId", 11); | 235 dict.SetInteger("parentId", 11); |
| 236 dict.SetBoolean("visible", false); | 236 dict.SetBoolean("visible", false); |
| 237 dict.SetBoolean("hitTestable", false); | 237 dict.SetBoolean("hitTestable", false); |
| 238 dict.SetBoolean("lockToFov", true); | 238 dict.SetBoolean("lockToFov", true); |
| 239 dict.SetBoolean("contentQuad", true); | 239 dict.SetInteger("fillType", Fill::SPRITE); |
| 240 dict.SetInteger("xAnchoring", XAnchoring::XLEFT); | 240 dict.SetInteger("xAnchoring", XAnchoring::XLEFT); |
| 241 dict.SetInteger("yAnchoring", YAnchoring::YTOP); | 241 dict.SetInteger("yAnchoring", YAnchoring::YTOP); |
| 242 dict.SetDouble("opacity", 0.357); | 242 dict.SetDouble("opacity", 0.357); |
| 243 | 243 |
| 244 std::unique_ptr<base::DictionaryValue> copy_rect(new base::DictionaryValue); | 244 std::unique_ptr<base::DictionaryValue> copy_rect(new base::DictionaryValue); |
| 245 copy_rect->SetInteger("x", 100); | 245 copy_rect->SetInteger("x", 100); |
| 246 copy_rect->SetInteger("y", 101); | 246 copy_rect->SetInteger("y", 101); |
| 247 copy_rect->SetInteger("width", 102); | 247 copy_rect->SetInteger("width", 102); |
| 248 copy_rect->SetInteger("height", 103); | 248 copy_rect->SetInteger("height", 103); |
| 249 dict.Set("copyRect", std::move(copy_rect)); | 249 dict.Set("copyRect", std::move(copy_rect)); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 274 | 274 |
| 275 scene.AddUiElementFromDict(dict); | 275 scene.AddUiElementFromDict(dict); |
| 276 const auto *element = scene.GetUiElementById(10); | 276 const auto *element = scene.GetUiElementById(10); |
| 277 EXPECT_NE(element, nullptr); | 277 EXPECT_NE(element, nullptr); |
| 278 | 278 |
| 279 EXPECT_EQ(element->id, 10); | 279 EXPECT_EQ(element->id, 10); |
| 280 EXPECT_EQ(element->parent_id, 11); | 280 EXPECT_EQ(element->parent_id, 11); |
| 281 EXPECT_EQ(element->visible, false); | 281 EXPECT_EQ(element->visible, false); |
| 282 EXPECT_EQ(element->hit_testable, false); | 282 EXPECT_EQ(element->hit_testable, false); |
| 283 EXPECT_EQ(element->lock_to_fov, true); | 283 EXPECT_EQ(element->lock_to_fov, true); |
| 284 EXPECT_EQ(element->content_quad, true); | 284 EXPECT_EQ(element->fill, Fill::SPRITE); |
| 285 EXPECT_EQ(element->x_anchoring, XAnchoring::XLEFT); | 285 EXPECT_EQ(element->x_anchoring, XAnchoring::XLEFT); |
| 286 EXPECT_EQ(element->y_anchoring, YAnchoring::YTOP); | 286 EXPECT_EQ(element->y_anchoring, YAnchoring::YTOP); |
| 287 EXPECT_FLOAT_EQ(element->opacity, 0.357); | 287 EXPECT_FLOAT_EQ(element->opacity, 0.357); |
| 288 | 288 |
| 289 EXPECT_EQ(element->copy_rect.x, 100); | 289 EXPECT_EQ(element->copy_rect.x, 100); |
| 290 EXPECT_EQ(element->copy_rect.y, 101); | 290 EXPECT_EQ(element->copy_rect.y, 101); |
| 291 EXPECT_EQ(element->copy_rect.width, 102); | 291 EXPECT_EQ(element->copy_rect.width, 102); |
| 292 EXPECT_EQ(element->copy_rect.height, 103); | 292 EXPECT_EQ(element->copy_rect.height, 103); |
| 293 | 293 |
| 294 EXPECT_FLOAT_EQ(element->size.x, 200); | 294 EXPECT_FLOAT_EQ(element->size.x, 200); |
| 295 EXPECT_FLOAT_EQ(element->size.y, 201); | 295 EXPECT_FLOAT_EQ(element->size.y, 201); |
| 296 EXPECT_FLOAT_EQ(element->size.z, 1); | 296 EXPECT_FLOAT_EQ(element->size.z, 1); |
| 297 | 297 |
| 298 EXPECT_FLOAT_EQ(element->scale.x, 300); | 298 EXPECT_FLOAT_EQ(element->scale.x, 300); |
| 299 EXPECT_FLOAT_EQ(element->scale.y, 301); | 299 EXPECT_FLOAT_EQ(element->scale.y, 301); |
| 300 EXPECT_FLOAT_EQ(element->scale.z, 302); | 300 EXPECT_FLOAT_EQ(element->scale.z, 302); |
| 301 | 301 |
| 302 EXPECT_FLOAT_EQ(element->rotation.x, 400); | 302 EXPECT_FLOAT_EQ(element->rotation.x, 400); |
| 303 EXPECT_FLOAT_EQ(element->rotation.y, 401); | 303 EXPECT_FLOAT_EQ(element->rotation.y, 401); |
| 304 EXPECT_FLOAT_EQ(element->rotation.z, 402); | 304 EXPECT_FLOAT_EQ(element->rotation.z, 402); |
| 305 EXPECT_FLOAT_EQ(element->rotation.angle, 403); | 305 EXPECT_FLOAT_EQ(element->rotation.angle, 403); |
| 306 | 306 |
| 307 EXPECT_FLOAT_EQ(element->translation.x, 500); | 307 EXPECT_FLOAT_EQ(element->translation.x, 500); |
| 308 EXPECT_FLOAT_EQ(element->translation.y, 501); | 308 EXPECT_FLOAT_EQ(element->translation.y, 501); |
| 309 EXPECT_FLOAT_EQ(element->translation.z, 502); | 309 EXPECT_FLOAT_EQ(element->translation.z, 502); |
| 310 } | 310 } |
| 311 | 311 |
| 312 TEST(UiScene, AddUiElementFromDictionary_Fill) { | |
| 313 UiScene scene; | |
| 314 base::DictionaryValue dict; | |
| 315 constexpr double EPSILON = 0.000001; | |
|
cjgrant
2017/02/02 14:48:25
This can be removed (see below).
tiborg1
2017/02/02 16:52:27
Done.
| |
| 316 | |
| 317 base::DictionaryValue copy_rect; | |
| 318 copy_rect.SetInteger("x", 1); | |
| 319 copy_rect.SetInteger("y", 2); | |
| 320 copy_rect.SetInteger("width", 3); | |
| 321 copy_rect.SetInteger("height", 4); | |
| 322 | |
| 323 base::DictionaryValue edge_color; | |
| 324 edge_color.SetDouble("r", 0.1); | |
| 325 edge_color.SetDouble("g", 0.2); | |
| 326 edge_color.SetDouble("b", 0.3); | |
| 327 edge_color.SetDouble("a", 0.4); | |
| 328 | |
| 329 base::DictionaryValue center_color; | |
| 330 center_color.SetDouble("r", 0.5); | |
| 331 center_color.SetDouble("g", 0.6); | |
| 332 center_color.SetDouble("b", 0.7); | |
| 333 center_color.SetDouble("a", 0.8); | |
| 334 | |
| 335 // Test SPRITE filling. | |
| 336 dict.SetInteger("id", 9); | |
| 337 dict.SetInteger("fillType", Fill::SPRITE); | |
| 338 dict.Set("copyRect", copy_rect.DeepCopy()); | |
| 339 scene.AddUiElementFromDict(dict); | |
| 340 const auto* element = scene.GetUiElementById(9); | |
| 341 | |
| 342 EXPECT_EQ(element->fill, Fill::SPRITE); | |
| 343 EXPECT_EQ(element->copy_rect.x, 1); | |
| 344 EXPECT_EQ(element->copy_rect.y, 2); | |
| 345 EXPECT_EQ(element->copy_rect.width, 3); | |
| 346 EXPECT_EQ(element->copy_rect.height, 4); | |
| 347 | |
| 348 // Test OPAQUE_GRADIENT filling. | |
| 349 dict.Clear(); | |
| 350 dict.SetInteger("id", 10); | |
| 351 dict.SetInteger("fillType", Fill::OPAQUE_GRADIENT); | |
| 352 dict.Set("edgeColor", edge_color.DeepCopy()); | |
| 353 dict.Set("centerColor", center_color.DeepCopy()); | |
| 354 scene.AddUiElementFromDict(dict); | |
| 355 element = scene.GetUiElementById(10); | |
| 356 | |
| 357 EXPECT_EQ(element->fill, Fill::OPAQUE_GRADIENT); | |
| 358 EXPECT_NEAR(element->edge_color.r, 0.1, EPSILON); | |
|
cjgrant
2017/02/02 14:48:25
I think you want EXPECT_FLOAT_EQ() for these cases
tiborg1
2017/02/02 16:52:27
Oh yes, this makes it way more elegant :) Done.
| |
| 359 EXPECT_NEAR(element->edge_color.g, 0.2, EPSILON); | |
| 360 EXPECT_NEAR(element->edge_color.b, 0.3, EPSILON); | |
| 361 EXPECT_NEAR(element->edge_color.a, 0.4, EPSILON); | |
| 362 EXPECT_NEAR(element->center_color.r, 0.5, EPSILON); | |
| 363 EXPECT_NEAR(element->center_color.g, 0.6, EPSILON); | |
| 364 EXPECT_NEAR(element->center_color.b, 0.7, EPSILON); | |
| 365 EXPECT_NEAR(element->center_color.a, 0.8, EPSILON); | |
| 366 | |
| 367 // Test GRID_GRADIENT filling. | |
| 368 dict.Clear(); | |
| 369 dict.SetInteger("id", 11); | |
| 370 dict.SetInteger("fillType", Fill::GRID_GRADIENT); | |
| 371 dict.Set("edgeColor", edge_color.DeepCopy()); | |
| 372 dict.Set("centerColor", center_color.DeepCopy()); | |
| 373 dict.SetInteger("tileNumber", 10); | |
| 374 scene.AddUiElementFromDict(dict); | |
| 375 element = scene.GetUiElementById(11); | |
| 376 | |
| 377 EXPECT_EQ(element->fill, Fill::GRID_GRADIENT); | |
| 378 EXPECT_NEAR(element->edge_color.r, 0.1, EPSILON); | |
| 379 EXPECT_NEAR(element->edge_color.g, 0.2, EPSILON); | |
| 380 EXPECT_NEAR(element->edge_color.b, 0.3, EPSILON); | |
| 381 EXPECT_NEAR(element->edge_color.a, 0.4, EPSILON); | |
| 382 EXPECT_NEAR(element->center_color.r, 0.5, EPSILON); | |
| 383 EXPECT_NEAR(element->center_color.g, 0.6, EPSILON); | |
| 384 EXPECT_NEAR(element->center_color.b, 0.7, EPSILON); | |
| 385 EXPECT_NEAR(element->center_color.a, 0.8, EPSILON); | |
| 386 EXPECT_EQ(element->tile_number, 10u); | |
| 387 | |
| 388 // Test CONTENT filling. | |
| 389 dict.Clear(); | |
| 390 dict.SetInteger("id", 12); | |
| 391 dict.SetInteger("fillType", Fill::CONTENT); | |
| 392 scene.AddUiElementFromDict(dict); | |
| 393 element = scene.GetUiElementById(12); | |
| 394 | |
| 395 EXPECT_EQ(element->fill, Fill::CONTENT); | |
| 396 } | |
| 397 | |
| 312 TEST(UiScene, AddAnimationFromDictionary) { | 398 TEST(UiScene, AddAnimationFromDictionary) { |
| 313 UiScene scene; | 399 UiScene scene; |
| 314 addElement(&scene, 0); | 400 addElement(&scene, 0); |
| 315 | 401 |
| 316 base::DictionaryValue dict; | 402 base::DictionaryValue dict; |
| 317 | 403 |
| 318 dict.SetInteger("id", 10); | 404 dict.SetInteger("id", 10); |
| 319 dict.SetInteger("meshId", 0); | 405 dict.SetInteger("meshId", 0); |
| 320 dict.SetDouble("startInMillis", 12345); | 406 dict.SetDouble("startInMillis", 12345); |
| 321 dict.SetDouble("durationMillis", 54321); | 407 dict.SetDouble("durationMillis", 54321); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 EXPECT_FLOAT_EQ(animation->from[0], 300); | 444 EXPECT_FLOAT_EQ(animation->from[0], 300); |
| 359 EXPECT_FLOAT_EQ(animation->from[1], 301); | 445 EXPECT_FLOAT_EQ(animation->from[1], 301); |
| 360 EXPECT_FLOAT_EQ(animation->from[2], 302); | 446 EXPECT_FLOAT_EQ(animation->from[2], 302); |
| 361 EXPECT_FLOAT_EQ(animation->from[3], 303); | 447 EXPECT_FLOAT_EQ(animation->from[3], 303); |
| 362 | 448 |
| 363 EXPECT_EQ(animation->start, 22345000); | 449 EXPECT_EQ(animation->start, 22345000); |
| 364 EXPECT_EQ(animation->duration, 54321000); | 450 EXPECT_EQ(animation->duration, 54321000); |
| 365 } | 451 } |
| 366 | 452 |
| 367 } // namespace vr_shell | 453 } // namespace vr_shell |
| OLD | NEW |