Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 } | |
| OLD | NEW |