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

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

Issue 2316263002: Notifications in sensitive contexts now display origin + small icon (Closed)
Patch Set: Moved public notification creation and icon generation to NotificationBuilderBase Created 4 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.notifications;
6
7 import android.app.Notification;
8 import android.content.Context;
9 import android.content.res.Resources;
10 import android.graphics.Bitmap;
11 import android.test.suitebuilder.annotation.MediumTest;
12
13 import org.chromium.base.test.util.Feature;
14 import org.chromium.content.browser.test.NativeLibraryTestBase;
15
16 /**
17 * Instrumentation unit tests for NotificationBuilderBase.
18 */
19 public class NotificationBuilderBaseTest extends NativeLibraryTestBase {
20 @Override
21 public void setUp() throws Exception {
22 super.setUp();
23 loadNativeLibraryNoBrowserProcess();
Peter Beverloo 2016/09/12 17:52:03 Would it be worth documenting that not initializin
awdf 2016/09/14 12:30:29 Done.
24 }
25
26 /**
27 * Tests the three paths for ensuring that a notification will be shown with a normalized icon:
28 * (1) NULL bitmaps should have an auto-generated image.
29 * (2) Large bitmaps should be resized to the device's intended size.
30 * (3) Smaller bitmaps should be left alone.
31 */
32 @MediumTest
33 @Feature({"Browser", "Notifications"})
34 public void testEnsureNormalizedIconBehavior() throws Exception {
35 // Get the dimensions of the notification icon that will be presented to the user.
36 Context appContext = getInstrumentation().getTargetContext().getApplicat ionContext();
37 Resources resources = appContext.getResources();
38
39 int largeIconWidthPx =
40 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_width);
41 int largeIconHeightPx =
42 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_height);
43
44 String origin = "https://example.com";
45
46 NotificationBuilderBase notificationBuilder = new NotificationBuilderBas e(resources) {
47 @Override
48 public Notification build() {
49 return null;
50 }
51 };
Peter Beverloo 2016/09/12 17:52:02 There's nothing in your code that calls build(), s
awdf 2016/09/14 12:30:29 NotificationBuilderBase is abstract so in order to
Peter Beverloo 2016/09/14 14:06:54 Acknowledged.
52 Bitmap fromNullIcon = notificationBuilder.ensureNormalizedIcon(null, ori gin);
53 assertNotNull(fromNullIcon);
54 assertEquals(largeIconWidthPx, fromNullIcon.getWidth());
55 assertEquals(largeIconHeightPx, fromNullIcon.getHeight());
56
57 Bitmap largeIcon = Bitmap.createBitmap(
58 largeIconWidthPx * 2, largeIconHeightPx * 2, Bitmap.Config.ALPHA _8);
59
60 Bitmap fromLargeIcon = notificationBuilder.ensureNormalizedIcon(largeIco n, origin);
61 assertNotNull(fromLargeIcon);
62 assertEquals(largeIconWidthPx, fromLargeIcon.getWidth());
63 assertEquals(largeIconHeightPx, fromLargeIcon.getHeight());
64
65 Bitmap smallIcon = Bitmap.createBitmap(
66 largeIconWidthPx / 2, largeIconHeightPx / 2, Bitmap.Config.ALPHA _8);
67
68 Bitmap fromSmallIcon = notificationBuilder.ensureNormalizedIcon(smallIco n, origin);
69 assertNotNull(fromSmallIcon);
70 assertEquals(smallIcon, fromSmallIcon);
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698