Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/android/vr_shell/ui_scene_unittest.cc

Issue 2668093002: VrShell background implemented in JS. (Closed)
Patch Set: Fixed tests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene.cc ('k') | chrome/browser/android/vr_shell/vr_math.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 std::unique_ptr<base::DictionaryValue> copy_rect(new base::DictionaryValue);
84 copy_rect->SetInteger("x", 100);
85 copy_rect->SetInteger("y", 101);
86 copy_rect->SetInteger("width", 102);
87 copy_rect->SetInteger("height", 103);
88 dict.Set("copyRect", std::move(copy_rect));
83 scene.UpdateUiElementFromDict(dict); 89 scene.UpdateUiElementFromDict(dict);
84 EXPECT_EQ(scene.GetContentQuad(), nullptr); 90 EXPECT_EQ(scene.GetContentQuad(), nullptr);
85 91
86 dict.SetBoolean("contentQuad", true); 92 dict.SetInteger("fillType", Fill::CONTENT);
87 scene.UpdateUiElementFromDict(dict); 93 scene.UpdateUiElementFromDict(dict);
88 EXPECT_NE(scene.GetContentQuad(), nullptr); 94 EXPECT_NE(scene.GetContentQuad(), nullptr);
89 95
90 scene.RemoveUiElement(0); 96 scene.RemoveUiElement(0);
91 EXPECT_EQ(scene.GetContentQuad(), nullptr); 97 EXPECT_EQ(scene.GetContentQuad(), nullptr);
92 } 98 }
93 99
94 TEST(UiScene, AddRemoveAnimations) { 100 TEST(UiScene, AddRemoveAnimations) {
95 UiScene scene; 101 UiScene scene;
96 addElement(&scene, 0); 102 addElement(&scene, 0);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 UiScene scene; 235 UiScene scene;
230 addElement(&scene, 11); 236 addElement(&scene, 11);
231 237
232 base::DictionaryValue dict; 238 base::DictionaryValue dict;
233 239
234 dict.SetInteger("id", 10); 240 dict.SetInteger("id", 10);
235 dict.SetInteger("parentId", 11); 241 dict.SetInteger("parentId", 11);
236 dict.SetBoolean("visible", false); 242 dict.SetBoolean("visible", false);
237 dict.SetBoolean("hitTestable", false); 243 dict.SetBoolean("hitTestable", false);
238 dict.SetBoolean("lockToFov", true); 244 dict.SetBoolean("lockToFov", true);
239 dict.SetBoolean("contentQuad", true); 245 dict.SetInteger("fillType", Fill::SPRITE);
240 dict.SetInteger("xAnchoring", XAnchoring::XLEFT); 246 dict.SetInteger("xAnchoring", XAnchoring::XLEFT);
241 dict.SetInteger("yAnchoring", YAnchoring::YTOP); 247 dict.SetInteger("yAnchoring", YAnchoring::YTOP);
242 dict.SetDouble("opacity", 0.357); 248 dict.SetDouble("opacity", 0.357);
243 249
244 std::unique_ptr<base::DictionaryValue> copy_rect(new base::DictionaryValue); 250 std::unique_ptr<base::DictionaryValue> copy_rect(new base::DictionaryValue);
245 copy_rect->SetInteger("x", 100); 251 copy_rect->SetInteger("x", 100);
246 copy_rect->SetInteger("y", 101); 252 copy_rect->SetInteger("y", 101);
247 copy_rect->SetInteger("width", 102); 253 copy_rect->SetInteger("width", 102);
248 copy_rect->SetInteger("height", 103); 254 copy_rect->SetInteger("height", 103);
249 dict.Set("copyRect", std::move(copy_rect)); 255 dict.Set("copyRect", std::move(copy_rect));
(...skipping 24 matching lines...) Expand all
274 280
275 scene.AddUiElementFromDict(dict); 281 scene.AddUiElementFromDict(dict);
276 const auto *element = scene.GetUiElementById(10); 282 const auto *element = scene.GetUiElementById(10);
277 EXPECT_NE(element, nullptr); 283 EXPECT_NE(element, nullptr);
278 284
279 EXPECT_EQ(element->id, 10); 285 EXPECT_EQ(element->id, 10);
280 EXPECT_EQ(element->parent_id, 11); 286 EXPECT_EQ(element->parent_id, 11);
281 EXPECT_EQ(element->visible, false); 287 EXPECT_EQ(element->visible, false);
282 EXPECT_EQ(element->hit_testable, false); 288 EXPECT_EQ(element->hit_testable, false);
283 EXPECT_EQ(element->lock_to_fov, true); 289 EXPECT_EQ(element->lock_to_fov, true);
284 EXPECT_EQ(element->content_quad, true); 290 EXPECT_EQ(element->fill, Fill::SPRITE);
285 EXPECT_EQ(element->x_anchoring, XAnchoring::XLEFT); 291 EXPECT_EQ(element->x_anchoring, XAnchoring::XLEFT);
286 EXPECT_EQ(element->y_anchoring, YAnchoring::YTOP); 292 EXPECT_EQ(element->y_anchoring, YAnchoring::YTOP);
287 EXPECT_FLOAT_EQ(element->opacity, 0.357); 293 EXPECT_FLOAT_EQ(element->opacity, 0.357);
288 294
289 EXPECT_EQ(element->copy_rect.x, 100); 295 EXPECT_EQ(element->copy_rect.x, 100);
290 EXPECT_EQ(element->copy_rect.y, 101); 296 EXPECT_EQ(element->copy_rect.y, 101);
291 EXPECT_EQ(element->copy_rect.width, 102); 297 EXPECT_EQ(element->copy_rect.width, 102);
292 EXPECT_EQ(element->copy_rect.height, 103); 298 EXPECT_EQ(element->copy_rect.height, 103);
293 299
294 EXPECT_FLOAT_EQ(element->size.x, 200); 300 EXPECT_FLOAT_EQ(element->size.x, 200);
295 EXPECT_FLOAT_EQ(element->size.y, 201); 301 EXPECT_FLOAT_EQ(element->size.y, 201);
296 EXPECT_FLOAT_EQ(element->size.z, 1); 302 EXPECT_FLOAT_EQ(element->size.z, 1);
297 303
298 EXPECT_FLOAT_EQ(element->scale.x, 300); 304 EXPECT_FLOAT_EQ(element->scale.x, 300);
299 EXPECT_FLOAT_EQ(element->scale.y, 301); 305 EXPECT_FLOAT_EQ(element->scale.y, 301);
300 EXPECT_FLOAT_EQ(element->scale.z, 302); 306 EXPECT_FLOAT_EQ(element->scale.z, 302);
301 307
302 EXPECT_FLOAT_EQ(element->rotation.x, 400); 308 EXPECT_FLOAT_EQ(element->rotation.x, 400);
303 EXPECT_FLOAT_EQ(element->rotation.y, 401); 309 EXPECT_FLOAT_EQ(element->rotation.y, 401);
304 EXPECT_FLOAT_EQ(element->rotation.z, 402); 310 EXPECT_FLOAT_EQ(element->rotation.z, 402);
305 EXPECT_FLOAT_EQ(element->rotation.angle, 403); 311 EXPECT_FLOAT_EQ(element->rotation.angle, 403);
306 312
307 EXPECT_FLOAT_EQ(element->translation.x, 500); 313 EXPECT_FLOAT_EQ(element->translation.x, 500);
308 EXPECT_FLOAT_EQ(element->translation.y, 501); 314 EXPECT_FLOAT_EQ(element->translation.y, 501);
309 EXPECT_FLOAT_EQ(element->translation.z, 502); 315 EXPECT_FLOAT_EQ(element->translation.z, 502);
310 } 316 }
311 317
318 TEST(UiScene, AddUiElementFromDictionary_Fill) {
319 UiScene scene;
320 base::DictionaryValue dict;
321
322 base::DictionaryValue copy_rect;
323 copy_rect.SetInteger("x", 1);
324 copy_rect.SetInteger("y", 2);
325 copy_rect.SetInteger("width", 3);
326 copy_rect.SetInteger("height", 4);
327
328 base::DictionaryValue edge_color;
329 edge_color.SetDouble("r", 0.1);
330 edge_color.SetDouble("g", 0.2);
331 edge_color.SetDouble("b", 0.3);
332 edge_color.SetDouble("a", 0.4);
333
334 base::DictionaryValue center_color;
335 center_color.SetDouble("r", 0.5);
336 center_color.SetDouble("g", 0.6);
337 center_color.SetDouble("b", 0.7);
338 center_color.SetDouble("a", 0.8);
339
340 // Test SPRITE filling.
341 dict.SetInteger("id", 9);
342 dict.SetInteger("fillType", Fill::SPRITE);
343 dict.Set("copyRect", copy_rect.DeepCopy());
344 scene.AddUiElementFromDict(dict);
345 const auto* element = scene.GetUiElementById(9);
346
347 EXPECT_EQ(element->fill, Fill::SPRITE);
348 EXPECT_EQ(element->copy_rect.x, 1);
349 EXPECT_EQ(element->copy_rect.y, 2);
350 EXPECT_EQ(element->copy_rect.width, 3);
351 EXPECT_EQ(element->copy_rect.height, 4);
352
353 // Test OPAQUE_GRADIENT filling.
354 dict.Clear();
355 dict.SetInteger("id", 10);
356 dict.SetInteger("fillType", Fill::OPAQUE_GRADIENT);
357 dict.Set("edgeColor", edge_color.DeepCopy());
358 dict.Set("centerColor", center_color.DeepCopy());
359 scene.AddUiElementFromDict(dict);
360 element = scene.GetUiElementById(10);
361
362 EXPECT_EQ(element->fill, Fill::OPAQUE_GRADIENT);
363 EXPECT_FLOAT_EQ(element->edge_color.r, 0.1);
364 EXPECT_FLOAT_EQ(element->edge_color.g, 0.2);
365 EXPECT_FLOAT_EQ(element->edge_color.b, 0.3);
366 EXPECT_FLOAT_EQ(element->edge_color.a, 0.4);
367 EXPECT_FLOAT_EQ(element->center_color.r, 0.5);
368 EXPECT_FLOAT_EQ(element->center_color.g, 0.6);
369 EXPECT_FLOAT_EQ(element->center_color.b, 0.7);
370 EXPECT_FLOAT_EQ(element->center_color.a, 0.8);
371
372 // Test GRID_GRADIENT filling.
373 dict.Clear();
374 dict.SetInteger("id", 11);
375 dict.SetInteger("fillType", Fill::GRID_GRADIENT);
376 dict.Set("edgeColor", edge_color.DeepCopy());
377 dict.Set("centerColor", center_color.DeepCopy());
378 dict.SetInteger("gridlineCount", 10);
379 scene.AddUiElementFromDict(dict);
380 element = scene.GetUiElementById(11);
381
382 EXPECT_EQ(element->fill, Fill::GRID_GRADIENT);
383 EXPECT_FLOAT_EQ(element->edge_color.r, 0.1);
384 EXPECT_FLOAT_EQ(element->edge_color.g, 0.2);
385 EXPECT_FLOAT_EQ(element->edge_color.b, 0.3);
386 EXPECT_FLOAT_EQ(element->edge_color.a, 0.4);
387 EXPECT_FLOAT_EQ(element->center_color.r, 0.5);
388 EXPECT_FLOAT_EQ(element->center_color.g, 0.6);
389 EXPECT_FLOAT_EQ(element->center_color.b, 0.7);
390 EXPECT_FLOAT_EQ(element->center_color.a, 0.8);
391 EXPECT_EQ(element->gridline_count, 10);
392
393 // Test CONTENT filling.
394 dict.Clear();
395 dict.SetInteger("id", 12);
396 dict.SetInteger("fillType", Fill::CONTENT);
397 scene.AddUiElementFromDict(dict);
398 element = scene.GetUiElementById(12);
399
400 EXPECT_EQ(element->fill, Fill::CONTENT);
401 }
402
312 TEST(UiScene, AddAnimationFromDictionary) { 403 TEST(UiScene, AddAnimationFromDictionary) {
313 UiScene scene; 404 UiScene scene;
314 addElement(&scene, 0); 405 addElement(&scene, 0);
315 406
316 base::DictionaryValue dict; 407 base::DictionaryValue dict;
317 408
318 dict.SetInteger("id", 10); 409 dict.SetInteger("id", 10);
319 dict.SetInteger("meshId", 0); 410 dict.SetInteger("meshId", 0);
320 dict.SetDouble("startInMillis", 12345); 411 dict.SetDouble("startInMillis", 12345);
321 dict.SetDouble("durationMillis", 54321); 412 dict.SetDouble("durationMillis", 54321);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 EXPECT_FLOAT_EQ(animation->from[0], 300); 449 EXPECT_FLOAT_EQ(animation->from[0], 300);
359 EXPECT_FLOAT_EQ(animation->from[1], 301); 450 EXPECT_FLOAT_EQ(animation->from[1], 301);
360 EXPECT_FLOAT_EQ(animation->from[2], 302); 451 EXPECT_FLOAT_EQ(animation->from[2], 302);
361 EXPECT_FLOAT_EQ(animation->from[3], 303); 452 EXPECT_FLOAT_EQ(animation->from[3], 303);
362 453
363 EXPECT_EQ(animation->start, 22345000); 454 EXPECT_EQ(animation->start, 22345000);
364 EXPECT_EQ(animation->duration, 54321000); 455 EXPECT_EQ(animation->duration, 54321000);
365 } 456 }
366 457
367 } // namespace vr_shell 458 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene.cc ('k') | chrome/browser/android/vr_shell/vr_math.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698