Bug 1204793 - Testcase for checking the agent active state when changing the volume. r=baku
authorAlastor Wu <alwu@mozilla.com>
Fri, 25 Dec 2015 18:47:08 +0800
changeset 315657 7b7b730f7f8ef0b69950cd259150dcdb41ef5e26
parent 315656 47c80dd3fca6c5a0aeef32798562d6dc11a4d0a6
child 315658 35794bec70ba6a805f2e8031b53d7c43e9ea9206
push id1079
push userjlund@mozilla.com
push dateFri, 15 Apr 2016 21:02:33 +0000
treeherdermozilla-release@575fbf6786d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1204793
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1204793 - Testcase for checking the agent active state when changing the volume. r=baku
dom/browser-element/mochitest/browserElement_ActiveStateChangeOnChangingMutedOrVolume.js
dom/browser-element/mochitest/file_browserElement_ActiveStateChangeOnChangingMutedOrVolume.html
dom/browser-element/mochitest/mochitest-oop.ini
dom/browser-element/mochitest/mochitest.ini
dom/browser-element/mochitest/test_browserElement_inproc_ActiveStateChangeOnChangingMutedOrVolume.html
dom/browser-element/mochitest/test_browserElement_oop_ActiveStateChangeOnChangingMutedOrVolume.html
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_ActiveStateChangeOnChangingMutedOrVolume.js
@@ -0,0 +1,126 @@
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.addPermission();
+
+var fileURL = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_ActiveStateChangeOnChangingMutedOrVolume.html';
+var generator = runTests();
+var testFrame;
+var ac;
+
+function assert(aVal, aMessage) {
+  return (!aVal) ? error(aMessage) : 0;
+}
+
+function error(aMessage) {
+  ok(false, "Error : " + aMessage);
+  finish();
+}
+
+function continueTest() {
+  try {
+    generator.next();
+  } catch (e if e instanceof StopIteration) {
+    error("Stop test because of exception!");
+  }
+}
+
+function finish() {
+  document.body.removeChild(testFrame);
+  SimpleTest.finish();
+}
+
+function setCommand(aArg) {
+  assert(!!ac, "Audio channel doesn't exist!");
+  info("# Command = " + aArg);
+
+  testFrame.src = fileURL + '#' + aArg;
+  var expectedActive = false;
+  switch (aArg) {
+    case 'play':
+    case 'unmute':
+    case 'volume-1':
+      expectedActive = true;
+      break;
+    case 'pause':
+    case 'mute':
+    case 'volume-0':
+      expectedActive = false;
+      break;
+    default :
+      error("Undefined command!");
+  }
+
+  ac.onactivestatechanged = () => {
+    ac.onactivestatechanged = null;
+    ac.isActive().onsuccess = (e) => {
+      is(expectedActive, e.target.result,
+         "Correct active state = " + expectedActive);
+      continueTest();
+    }
+  };
+}
+
+function runTests() {
+  setCommand('play');
+  yield undefined;
+
+  setCommand('mute');
+  yield undefined;
+
+  setCommand('unmute');
+  yield undefined;
+
+  setCommand('volume-0');
+  yield undefined;
+
+  setCommand('volume-1');
+  yield undefined;
+
+  setCommand('pause');
+  yield undefined;
+
+  finish();
+  yield undefined;
+}
+
+function setupTestFrame() {
+  testFrame = document.createElement('iframe');
+  testFrame.setAttribute('mozbrowser', 'true');
+  testFrame.setAttribute('mozapp', 'http://example.org/manifest.webapp');
+  testFrame.src = fileURL;
+
+  function loadend() {
+    testFrame.removeEventListener('mozbrowserloadend', loadend);
+    ok("allowedAudioChannels" in testFrame, "allowedAudioChannels exist");
+    var channels = testFrame.allowedAudioChannels;
+    is(channels.length, 1, "1 audio channel by default");
+
+    ac = channels[0];
+
+    ok(ac instanceof BrowserElementAudioChannel, "Correct class");
+    ok("isActive" in ac, "isActive exists");
+    ok("onactivestatechanged" in ac, "onactivestatechanged exists");
+
+    generator.next();
+  }
+
+  function alertError(e) {
+    testFrame.removeEventListener('mozbrowsershowmodalprompt', alertError);
+    var message = e.detail.message
+    error(message);
+  }
+
+  testFrame.addEventListener('mozbrowserloadend', loadend);
+  testFrame.addEventListener('mozbrowsershowmodalprompt', alertError);
+  document.body.appendChild(testFrame);
+}
+
+addEventListener('testready', function() {
+  SpecialPowers.pushPrefEnv({'set': [["b2g.system_manifest_url", "http://mochi.test:8888/manifest.webapp"]]},
+                            function() {
+    SimpleTest.executeSoon(setupTestFrame);
+  });
+});
+
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/file_browserElement_ActiveStateChangeOnChangingMutedOrVolume.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+<script type="application/javascript;version=1.7">
+var audio = new Audio();
+audio.src = "audio.ogg";
+audio.loop = true;
+
+function runCommands()
+{
+  switch(location.hash) {
+    case '#play':
+      audio.play();
+      break;
+    case '#mute':
+      audio.muted = true;
+      break;
+    case '#unmute':
+      audio.muted = false;
+      break;
+    case '#volume-0':
+      audio.volume = 0.0;
+      break;
+    case '#volume-1':
+      audio.volume = 1.0;
+      break;
+    case '#pause':
+      audio.pause();
+      break;
+    default :
+      alert("Undefined command!");
+  }
+}
+window.addEventListener('hashchange', runCommands);
+</script>
+</body>
+</html>
\ No newline at end of file
--- a/dom/browser-element/mochitest/mochitest-oop.ini
+++ b/dom/browser-element/mochitest/mochitest-oop.ini
@@ -119,8 +119,9 @@ disabled = bug 924771
 disabled = bug 924771
 [test_browserElement_oop_GetContentDimensions.html]
 [test_browserElement_oop_AudioChannel.html]
 [test_browserElement_oop_AudioChannel_nested.html]
 [test_browserElement_oop_SetNFCFocus.html]
 [test_browserElement_oop_getWebManifest.html]
 [test_browserElement_oop_OpenWindowEmpty.html]
 skip-if = (toolkit == 'gonk') # Test doesn't work on B2G emulator
