OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_manager.h" | 5 #include "chrome/browser/android/vr_shell/ui_scene_manager.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/test/scoped_task_environment.h" | 9 #include "base/test/scoped_task_environment.h" |
10 #include "chrome/browser/android/vr_shell/ui_browser_interface.h" | 10 #include "chrome/browser/android/vr_shell/ui_browser_interface.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 scene_ = base::MakeUnique<UiScene>(); | 70 scene_ = base::MakeUnique<UiScene>(); |
71 manager_ = base::MakeUnique<UiSceneManager>( | 71 manager_ = base::MakeUnique<UiSceneManager>( |
72 browser_.get(), scene_.get(), kNotInCct, kInWebVr, kAutopresented); | 72 browser_.get(), scene_.get(), kNotInCct, kInWebVr, kAutopresented); |
73 } | 73 } |
74 | 74 |
75 bool IsVisible(UiElementDebugId debug_id) { | 75 bool IsVisible(UiElementDebugId debug_id) { |
76 UiElement* element = scene_->GetUiElementByDebugId(debug_id); | 76 UiElement* element = scene_->GetUiElementByDebugId(debug_id); |
77 return element ? element->visible() : false; | 77 return element ? element->visible() : false; |
78 } | 78 } |
79 | 79 |
| 80 // Verify that only the elements in the set are visible. |
80 void VerifyElementsVisible(const std::string& debug_name, | 81 void VerifyElementsVisible(const std::string& debug_name, |
81 const std::set<UiElementDebugId>& elements) { | 82 const std::set<UiElementDebugId>& debug_ids) { |
82 SCOPED_TRACE(debug_name); | 83 SCOPED_TRACE(debug_name); |
83 for (const auto& element : scene_->GetUiElements()) { | 84 for (const auto& element : scene_->GetUiElements()) { |
84 SCOPED_TRACE(element->debug_id()); | 85 SCOPED_TRACE(element->debug_id()); |
85 bool should_be_visible = | 86 bool should_be_visible = |
86 elements.find(element->debug_id()) != elements.end(); | 87 debug_ids.find(element->debug_id()) != debug_ids.end(); |
87 EXPECT_EQ(should_be_visible, element->visible()); | 88 EXPECT_EQ(should_be_visible, element->visible()); |
88 } | 89 } |
89 } | 90 } |
90 | 91 |
| 92 // Return false if not all elements in the set match the specified visibility |
| 93 // state. Other elements are ignored. |
| 94 bool VerifyVisibility(const std::set<UiElementDebugId>& debug_ids, |
| 95 bool visible) { |
| 96 for (const auto& element : scene_->GetUiElements()) { |
| 97 if (debug_ids.find(element->debug_id()) != debug_ids.end() && |
| 98 element->visible() != visible) { |
| 99 return false; |
| 100 } |
| 101 } |
| 102 return true; |
| 103 } |
| 104 |
91 base::test::ScopedTaskEnvironment scoped_task_environment_; | 105 base::test::ScopedTaskEnvironment scoped_task_environment_; |
92 std::unique_ptr<MockBrowserInterface> browser_; | 106 std::unique_ptr<MockBrowserInterface> browser_; |
93 std::unique_ptr<UiScene> scene_; | 107 std::unique_ptr<UiScene> scene_; |
94 std::unique_ptr<UiSceneManager> manager_; | 108 std::unique_ptr<UiSceneManager> manager_; |
95 }; | 109 }; |
96 | 110 |
97 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { | 111 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { |
98 MakeManager(kNotInCct, kInWebVr); | 112 MakeManager(kNotInCct, kInWebVr); |
99 | 113 |
100 // Clicking app button should trigger to exit presentation. | 114 // Clicking app button should trigger to exit presentation. |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 365 |
352 // Transition to WebVR mode | 366 // Transition to WebVR mode |
353 manager_->SetWebVrMode(true, false, false); | 367 manager_->SetWebVrMode(true, false, false); |
354 manager_->SetWebVrSecureOrigin(true); | 368 manager_->SetWebVrSecureOrigin(true); |
355 | 369 |
356 // All elements should be hidden. | 370 // All elements should be hidden. |
357 VerifyElementsVisible("Elements hidden", std::set<UiElementDebugId>{}); | 371 VerifyElementsVisible("Elements hidden", std::set<UiElementDebugId>{}); |
358 } | 372 } |
359 | 373 |
360 TEST_F(UiSceneManagerTest, CaptureIndicatorsVisibility) { | 374 TEST_F(UiSceneManagerTest, CaptureIndicatorsVisibility) { |
| 375 const std::set<UiElementDebugId> indicators = { |
| 376 kAudioCaptureIndicator, kVideoCaptureIndicator, kScreenCaptureIndicator, |
| 377 kLocationAccessIndicator, |
| 378 }; |
| 379 |
361 MakeManager(kNotInCct, kNotInWebVr); | 380 MakeManager(kNotInCct, kNotInWebVr); |
362 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); | 381 EXPECT_TRUE(VerifyVisibility(indicators, false)); |
363 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); | |
364 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); | |
365 EXPECT_FALSE(IsVisible(kLocationAccessIndicator)); | |
366 | 382 |
367 manager_->SetAudioCapturingIndicator(true); | 383 manager_->SetAudioCapturingIndicator(true); |
368 manager_->SetVideoCapturingIndicator(true); | 384 manager_->SetVideoCapturingIndicator(true); |
369 manager_->SetScreenCapturingIndicator(true); | 385 manager_->SetScreenCapturingIndicator(true); |
370 manager_->SetLocationAccessIndicator(true); | 386 manager_->SetLocationAccessIndicator(true); |
| 387 EXPECT_TRUE(VerifyVisibility(indicators, true)); |
371 | 388 |
372 EXPECT_TRUE(IsVisible(kAudioCaptureIndicator)); | 389 // Go into non-browser modes and make sure all indicators are hidden. |
373 EXPECT_TRUE(IsVisible(kVideoCaptureIndicator)); | 390 manager_->SetWebVrMode(true, false, false); |
374 EXPECT_TRUE(IsVisible(kScreenCaptureIndicator)); | 391 EXPECT_TRUE(VerifyVisibility(indicators, false)); |
375 EXPECT_TRUE(IsVisible(kLocationAccessIndicator)); | 392 manager_->SetWebVrMode(false, false, false); |
| 393 manager_->SetFullscreen(true); |
| 394 EXPECT_TRUE(VerifyVisibility(indicators, false)); |
| 395 manager_->SetFullscreen(false); |
376 | 396 |
377 manager_->SetWebVrMode(true, false, false); | 397 // Back to browser, make sure the indicators reappear. |
378 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); | 398 EXPECT_TRUE(VerifyVisibility(indicators, true)); |
379 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); | |
380 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); | |
381 EXPECT_FALSE(IsVisible(kLocationAccessIndicator)); | |
382 | 399 |
383 manager_->SetWebVrMode(false, false, false); | 400 // Ensure they can be turned off. |
384 EXPECT_TRUE(IsVisible(kAudioCaptureIndicator)); | |
385 EXPECT_TRUE(IsVisible(kVideoCaptureIndicator)); | |
386 EXPECT_TRUE(IsVisible(kScreenCaptureIndicator)); | |
387 EXPECT_TRUE(IsVisible(kLocationAccessIndicator)); | |
388 | |
389 manager_->SetAudioCapturingIndicator(false); | 401 manager_->SetAudioCapturingIndicator(false); |
390 manager_->SetVideoCapturingIndicator(false); | 402 manager_->SetVideoCapturingIndicator(false); |
391 manager_->SetScreenCapturingIndicator(false); | 403 manager_->SetScreenCapturingIndicator(false); |
392 manager_->SetLocationAccessIndicator(false); | 404 manager_->SetLocationAccessIndicator(false); |
| 405 EXPECT_TRUE(VerifyVisibility(indicators, false)); |
| 406 } |
393 | 407 |
394 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); | |
395 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); | |
396 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); | |
397 EXPECT_FALSE(IsVisible(kLocationAccessIndicator)); | |
398 } | |
399 } // namespace vr_shell | 408 } // namespace vr_shell |
OLD | NEW |