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

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

Issue 2913633002: [vr] Clicking on the security icon should prompt the user to bail out of VR (Closed)
Patch Set: rebase Created 3 years, 6 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/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"
11 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" 11 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h"
12 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" 12 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h"
13 #include "chrome/browser/android/vr_shell/ui_scene.h" 13 #include "chrome/browser/android/vr_shell/ui_scene.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using testing::InSequence;
18
19 namespace vr_shell { 17 namespace vr_shell {
20 18
21 namespace { 19 namespace {
22 20
23 class MockBrowserInterface : public UiBrowserInterface { 21 class MockBrowserInterface : public UiBrowserInterface {
24 public: 22 public:
25 MockBrowserInterface() {} 23 MockBrowserInterface() {}
26 ~MockBrowserInterface() override {} 24 ~MockBrowserInterface() override {}
27 25
28 MOCK_METHOD0(ExitPresent, void()); 26 MOCK_METHOD0(ExitPresent, void());
29 MOCK_METHOD0(ExitFullscreen, void()); 27 MOCK_METHOD0(ExitFullscreen, void());
30 MOCK_METHOD0(NavigateBack, void()); 28 MOCK_METHOD0(NavigateBack, void());
31 MOCK_METHOD0(ExitCct, void()); 29 MOCK_METHOD0(ExitCct, void());
32 MOCK_METHOD1(OnUnsupportedMode, void(UiUnsupportedMode mode)); 30 MOCK_METHOD1(OnUnsupportedMode, void(UiUnsupportedMode mode));
33 31
34 private: 32 private:
35 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface); 33 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface);
36 }; 34 };
37 35
36 std::set<UiElementDebugId> kElementsVisibleInBrowsing = {
37 kContentQuad, kBackplane, kCeiling, kFloor, kUrlBar, kLoadingIndicator};
38
38 } // namespace 39 } // namespace
39 40
40 class UiSceneManagerTest : public testing::Test { 41 class UiSceneManagerTest : public testing::Test {
41 public: 42 public:
42 void SetUp() override { browser_ = base::MakeUnique<MockBrowserInterface>(); } 43 void SetUp() override { browser_ = base::MakeUnique<MockBrowserInterface>(); }
43 44
44 protected: 45 protected:
45 enum InCct : bool { 46 enum InCct : bool {
46 kNotInCct = false, 47 kNotInCct = false,
47 kInCct = true, 48 kInCct = true,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 189
189 manager_->SetIncognito(false); 190 manager_->SetIncognito(false);
190 191
191 { 192 {
192 SCOPED_TRACE("Exited Incognito"); 193 SCOPED_TRACE("Exited Incognito");
193 EXPECT_EQ(initial_background, scene_->GetWorldBackgroundColor()); 194 EXPECT_EQ(initial_background, scene_->GetWorldBackgroundColor());
194 } 195 }
195 } 196 }
196 197
197 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) { 198 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) {
198 std::set<UiElementDebugId> visible_in_browsing = {
199 UiElementDebugId::kContentQuad, UiElementDebugId::kBackplane,
200 UiElementDebugId::kCeiling, UiElementDebugId::kFloor,
201 UiElementDebugId::kUrlBar, UiElementDebugId::kLoadingIndicator};
202 std::set<UiElementDebugId> visible_in_fullscreen = { 199 std::set<UiElementDebugId> visible_in_fullscreen = {
203 UiElementDebugId::kContentQuad, UiElementDebugId::kCloseButton, 200 kContentQuad, kCloseButton, kBackplane, kCeiling, kFloor};
204 UiElementDebugId::kBackplane, UiElementDebugId::kCeiling,
205 UiElementDebugId::kFloor};
206 201
207 MakeManager(kNotInCct, kNotInWebVr); 202 MakeManager(kNotInCct, kNotInWebVr);
208 203
209 // Hold onto the background color to make sure it changes. 204 // Hold onto the background color to make sure it changes.
210 SkColor initial_background = scene_->GetWorldBackgroundColor(); 205 SkColor initial_background = scene_->GetWorldBackgroundColor();
211 206
212 for (const auto& element : scene_->GetUiElements()) { 207 for (const auto& element : scene_->GetUiElements()) {
213 SCOPED_TRACE(element->debug_id()); 208 SCOPED_TRACE(element->debug_id());
214 bool should_be_visible = visible_in_browsing.find(element->debug_id()) != 209 bool should_be_visible =
215 visible_in_browsing.end(); 210 kElementsVisibleInBrowsing.find(element->debug_id()) !=
211 kElementsVisibleInBrowsing.end();
216 EXPECT_EQ(should_be_visible, element->visible()); 212 EXPECT_EQ(should_be_visible, element->visible());
217 } 213 }
218 214
219 // Transistion to fullscreen. 215 // Transistion to fullscreen.
220 manager_->SetFullscreen(true); 216 manager_->SetFullscreen(true);
221 217
222 // Content elements should be visible, control elements should be hidden. 218 // Content elements should be visible, control elements should be hidden.
223 for (const auto& element : scene_->GetUiElements()) { 219 for (const auto& element : scene_->GetUiElements()) {
224 SCOPED_TRACE(element->debug_id()); 220 SCOPED_TRACE(element->debug_id());
225 bool should_be_visible = visible_in_fullscreen.find(element->debug_id()) != 221 bool should_be_visible = visible_in_fullscreen.find(element->debug_id()) !=
226 visible_in_fullscreen.end(); 222 visible_in_fullscreen.end();
227 EXPECT_EQ(should_be_visible, element->visible()); 223 EXPECT_EQ(should_be_visible, element->visible());
228 } 224 }
229 225
230 { 226 {
231 SCOPED_TRACE("Entered Fullsceen"); 227 SCOPED_TRACE("Entered Fullsceen");
232 // Make sure background has changed for fullscreen. 228 // Make sure background has changed for fullscreen.
233 EXPECT_NE(initial_background, scene_->GetWorldBackgroundColor()); 229 EXPECT_NE(initial_background, scene_->GetWorldBackgroundColor());
234 } 230 }
235 231
236 // Exit fullscreen. 232 // Exit fullscreen.
237 manager_->SetFullscreen(false); 233 manager_->SetFullscreen(false);
238 234
239 // Everything should return to original state after leaving fullscreen. 235 // Everything should return to original state after leaving fullscreen.
240 for (const auto& element : scene_->GetUiElements()) { 236 for (const auto& element : scene_->GetUiElements()) {
241 SCOPED_TRACE(element->debug_id()); 237 SCOPED_TRACE(element->debug_id());
242 bool should_be_visible = visible_in_browsing.find(element->debug_id()) != 238 bool should_be_visible =
243 visible_in_browsing.end(); 239 kElementsVisibleInBrowsing.find(element->debug_id()) !=
240 kElementsVisibleInBrowsing.end();
244 EXPECT_EQ(should_be_visible, element->visible()); 241 EXPECT_EQ(should_be_visible, element->visible());
245 } 242 }
246 { 243 {
247 SCOPED_TRACE("Exited Fullsceen"); 244 SCOPED_TRACE("Exited Fullsceen");
248 EXPECT_EQ(initial_background, scene_->GetWorldBackgroundColor()); 245 EXPECT_EQ(initial_background, scene_->GetWorldBackgroundColor());
249 } 246 }
250 } 247 }
251 248
249 TEST_F(UiSceneManagerTest, UiUpdatesExitPrompt) {
250 std::set<UiElementDebugId> visible_when_prompting = {kExitPrompt, kBackplane,
251 kCeiling, kFloor};
252 MakeManager(kNotInCct, kNotInWebVr);
253
254 manager_->SetWebVrSecureOrigin(true);
255
256 // Initial state.
257 for (const auto& element : scene_->GetUiElements()) {
258 SCOPED_TRACE(element->debug_id());
259 bool should_be_visible =
260 kElementsVisibleInBrowsing.find(element->debug_id()) !=
261 kElementsVisibleInBrowsing.end();
262 EXPECT_EQ(should_be_visible, element->visible());
263 }
264
265 // Exit prompt visible state.
266 manager_->OnSecurityIconClicked();
267 for (const auto& element : scene_->GetUiElements()) {
268 SCOPED_TRACE(element->debug_id());
269 bool should_be_visible = visible_when_prompting.find(element->debug_id()) !=
270 visible_when_prompting.end();
271 EXPECT_EQ(should_be_visible, element->visible());
272 }
273
274 // Back to initial state.
275 manager_->OnExitPromptPrimaryButtonClicked();
276 for (const auto& element : scene_->GetUiElements()) {
277 SCOPED_TRACE(element->debug_id());
278 bool should_be_visible =
279 kElementsVisibleInBrowsing.find(element->debug_id()) !=
280 kElementsVisibleInBrowsing.end();
281 EXPECT_EQ(should_be_visible, element->visible());
282 }
283 }
284
252 TEST_F(UiSceneManagerTest, UiUpdatesForWebVR) { 285 TEST_F(UiSceneManagerTest, UiUpdatesForWebVR) {
253 MakeManager(kNotInCct, kInWebVr); 286 MakeManager(kNotInCct, kInWebVr);
254 287
255 manager_->SetWebVrSecureOrigin(true); 288 manager_->SetWebVrSecureOrigin(true);
256 manager_->SetAudioCapturingIndicator(true); 289 manager_->SetAudioCapturingIndicator(true);
257 manager_->SetVideoCapturingIndicator(true); 290 manager_->SetVideoCapturingIndicator(true);
258 manager_->SetScreenCapturingIndicator(true); 291 manager_->SetScreenCapturingIndicator(true);
259 292
260 // All elements should be hidden. 293 // All elements should be hidden.
261 for (const auto& element : scene_->GetUiElements()) { 294 for (const auto& element : scene_->GetUiElements()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 340
308 manager_->SetAudioCapturingIndicator(false); 341 manager_->SetAudioCapturingIndicator(false);
309 manager_->SetVideoCapturingIndicator(false); 342 manager_->SetVideoCapturingIndicator(false);
310 manager_->SetScreenCapturingIndicator(false); 343 manager_->SetScreenCapturingIndicator(false);
311 344
312 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); 345 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator));
313 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); 346 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator));
314 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); 347 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator));
315 } 348 }
316 } // namespace vr_shell 349 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_manager.cc ('k') | chrome/browser/android/vr_shell/ui_unsupported_mode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698