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

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: cjgrant's comments 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/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"
11 #include "chrome/browser/android/vr_shell/ui_scene.h" 11 #include "chrome/browser/android/vr_shell/ui_scene.h"
12 #include "chrome/browser/android/vr_shell/vr_browser_interface.h" 12 #include "chrome/browser/android/vr_shell/vr_browser_interface.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using testing::InSequence; 16 namespace vr_shell {
17 17
18 namespace vr_shell { 18 using UiElementDebugId::kContentQuad;
cjgrant 2017/06/05 20:47:17 Oops, I didn't mean this. But actually, if you di
ymalik 2017/06/06 02:14:09 Ah, the reason this works is because its not a str
19 using UiElementDebugId::kBackplane;
20 using UiElementDebugId::kCeiling;
21 using UiElementDebugId::kFloor;
22 using UiElementDebugId::kUrlBar;
23 using UiElementDebugId::kLoadingIndicator;
24 using UiElementDebugId::kExitPrompt;
19 25
20 namespace { 26 namespace {
21 27
22 class MockBrowserInterface : public VrBrowserInterface { 28 class MockBrowserInterface : public VrBrowserInterface {
23 public: 29 public:
24 MockBrowserInterface() {} 30 MockBrowserInterface() {}
25 ~MockBrowserInterface() override {} 31 ~MockBrowserInterface() override {}
26 32
27 MOCK_METHOD1(ContentSurfaceChanged, void(jobject)); 33 MOCK_METHOD1(ContentSurfaceChanged, void(jobject));
28 MOCK_METHOD0(GvrDelegateReady, void()); 34 MOCK_METHOD0(GvrDelegateReady, void());
(...skipping 17 matching lines...) Expand all
46 MOCK_METHOD1(ToggleCardboardGamepad, void(bool)); 52 MOCK_METHOD1(ToggleCardboardGamepad, void(bool));
47 MOCK_METHOD1(OnUnsupportedMode, void(UiUnsupportedMode)); 53 MOCK_METHOD1(OnUnsupportedMode, void(UiUnsupportedMode));
48 54
49 // 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.
50 void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent>) {} 56 void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent>) {}
51 57
52 private: 58 private:
53 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface); 59 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface);
54 }; 60 };
55 61
62 std::set<UiElementDebugId> kElementsVisibleInBrowsing = {
63 kContentQuad, kBackplane, kCeiling, kFloor, kUrlBar, kLoadingIndicator};
64
56 } // namespace 65 } // namespace
57 66
58 class UiSceneManagerTest : public testing::Test { 67 class UiSceneManagerTest : public testing::Test {
59 public: 68 public:
60 void SetUp() override { browser_ = base::MakeUnique<MockBrowserInterface>(); } 69 void SetUp() override { browser_ = base::MakeUnique<MockBrowserInterface>(); }
61 70
62 protected: 71 protected:
63 enum InCct : bool { 72 enum InCct : bool {
64 kNotInCct = false, 73 kNotInCct = false,
65 kInCct = true, 74 kInCct = true,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 198
190 manager_->SetIncognito(false); 199 manager_->SetIncognito(false);
191 200
192 { 201 {
193 SCOPED_TRACE("Exited Incognito"); 202 SCOPED_TRACE("Exited Incognito");
194 EXPECT_EQ(initial_background, scene_->GetBackgroundColor()); 203 EXPECT_EQ(initial_background, scene_->GetBackgroundColor());
195 } 204 }
196 } 205 }
197 206
198 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) { 207 TEST_F(UiSceneManagerTest, UiUpdatesForFullscreenChanges) {
199 std::set<UiElementDebugId> visible_in_browsing = { 208 std::set<UiElementDebugId> visible_in_fullscreen = {kContentQuad, kBackplane,
200 UiElementDebugId::kContentQuad, UiElementDebugId::kBackplane, 209 kCeiling, kFloor};
201 UiElementDebugId::kCeiling, UiElementDebugId::kFloor,
202 UiElementDebugId::kUrlBar, UiElementDebugId::kLoadingIndicator};
203 std::set<UiElementDebugId> visible_in_fullscreen = {
204 UiElementDebugId::kContentQuad, UiElementDebugId::kBackplane,
205 UiElementDebugId::kCeiling, UiElementDebugId::kFloor};
206 210
207 MakeManager(kNotInCct, kNotInWebVr); 211 MakeManager(kNotInCct, kNotInWebVr);
208 212
209 // Hold onto the background color to make sure it changes. 213 // Hold onto the background color to make sure it changes.
210 SkColor initial_background = scene_->GetBackgroundColor(); 214 SkColor initial_background = scene_->GetBackgroundColor();
211 215
212 for (const auto& element : scene_->GetUiElements()) { 216 for (const auto& element : scene_->GetUiElements()) {
213 SCOPED_TRACE(element->debug_id()); 217 SCOPED_TRACE(element->debug_id());
214 bool should_be_visible = visible_in_browsing.find(element->debug_id()) != 218 bool should_be_visible =
215 visible_in_browsing.end(); 219 kElementsVisibleInBrowsing.find(element->debug_id()) !=
220 kElementsVisibleInBrowsing.end();
216 EXPECT_EQ(should_be_visible, element->visible()); 221 EXPECT_EQ(should_be_visible, element->visible());
217 } 222 }
218 223
219 // Transistion to fullscreen. 224 // Transistion to fullscreen.
220 manager_->SetFullscreen(true); 225 manager_->SetFullscreen(true);
221 226
222 // Content elements should be visible, control elements should be hidden. 227 // Content elements should be visible, control elements should be hidden.
223 for (const auto& element : scene_->GetUiElements()) { 228 for (const auto& element : scene_->GetUiElements()) {
224 SCOPED_TRACE(element->debug_id()); 229 SCOPED_TRACE(element->debug_id());
225 bool should_be_visible = visible_in_fullscreen.find(element->debug_id()) != 230 bool should_be_visible = visible_in_fullscreen.find(element->debug_id()) !=
226 visible_in_fullscreen.end(); 231 visible_in_fullscreen.end();
227 EXPECT_EQ(should_be_visible, element->visible()); 232 EXPECT_EQ(should_be_visible, element->visible());
228 } 233 }
229 234
230 { 235 {
231 SCOPED_TRACE("Entered Fullsceen"); 236 SCOPED_TRACE("Entered Fullsceen");
232 // Make sure background has changed for fullscreen. 237 // Make sure background has changed for fullscreen.
233 EXPECT_NE(initial_background, scene_->GetBackgroundColor()); 238 EXPECT_NE(initial_background, scene_->GetBackgroundColor());
234 } 239 }
235 240
236 // Exit fullscreen. 241 // Exit fullscreen.
237 manager_->SetFullscreen(false); 242 manager_->SetFullscreen(false);
238 243
239 // Everything should return to original state after leaving fullscreen. 244 // Everything should return to original state after leaving fullscreen.
240 for (const auto& element : scene_->GetUiElements()) { 245 for (const auto& element : scene_->GetUiElements()) {
241 SCOPED_TRACE(element->debug_id()); 246 SCOPED_TRACE(element->debug_id());
242 bool should_be_visible = visible_in_browsing.find(element->debug_id()) != 247 bool should_be_visible =
243 visible_in_browsing.end(); 248 kElementsVisibleInBrowsing.find(element->debug_id()) !=
249 kElementsVisibleInBrowsing.end();
244 EXPECT_EQ(should_be_visible, element->visible()); 250 EXPECT_EQ(should_be_visible, element->visible());
245 } 251 }
246 { 252 {
247 SCOPED_TRACE("Exited Fullsceen"); 253 SCOPED_TRACE("Exited Fullsceen");
248 EXPECT_EQ(initial_background, scene_->GetBackgroundColor()); 254 EXPECT_EQ(initial_background, scene_->GetBackgroundColor());
249 } 255 }
250 } 256 }
251 257
258 TEST_F(UiSceneManagerTest, UiUpdatesExitPrompt) {
259 std::set<UiElementDebugId> visible_when_prompting = {kExitPrompt, kBackplane,
260 kCeiling, kFloor};
261 MakeManager(kNotInCct, kNotInWebVr);
262
263 manager_->SetWebVrSecureOrigin(true);
264
265 // Initial state.
266 for (const auto& element : scene_->GetUiElements()) {
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
274 // Exit prompt visible state.
275 manager_->OnSecurityIconClicked();
276 for (const auto& element : scene_->GetUiElements()) {
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
283 // Back to initial state.
284 manager_->OnExitPromptPrimaryButtonClicked();
285 for (const auto& element : scene_->GetUiElements()) {
286 SCOPED_TRACE(element->debug_id());
287 bool should_be_visible =
288 kElementsVisibleInBrowsing.find(element->debug_id()) !=
289 kElementsVisibleInBrowsing.end();
290 EXPECT_EQ(should_be_visible, element->visible());
291 }
292 }
293
252 TEST_F(UiSceneManagerTest, UiUpdatesForWebVR) { 294 TEST_F(UiSceneManagerTest, UiUpdatesForWebVR) {
253 MakeManager(kNotInCct, kInWebVr); 295 MakeManager(kNotInCct, kInWebVr);
254 296
255 manager_->SetWebVrSecureOrigin(true); 297 manager_->SetWebVrSecureOrigin(true);
256 manager_->SetAudioCapturingIndicator(true); 298 manager_->SetAudioCapturingIndicator(true);
257 manager_->SetVideoCapturingIndicator(true); 299 manager_->SetVideoCapturingIndicator(true);
258 manager_->SetScreenCapturingIndicator(true); 300 manager_->SetScreenCapturingIndicator(true);
259 301
260 // All elements should be hidden. 302 // All elements should be hidden.
261 for (const auto& element : scene_->GetUiElements()) { 303 for (const auto& element : scene_->GetUiElements()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 349
308 manager_->SetAudioCapturingIndicator(false); 350 manager_->SetAudioCapturingIndicator(false);
309 manager_->SetVideoCapturingIndicator(false); 351 manager_->SetVideoCapturingIndicator(false);
310 manager_->SetScreenCapturingIndicator(false); 352 manager_->SetScreenCapturingIndicator(false);
311 353
312 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator)); 354 EXPECT_FALSE(IsVisible(kAudioCaptureIndicator));
313 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator)); 355 EXPECT_FALSE(IsVisible(kVideoCaptureIndicator));
314 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator)); 356 EXPECT_FALSE(IsVisible(kScreenCaptureIndicator));
315 } 357 }
316 } // namespace vr_shell 358 } // 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