| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.media.ui; | 5 package org.chromium.chrome.browser.media.ui; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 | 8 |
| 9 import android.app.Notification; | 9 import android.app.Notification; |
| 10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
| 11 import android.view.View; | 11 import android.view.View; |
| 12 import android.widget.TextView; | 12 import android.widget.TextView; |
| 13 | 13 |
| 14 import org.chromium.base.ObserverList; | 14 import org.chromium.base.ObserverList; |
| 15 import org.chromium.base.ThreadUtils; | 15 import org.chromium.base.ThreadUtils; |
| 16 import org.chromium.base.test.util.CommandLineFlags; |
| 16 import org.chromium.base.test.util.Restriction; | 17 import org.chromium.base.test.util.Restriction; |
| 17 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
| 18 import org.chromium.chrome.browser.ChromeActivity; | 19 import org.chromium.chrome.browser.ChromeActivity; |
| 20 import org.chromium.chrome.browser.ChromeFeatureList; |
| 19 import org.chromium.chrome.browser.tab.Tab; | 21 import org.chromium.chrome.browser.tab.Tab; |
| 20 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 22 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 21 import org.chromium.chrome.test.util.ChromeRestriction; | 23 import org.chromium.chrome.test.util.ChromeRestriction; |
| 22 import org.chromium.chrome.test.util.browser.TabTitleObserver; | 24 import org.chromium.chrome.test.util.browser.TabTitleObserver; |
| 23 import org.chromium.content.browser.test.util.Criteria; | 25 import org.chromium.content.browser.test.util.Criteria; |
| 24 import org.chromium.content.browser.test.util.CriteriaHelper; | 26 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 25 import org.chromium.content.browser.test.util.JavaScriptUtils; | 27 import org.chromium.content.browser.test.util.JavaScriptUtils; |
| 26 import org.chromium.content_public.browser.WebContentsObserver; | 28 import org.chromium.content_public.browser.WebContentsObserver; |
| 27 import org.chromium.content_public.common.MediaMetadata; | 29 import org.chromium.content_public.common.MediaMetadata; |
| 28 | 30 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 super(ChromeActivity.class); | 41 super(ChromeActivity.class); |
| 40 } | 42 } |
| 41 | 43 |
| 42 @Override | 44 @Override |
| 43 protected void setUp() throws Exception { | 45 protected void setUp() throws Exception { |
| 44 super.setUp(); | 46 super.setUp(); |
| 45 mTab = getActivity().getActivityTab(); | 47 mTab = getActivity().getActivityTab(); |
| 46 simulateUpdateTitle(mTab, "title1"); | 48 simulateUpdateTitle(mTab, "title1"); |
| 47 } | 49 } |
| 48 | 50 |
| 49 @SmallTest | 51 private void testSessionStatePlayingInternal() throws InterruptedException { |
| 50 public void testSessionStatePlaying() throws InterruptedException { | |
| 51 simulateMediaSessionStateChanged(mTab, true, false); | 52 simulateMediaSessionStateChanged(mTab, true, false); |
| 52 assertTitleMatches("title1"); | 53 assertTitleMatches("title1"); |
| 53 simulateUpdateTitle(mTab, "title2"); | 54 simulateUpdateTitle(mTab, "title2"); |
| 54 assertTitleMatches("title2"); | 55 assertTitleMatches("title2"); |
| 55 } | 56 } |
| 56 | 57 |
| 57 @SmallTest | 58 private void testSessionStatePausedInternal() throws InterruptedException { |
| 58 public void testSessionStatePaused() throws InterruptedException { | |
| 59 simulateMediaSessionStateChanged(mTab, true, true); | 59 simulateMediaSessionStateChanged(mTab, true, true); |
| 60 assertTitleMatches("title1"); | 60 assertTitleMatches("title1"); |
| 61 simulateUpdateTitle(mTab, "title2"); | 61 simulateUpdateTitle(mTab, "title2"); |
| 62 assertTitleMatches("title2"); | 62 assertTitleMatches("title2"); |
| 63 } | 63 } |
| 64 | 64 |
| 65 @SmallTest | 65 private void testSessionStateUncontrollableInternal() throws InterruptedExce
ption { |
| 66 public void testSessionStateUncontrollable() throws InterruptedException { | |
| 67 simulateMediaSessionStateChanged(mTab, true, false); | 66 simulateMediaSessionStateChanged(mTab, true, false); |
| 68 assertTitleMatches("title1"); | 67 assertTitleMatches("title1"); |
| 69 simulateMediaSessionStateChanged(mTab, false, false); | 68 simulateMediaSessionStateChanged(mTab, false, false); |
| 70 simulateUpdateTitle(mTab, "title2"); | 69 simulateUpdateTitle(mTab, "title2"); |
| 71 } | 70 } |
| 72 | 71 |
| 73 @SmallTest | 72 private void testMediaMetadataSetsTitleInternal() throws InterruptedExceptio
n { |
| 74 public void testMediaMetadaSetsTitle() throws InterruptedException { | |
| 75 simulateMediaSessionStateChanged(mTab, true, false, new MediaMetadata("t
itle2", "", "")); | 73 simulateMediaSessionStateChanged(mTab, true, false, new MediaMetadata("t
itle2", "", "")); |
| 76 assertTitleMatches("title2"); | 74 assertTitleMatches("title2"); |
| 77 } | 75 } |
| 78 | 76 |
| 79 @SmallTest | 77 private void testMediaMetadataOverridesTitleInternal() throws InterruptedExc
eption { |
| 80 public void testMediaMetadaOverridesTitle() throws InterruptedException { | |
| 81 simulateMediaSessionStateChanged(mTab, true, false, new MediaMetadata("t
itle2", "", "")); | 78 simulateMediaSessionStateChanged(mTab, true, false, new MediaMetadata("t
itle2", "", "")); |
| 82 assertTitleMatches("title2"); | 79 assertTitleMatches("title2"); |
| 83 | 80 |
| 84 simulateUpdateTitle(mTab, "title3"); | 81 simulateUpdateTitle(mTab, "title3"); |
| 85 assertTitleMatches("title2"); | 82 assertTitleMatches("title2"); |
| 86 } | 83 } |
| 87 | 84 |
| 88 /** | 85 /** |
| 89 * Test if a notification accepts the title update from another tab, using t
he following steps: | 86 * Test if a notification accepts the title update from another tab, using t
he following steps: |
| 90 * 1. set the title of mTab, start the media session, a notification shoul
d show up; | 87 * 1. set the title of mTab, start the media session, a notification shoul
d show up; |
| 91 * 2. stop the media session of mTab, the notification shall hide; | 88 * 2. stop the media session of mTab, the notification shall hide; |
| 92 * 3. create newTab, set the title of mTab, start the media session of mTa
b, | 89 * 3. create newTab, set the title of mTab, start the media session of mTa
b, |
| 93 * a notification should show up; | 90 * a notification should show up; |
| 94 * 4. change the title of newTab and then mTab to different names, | 91 * 4. change the title of newTab and then mTab to different names, |
| 95 * the notification should have the title of newTab. | 92 * the notification should have the title of newTab. |
| 96 */ | 93 */ |
| 97 @SmallTest | 94 private void testMultipleTabsInternal() throws Throwable { |
| 98 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | |
| 99 public void testMultipleTabs() throws Throwable { | |
| 100 simulateMediaSessionStateChanged(mTab, true, false); | 95 simulateMediaSessionStateChanged(mTab, true, false); |
| 101 assertTitleMatches("title1"); | 96 assertTitleMatches("title1"); |
| 102 simulateMediaSessionStateChanged(mTab, false, false); | 97 simulateMediaSessionStateChanged(mTab, false, false); |
| 103 | 98 |
| 104 Tab newTab = loadUrlInNewTab("about:blank"); | 99 Tab newTab = loadUrlInNewTab("about:blank"); |
| 105 assertNotNull(newTab); | 100 assertNotNull(newTab); |
| 106 | 101 |
| 107 simulateMediaSessionStateChanged(newTab, true, false); | 102 simulateMediaSessionStateChanged(newTab, true, false); |
| 108 simulateUpdateTitle(newTab, "title3"); | 103 simulateUpdateTitle(newTab, "title3"); |
| 109 simulateUpdateTitle(mTab, "title2"); | 104 simulateUpdateTitle(mTab, "title2"); |
| 110 assertTitleMatches("title3"); | 105 assertTitleMatches("title3"); |
| 111 } | 106 } |
| 112 | 107 |
| 108 @SmallTest |
| 109 @CommandLineFlags.Add("enable-features=MediaStyleNotification") |
| 110 public void testSessionStatePlaying_MediaStyleNotification() throws Interrup
tedException { |
| 111 testSessionStatePlayingInternal(); |
| 112 } |
| 113 |
| 114 @SmallTest |
| 115 @CommandLineFlags.Add("enable-features=MediaStyleNotification") |
| 116 public void testSessionStatePaused_MediaStyleNotification() throws Interrupt
edException { |
| 117 testSessionStatePausedInternal(); |
| 118 } |
| 119 |
| 120 @SmallTest |
| 121 @CommandLineFlags.Add("enable-features=MediaStyleNotification") |
| 122 public void testSessionStateUncontrollable_MediaStyleNotification() |
| 123 throws InterruptedException { |
| 124 testSessionStateUncontrollableInternal(); |
| 125 } |
| 126 |
| 127 @SmallTest |
| 128 @CommandLineFlags.Add("enable-features=MediaStyleNotification") |
| 129 public void testMediaMetadataSetsTitle_MediaStyleNotification() throws Inter
ruptedException { |
| 130 testMediaMetadataSetsTitleInternal(); |
| 131 } |
| 132 |
| 133 @SmallTest |
| 134 @CommandLineFlags.Add("enable-features=MediaStyleNotification") |
| 135 public void testMediaMetadataOverridesTitle_MediaStyleNotification() |
| 136 throws InterruptedException { |
| 137 testMediaMetadataOverridesTitleInternal(); |
| 138 } |
| 139 |
| 140 @SmallTest |
| 141 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 142 @CommandLineFlags.Add("enable-features=MediaStyleNotification") |
| 143 public void testMultipleTabs_MediaStyleNotification() throws Throwable { |
| 144 testMultipleTabsInternal(); |
| 145 } |
| 146 |
| 147 @SmallTest |
| 148 @CommandLineFlags.Add("disable-features=MediaStyleNotification") |
| 149 public void testSessionStatePlaying_CustomNotification() throws InterruptedE
xception { |
| 150 testSessionStatePlayingInternal(); |
| 151 } |
| 152 |
| 153 @SmallTest |
| 154 @CommandLineFlags.Add("disable-features=MediaStyleNotification") |
| 155 public void testSessionStatePaused_CustomNotification() throws InterruptedEx
ception { |
| 156 testSessionStatePausedInternal(); |
| 157 } |
| 158 |
| 159 @SmallTest |
| 160 @CommandLineFlags.Add("disable-features=MediaStyleNotification") |
| 161 public void testSessionStateUncontrollable_CustomNotification() throws Inter
ruptedException { |
| 162 testSessionStateUncontrollableInternal(); |
| 163 } |
| 164 |
| 165 @SmallTest |
| 166 @CommandLineFlags.Add("disable-features=MediaStyleNotification") |
| 167 public void testMediaMetadataSetsTitle_CustomNotification() throws Interrupt
edException { |
| 168 testMediaMetadataSetsTitleInternal(); |
| 169 } |
| 170 |
| 171 @SmallTest |
| 172 @CommandLineFlags.Add("disable-features=MediaStyleNotification") |
| 173 public void testMediaMetadataOverridesTitle_CustomNotification() throws Inte
rruptedException { |
| 174 testMediaMetadataOverridesTitleInternal(); |
| 175 } |
| 176 |
| 177 @SmallTest |
| 178 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 179 @CommandLineFlags.Add("disable-features=MediaStyleNotification") |
| 180 public void testMultipleTabs_CustomNotification() throws Throwable { |
| 181 testMultipleTabsInternal(); |
| 182 } |
| 183 |
| 113 @Override | 184 @Override |
| 114 public void startMainActivity() throws InterruptedException { | 185 public void startMainActivity() throws InterruptedException { |
| 115 startMainActivityOnBlankPage(); | 186 startMainActivityOnBlankPage(); |
| 116 } | 187 } |
| 117 | 188 |
| 118 private void simulateMediaSessionStateChanged( | 189 private void simulateMediaSessionStateChanged( |
| 119 final Tab tab, final boolean isControllable, final boolean isSuspend
ed) { | 190 final Tab tab, final boolean isControllable, final boolean isSuspend
ed) { |
| 120 simulateMediaSessionStateChanged( | 191 simulateMediaSessionStateChanged( |
| 121 tab, isControllable, isSuspended, new MediaMetadata("", "", ""))
; | 192 tab, isControllable, isSuspended, new MediaMetadata("", "", ""))
; |
| 122 } | 193 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 233 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 163 @Override | 234 @Override |
| 164 public void run() { | 235 public void run() { |
| 165 Notification notification = | 236 Notification notification = |
| 166 MediaNotificationManager | 237 MediaNotificationManager |
| 167 .getNotificationBuilderForTesting(NOTIFICATI
ON_ID) | 238 .getNotificationBuilderForTesting(NOTIFICATI
ON_ID) |
| 168 .build(); | 239 .build(); |
| 169 | 240 |
| 170 View contentView = notification.contentView.apply( | 241 View contentView = notification.contentView.apply( |
| 171 getActivity().getApplicationContext(), null); | 242 getActivity().getApplicationContext(), null); |
| 172 TextView titleView = (TextView) contentView.findViewById(R.i
d.title); | 243 String observedText = null; |
| 173 assertEquals(title, titleView.getText()); | 244 if (ChromeFeatureList.isEnabled(ChromeFeatureList.MEDIA_STYL
E_NOTIFICATION)) { |
| 245 observedText = ((TextView) contentView.findViewById(andr
oid.R.id.title)) |
| 246 .getText() |
| 247 .toString(); |
| 248 } else { |
| 249 observedText = ((TextView) contentView.findViewById(R.id
.title)) |
| 250 .getText() |
| 251 .toString(); |
| 252 } |
| 253 assertEquals(title, observedText); |
| 174 } | 254 } |
| 175 }); | 255 }); |
| 176 } | 256 } |
| 177 } | 257 } |
| OLD | NEW |