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; | |
15 import org.chromium.base.ThreadUtils; | 14 import org.chromium.base.ThreadUtils; |
16 import org.chromium.base.test.util.Restriction; | 15 import org.chromium.base.test.util.Restriction; |
17 import org.chromium.base.test.util.RetryOnFailure; | 16 import org.chromium.base.test.util.RetryOnFailure; |
18 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
19 import org.chromium.chrome.browser.ChromeActivity; | 18 import org.chromium.chrome.browser.ChromeActivity; |
20 import org.chromium.chrome.browser.tab.Tab; | 19 import org.chromium.chrome.browser.tab.Tab; |
21 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 20 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
22 import org.chromium.chrome.test.util.ChromeRestriction; | 21 import org.chromium.chrome.test.util.ChromeRestriction; |
23 import org.chromium.chrome.test.util.browser.TabTitleObserver; | 22 import org.chromium.chrome.test.util.browser.TabTitleObserver; |
| 23 import org.chromium.content.browser.ChromeMediaSession; |
24 import org.chromium.content.browser.test.util.Criteria; | 24 import org.chromium.content.browser.test.util.Criteria; |
25 import org.chromium.content.browser.test.util.CriteriaHelper; | 25 import org.chromium.content.browser.test.util.CriteriaHelper; |
26 import org.chromium.content.browser.test.util.JavaScriptUtils; | 26 import org.chromium.content.browser.test.util.JavaScriptUtils; |
27 import org.chromium.content_public.browser.WebContentsObserver; | |
28 import org.chromium.content_public.common.MediaMetadata; | 27 import org.chromium.content_public.common.MediaMetadata; |
29 | 28 |
30 /** | 29 /** |
31 * Test of media notifications to see whether the text updates when the tab titl
e changes or the | 30 * Test of media notifications to see whether the text updates when the tab titl
e changes or the |
32 * MediaMetadata gets updated. | 31 * MediaMetadata gets updated. |
33 */ | 32 */ |
34 @RetryOnFailure | 33 @RetryOnFailure |
35 public class NotificationTitleUpdatedTest extends ChromeActivityTestCaseBase<Chr
omeActivity> { | 34 public class NotificationTitleUpdatedTest extends ChromeActivityTestCaseBase<Chr
omeActivity> { |
36 private static final int NOTIFICATION_ID = R.id.media_playback_notification; | 35 private static final int NOTIFICATION_ID = R.id.media_playback_notification; |
37 | 36 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 @Override | 142 @Override |
144 public void startMainActivity() throws InterruptedException { | 143 public void startMainActivity() throws InterruptedException { |
145 startMainActivityOnBlankPage(); | 144 startMainActivityOnBlankPage(); |
146 } | 145 } |
147 | 146 |
148 private void simulateMediaSessionStateChanged( | 147 private void simulateMediaSessionStateChanged( |
149 final Tab tab, final boolean isControllable, final boolean isSuspend
ed) { | 148 final Tab tab, final boolean isControllable, final boolean isSuspend
ed) { |
150 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 149 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
151 @Override | 150 @Override |
152 public void run() { | 151 public void run() { |
153 ObserverList.RewindableIterator<WebContentsObserver> observe
rs = | 152 ChromeMediaSession.fromWebContents(tab.getWebContents()) |
154 tab.getWebContents().getObserversForTesting(); | 153 .mediaSessionStateChanged(isControllable, isSuspende
d); |
155 while (observers.hasNext()) { | |
156 observers.next().mediaSessionStateChanged(isControllable
, isSuspended); | |
157 } | |
158 } | 154 } |
159 }); | 155 }); |
160 } | 156 } |
161 | 157 |
162 private void simulateMediaSessionMetadataChanged(final Tab tab, final MediaM
etadata metadata) { | 158 private void simulateMediaSessionMetadataChanged(final Tab tab, final MediaM
etadata metadata) { |
163 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 159 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
164 @Override | 160 @Override |
165 public void run() { | 161 public void run() { |
166 ObserverList.RewindableIterator<WebContentsObserver> observers = | 162 ChromeMediaSession.fromWebContents(tab.getWebContents()) |
167 tab.getWebContents().getObserversForTesting(); | 163 .mediaSessionMetadataChanged(metadata); |
168 while (observers.hasNext()) { | |
169 observers.next().mediaSessionMetadataChanged(metadata); | |
170 } | |
171 } | 164 } |
172 }); | 165 }); |
173 } | 166 } |
174 | 167 |
175 private void simulateUpdateTitle(Tab tab, String title) { | 168 private void simulateUpdateTitle(Tab tab, String title) { |
176 try { | 169 try { |
177 TabTitleObserver observer = new TabTitleObserver(tab, title); | 170 TabTitleObserver observer = new TabTitleObserver(tab, title); |
178 JavaScriptUtils.executeJavaScriptAndWaitForResult( | 171 JavaScriptUtils.executeJavaScriptAndWaitForResult( |
179 tab.getWebContents(), | 172 tab.getWebContents(), |
180 "document.title = '" + title + "';"); | 173 "document.title = '" + title + "';"); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // The TextView id will be in Chrome's namespace. | 205 // The TextView id will be in Chrome's namespace. |
213 view = (TextView) contentView.findViewById(R.id.title); | 206 view = (TextView) contentView.findViewById(R.id.title); |
214 } | 207 } |
215 observedText = view.getText().toString(); | 208 observedText = view.getText().toString(); |
216 | 209 |
217 assertEquals(title, observedText); | 210 assertEquals(title, observedText); |
218 } | 211 } |
219 }); | 212 }); |
220 } | 213 } |
221 } | 214 } |
OLD | NEW |