Chromium Code Reviews| 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); |
|
amp
2017/06/23 18:36:59
Does anything different happen if some of the indi
cjgrant
2017/06/23 19:38:26
Nope, but, Amir and I talked about additional test
| |
| 368 manager_->SetVideoCapturingIndicator(true); | 384 manager_->SetVideoCapturingIndicator(true); |
| 369 manager_->SetScreenCapturingIndicator(true); | 385 manager_->SetScreenCapturingIndicator(true); |
| 370 manager_->SetLocationAccessIndicator(true); | 386 manager_->SetLocationAccessIndicator(true); |
| 371 | 387 EXPECT_TRUE(VerifyVisibility(indicators, true)); |
| 372 EXPECT_TRUE(IsVisible(kAudioCaptureIndicator)); | |
| 373 EXPECT_TRUE(IsVisible(kVideoCaptureIndicator)); | |
| 374 EXPECT_TRUE(IsVisible(kScreenCaptureIndicator)); | |
| 375 EXPECT_TRUE(IsVisible(kLocationAccessIndicator)); | |
| 376 | 388 |
| 377 manager_->SetWebVrMode(true, false, false); | 389 manager_->SetWebVrMode(true, false, false); |
| 378 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); | 390 EXPECT_TRUE(VerifyVisibility(indicators, false)); |
| 379 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); | |
| 380 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); | |
| 381 EXPECT_FALSE(IsVisible(kLocationAccessIndicator)); | |
| 382 | 391 |
| 383 manager_->SetWebVrMode(false, false, false); | 392 manager_->SetWebVrMode(false, false, false); |
| 384 EXPECT_TRUE(IsVisible(kAudioCaptureIndicator)); | 393 EXPECT_TRUE(VerifyVisibility(indicators, true)); |
| 385 EXPECT_TRUE(IsVisible(kVideoCaptureIndicator)); | 394 |
| 386 EXPECT_TRUE(IsVisible(kScreenCaptureIndicator)); | 395 manager_->SetFullscreen(true); |
|
asimjour1
2017/06/23 13:28:41
We miss the transition from Fullscreen to WebVr.
cjgrant
2017/06/23 19:38:26
Discussed offline. The intent isn't really to cov
| |
| 387 EXPECT_TRUE(IsVisible(kLocationAccessIndicator)); | 396 EXPECT_TRUE(VerifyVisibility(indicators, false)); |
| 397 manager_->SetFullscreen(false); | |
| 398 EXPECT_TRUE(VerifyVisibility(indicators, true)); | |
| 388 | 399 |
| 389 manager_->SetAudioCapturingIndicator(false); | 400 manager_->SetAudioCapturingIndicator(false); |
| 390 manager_->SetVideoCapturingIndicator(false); | 401 manager_->SetVideoCapturingIndicator(false); |
| 391 manager_->SetScreenCapturingIndicator(false); | 402 manager_->SetScreenCapturingIndicator(false); |
| 392 manager_->SetLocationAccessIndicator(false); | 403 manager_->SetLocationAccessIndicator(false); |
| 404 EXPECT_TRUE(VerifyVisibility(indicators, false)); | |
| 405 } | |
| 393 | 406 |
| 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 | 407 } // namespace vr_shell |
| OLD | NEW |