Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1133)

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/AudioFocusManagerTest.java

Issue 1131793004: Migrate AudioFocusChangeListener to browser and always send GAIN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: webview suggestions from boliu Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/javatests/src/org/chromium/content/browser/AudioFocusManagerTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/AudioFocusManagerTest.java b/content/public/android/javatests/src/org/chromium/content/browser/AudioFocusManagerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..12cb96f1aa4bfb9408ec837a6ebf4fb4dac68334
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/AudioFocusManagerTest.java
@@ -0,0 +1,99 @@
+// Copyright 2015 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.
+
+package org.chromium.content.browser;
+
+import android.content.Context;
+import android.media.AudioManager;
+import android.media.AudioManager.OnAudioFocusChangeListener;
+import android.test.suitebuilder.annotation.MediumTest;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.content.browser.test.util.DOMUtils;
+import org.chromium.content_shell_apk.ContentShellTestBase;
+
+/**
+ * Test AudioFocus behavior between Chromium and external media players.
+ */
+public class AudioFocusManagerTest extends ContentShellTestBase {
+ private static final String MULTIPLE_AUDIO_TEST_URL =
+ "content/test/data/android/multiple_audio_test.html";
+ private static final String FIRST_AUDIO_ID = "firstAudio";
+ private static final String SECOND_AUDIO_ID = "secondAudio";
+ private static final String PLAY_FIRST_BUTTON = "playFirstButton";
+ private static final String PLAY_SECOND_BUTTON = "playSecondButton";
+ private static final String PAUSE_FIRST_BUTTON = "pauseFirstButton";
+ private static final String PAUSE_SECOND_BUTTON = "pauseSecondButton";
+ private static final String REDUCE_FIRST_VOLUME_BUTTON = "reduceFirstVolumeButton";
+ private static final String RESET_FIRST_VOLUME_BUTTON = "resetFirstVolumeButton";
+
+ private OnAudioFocusChangeListener mExternalAFChangeListener;
+ private AudioManager mAudioManager;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ try {
+ startActivityWithTestUrl(MULTIPLE_AUDIO_TEST_URL);
+ } catch (Throwable t) {
+ fail("Could not load test page: " + MULTIPLE_AUDIO_TEST_URL);
+ }
+
+ // Setup an AudioFocusChangeListener to mimic an external app.
+ mExternalAFChangeListener = new OnAudioFocusChangeListener() {
+ @Override
+ public void onAudioFocusChange(int focusChange) {
+ }
+ };
+ mAudioManager = (AudioManager) getInstrumentation().getTargetContext().getSystemService(
+ Context.AUDIO_SERVICE);
+ }
+
+ @MediumTest
+ @Feature({"Browser"})
+ public void testInterruption() throws Throwable {
+ // Play two audio elements.
+ tapButton(PLAY_FIRST_BUTTON);
+ assertTrue("First audio element did not start",
+ DOMUtils.waitForVideoState(getWebContents(),
+ FIRST_AUDIO_ID,
+ DOMUtils.VIDEO_STATE_PLAYING));
+ tapButton(PLAY_SECOND_BUTTON);
+ assertTrue("Second audio element did not start",
+ DOMUtils.waitForVideoState(getWebContents(),
+ SECOND_AUDIO_ID,
+ DOMUtils.VIDEO_STATE_PLAYING));
+
+ // Request audio focus away from webpage audio with DUCK.
+ mAudioManager.requestAudioFocus(mExternalAFChangeListener,
+ AudioManager.STREAM_MUSIC,
+ AudioManager.AUDIOFOCUS_GAIN);
+
+ // Audio in page should be stopped.
+ assertTrue("First audio element did not stop after losing audio focus",
+ DOMUtils.waitForVideoState(getWebContents(),
+ FIRST_AUDIO_ID,
+ DOMUtils.VIDEO_STATE_PAUSED));
+ assertTrue("Second audio element did not stop after losing audio focus",
+ DOMUtils.waitForVideoState(getWebContents(),
+ SECOND_AUDIO_ID,
+ DOMUtils.VIDEO_STATE_PAUSED));
+
+ // Restart one of the audio elements.
+ tapButton(PLAY_FIRST_BUTTON);
+ assertTrue("First audio element did not resume after calling play",
+ DOMUtils.waitForVideoState(getWebContents(),
+ FIRST_AUDIO_ID,
+ DOMUtils.VIDEO_STATE_PLAYING));
+ assertTrue("Second audio element resumed without calling play on first",
+ DOMUtils.isVideoPaused(getWebContents(), SECOND_AUDIO_ID));
+
+ mAudioManager.abandonAudioFocus(mExternalAFChangeListener);
+ }
+
+ private void tapButton(String button) throws Exception {
+ DOMUtils.clickNode(this, getContentViewCore(), button);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698