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" | |
9 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" | |
10 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_identifiers.h" | |
8 #include "chrome/browser/android/vr_shell/ui_scene.h" | 11 #include "chrome/browser/android/vr_shell/ui_scene.h" |
9 #include "chrome/browser/android/vr_shell/vr_browser_interface.h" | 12 #include "chrome/browser/android/vr_shell/vr_browser_interface.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
12 | 15 |
13 using testing::InSequence; | 16 using testing::InSequence; |
14 | 17 |
15 namespace vr_shell { | 18 namespace vr_shell { |
16 | 19 |
17 namespace { | 20 namespace { |
(...skipping 27 matching lines...) Expand all Loading... | |
45 | 48 |
46 private: | 49 private: |
47 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface); | 50 DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface); |
48 }; | 51 }; |
49 | 52 |
50 } // namespace | 53 } // namespace |
51 | 54 |
52 class UiSceneManagerTest : public testing::Test { | 55 class UiSceneManagerTest : public testing::Test { |
53 public: | 56 public: |
54 void SetUp() override { | 57 void SetUp() override { |
58 // TODO(mthiesse): When we have UI to test for CCT, we'll need to modify | |
mthiesse
2017/05/18 23:47:09
Seems like you can remove this TODO now?
cjgrant
2017/05/19 14:19:13
Done, and I also added a test for the button. PTAL
| |
59 // setup to allow us to test CCT mode. | |
55 browser_ = base::MakeUnique<MockBrowserInterface>(); | 60 browser_ = base::MakeUnique<MockBrowserInterface>(); |
56 scene_ = base::MakeUnique<UiScene>(); | 61 scene_ = base::MakeUnique<UiScene>(); |
57 // TODO(mthiesse): When we have UI to test for CCT, we'll need to modify | 62 } |
58 // setup to allow us to test CCT mode. | 63 |
59 bool in_cct = false; | 64 protected: |
60 bool in_web_vr = true; | 65 enum InCct { |
66 kNotInCct = false, | |
67 kInCct = true, | |
68 }; | |
69 | |
70 enum InWebVr { | |
71 kNotInWebVr = false, | |
72 kInWebVr = true, | |
73 }; | |
74 | |
75 void MakeManager(InCct in_cct, InWebVr in_web_vr) { | |
61 manager_ = base::MakeUnique<UiSceneManager>(browser_.get(), scene_.get(), | 76 manager_ = base::MakeUnique<UiSceneManager>(browser_.get(), scene_.get(), |
62 in_cct, in_web_vr); | 77 in_cct, in_web_vr); |
63 } | 78 } |
64 | 79 |
65 protected: | 80 bool IsVisible(UiElementIdentifier identifier) { |
81 for (auto& element : scene_->GetUiElements()) { | |
82 if (element->identifier() != identifier) | |
83 continue; | |
84 return element->visible(); | |
85 } | |
86 ADD_FAILURE(); | |
87 return false; | |
88 } | |
89 | |
90 base::test::ScopedTaskEnvironment scoped_task_environment_; | |
66 std::unique_ptr<MockBrowserInterface> browser_; | 91 std::unique_ptr<MockBrowserInterface> browser_; |
67 std::unique_ptr<UiScene> scene_; | 92 std::unique_ptr<UiScene> scene_; |
68 std::unique_ptr<UiSceneManager> manager_; | 93 std::unique_ptr<UiSceneManager> manager_; |
69 }; | 94 }; |
70 | 95 |
71 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { | 96 TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { |
97 MakeManager(kNotInCct, kInWebVr); | |
98 | |
72 // Clicking app button should trigger to exit presentation. | 99 // Clicking app button should trigger to exit presentation. |
73 EXPECT_CALL(*browser_, ExitPresent()).Times(1); | 100 EXPECT_CALL(*browser_, ExitPresent()).Times(1); |
74 // And also trigger exit fullscreen. | 101 // And also trigger exit fullscreen. |
75 EXPECT_CALL(*browser_, ExitFullscreen()).Times(1); | 102 EXPECT_CALL(*browser_, ExitFullscreen()).Times(1); |
76 manager_->OnAppButtonClicked(); | 103 manager_->OnAppButtonClicked(); |
77 } | 104 } |
78 | 105 |
106 TEST_F(UiSceneManagerTest, WebVrWarningsShowWhenInitiallyInWebVr) { | |
107 MakeManager(kNotInCct, kInWebVr); | |
108 | |
109 EXPECT_EQ(IsVisible(kWebVrPermanentHttpSecurityWarning), true); | |
110 EXPECT_EQ(IsVisible(kWebVrTransientHttpSecurityWarning), true); | |
111 | |
112 manager_->SetWebVrSecureOrigin(true); | |
113 EXPECT_EQ(IsVisible(kWebVrPermanentHttpSecurityWarning), false); | |
114 EXPECT_EQ(IsVisible(kWebVrTransientHttpSecurityWarning), false); | |
115 | |
116 manager_->SetWebVrSecureOrigin(false); | |
117 EXPECT_EQ(IsVisible(kWebVrPermanentHttpSecurityWarning), true); | |
118 EXPECT_EQ(IsVisible(kWebVrTransientHttpSecurityWarning), true); | |
119 | |
120 manager_->SetWebVrMode(false); | |
121 EXPECT_EQ(IsVisible(kWebVrPermanentHttpSecurityWarning), false); | |
122 EXPECT_EQ(IsVisible(kWebVrTransientHttpSecurityWarning), false); | |
123 } | |
124 | |
125 TEST_F(UiSceneManagerTest, WebVrWarningsDoNotShowWhenInitiallyOutsideWebVr) { | |
126 MakeManager(kNotInCct, kNotInWebVr); | |
127 | |
128 EXPECT_EQ(IsVisible(kWebVrPermanentHttpSecurityWarning), false); | |
129 EXPECT_EQ(IsVisible(kWebVrTransientHttpSecurityWarning), false); | |
130 | |
131 manager_->SetWebVrMode(true); | |
132 EXPECT_EQ(IsVisible(kWebVrPermanentHttpSecurityWarning), true); | |
133 EXPECT_EQ(IsVisible(kWebVrTransientHttpSecurityWarning), true); | |
134 } | |
135 | |
79 } // namespace vr_shell | 136 } // namespace vr_shell |
OLD | NEW |