Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Side by Side Diff: chrome/browser/android/vr_shell/ui_scene_manager_unittest.cc

Issue 2873043002: VrShell: Add test for fullscreen transitions. (Closed)
Patch Set: rebase to use debug id enum instead of name one I created Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 bool IsVisible(UiElementDebugId debug_id) { 77 bool IsVisible(UiElementDebugId debug_id) {
78 UiElement* element = scene_->GetUiElementByDebugId(debug_id); 78 UiElement* element = scene_->GetUiElementByDebugId(debug_id);
79 return element ? element->visible() : false; 79 return element ? element->visible() : false;
80 } 80 }
81 81
82 base::test::ScopedTaskEnvironment scoped_task_environment_; 82 base::test::ScopedTaskEnvironment scoped_task_environment_;
83 std::unique_ptr<MockBrowserInterface> browser_; 83 std::unique_ptr<MockBrowserInterface> browser_;
84 std::unique_ptr<UiScene> scene_; 84 std::unique_ptr<UiScene> scene_;
85 std::unique_ptr<UiSceneManager> manager_; 85 std::unique_ptr<UiSceneManager> manager_;
86
87 bool ColorEquals(vr::Colorf expected, vr::Colorf actual) {
88 return (expected.r == actual.r) && (expected.g == actual.g) &&
89 (expected.b == actual.b) && (expected.a == actual.a);
90 }
86 }; 91 };
87 92
88 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { 93 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) {
89 MakeManager(kNotInCct, kInWebVr); 94 MakeManager(kNotInCct, kInWebVr);
90 95
91 // Clicking app button should trigger to exit presentation. 96 // Clicking app button should trigger to exit presentation.
92 EXPECT_CALL(*browser_, ExitPresent()).Times(1); 97 EXPECT_CALL(*browser_, ExitPresent()).Times(1);
93 // And also trigger exit fullscreen. 98 // And also trigger exit fullscreen.
94 EXPECT_CALL(*browser_, ExitFullscreen()).Times(1); 99 EXPECT_CALL(*browser_, ExitFullscreen()).Times(1);
95 manager_->OnAppButtonClicked(); 100 manager_->OnAppButtonClicked();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 136
132 MakeManager(kNotInCct, kNotInWebVr); 137 MakeManager(kNotInCct, kNotInWebVr);
133 EXPECT_FALSE(IsVisible(kCloseButton)); 138 EXPECT_FALSE(IsVisible(kCloseButton));
134 139
135 MakeManager(kInCct, kInWebVr); 140 MakeManager(kInCct, kInWebVr);
136 EXPECT_FALSE(IsVisible(kCloseButton)); 141 EXPECT_FALSE(IsVisible(kCloseButton));
137 manager_->SetWebVrMode(false); 142 manager_->SetWebVrMode(false);
138 EXPECT_TRUE(IsVisible(kCloseButton)); 143 EXPECT_TRUE(IsVisible(kCloseButton));
139 } 144 }
140 145
146 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) {
147 std::set<UiElementDebugId> visible_in_browsing = {
148 UiElementDebugId::kContentQuad, UiElementDebugId::kCeiling,
149 UiElementDebugId::kFloor, UiElementDebugId::kGrid,
150 UiElementDebugId::kBrowserBar, UiElementDebugId::kLoadingIndicator};
151 std::set<UiElementDebugId> visible_in_fullscreen = {
152 UiElementDebugId::kContentQuad};
153 std::set<UiElementDebugId> hidden_in_fullscreen = {
154 UiElementDebugId::kBrowserBar, UiElementDebugId::kLoadingIndicator};
155
156 MakeManager(kNotInCct, kNotInWebVr);
157
158 // Hold onto the background color to make sure it changes.
159 vr::Colorf initialBackground = scene_->GetBackgroundColor();
cjgrant 2017/05/23 18:58:11 initial_background
amp 2017/05/23 20:56:02 Done.
160
161 for (const auto& element : scene_->GetUiElements()) {
162 SCOPED_TRACE(element->debug_id());
163 bool should_be_visible = visible_in_browsing.find(element->debug_id()) !=
164 visible_in_browsing.end();
165 // Ignore elements not in the set.
166 if (should_be_visible) {
167 EXPECT_EQ(should_be_visible, element->visible());
168 }
169 }
170
171 // Transistion to fullscreen.
172 manager_->SetFullscreen(true);
173
174 // All elements should be hidden except for main content.
cjgrant 2017/05/23 18:58:11 Did we say the floor would stay visible in fullscr
amp 2017/05/23 20:56:02 Yes, at the point this test was written it wasn't
175 for (const auto& element : scene_->GetUiElements()) {
176 SCOPED_TRACE(element->debug_id());
177 bool should_be_visible = visible_in_fullscreen.find(element->debug_id()) !=
178 visible_in_fullscreen.end();
179 // Ignore elements not in the set.
cjgrant 2017/05/23 18:58:11 Since this test is focused on fullscreen, why igno
amp 2017/05/23 20:56:02 I went this way because not every element has a de
cjgrant 2017/05/23 21:27:31 But in fullscreen, there are only a few things vis
180 if (should_be_visible) {
181 EXPECT_EQ(should_be_visible, element->visible());
182 }
183 bool should_be_hidden = hidden_in_fullscreen.find(element->debug_id()) !=
184 hidden_in_fullscreen.end();
185 // Ignore elements not in the set.
186 if (should_be_hidden) {
187 EXPECT_FALSE(element->visible());
188 }
189 }
190
191 {
192 SCOPED_TRACE("Entered Fullsceen");
193 // Make sure background has changed for fullscreen.
194 EXPECT_FALSE(ColorEquals(initialBackground, scene_->GetBackgroundColor()));
195 }
196
197 // Exit fullscreen.
198 manager_->SetFullscreen(false);
199
200 // Everything should return to original state after leaving fullscreen.
201 for (const auto& element : scene_->GetUiElements()) {
202 SCOPED_TRACE(element->debug_id());
203 bool should_be_visible = visible_in_browsing.find(element->debug_id()) !=
204 visible_in_browsing.end();
205 // Ignore elements not in the set.
206 if (should_be_visible) {
207 EXPECT_EQ(should_be_visible, element->visible());
208 }
209 }
210 {
211 SCOPED_TRACE("Exited Fullsceen");
212 EXPECT_TRUE(ColorEquals(initialBackground, scene_->GetBackgroundColor()));
213 }
214 }
215
141 } // namespace vr_shell 216 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698