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 19 matching lines...) Expand all Loading... | |
| 30 MOCK_METHOD1(OnUnsupportedMode, void(UiUnsupportedMode mode)); | 30 MOCK_METHOD1(OnUnsupportedMode, void(UiUnsupportedMode mode)); |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface); | 33 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface); |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 std::set<UiElementDebugId> kElementsVisibleInBrowsing = { | 36 std::set<UiElementDebugId> kElementsVisibleInBrowsing = { |
| 37 kContentQuad, kBackplane, kCeiling, kFloor, kUrlBar}; | 37 kContentQuad, kBackplane, kCeiling, kFloor, kUrlBar}; |
| 38 std::set<UiElementDebugId> kElementsVisibleWithExitPrompt = { | 38 std::set<UiElementDebugId> kElementsVisibleWithExitPrompt = { |
| 39 kExitPrompt, kExitPromptBackplane, kCeiling, kFloor}; | 39 kExitPrompt, kExitPromptBackplane, kCeiling, kFloor}; |
| 40 std::set<UiElementDebugId> kElementsVisibleForSplashScreen = { | |
|
cjgrant
2017/06/23 19:26:33
If used in only one test, should be in the test, I
ymalik
2017/06/25 20:27:14
Done.
| |
| 41 kSplashScreenIcon}; | |
| 40 | 42 |
| 41 } // namespace | 43 } // namespace |
| 42 | 44 |
| 43 class UiSceneManagerTest : public testing::Test { | 45 class UiSceneManagerTest : public testing::Test { |
| 44 public: | 46 public: |
| 45 void SetUp() override { browser_ = base::MakeUnique<MockBrowserInterface>(); } | 47 void SetUp() override { browser_ = base::MakeUnique<MockBrowserInterface>(); } |
| 46 | 48 |
| 47 protected: | 49 protected: |
| 48 enum InCct : bool { | 50 enum InCct : bool { |
| 49 kNotInCct = false, | 51 kNotInCct = false, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 62 | 64 |
| 63 void MakeManager(InCct in_cct, InWebVr in_web_vr) { | 65 void MakeManager(InCct in_cct, InWebVr in_web_vr) { |
| 64 scene_ = base::MakeUnique<UiScene>(); | 66 scene_ = base::MakeUnique<UiScene>(); |
| 65 manager_ = base::MakeUnique<UiSceneManager>( | 67 manager_ = base::MakeUnique<UiSceneManager>( |
| 66 browser_.get(), scene_.get(), in_cct, in_web_vr, kNotAutopresented); | 68 browser_.get(), scene_.get(), in_cct, in_web_vr, kNotAutopresented); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void MakeAutoPresentedManager() { | 71 void MakeAutoPresentedManager() { |
| 70 scene_ = base::MakeUnique<UiScene>(); | 72 scene_ = base::MakeUnique<UiScene>(); |
| 71 manager_ = base::MakeUnique<UiSceneManager>( | 73 manager_ = base::MakeUnique<UiSceneManager>( |
| 72 browser_.get(), scene_.get(), kNotInCct, kInWebVr, kAutopresented); | 74 browser_.get(), scene_.get(), kNotInCct, kNotInWebVr, kAutopresented); |
| 73 } | 75 } |
| 74 | 76 |
| 75 bool IsVisible(UiElementDebugId debug_id) { | 77 bool IsVisible(UiElementDebugId debug_id) { |
| 76 UiElement* element = scene_->GetUiElementByDebugId(debug_id); | 78 UiElement* element = scene_->GetUiElementByDebugId(debug_id); |
| 77 return element ? element->visible() : false; | 79 return element ? element->visible() : false; |
| 78 } | 80 } |
| 79 | 81 |
| 80 void VerifyElementsVisible(const std::string& debug_name, | 82 void VerifyElementsVisible(const std::string& debug_name, |
| 81 const std::set<UiElementDebugId>& elements) { | 83 const std::set<UiElementDebugId>& elements) { |
| 82 SCOPED_TRACE(debug_name); | 84 SCOPED_TRACE(debug_name); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 111 EXPECT_TRUE(IsVisible(kWebVrTransientHttpSecurityWarning)); | 113 EXPECT_TRUE(IsVisible(kWebVrTransientHttpSecurityWarning)); |
| 112 | 114 |
| 113 manager_->SetWebVrSecureOrigin(true); | 115 manager_->SetWebVrSecureOrigin(true); |
| 114 EXPECT_FALSE(IsVisible(kWebVrPermanentHttpSecurityWarning)); | 116 EXPECT_FALSE(IsVisible(kWebVrPermanentHttpSecurityWarning)); |
| 115 EXPECT_FALSE(IsVisible(kWebVrTransientHttpSecurityWarning)); | 117 EXPECT_FALSE(IsVisible(kWebVrTransientHttpSecurityWarning)); |
| 116 | 118 |
| 117 manager_->SetWebVrSecureOrigin(false); | 119 manager_->SetWebVrSecureOrigin(false); |
| 118 EXPECT_TRUE(IsVisible(kWebVrPermanentHttpSecurityWarning)); | 120 EXPECT_TRUE(IsVisible(kWebVrPermanentHttpSecurityWarning)); |
| 119 EXPECT_TRUE(IsVisible(kWebVrTransientHttpSecurityWarning)); | 121 EXPECT_TRUE(IsVisible(kWebVrTransientHttpSecurityWarning)); |
| 120 | 122 |
| 121 manager_->SetWebVrMode(false, false); | 123 manager_->SetWebVrMode(false); |
| 122 EXPECT_FALSE(IsVisible(kWebVrPermanentHttpSecurityWarning)); | 124 EXPECT_FALSE(IsVisible(kWebVrPermanentHttpSecurityWarning)); |
| 123 EXPECT_FALSE(IsVisible(kWebVrTransientHttpSecurityWarning)); | 125 EXPECT_FALSE(IsVisible(kWebVrTransientHttpSecurityWarning)); |
| 124 } | 126 } |
| 125 | 127 |
| 126 TEST_F(UiSceneManagerTest, WebVrWarningsDoNotShowWhenInitiallyOutsideWebVr) { | 128 TEST_F(UiSceneManagerTest, WebVrWarningsDoNotShowWhenInitiallyOutsideWebVr) { |
| 127 MakeManager(kNotInCct, kNotInWebVr); | 129 MakeManager(kNotInCct, kNotInWebVr); |
| 128 | 130 |
| 129 EXPECT_FALSE(IsVisible(kWebVrPermanentHttpSecurityWarning)); | 131 EXPECT_FALSE(IsVisible(kWebVrPermanentHttpSecurityWarning)); |
| 130 EXPECT_FALSE(IsVisible(kWebVrTransientHttpSecurityWarning)); | 132 EXPECT_FALSE(IsVisible(kWebVrTransientHttpSecurityWarning)); |
| 131 | 133 |
| 132 manager_->SetWebVrMode(true, false); | 134 manager_->SetWebVrMode(true); |
| 133 EXPECT_TRUE(IsVisible(kWebVrPermanentHttpSecurityWarning)); | 135 EXPECT_TRUE(IsVisible(kWebVrPermanentHttpSecurityWarning)); |
| 134 EXPECT_TRUE(IsVisible(kWebVrTransientHttpSecurityWarning)); | 136 EXPECT_TRUE(IsVisible(kWebVrTransientHttpSecurityWarning)); |
| 135 } | 137 } |
| 136 | 138 |
| 137 TEST_F(UiSceneManagerTest, CloseButtonVisibleInCctFullscreen) { | 139 TEST_F(UiSceneManagerTest, CloseButtonVisibleInCctFullscreen) { |
| 138 // Button should be visible in cct. | 140 // Button should be visible in cct. |
| 139 MakeManager(kInCct, kNotInWebVr); | 141 MakeManager(kInCct, kNotInWebVr); |
| 140 EXPECT_TRUE(IsVisible(kCloseButton)); | 142 EXPECT_TRUE(IsVisible(kCloseButton)); |
| 141 | 143 |
| 142 // Button should not be visible when not in cct or fullscreen. | 144 // Button should not be visible when not in cct or fullscreen. |
| 143 MakeManager(kNotInCct, kNotInWebVr); | 145 MakeManager(kNotInCct, kNotInWebVr); |
| 144 EXPECT_FALSE(IsVisible(kCloseButton)); | 146 EXPECT_FALSE(IsVisible(kCloseButton)); |
| 145 | 147 |
| 146 // Button should be visible in fullscreen and hidden when leaving fullscreen. | 148 // Button should be visible in fullscreen and hidden when leaving fullscreen. |
| 147 manager_->SetFullscreen(true); | 149 manager_->SetFullscreen(true); |
| 148 EXPECT_TRUE(IsVisible(kCloseButton)); | 150 EXPECT_TRUE(IsVisible(kCloseButton)); |
| 149 manager_->SetFullscreen(false); | 151 manager_->SetFullscreen(false); |
| 150 EXPECT_FALSE(IsVisible(kCloseButton)); | 152 EXPECT_FALSE(IsVisible(kCloseButton)); |
| 151 | 153 |
| 152 // Button should not be visible when in WebVR. | 154 // Button should not be visible when in WebVR. |
| 153 MakeManager(kInCct, kInWebVr); | 155 MakeManager(kInCct, kInWebVr); |
| 154 EXPECT_FALSE(IsVisible(kCloseButton)); | 156 EXPECT_FALSE(IsVisible(kCloseButton)); |
| 155 manager_->SetWebVrMode(false, false); | 157 manager_->SetWebVrMode(false); |
| 156 EXPECT_TRUE(IsVisible(kCloseButton)); | 158 EXPECT_TRUE(IsVisible(kCloseButton)); |
| 157 | 159 |
| 158 // Button should be visible in Cct across transistions in fullscreen. | 160 // Button should be visible in Cct across transistions in fullscreen. |
| 159 MakeManager(kInCct, kNotInWebVr); | 161 MakeManager(kInCct, kNotInWebVr); |
| 160 EXPECT_TRUE(IsVisible(kCloseButton)); | 162 EXPECT_TRUE(IsVisible(kCloseButton)); |
| 161 manager_->SetFullscreen(true); | 163 manager_->SetFullscreen(true); |
| 162 EXPECT_TRUE(IsVisible(kCloseButton)); | 164 EXPECT_TRUE(IsVisible(kCloseButton)); |
| 163 manager_->SetFullscreen(false); | 165 manager_->SetFullscreen(false); |
| 164 EXPECT_TRUE(IsVisible(kCloseButton)); | 166 EXPECT_TRUE(IsVisible(kCloseButton)); |
| 165 } | 167 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 } | 214 } |
| 213 | 215 |
| 214 manager_->SetIncognito(false); | 216 manager_->SetIncognito(false); |
| 215 | 217 |
| 216 { | 218 { |
| 217 SCOPED_TRACE("Exited Incognito"); | 219 SCOPED_TRACE("Exited Incognito"); |
| 218 EXPECT_EQ(initial_background, scene_->GetWorldBackgroundColor()); | 220 EXPECT_EQ(initial_background, scene_->GetWorldBackgroundColor()); |
| 219 } | 221 } |
| 220 } | 222 } |
| 221 | 223 |
| 222 TEST_F(UiSceneManagerTest, WebVrAutopresentedInitially) { | 224 TEST_F(UiSceneManagerTest, WebVrAutopresented) { |
| 223 MakeAutoPresentedManager(); | 225 MakeAutoPresentedManager(); |
| 226 | |
| 224 manager_->SetWebVrSecureOrigin(true); | 227 manager_->SetWebVrSecureOrigin(true); |
| 228 | |
| 229 // Initially, we should only show the splash screen. | |
| 230 VerifyElementsVisible("Initial", kElementsVisibleForSplashScreen); | |
| 231 | |
| 232 // Enter WebVR with autopresentation. | |
| 233 manager_->SetWebVrMode(true); | |
| 225 VerifyElementsVisible("Autopresented", | 234 VerifyElementsVisible("Autopresented", |
| 226 std::set<UiElementDebugId>{kTransientUrlBar}); | 235 std::set<UiElementDebugId>{kTransientUrlBar}); |
| 227 } | 236 } |
| 228 | |
| 229 TEST_F(UiSceneManagerTest, WebVrAutopresented) { | |
| 230 MakeManager(kNotInCct, kNotInWebVr); | |
| 231 | |
| 232 manager_->SetWebVrSecureOrigin(true); | |
| 233 | |
| 234 // Initial state. | |
| 235 VerifyElementsVisible("Initial", kElementsVisibleInBrowsing); | |
| 236 | |
| 237 // Enter WebVR with autopresentation. | |
| 238 manager_->SetWebVrMode(true, true); | |
| 239 VerifyElementsVisible("Autopresented", | |
| 240 std::set<UiElementDebugId>{kTransientUrlBar}); | |
| 241 } | |
| 242 | 237 |
| 243 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) { | 238 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) { |
| 244 std::set<UiElementDebugId> visible_in_fullscreen = { | 239 std::set<UiElementDebugId> visible_in_fullscreen = { |
| 245 kContentQuad, kCloseButton, kBackplane, kCeiling, kFloor}; | 240 kContentQuad, kCloseButton, kBackplane, kCeiling, kFloor}; |
| 246 | 241 |
| 247 MakeManager(kNotInCct, kNotInWebVr); | 242 MakeManager(kNotInCct, kNotInWebVr); |
| 248 | 243 |
| 249 // Hold onto the background color to make sure it changes. | 244 // Hold onto the background color to make sure it changes. |
| 250 SkColor initial_background = scene_->GetWorldBackgroundColor(); | 245 SkColor initial_background = scene_->GetWorldBackgroundColor(); |
| 251 VerifyElementsVisible("Initial", kElementsVisibleInBrowsing); | 246 VerifyElementsVisible("Initial", kElementsVisibleInBrowsing); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 VerifyElementsVisible("Elements hidden", std::set<UiElementDebugId>{}); | 311 VerifyElementsVisible("Elements hidden", std::set<UiElementDebugId>{}); |
| 317 } | 312 } |
| 318 | 313 |
| 319 TEST_F(UiSceneManagerTest, UiUpdateTransitionToWebVR) { | 314 TEST_F(UiSceneManagerTest, UiUpdateTransitionToWebVR) { |
| 320 MakeManager(kNotInCct, kNotInWebVr); | 315 MakeManager(kNotInCct, kNotInWebVr); |
| 321 manager_->SetAudioCapturingIndicator(true); | 316 manager_->SetAudioCapturingIndicator(true); |
| 322 manager_->SetVideoCapturingIndicator(true); | 317 manager_->SetVideoCapturingIndicator(true); |
| 323 manager_->SetScreenCapturingIndicator(true); | 318 manager_->SetScreenCapturingIndicator(true); |
| 324 | 319 |
| 325 // Transition to WebVR mode | 320 // Transition to WebVR mode |
| 326 manager_->SetWebVrMode(true, false); | 321 manager_->SetWebVrMode(true); |
| 327 manager_->SetWebVrSecureOrigin(true); | 322 manager_->SetWebVrSecureOrigin(true); |
| 328 | 323 |
| 329 // All elements should be hidden. | 324 // All elements should be hidden. |
| 330 VerifyElementsVisible("Elements hidden", std::set<UiElementDebugId>{}); | 325 VerifyElementsVisible("Elements hidden", std::set<UiElementDebugId>{}); |
| 331 } | 326 } |
| 332 | 327 |
| 333 TEST_F(UiSceneManagerTest, CaptureIndicatorsVisibility) { | 328 TEST_F(UiSceneManagerTest, CaptureIndicatorsVisibility) { |
| 334 MakeManager(kNotInCct, kNotInWebVr); | 329 MakeManager(kNotInCct, kNotInWebVr); |
| 335 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); | 330 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); |
| 336 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); | 331 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); |
| 337 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); | 332 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); |
| 338 | 333 |
| 339 manager_->SetAudioCapturingIndicator(true); | 334 manager_->SetAudioCapturingIndicator(true); |
| 340 manager_->SetVideoCapturingIndicator(true); | 335 manager_->SetVideoCapturingIndicator(true); |
| 341 manager_->SetScreenCapturingIndicator(true); | 336 manager_->SetScreenCapturingIndicator(true); |
| 342 | 337 |
| 343 EXPECT_TRUE(IsVisible(kAudioCaptureIndicator)); | 338 EXPECT_TRUE(IsVisible(kAudioCaptureIndicator)); |
| 344 EXPECT_TRUE(IsVisible(kVideoCaptureIndicator)); | 339 EXPECT_TRUE(IsVisible(kVideoCaptureIndicator)); |
| 345 EXPECT_TRUE(IsVisible(kScreenCaptureIndicator)); | 340 EXPECT_TRUE(IsVisible(kScreenCaptureIndicator)); |
| 346 | 341 |
| 347 manager_->SetWebVrMode(true, false); | 342 manager_->SetWebVrMode(true); |
| 348 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); | 343 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); |
| 349 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); | 344 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); |
| 350 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); | 345 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); |
| 351 | 346 |
| 352 manager_->SetWebVrMode(false, false); | 347 manager_->SetWebVrMode(false); |
| 353 EXPECT_TRUE(IsVisible(kAudioCaptureIndicator)); | 348 EXPECT_TRUE(IsVisible(kAudioCaptureIndicator)); |
| 354 EXPECT_TRUE(IsVisible(kVideoCaptureIndicator)); | 349 EXPECT_TRUE(IsVisible(kVideoCaptureIndicator)); |
| 355 EXPECT_TRUE(IsVisible(kScreenCaptureIndicator)); | 350 EXPECT_TRUE(IsVisible(kScreenCaptureIndicator)); |
| 356 | 351 |
| 357 manager_->SetAudioCapturingIndicator(false); | 352 manager_->SetAudioCapturingIndicator(false); |
| 358 manager_->SetVideoCapturingIndicator(false); | 353 manager_->SetVideoCapturingIndicator(false); |
| 359 manager_->SetScreenCapturingIndicator(false); | 354 manager_->SetScreenCapturingIndicator(false); |
| 360 | 355 |
| 361 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); | 356 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); |
| 362 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); | 357 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); |
| 363 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); | 358 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); |
| 364 } | 359 } |
| 365 } // namespace vr_shell | 360 } // namespace vr_shell |
| OLD | NEW |