+[test_browserElement_oop_ActiveStateChangeOnChangingMutedOrVolume.html]
--- a/dom/browser-element/mochitest/mochitest.ini
+++ b/dom/browser-element/mochitest/mochitest.ini
@@ -1,15 +1,16 @@
 [DEFAULT]
 skip-if = buildapp == 'mulet' || (buildapp == 'b2g' && (toolkit != 'gonk' || debug)) || e10s
 support-files =
   ../../../browser/base/content/test/general/audio.ogg
   ../../../dom/media/test/short-video.ogv
   async.js
   browserElementTestHelpers.js
+  browserElement_ActiveStateChangeOnChangingMutedOrVolume.js
   browserElement_Alert.js
   browserElement_AlertInFrame.js
   browserElement_AllowEmbedAppsInNestedOOIframe.js
   browserElement_AppFramePermission.js
   browserElement_AppWindowNamespace.js
   browserElement_AudioPlayback.js
   browserElement_Auth.js
   browserElement_BackForward.js
@@ -79,16 +80,17 @@ support-files =
   browserElement_XFrameOptions.js
   browserElement_XFrameOptionsAllowFrom.js
   browserElement_XFrameOptionsDeny.js
   browserElement_XFrameOptionsSameOrigin.js
   browserElement_XFrameOptionsSameOrigin.js
   browserElement_GetContentDimensions.js
   browserElement_AudioChannel.js
   browserElement_AudioChannel_nested.js
+  file_browserElement_ActiveStateChangeOnChangingMutedOrVolume.html
   file_browserElement_AlertInFrame.html
   file_browserElement_AlertInFrame_Inner.html
   file_browserElement_AllowEmbedAppsInNestedOOIframe.html
   file_browserElement_AppFramePermission.html
   file_browserElement_AppWindowNamespace.html
   file_browserElement_AudioChannel_nested.html
   file_browserElement_Viewmode.html
   file_browserElement_ThemeColor.html
@@ -253,8 +255,9 @@ skip-if = (toolkit == 'android' && proce
 disabled = bug 774100
 [test_browserElement_inproc_GetContentDimensions.html]
 [test_browserElement_inproc_AudioChannel.html]
 [test_browserElement_inproc_AudioChannel_nested.html]
 [test_browserElement_inproc_SetNFCFocus.html]
 [test_browserElement_inproc_getStructuredData.html]
 [test_browserElement_inproc_OpenWindowEmpty.html]
 skip-if = (toolkit == 'gonk') # Test doesn't work on B2G emulator
+[test_browserElement_inproc_ActiveStateChangeOnChangingMutedOrVolume.html]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_inproc_ActiveStateChangeOnChangingMutedOrVolume.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test ActiveStateChangeOnChangingMutedOrVolume</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script type="application/javascript;version=1.7" src="browserElement_ActiveStateChangeOnChangingMutedOrVolume.js">
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_oop_ActiveStateChangeOnChangingMutedOrVolume.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test ActiveStateChangeOnChangingMutedOrVolume</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script type="application/javascript;version=1.7" src="browserElement_ActiveStateChangeOnChangingMutedOrVolume.js">
+</script>
+</body>
+</html>