Bug 1485189 - part2 : add test. r=timdream
authoralwu <alwu@mozilla.com>
Wed, 29 Aug 2018 16:49:06 +0000
changeset 482289 cc07ed4ce971e934b151f6e85c1f8e7ddd814b74
parent 482288 58fc60f3fdf14a5534faba7161e35efdbeb05b01
child 482290 9993da7e33003f7bb3ae2b4b5da185038d67e9fc
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewerstimdream
bugs1485189
milestone63.0a1
Bug 1485189 - part2 : add test. r=timdream Differential Revision: https://phabricator.services.mozilla.com/D4268
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_mozAutoplayMediaBlocked.html
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -31,16 +31,17 @@ skip-if = debug
 [test_desktop_useragent.html]
 [test_device_search_engine.html]
 [test_get_last_visited.html]
 [test_home_provider.html]
 [test_hidden_select_option.html]
 [test_identity_mode.html]
 [test_media_playback.html]
 [test_migrate_ui.html]
+[test_mozAutoplayMediaBlocked.html]
 [test_network_manager.html]
 [test_offline_page.html]
 skip-if = true # Bug 1241478
 [test_reader_view.html]
 [test_resource_substitutions.html]
 [test_restricted_profiles.html]
 [test_select_disabled.html]
 [test_selectoraddtab.html]
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_mozAutoplayMediaBlocked.html
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>MozAutoplayMediaBlocked test</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/AddTask.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="head.js"></script>
+  <script type="application/javascript">
+/**
+ * This test is used to check whether 'MozAutoplayMediaBlocked' would be fired
+ * correctly when the media was blocked.
+ */
+"use strict";
+
+ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+ChromeUtils.import("resource://gre/modules/Task.jsm");
+
+let gChromeWin;
+let gBrowserApp;
+
+const URL = "http://example.org/chrome/mobile/android/tests/browser/chrome/media_playback.html";
+
+// Waiting for a tab to load or restore can be slow on the emulator.
+SimpleTest.requestLongerTimeout(2);
+
+(function setup_testing_env() {
+  gChromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+  gBrowserApp = gChromeWin.BrowserApp;
+
+  Services.prefs.setIntPref("media.autoplay.default", 1 /* BLOCKED */);
+  Services.prefs.setBoolPref("media.autoplay.enabled.user-gestures-needed", true);
+})();
+
+add_task(async function test_MozAutoplayMediaBlocked() {
+  info("- open a new tab -");
+  let tab = gBrowserApp.addTab(URL);
+  let browser = tab.browser;
+
+  const mediaBlockedPromise = promiseBrowserEvent(browser, "MozAutoplayMediaBlocked");
+
+  info("- wait for loading tab's content -");
+  await promiseBrowserEvent(browser, "load");
+
+  info("- wait for 'MozAutoplayMediaBlocked' event -");
+  await mediaBlockedPromise;
+  ok(true, "got `MozAutoplayMediaBlocked` event");
+
+  info("- remove tab -");
+  gBrowserApp.closeTab(tab);
+});
+
+  </script>
+</head>
+<body>
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>