Bug 1357639 - part7 : add check for notification's content.
Add check for media notification's small icon, title and content text.
MozReview-Commit-ID: AOhag8gQVqs
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/MediaPlaybackTest.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/MediaPlaybackTest.java
@@ -12,16 +12,17 @@ import org.mozilla.gecko.media.AudioFocu
import org.mozilla.gecko.media.AudioFocusAgent.State;
import org.mozilla.gecko.media.MediaControlService;
import android.content.Intent;
import android.content.Context;
import android.app.Notification;
import android.app.NotificationManager;
+import android.graphics.drawable.Icon;
import android.os.Build;
import android.service.notification.StatusBarNotification;
import com.robotium.solo.Condition;
abstract class MediaPlaybackTest extends BaseTest {
private Context mContext;
private int mPrevIcon = 0;
@@ -123,35 +124,44 @@ abstract class MediaPlaybackTest extends
final Tab tab = Tabs.getInstance().getSelectedTab();
mAsserter.ok(isTabPlaying == tab.isMediaPlaying(),
"Checking the media playing state of tab, isTabPlaying = " + isTabPlaying,
"Tab's media playing state is correct.");
if (clearNotification) {
checkIfMediaNotificationBeCleared();
} else {
- checkMediaNotificationStates(isTabPlaying);
+ checkMediaNotificationStates(tab, isTabPlaying);
}
}
- protected final void checkMediaNotificationStates(boolean isTabPlaying) {
+ protected final void checkMediaNotificationStates(final Tab tab,
+ final boolean isTabPlaying) {
if (!isAvailableToCheckNotification()) {
return;
}
NotificationManager notificationManager = (NotificationManager)
getContext().getSystemService(Context.NOTIFICATION_SERVICE);
StatusBarNotification[] sbns = notificationManager.getActiveNotifications();
mAsserter.is(sbns.length, 1,
"Should only have one notification in system's status bar.");
Notification notification = sbns[0].getNotification();
+ mAsserter.is(notification.icon,
+ R.drawable.flat_icon,
+ "Notification shows correct small icon.");
+ mAsserter.is(notification.extras.get(Notification.EXTRA_TITLE),
+ tab.getTitle(),
+ "Notification shows correct title.");
+ mAsserter.is(notification.extras.get(Notification.EXTRA_TEXT),
+ tab.getURL(),
+ "Notification shows correct text.");
mAsserter.is(notification.actions.length, 1,
"Only has one action in notification.");
-
mAsserter.is(notification.actions[0].title,
getContext().getString(isTabPlaying ? R.string.media_pause : R.string.media_play),
"Action has correct title.");
mAsserter.is(notification.actions[0].icon,
isTabPlaying ? R.drawable.ic_media_pause : R.drawable.ic_media_play,
"Action has correct icon.");
}
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testMediaControl.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testMediaControl.java
@@ -1,14 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.tests;
+import org.mozilla.gecko.Tab;
+import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.media.MediaControlService;
import android.media.AudioManager;
public class testMediaControl extends MediaPlaybackTest {
public void testMediaControl() {
info("- ensure the test is running on correct Android version -");
checkAndroidVersionForMediaControlTest();
@@ -107,18 +109,19 @@ public class testMediaControl extends Me
info("- check whether audio starts playing -");
checkIfMediaPlayingSuccess(true /* playing */);
info("- switch to the another tab -");
final String BLANK_URL = getAbsoluteUrl(mStringHelper.ROBOCOP_BLANK_PAGE_01_URL);
addTab(BLANK_URL);
- info("- the media control shouldn't be changed -");
- checkMediaNotificationStates(true /* playing */);
+ info("- the media control shouldn't be changed and display the info of audible tab -");
+ final Tab tab = Tabs.getInstance().getFirstTabForUrl(MEDIA_URL);
+ checkMediaNotificationStates(tab, true /* playing */);
info("- close tab -");
closeAllTabs();
}
private void testCloseTab() {
info("- load URL -");
final String MEDIA_URL = getAbsoluteUrl(mStringHelper.ROBOCOP_MEDIA_PLAYBACK_LOOP_URL);