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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 bool IsVisible(UiElementDebugId debug_id) { | 78 bool IsVisible(UiElementDebugId debug_id) { |
79 UiElement* element = scene_->GetUiElementByDebugId(debug_id); | 79 UiElement* element = scene_->GetUiElementByDebugId(debug_id); |
80 return element ? element->visible() : false; | 80 return element ? element->visible() : false; |
81 } | 81 } |
82 | 82 |
83 base::test::ScopedTaskEnvironment scoped_task_environment_; | 83 base::test::ScopedTaskEnvironment scoped_task_environment_; |
84 std::unique_ptr<MockBrowserInterface> browser_; | 84 std::unique_ptr<MockBrowserInterface> browser_; |
85 std::unique_ptr<UiScene> scene_; | 85 std::unique_ptr<UiScene> scene_; |
86 std::unique_ptr<UiSceneManager> manager_; | 86 std::unique_ptr<UiSceneManager> manager_; |
| 87 |
| 88 bool ColorEquals(vr::Colorf expected, vr::Colorf actual) { |
| 89 return (expected.r == actual.r) && (expected.g == actual.g) && |
| 90 (expected.b == actual.b) && (expected.a == actual.a); |
| 91 } |
87 }; | 92 }; |
88 | 93 |
89 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { | 94 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { |
90 MakeManager(kNotInCct, kInWebVr); | 95 MakeManager(kNotInCct, kInWebVr); |
91 | 96 |
92 // Clicking app button should trigger to exit presentation. | 97 // Clicking app button should trigger to exit presentation. |
93 EXPECT_CALL(*browser_, ExitPresent()).Times(1); | 98 EXPECT_CALL(*browser_, ExitPresent()).Times(1); |
94 // And also trigger exit fullscreen. | 99 // And also trigger exit fullscreen. |
95 EXPECT_CALL(*browser_, ExitFullscreen()).Times(1); | 100 EXPECT_CALL(*browser_, ExitFullscreen()).Times(1); |
96 manager_->OnAppButtonClicked(); | 101 manager_->OnAppButtonClicked(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 137 |
133 MakeManager(kNotInCct, kNotInWebVr); | 138 MakeManager(kNotInCct, kNotInWebVr); |
134 EXPECT_FALSE(IsVisible(kCloseButton)); | 139 EXPECT_FALSE(IsVisible(kCloseButton)); |
135 | 140 |
136 MakeManager(kInCct, kInWebVr); | 141 MakeManager(kInCct, kInWebVr); |
137 EXPECT_FALSE(IsVisible(kCloseButton)); | 142 EXPECT_FALSE(IsVisible(kCloseButton)); |
138 manager_->SetWebVrMode(false); | 143 manager_->SetWebVrMode(false); |
139 EXPECT_TRUE(IsVisible(kCloseButton)); | 144 EXPECT_TRUE(IsVisible(kCloseButton)); |
140 } | 145 } |
141 | 146 |
| 147 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) { |
| 148 std::set<UiElementDebugId> visible_in_browsing = { |
| 149 UiElementDebugId::kContentQuad, UiElementDebugId::kBackplane, |
| 150 UiElementDebugId::kCeiling, UiElementDebugId::kFloor, |
| 151 UiElementDebugId::kFloorGrid, UiElementDebugId::kUrlBar, |
| 152 UiElementDebugId::kLoadingIndicator}; |
| 153 std::set<UiElementDebugId> visible_in_fullscreen = { |
| 154 UiElementDebugId::kContentQuad, UiElementDebugId::kBackplane, |
| 155 UiElementDebugId::kCeiling, UiElementDebugId::kFloor, |
| 156 UiElementDebugId::kFloorGrid}; |
| 157 |
| 158 MakeManager(kNotInCct, kNotInWebVr); |
| 159 |
| 160 // Hold onto the background color to make sure it changes. |
| 161 vr::Colorf initial_background = scene_->GetBackgroundColor(); |
| 162 |
| 163 for (const auto& element : scene_->GetUiElements()) { |
| 164 SCOPED_TRACE(element->debug_id()); |
| 165 bool should_be_visible = visible_in_browsing.find(element->debug_id()) != |
| 166 visible_in_browsing.end(); |
| 167 EXPECT_EQ(should_be_visible, element->visible()); |
| 168 } |
| 169 |
| 170 // Transistion to fullscreen. |
| 171 manager_->SetFullscreen(true); |
| 172 |
| 173 // Content elements should be visible, control elements should be hidden. |
| 174 for (const auto& element : scene_->GetUiElements()) { |
| 175 SCOPED_TRACE(element->debug_id()); |
| 176 bool should_be_visible = visible_in_fullscreen.find(element->debug_id()) != |
| 177 visible_in_fullscreen.end(); |
| 178 EXPECT_EQ(should_be_visible, element->visible()); |
| 179 } |
| 180 |
| 181 { |
| 182 SCOPED_TRACE("Entered Fullsceen"); |
| 183 // Make sure background has changed for fullscreen. |
| 184 EXPECT_FALSE(ColorEquals(initial_background, scene_->GetBackgroundColor())); |
| 185 } |
| 186 |
| 187 // Exit fullscreen. |
| 188 manager_->SetFullscreen(false); |
| 189 |
| 190 // Everything should return to original state after leaving fullscreen. |
| 191 for (const auto& element : scene_->GetUiElements()) { |
| 192 SCOPED_TRACE(element->debug_id()); |
| 193 bool should_be_visible = visible_in_browsing.find(element->debug_id()) != |
| 194 visible_in_browsing.end(); |
| 195 EXPECT_EQ(should_be_visible, element->visible()); |
| 196 } |
| 197 { |
| 198 SCOPED_TRACE("Exited Fullsceen"); |
| 199 EXPECT_TRUE(ColorEquals(initial_background, scene_->GetBackgroundColor())); |
| 200 } |
| 201 } |
| 202 |
142 } // namespace vr_shell | 203 } // namespace vr_shell |
OLD | NEW |