Bug 1366167 - Test for Enable DRM prompt. r=Gijs
We recently accidentally broke the "Enable DRM" prompt without realising, so
this adds a test that if EME is disabled and is attempted to be used we we
prompt the user to enable EME.
It is important we don't regress this feature as without it users with DRM
disabled (which is our Linux popuation by default) may try to playback DRM
protected video and it won't work and there won't be an obvious way to make it
work.
MozReview-Commit-ID: D4X7D4wkwRy
--- a/browser/base/content/test/plugins/browser.ini
+++ b/browser/base/content/test/plugins/browser.ini
@@ -3,16 +3,17 @@ support-files =
blocklist_proxy.js
blockNoPlugins.xml
blockPluginHard.xml
blockPluginInfoURL.xml
blockPluginVulnerableNoUpdate.xml
blockPluginVulnerableUpdatable.xml
browser_clearplugindata.html
browser_clearplugindata_noage.html
+ empty_file.html
head.js
plugin_add_dynamically.html
plugin_alternate_content.html
plugin_big.html
plugin_both.html
plugin_both2.html
plugin_bug744745.html
plugin_bug749455.html
@@ -87,16 +88,17 @@ tags = blocklist
tags = blocklist
[browser_pluginnotification.js]
tags = blocklist
[browser_plugin_reloading.js]
tags = blocklist
[browser_blocklist_content.js]
skip-if = !e10s
tags = blocklist
+[browser_enable_DRM_prompt.js]
[browser_globalplugin_crashinfobar.js]
skip-if = !crashreporter
[browser_pluginCrashCommentAndURL.js]
skip-if = !crashreporter
[browser_pageInfo_plugins.js]
[browser_pluginCrashReportNonDeterminism.js]
skip-if = !crashreporter || os == 'linux' # Bug 1152811
[browser_private_clicktoplay.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/plugins/browser_enable_DRM_prompt.js
@@ -0,0 +1,67 @@
+/*
+ * Bug 1366167 - Tests that the "Enable DRM" prompt shows if EME is requested while EME is disabled.
+ */
+
+const TEST_URL =
+ getRootDirectory(gTestPath).replace("chrome://mochitests/content",
+ "https://example.com") + "empty_file.html";
+
+add_task(async function() {
+ await BrowserTestUtils.withNewTab(TEST_URL, async function(browser) {
+ // Note: SpecialPowers.pushPrefEnv has problems with the "Enable DRM"
+ // button on the notification box toggling the prefs. So manually
+ // set/unset the prefs the UI we're testing toggles.
+ let emeWasEnabled = Services.prefs.getBoolPref("media.eme.enabled", false);
+ let cdmWasEnabled = Services.prefs.getBoolPref("media.gmp-widevinecdm.enabled", false);
+
+ // Restore the preferences to their pre-test state on test finish.
+ registerCleanupFunction(function() {
+ Services.prefs.setBoolPref("media.eme.enabled", emeWasEnabled);
+ Services.prefs.setBoolPref("media.gmp-widevinecdm.enabled", cdmWasEnabled);
+ });
+
+ // Turn off EME and Widevine CDM.
+ Services.prefs.setBoolPref("media.eme.enabled", false);
+ Services.prefs.setBoolPref("media.gmp-widevinecdm.enabled", false);
+
+ // Have content request access to Widevine, UI should drop down to
+ // prompt user to enable DRM.
+ let result = await ContentTask.spawn(browser, {}, async function() {
+ try {
+ let config = [{
+ initDataTypes: ["webm"],
+ videoCapabilities: [{contentType: 'video/webm; codecs="vp9"'}],
+ }];
+ await content.navigator.requestMediaKeySystemAccess("com.widevine.alpha", config);
+ } catch (ex) {
+ return {rejected: true};
+ }
+ return {rejected: false};
+ });
+ is(result.rejected, true, "EME request should be denied because EME disabled.");
+
+ // Verify the UI prompt showed.
+ let box = gBrowser.getNotificationBox(browser);
+ let notification = box.currentNotification;
+
+ ok(notification, "Notification should be visible");
+ is(notification.value, "drmContentDisabled",
+ "Should be showing the right notification");
+
+ // Verify the "Enable DRM" button is there.
+ let buttons = notification.querySelectorAll(".notification-button");
+ is(buttons.length, 1, "Should have one button.");
+
+ // Prepare a Promise that should resolve when the "Enable DRM" button's
+ // page reload completes.
+ let refreshPromise = BrowserTestUtils.browserLoaded(browser);
+ buttons[0].click();
+
+ // Wait for the reload to complete.
+ await refreshPromise;
+
+ // Verify clicking the "Enable DRM" button enabled DRM.
+ let enabled = Services.prefs.getBoolPref("media.eme.enabled", true);
+ is(enabled, true, "EME should be enabled after click on 'Enable DRM' button");
+ });
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/plugins/empty_file.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ This page is intentionally left blank.
+ </body>
+</html>