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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationUIManagerIntentTest.java

Issue 1847573003: Use the ChromeBrowserInitializer on incoming notification intents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationService.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.notifications; 5 package org.chromium.chrome.browser.notifications;
6 6
7 import android.app.Notification; 7 import android.app.Notification;
8 import android.app.PendingIntent;
8 import android.content.Context; 9 import android.content.Context;
9 import android.content.Intent; 10 import android.content.Intent;
10 import android.test.suitebuilder.annotation.MediumTest; 11 import android.test.suitebuilder.annotation.MediumTest;
11 12
12 import org.chromium.base.library_loader.LibraryLoader; 13 import org.chromium.base.library_loader.LibraryLoader;
13 import org.chromium.base.test.util.Feature; 14 import org.chromium.base.test.util.Feature;
14 import org.chromium.chrome.browser.ChromeActivity; 15 import org.chromium.chrome.browser.ChromeActivity;
15 import org.chromium.chrome.browser.document.ChromeLauncherActivity; 16 import org.chromium.chrome.browser.document.ChromeLauncherActivity;
16 import org.chromium.chrome.browser.preferences.Preferences; 17 import org.chromium.chrome.browser.preferences.Preferences;
17 import org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences ; 18 import org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences ;
18 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; 19 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences;
19 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 20 import org.chromium.chrome.test.ChromeActivityTestCaseBase;
20 import org.chromium.chrome.test.util.ActivityUtils; 21 import org.chromium.chrome.test.util.ActivityUtils;
22 import org.chromium.content.browser.test.util.Criteria;
23 import org.chromium.content.browser.test.util.CriteriaHelper;
21 24
22 /** 25 /**
23 * Instrumentation tests for the Notification UI Manager implementation on Andro id. 26 * Instrumentation tests for the Notification UI Manager implementation on Andro id.
24 * 27 *
25 * Exercises the handling of intents and explicitly does not do anything in star tMainActivity so 28 * Exercises the handling of intents and explicitly does not do anything in star tMainActivity so
26 * that the responsibility for correct initialization, e.g. loading the native l ibrary, lies with 29 * that the responsibility for correct initialization, e.g. loading the native l ibrary, lies with
27 * the code exercised by this test. 30 * the code exercised by this test.
28 */ 31 */
29 public class NotificationUIManagerIntentTest extends ChromeActivityTestCaseBase< ChromeActivity> { 32 public class NotificationUIManagerIntentTest extends ChromeActivityTestCaseBase< ChromeActivity> {
30 /** 33 /**
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 public void run() { 109 public void run() {
107 context.startActivity(intent); 110 context.startActivity(intent);
108 } 111 }
109 }); 112 });
110 assertNotNull("Could not find the Preferences activity", activity); 113 assertNotNull("Could not find the Preferences activity", activity);
111 114
112 SingleWebsitePreferences fragment = 115 SingleWebsitePreferences fragment =
113 ActivityUtils.waitForFragmentToAttach(activity, SingleWebsitePre ferences.class); 116 ActivityUtils.waitForFragmentToAttach(activity, SingleWebsitePre ferences.class);
114 assertNotNull("Could not find the SingleWebsitePreferences fragment", fr agment); 117 assertNotNull("Could not find the SingleWebsitePreferences fragment", fr agment);
115 } 118 }
119
120 /**
121 * Tests the browser initialization code when a notification has been activa ted. This will be
122 * routed through the NotificationService which starts the browser process, which in turn will
123 * create an instance of the NotificationUIManager.
124 *
125 * The created intend does not carry significant data and is expected to fai l, but has to be
Michael van Ouwerkerk 2016/03/31 10:00:04 s/intend/intent/
Peter Beverloo 2016/03/31 15:12:17 Done.
126 * sufficient for the Java code to trigger start-up of the browser process.
127 */
128 @MediumTest
129 @Feature({"Browser", "Notifications"})
130 public void testLaunchProcessForNotificationActivation() throws Exception {
131 assertFalse("The native library should not be loaded yet", LibraryLoader .isInitialized());
132 assertNull(NotificationUIManager.getInstanceForTests());
133
134 final Context context = getInstrumentation().getTargetContext().getAppli cationContext();
Michael van Ouwerkerk 2016/03/31 10:00:04 tiny nit: no need for |final| here as it is not us
Peter Beverloo 2016/03/31 15:12:17 Done.
135
136 Intent intent = new Intent(NotificationConstants.ACTION_CLICK_NOTIFICATI ON);
137 intent.setClass(context, NotificationService.Receiver.class);
138
139 intent.putExtra(NotificationConstants.EXTRA_PERSISTENT_NOTIFICATION_ID, 42);
140 intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_ORIGIN, "e xample.com");
141 intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_TAG, "");
142
143 PendingIntent pendingIntent = PendingIntent.getBroadcast(
144 context, 0 /* request code */, intent, PendingIntent.FLAG_UPDATE _CURRENT);
145
146 // Send the pending intent. This will begin starting up the browser proc ess.
147 pendingIntent.send();
148
149 CriteriaHelper.pollUiThread(new Criteria("Browser process was never star ted.") {
150 @Override
151 public boolean isSatisfied() {
152 return NotificationUIManager.getInstanceForTests() != null;
153 }
154 });
155
156 assertNotNull(NotificationUIManager.getInstanceForTests());
Michael van Ouwerkerk 2016/03/31 10:00:04 Perhaps for symmetry with the start of this test,
Peter Beverloo 2016/03/31 15:12:17 Done.
157 }
116 } 158 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationService.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698