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/test/scoped_task_environment.h" | 8 #include "base/test/scoped_task_environment.h" |
| 9 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" | 9 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" |
| 10 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" | 10 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 | 54 |
| 55 // Stub this as scoped pointers don't work as mock method parameters. | 55 // Stub this as scoped pointers don't work as mock method parameters. |
| 56 void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent>) {} | 56 void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent>) {} |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface); | 59 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 std::set<UiElementDebugId> kElementsVisibleInBrowsing = { | 62 std::set<UiElementDebugId> kElementsVisibleInBrowsing = { |
| 63 kContentQuad, kBackplane, kCeiling, kFloor, kUrlBar, kLoadingIndicator}; | 63 kContentQuad, kBackplane, kCeiling, kFloor, kUrlBar, kLoadingIndicator}; |
| 64 std::set<UiElementDebugId> kElementsVisibleWithExitPrompt = { | |
|
cjgrant
2017/06/06 21:21:56
If this is only used in one test, it could live th
ymalik
2017/06/07 14:55:59
Its used by two tests. The primary button click an
| |
| 65 kExitPrompt, kExitPromptBackplane, kCeiling, kFloor}; | |
| 64 | 66 |
| 65 } // namespace | 67 } // namespace |
| 66 | 68 |
| 67 class UiSceneManagerTest : public testing::Test { | 69 class UiSceneManagerTest : public testing::Test { |
| 68 public: | 70 public: |
| 69 void SetUp() override { browser_ = base::MakeUnique<MockBrowserInterface>(); } | 71 void SetUp() override { browser_ = base::MakeUnique<MockBrowserInterface>(); } |
| 70 | 72 |
| 71 protected: | 73 protected: |
| 72 enum InCct : bool { | 74 enum InCct : bool { |
| 73 kNotInCct = false, | 75 kNotInCct = false, |
| 74 kInCct = true, | 76 kInCct = true, |
| 75 }; | 77 }; |
| 76 | 78 |
| 77 enum InWebVr : bool { | 79 enum InWebVr : bool { |
| 78 kNotInWebVr = false, | 80 kNotInWebVr = false, |
| 79 kInWebVr = true, | 81 kInWebVr = true, |
| 80 }; | 82 }; |
| 81 | 83 |
| 82 void MakeManager(InCct in_cct, InWebVr in_web_vr) { | 84 void MakeManager(InCct in_cct, InWebVr in_web_vr) { |
| 83 scene_ = base::MakeUnique<UiScene>(); | 85 scene_ = base::MakeUnique<UiScene>(); |
| 84 manager_ = base::MakeUnique<UiSceneManager>(browser_.get(), scene_.get(), | 86 manager_ = base::MakeUnique<UiSceneManager>(browser_.get(), scene_.get(), |
| 85 in_cct, in_web_vr); | 87 in_cct, in_web_vr); |
| 86 } | 88 } |
| 87 | 89 |
| 88 bool IsVisible(UiElementDebugId debug_id) { | 90 bool IsVisible(UiElementDebugId debug_id) { |
| 89 UiElement* element = scene_->GetUiElementByDebugId(debug_id); | 91 UiElement* element = scene_->GetUiElementByDebugId(debug_id); |
| 90 return element ? element->visible() : false; | 92 return element ? element->visible() : false; |
| 91 } | 93 } |
| 92 | 94 |
| 95 void VerifyElementsVisible(std::set<UiElementDebugId> elements) { | |
|
cjgrant
2017/06/06 21:21:56
const&
ymalik
2017/06/07 14:55:58
Done.
| |
| 96 for (const auto& element : scene_->GetUiElements()) { | |
| 97 SCOPED_TRACE(element->debug_id()); | |
|
cjgrant
2017/06/06 21:21:56
If an element is wrong, does the trace still ident
amp
2017/06/06 21:42:43
Yes it fails on a specific line number, but then t
amp
2017/06/06 21:46:22
Oh wait, realized the question was if this would s
ymalik
2017/06/07 14:55:58
Ah good catch.
I don't think SCOPED_TRACE('[test
cjgrant
2017/06/07 16:03:06
I played with this a bit, and I think what you hav
amp
2017/06/07 17:18:41
Cumbersome, but it's not really useful if you don'
| |
| 98 bool should_be_visible = | |
| 99 elements.find(element->debug_id()) != elements.end(); | |
| 100 EXPECT_EQ(should_be_visible, element->visible()); | |
| 101 } | |
| 102 } | |
| 103 | |
| 93 base::test::ScopedTaskEnvironment scoped_task_environment_; | 104 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 94 std::unique_ptr<MockBrowserInterface> browser_; | 105 std::unique_ptr<MockBrowserInterface> browser_; |
| 95 std::unique_ptr<UiScene> scene_; | 106 std::unique_ptr<UiScene> scene_; |
| 96 std::unique_ptr<UiSceneManager> manager_; | 107 std::unique_ptr<UiSceneManager> manager_; |
| 97 }; | 108 }; |
| 98 | 109 |
| 99 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { | 110 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { |
| 100 MakeManager(kNotInCct, kInWebVr); | 111 MakeManager(kNotInCct, kInWebVr); |
| 101 | 112 |
| 102 // Clicking app button should trigger to exit presentation. | 113 // Clicking app button should trigger to exit presentation. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 } | 216 } |
| 206 | 217 |
| 207 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) { | 218 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) { |
| 208 std::set<UiElementDebugId> visible_in_fullscreen = {kContentQuad, kBackplane, | 219 std::set<UiElementDebugId> visible_in_fullscreen = {kContentQuad, kBackplane, |
| 209 kCeiling, kFloor}; | 220 kCeiling, kFloor}; |
| 210 | 221 |
| 211 MakeManager(kNotInCct, kNotInWebVr); | 222 MakeManager(kNotInCct, kNotInWebVr); |
| 212 | 223 |
| 213 // Hold onto the background color to make sure it changes. | 224 // Hold onto the background color to make sure it changes. |
| 214 SkColor initial_background = scene_->GetBackgroundColor(); | 225 SkColor initial_background = scene_->GetBackgroundColor(); |
| 226 VerifyElementsVisible(kElementsVisibleInBrowsing); | |
| 215 | 227 |
| 216 for (const auto& element : scene_->GetUiElements()) { | 228 // In fullscreen mode, content elements should be visible, control elements |
|
amp
2017/06/06 21:42:43
My latest change (about to go in) changes this aga
ymalik
2017/06/07 14:55:59
Acknowledged.
| |
| 217 SCOPED_TRACE(element->debug_id()); | 229 // should be hidden. |
| 218 bool should_be_visible = | |
| 219 kElementsVisibleInBrowsing.find(element->debug_id()) != | |
| 220 kElementsVisibleInBrowsing.end(); | |
| 221 EXPECT_EQ(should_be_visible, element->visible()); | |
| 222 } | |
| 223 | |
| 224 // Transistion to fullscreen. | |
| 225 manager_->SetFullscreen(true); | 230 manager_->SetFullscreen(true); |
| 226 | 231 VerifyElementsVisible(visible_in_fullscreen); |
| 227 // Content elements should be visible, control elements should be hidden. | |
| 228 for (const auto& element : scene_->GetUiElements()) { | |
| 229 SCOPED_TRACE(element->debug_id()); | |
| 230 bool should_be_visible = visible_in_fullscreen.find(element->debug_id()) != | |
| 231 visible_in_fullscreen.end(); | |
| 232 EXPECT_EQ(should_be_visible, element->visible()); | |
| 233 } | |
| 234 | |
| 235 { | 232 { |
| 236 SCOPED_TRACE("Entered Fullsceen"); | 233 SCOPED_TRACE("Entered Fullsceen"); |
| 237 // Make sure background has changed for fullscreen. | 234 // Make sure background has changed for fullscreen. |
| 238 EXPECT_NE(initial_background, scene_->GetBackgroundColor()); | 235 EXPECT_NE(initial_background, scene_->GetBackgroundColor()); |
| 239 } | 236 } |
| 240 | 237 |
| 241 // Exit fullscreen. | 238 // Everything should return to original state after leaving fullscreen. |
| 242 manager_->SetFullscreen(false); | 239 manager_->SetFullscreen(false); |
| 243 | 240 VerifyElementsVisible(kElementsVisibleInBrowsing); |
| 244 // Everything should return to original state after leaving fullscreen. | |
| 245 for (const auto& element : scene_->GetUiElements()) { | |
| 246 SCOPED_TRACE(element->debug_id()); | |
| 247 bool should_be_visible = | |
| 248 kElementsVisibleInBrowsing.find(element->debug_id()) != | |
| 249 kElementsVisibleInBrowsing.end(); | |
| 250 EXPECT_EQ(should_be_visible, element->visible()); | |
| 251 } | |
| 252 { | 241 { |
| 253 SCOPED_TRACE("Exited Fullsceen"); | 242 SCOPED_TRACE("Exited Fullsceen"); |
| 254 EXPECT_EQ(initial_background, scene_->GetBackgroundColor()); | 243 EXPECT_EQ(initial_background, scene_->GetBackgroundColor()); |
| 255 } | 244 } |
| 256 } | 245 } |
| 257 | 246 |
| 258 TEST_F(UiSceneManagerTest, UiUpdatesExitPrompt) { | 247 TEST_F(UiSceneManagerTest, UiUpdatesExitPrompt) { |
| 259 std::set<UiElementDebugId> visible_when_prompting = {kExitPrompt, kBackplane, | |
| 260 kCeiling, kFloor}; | |
| 261 MakeManager(kNotInCct, kNotInWebVr); | 248 MakeManager(kNotInCct, kNotInWebVr); |
| 262 | 249 |
| 263 manager_->SetWebVrSecureOrigin(true); | 250 manager_->SetWebVrSecureOrigin(true); |
| 264 | 251 |
| 265 // Initial state. | 252 // Initial state. |
| 266 for (const auto& element : scene_->GetUiElements()) { | 253 VerifyElementsVisible(kElementsVisibleInBrowsing); |
| 267 SCOPED_TRACE(element->debug_id()); | |
| 268 bool should_be_visible = | |
| 269 kElementsVisibleInBrowsing.find(element->debug_id()) != | |
| 270 kElementsVisibleInBrowsing.end(); | |
| 271 EXPECT_EQ(should_be_visible, element->visible()); | |
| 272 } | |
| 273 | 254 |
| 274 // Exit prompt visible state. | 255 // Exit prompt visible state. |
| 275 manager_->OnSecurityIconClicked(); | 256 manager_->OnSecurityIconClicked(); |
| 276 for (const auto& element : scene_->GetUiElements()) { | 257 VerifyElementsVisible(kElementsVisibleWithExitPrompt); |
| 277 SCOPED_TRACE(element->debug_id()); | |
| 278 bool should_be_visible = visible_when_prompting.find(element->debug_id()) != | |
| 279 visible_when_prompting.end(); | |
| 280 EXPECT_EQ(should_be_visible, element->visible()); | |
| 281 } | |
| 282 | 258 |
| 283 // Back to initial state. | 259 // Back to initial state. |
| 284 manager_->OnExitPromptPrimaryButtonClicked(); | 260 manager_->OnExitPromptPrimaryButtonClicked(); |
| 285 for (const auto& element : scene_->GetUiElements()) { | 261 VerifyElementsVisible(kElementsVisibleInBrowsing); |
| 286 SCOPED_TRACE(element->debug_id()); | 262 } |
| 287 bool should_be_visible = | 263 |
| 288 kElementsVisibleInBrowsing.find(element->debug_id()) != | 264 TEST_F(UiSceneManagerTest, BackplaneClickClosesExitPrompt) { |
| 289 kElementsVisibleInBrowsing.end(); | 265 MakeManager(kNotInCct, kNotInWebVr); |
| 290 EXPECT_EQ(should_be_visible, element->visible()); | 266 |
| 291 } | 267 manager_->SetWebVrSecureOrigin(true); |
| 268 | |
| 269 // Initial state. | |
| 270 VerifyElementsVisible(kElementsVisibleInBrowsing); | |
| 271 | |
| 272 // Exit prompt visible state. | |
| 273 manager_->OnSecurityIconClicked(); | |
| 274 VerifyElementsVisible(kElementsVisibleWithExitPrompt); | |
| 275 | |
| 276 // Back to initial state. | |
| 277 manager_->OnExitPromptBackplaneClicked(); | |
| 278 VerifyElementsVisible(kElementsVisibleInBrowsing); | |
| 292 } | 279 } |
| 293 | 280 |
| 294 TEST_F(UiSceneManagerTest, UiUpdatesForWebVR) { | 281 TEST_F(UiSceneManagerTest, UiUpdatesForWebVR) { |
| 295 MakeManager(kNotInCct, kInWebVr); | 282 MakeManager(kNotInCct, kInWebVr); |
| 296 | 283 |
| 297 manager_->SetWebVrSecureOrigin(true); | 284 manager_->SetWebVrSecureOrigin(true); |
| 298 manager_->SetAudioCapturingIndicator(true); | 285 manager_->SetAudioCapturingIndicator(true); |
| 299 manager_->SetVideoCapturingIndicator(true); | 286 manager_->SetVideoCapturingIndicator(true); |
| 300 manager_->SetScreenCapturingIndicator(true); | 287 manager_->SetScreenCapturingIndicator(true); |
| 301 | 288 |
| 302 // All elements should be hidden. | 289 // All elements should be hidden. |
| 303 for (const auto& element : scene_->GetUiElements()) { | 290 VerifyElementsVisible({}); |
| 304 SCOPED_TRACE(element->debug_id()); | |
| 305 EXPECT_FALSE(element->visible()); | |
| 306 } | |
| 307 } | 291 } |
| 308 | 292 |
| 309 TEST_F(UiSceneManagerTest, UiUpdateTransitionToWebVR) { | 293 TEST_F(UiSceneManagerTest, UiUpdateTransitionToWebVR) { |
| 310 MakeManager(kNotInCct, kNotInWebVr); | 294 MakeManager(kNotInCct, kNotInWebVr); |
| 311 manager_->SetAudioCapturingIndicator(true); | 295 manager_->SetAudioCapturingIndicator(true); |
| 312 manager_->SetVideoCapturingIndicator(true); | 296 manager_->SetVideoCapturingIndicator(true); |
| 313 manager_->SetScreenCapturingIndicator(true); | 297 manager_->SetScreenCapturingIndicator(true); |
| 314 | 298 |
| 315 // Transition to WebVR mode | 299 // Transition to WebVR mode |
| 316 manager_->SetWebVrMode(true); | 300 manager_->SetWebVrMode(true); |
| 317 manager_->SetWebVrSecureOrigin(true); | 301 manager_->SetWebVrSecureOrigin(true); |
| 318 | 302 |
| 319 // All elements should be hidden. | 303 // All elements should be hidden. |
| 320 for (const auto& element : scene_->GetUiElements()) { | 304 VerifyElementsVisible({}); |
|
cjgrant
2017/06/06 21:21:56
Thanks for adjusting all these call sites! code_s
ymalik
2017/06/07 14:55:59
Acknowledged.
| |
| 321 SCOPED_TRACE(element->debug_id()); | |
| 322 EXPECT_FALSE(element->visible()); | |
| 323 } | |
| 324 } | 305 } |
| 325 | 306 |
| 326 TEST_F(UiSceneManagerTest, CaptureIndicatorsVisibility) { | 307 TEST_F(UiSceneManagerTest, CaptureIndicatorsVisibility) { |
| 327 MakeManager(kNotInCct, kNotInWebVr); | 308 MakeManager(kNotInCct, kNotInWebVr); |
| 328 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); | 309 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); |
| 329 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); | 310 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); |
| 330 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); | 311 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); |
| 331 | 312 |
| 332 manager_->SetAudioCapturingIndicator(true); | 313 manager_->SetAudioCapturingIndicator(true); |
| 333 manager_->SetVideoCapturingIndicator(true); | 314 manager_->SetVideoCapturingIndicator(true); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 349 | 330 |
| 350 manager_->SetAudioCapturingIndicator(false); | 331 manager_->SetAudioCapturingIndicator(false); |
| 351 manager_->SetVideoCapturingIndicator(false); | 332 manager_->SetVideoCapturingIndicator(false); |
| 352 manager_->SetScreenCapturingIndicator(false); | 333 manager_->SetScreenCapturingIndicator(false); |
| 353 | 334 |
| 354 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); | 335 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); |
| 355 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); | 336 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); |
| 356 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); | 337 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); |
| 357 } | 338 } |
| 358 } // namespace vr_shell | 339 } // namespace vr_shell |
| OLD | NEW |