1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#include <vector>
#include "base/containers/to_vector.h"
#include "base/functional/callback_helpers.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/vr/test/multi_class_browser_test.h"
#include "chrome/browser/vr/test/ui_utils.h"
#include "chrome/browser/vr/test/webxr_vr_browser_test.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
// Browser tests for indicators shown at various phases of an immersive session.
// TODO(https://crbug.com/381000093): Fix tests on Android
#if !BUILDFLAG(IS_ANDROID)
namespace vr {
namespace {
struct TestIndicatorSetting {
TestIndicatorSetting(ContentSettingsType setting_type,
ContentSetting setting,
UserFriendlyElementName name,
bool visibility)
: content_setting_type(setting_type),
content_setting(setting),
element_name(name),
element_visibility(visibility) {}
ContentSettingsType content_setting_type;
ContentSetting content_setting;
UserFriendlyElementName element_name;
bool element_visibility;
};
struct TestContentSettings {
TestContentSettings(ContentSettingsType setting_type, ContentSetting setting)
: content_setting_type(setting_type), content_setting(setting) {}
ContentSettingsType content_setting_type;
ContentSetting content_setting;
};
// Helpers
std::vector<TestContentSettings> ExtractFrom(
const std::vector<TestIndicatorSetting>& test_indicator_settings) {
return base::ToVector(
test_indicator_settings, [](const TestIndicatorSetting& s) {
return TestContentSettings{s.content_setting_type, s.content_setting};
});
}
void SetMultipleContentSetting(
WebXrVrBrowserTestBase* t,
const std::vector<TestContentSettings>& test_settings) {
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(Profile::FromBrowserContext(
t->GetCurrentWebContents()->GetBrowserContext()));
for (const TestContentSettings& s : test_settings)
host_content_settings_map->SetContentSettingDefaultScope(
t->GetCurrentWebContents()->GetLastCommittedURL(),
t->GetCurrentWebContents()->GetLastCommittedURL(),
s.content_setting_type, s.content_setting);
}
void LoadGenericPageChangeDefaultPermissionAndEnterVr(
WebXrVrBrowserTestBase* t,
const std::vector<TestContentSettings>& test_settings) {
t->LoadFileAndAwaitInitialization("generic_webxr_page");
SetMultipleContentSetting(t, test_settings);
t->EnterSessionWithUserGestureOrFail();
}
// Tests that indicators are displayed in the headset when a device becomes
// in-use.
void TestIndicatorOnAccessForContentType(
WebXrVrBrowserTestBase* t,
ContentSettingsType content_setting_type,
const std::string& script,
UserFriendlyElementName element_name) {
// Enter VR while the content setting is CONTENT_SETTING_ASK to suppress
// its corresponding indicator from initially showing up.
LoadGenericPageChangeDefaultPermissionAndEnterVr(
t, {{content_setting_type, CONTENT_SETTING_ASK}});
// Now, change the setting to allow so the in-use indicator shows up on device
// usage.
SetMultipleContentSetting(t, {{content_setting_type, CONTENT_SETTING_ALLOW}});
t->RunJavaScriptOrFail(script);
auto utils = UiUtils::Create();
// Check if the location indicator shows.
utils->WaitForVisibilityStatus(element_name, true);
t->EndSessionOrFail();
}
// Tests indicators on entering immersive session.
void TestForInitialIndicatorForContentType(
WebXrVrBrowserTestBase* t,
const std::vector<TestIndicatorSetting>& test_indicator_settings) {
DCHECK(!test_indicator_settings.empty());
// Enter VR while the content setting is CONTENT_SETTING_ASK to suppress
// its corresponding indicator from initially showing up.
LoadGenericPageChangeDefaultPermissionAndEnterVr(
t, ExtractFrom(test_indicator_settings));
auto utils = UiUtils::Create();
// Check if the location indicator shows.
for (const TestIndicatorSetting& setting : test_indicator_settings)
utils->WaitForVisibilityStatus(setting.element_name,
setting.element_visibility);
t->EndSessionOrFail();
}
} // namespace
// Tests for indicators when they become in-use
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(TestLocationInUseIndicator) {
// Asking for location seems to work without any hardware/machine specific
// enabling/capability (unlike microphone, camera). Hence, this test.
TestIndicatorOnAccessForContentType(
t, ContentSettingsType::GEOLOCATION,
"navigator.geolocation.getCurrentPosition( ()=>{}, ()=>{} )",
UserFriendlyElementName::kWebXrLocationPermissionIndicator);
}
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(DISABLED_TestMicrophoneInUseIndicator) {
TestIndicatorOnAccessForContentType(
t, ContentSettingsType::MEDIASTREAM_MIC,
"navigator.getUserMedia( {audio : true}, ()=>{}, ()=>{} )",
UserFriendlyElementName::kWebXrAudioIndicator);
}
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(DISABLED_TestCameraInUseIndicator) {
TestIndicatorOnAccessForContentType(
t, ContentSettingsType::MEDIASTREAM_CAMERA,
"navigator.getUserMedia( {video : true}, ()=>{}, ()=>{} )",
UserFriendlyElementName::kWebXrVideoPermissionIndicator);
}
// Single indicator tests on entering immersive session
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(
TestLocationIndicatorWhenPermissionInitiallyAllowed) {
TestForInitialIndicatorForContentType(
t, {{ContentSettingsType::GEOLOCATION, CONTENT_SETTING_ALLOW,
UserFriendlyElementName::kWebXrLocationPermissionIndicator, true}});
}
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(
TestLocationIndicatorWhenPermissionInitiallyBlocked) {
TestForInitialIndicatorForContentType(
t, {{ContentSettingsType::GEOLOCATION, CONTENT_SETTING_BLOCK,
UserFriendlyElementName::kWebXrLocationPermissionIndicator, false}});
}
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(
TestLocationIndicatorWhenUserAskedToPrompt) {
TestForInitialIndicatorForContentType(
t, {{ContentSettingsType::GEOLOCATION, CONTENT_SETTING_ASK,
UserFriendlyElementName::kWebXrLocationPermissionIndicator, false}});
}
// Indicator combination tests on entering immersive session
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(
TestMultipleInitialIndicators_NoDevicesAllowed) {
TestForInitialIndicatorForContentType(
t,
{
{ContentSettingsType::GEOLOCATION, CONTENT_SETTING_ASK,
UserFriendlyElementName::kWebXrLocationPermissionIndicator, false},
{ContentSettingsType::MEDIASTREAM_MIC, CONTENT_SETTING_ASK,
UserFriendlyElementName::kWebXrAudioIndicator, false},
{ContentSettingsType::MEDIASTREAM_CAMERA, CONTENT_SETTING_BLOCK,
UserFriendlyElementName::kWebXrVideoPermissionIndicator, false},
});
}
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(
TestMultipleInitialIndicators_OneDeviceAllowed) {
TestForInitialIndicatorForContentType(
t,
{
{ContentSettingsType::GEOLOCATION, CONTENT_SETTING_ASK,
UserFriendlyElementName::kWebXrLocationPermissionIndicator, false},
{ContentSettingsType::MEDIASTREAM_MIC, CONTENT_SETTING_ALLOW,
UserFriendlyElementName::kWebXrAudioIndicator, true},
{ContentSettingsType::MEDIASTREAM_CAMERA, CONTENT_SETTING_BLOCK,
UserFriendlyElementName::kWebXrVideoPermissionIndicator, false},
});
}
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(
TestMultipleInitialIndicators_TwoDevicesAllowed) {
TestForInitialIndicatorForContentType(
t, {
{ContentSettingsType::GEOLOCATION, CONTENT_SETTING_ALLOW,
UserFriendlyElementName::kWebXrLocationPermissionIndicator, true},
{ContentSettingsType::MEDIASTREAM_MIC, CONTENT_SETTING_BLOCK,
UserFriendlyElementName::kWebXrAudioIndicator, false},
{ContentSettingsType::MEDIASTREAM_CAMERA, CONTENT_SETTING_ALLOW,
UserFriendlyElementName::kWebXrVideoPermissionIndicator, true},
});
}
WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(
TestMultipleInitialIndicators_ThreeDevicesAllowed) {
TestForInitialIndicatorForContentType(
t, {
{ContentSettingsType::GEOLOCATION, CONTENT_SETTING_ALLOW,
UserFriendlyElementName::kWebXrLocationPermissionIndicator, true},
{ContentSettingsType::MEDIASTREAM_MIC, CONTENT_SETTING_ALLOW,
UserFriendlyElementName::kWebXrAudioIndicator, true},
{ContentSettingsType::MEDIASTREAM_CAMERA, CONTENT_SETTING_ALLOW,
UserFriendlyElementName::kWebXrVideoPermissionIndicator, true},
});
}
} // namespace vr
#endif // if !BUILDFLAG(IS_ANDROID)
|