Commit ddcd5b21 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Autoplay: override autoplay restrictions on Chrome Apps/Extensions.

This is forcing no autoplay restrictions to all `Extensions`. It does
not apply to WebViews.

Bug: 788302
Change-Id: I9c7e89133279453382976ff0f79d285672a5f1ac
Reviewed-on: https://chromium-review.googlesource.com/803440Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523747}
parent 15a5eb56
...@@ -1084,6 +1084,17 @@ IN_PROC_BROWSER_TEST_P(WebViewTest, AudioStateJavascriptAPI) { ...@@ -1084,6 +1084,17 @@ IN_PROC_BROWSER_TEST_P(WebViewTest, AudioStateJavascriptAPI) {
<< message_; << message_;
} }
// Test that WebView does not override autoplay policy.
IN_PROC_BROWSER_TEST_P(WebViewTest, AutoplayPolicy) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kAutoplayPolicy,
switches::autoplay::kDocumentUserActivationRequiredPolicy);
ASSERT_TRUE(StartEmbeddedTestServer());
ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autoplay"))
<< message_;
}
// This test verifies that hiding the guest triggers WebContents::WasHidden(). // This test verifies that hiding the guest triggers WebContents::WasHidden().
IN_PROC_BROWSER_TEST_P(WebViewVisibilityTest, GuestVisibilityChanged) { IN_PROC_BROWSER_TEST_P(WebViewVisibilityTest, GuestVisibilityChanged) {
LoadAppWithGuest("web_view/visibility_changed"); LoadAppWithGuest("web_view/visibility_changed");
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/extension_apitest.h"
#include "media/base/media_switches.h"
class AutoplayExtensionBrowserTest : public ExtensionApiTest {
public:
void SetUpCommandLine(base::CommandLine* command_line) override {
ExtensionBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(
switches::kAutoplayPolicy,
switches::autoplay::kDocumentUserActivationRequiredPolicy);
}
};
IN_PROC_BROWSER_TEST_F(AutoplayExtensionBrowserTest, AutoplayAllowed) {
ASSERT_TRUE(RunExtensionTest("autoplay")) << message_;
}
...@@ -39,6 +39,11 @@ void SetPreferences(const extensions::Extension* extension, ...@@ -39,6 +39,11 @@ void SetPreferences(const extensions::Extension* extension,
// Enable WebGL features that regular pages can't access, since they add // Enable WebGL features that regular pages can't access, since they add
// more risk of fingerprinting. // more risk of fingerprinting.
webkit_prefs->privileged_webgl_extensions_enabled = true; webkit_prefs->privileged_webgl_extensions_enabled = true;
// Autoplay restrictions should not apply to extensions, packaged apps,
// hosted apps, etc. However, they should not apply to apps' webviews.
webkit_prefs->autoplay_policy =
content::AutoplayPolicy::kNoUserGestureRequired;
} }
} // namespace extension_webkit_preferences } // namespace extension_webkit_preferences
...@@ -1170,6 +1170,7 @@ test("browser_tests") { ...@@ -1170,6 +1170,7 @@ test("browser_tests") {
"../browser/extensions/app_background_page_apitest.cc", "../browser/extensions/app_background_page_apitest.cc",
"../browser/extensions/app_process_apitest.cc", "../browser/extensions/app_process_apitest.cc",
"../browser/extensions/app_window_overrides_browsertest.cc", "../browser/extensions/app_window_overrides_browsertest.cc",
"../browser/extensions/autoplay_browsertest.cc",
"../browser/extensions/background_app_browsertest.cc", "../browser/extensions/background_app_browsertest.cc",
"../browser/extensions/background_page_apitest.cc", "../browser/extensions/background_page_apitest.cc",
"../browser/extensions/background_scripts_apitest.cc", "../browser/extensions/background_scripts_apitest.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.test.runTests([
function autoplay_allowed_without_gesture() {
var audio = new Audio();
audio.src = 'test.mp4';
var allowed = false;
audio.play().then(function() {
allowed = true;
}, function(e) {
allowed = e.name != 'NotAllowedError';
}).then(function() {
chrome.test.assertTrue(allowed);
chrome.test.succeed();
});
}
]);
{
"name": "autoplay",
"description": "autoplay policy test",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"permissions": [ ]
}
<!--
* Copyright 2017 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<!DOCTYPE html>
<html>
<body>
<script src=guest.js></script>
</body>
</html>
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
window.addEventListener('message', function() {
var audio = document.createElement('audio');
audio.src = 'test.mp4';
audio.play().then(() => {
console.log('autoplayed');
}, e => {
console.log(e.name);
});
});
<!--
* Copyright 2017 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<!DOCTYPE html>
<html>
<body>
<webview></webview>
<script src=main.js></script>
</body>
</html>
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.test.getConfig(function(config) {
var guestUrl = 'http://localhost:' + config.testServer.port +
'/extensions/platform_apps/web_view/autoplay/guest.html';
var webview = document.querySelector('webview');
webview.addEventListener('loadstop', function() {
webview.onconsolemessage = function(e) {
chrome.test.assertEq('NotAllowedError', e.message);
chrome.test.succeed();
};
webview.contentWindow.postMessage(JSON.stringify('start'), '*');
}, { once: true });
webview.src = guestUrl;
});
{
"name": "<webview> autoplay policy api tests.",
"version": "1",
"permissions": [
"webview"
],
"app": {
"background": {
"scripts": ["test.js"]
}
}
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('main.html', {}, function() {});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment