Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationBuilderBaseTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationBuilderBaseTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationBuilderBaseTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..91ecaae73478ae76146c3151dbe8ddf835719b66 |
| --- /dev/null |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationBuilderBaseTest.java |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.notifications; |
| + |
| +import android.app.Notification; |
| +import android.content.Context; |
| +import android.content.res.Resources; |
| +import android.graphics.Bitmap; |
| +import android.test.suitebuilder.annotation.MediumTest; |
| + |
| +import org.chromium.base.test.util.Feature; |
| +import org.chromium.content.browser.test.NativeLibraryTestBase; |
| + |
| +/** |
| + * Instrumentation unit tests for NotificationBuilderBase. |
| + */ |
| +public class NotificationBuilderBaseTest extends NativeLibraryTestBase { |
| + @Override |
| + public void setUp() throws Exception { |
| + super.setUp(); |
| + 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.
|
| + } |
| + |
| + /** |
| + * Tests the three paths for ensuring that a notification will be shown with a normalized icon: |
| + * (1) NULL bitmaps should have an auto-generated image. |
| + * (2) Large bitmaps should be resized to the device's intended size. |
| + * (3) Smaller bitmaps should be left alone. |
| + */ |
| + @MediumTest |
| + @Feature({"Browser", "Notifications"}) |
| + public void testEnsureNormalizedIconBehavior() throws Exception { |
| + // Get the dimensions of the notification icon that will be presented to the user. |
| + Context appContext = getInstrumentation().getTargetContext().getApplicationContext(); |
| + Resources resources = appContext.getResources(); |
| + |
| + int largeIconWidthPx = |
| + resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); |
| + int largeIconHeightPx = |
| + resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); |
| + |
| + String origin = "https://example.com"; |
| + |
| + NotificationBuilderBase notificationBuilder = new NotificationBuilderBase(resources) { |
| + @Override |
| + public Notification build() { |
| + return null; |
| + } |
| + }; |
|
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.
|
| + Bitmap fromNullIcon = notificationBuilder.ensureNormalizedIcon(null, origin); |
| + assertNotNull(fromNullIcon); |
| + assertEquals(largeIconWidthPx, fromNullIcon.getWidth()); |
| + assertEquals(largeIconHeightPx, fromNullIcon.getHeight()); |
| + |
| + Bitmap largeIcon = Bitmap.createBitmap( |
| + largeIconWidthPx * 2, largeIconHeightPx * 2, Bitmap.Config.ALPHA_8); |
| + |
| + Bitmap fromLargeIcon = notificationBuilder.ensureNormalizedIcon(largeIcon, origin); |
| + assertNotNull(fromLargeIcon); |
| + assertEquals(largeIconWidthPx, fromLargeIcon.getWidth()); |
| + assertEquals(largeIconHeightPx, fromLargeIcon.getHeight()); |
| + |
| + Bitmap smallIcon = Bitmap.createBitmap( |
| + largeIconWidthPx / 2, largeIconHeightPx / 2, Bitmap.Config.ALPHA_8); |
| + |
| + Bitmap fromSmallIcon = notificationBuilder.ensureNormalizedIcon(smallIcon, origin); |
| + assertNotNull(fromSmallIcon); |
| + assertEquals(smallIcon, fromSmallIcon); |
| + } |
| +} |