| 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.notifications; | 5 package org.chromium.chrome.browser.notifications; |
| 6 | 6 |
| 7 import android.app.Notification; | 7 import android.app.Notification; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.res.Resources; | 9 import android.content.res.Resources; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| 11 import android.support.test.InstrumentationRegistry; | 11 import android.support.test.InstrumentationRegistry; |
| 12 import android.support.test.filters.MediumTest; | 12 import android.support.test.filters.MediumTest; |
| 13 | 13 |
| 14 import org.junit.Assert; | 14 import org.junit.Assert; |
| 15 import org.junit.Before; | 15 import org.junit.Before; |
| 16 import org.junit.Rule; | 16 import org.junit.Rule; |
| 17 import org.junit.Test; | 17 import org.junit.Test; |
| 18 import org.junit.runner.RunWith; | 18 import org.junit.runner.RunWith; |
| 19 | 19 |
| 20 import org.chromium.base.test.BaseJUnit4ClassRunner; | 20 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 21 import org.chromium.base.test.util.Feature; | 21 import org.chromium.base.test.util.Feature; |
| 22 import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions; |
| 22 import org.chromium.chrome.browser.util.UrlUtilities; | 23 import org.chromium.chrome.browser.util.UrlUtilities; |
| 23 import org.chromium.chrome.browser.widget.RoundedIconGenerator; | 24 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
| 24 import org.chromium.content.browser.test.NativeLibraryTestRule; | 25 import org.chromium.content.browser.test.NativeLibraryTestRule; |
| 25 | 26 |
| 26 /** | 27 /** |
| 27 * Instrumentation unit tests for NotificationBuilderBase. | 28 * Instrumentation unit tests for NotificationBuilderBase. |
| 28 * | 29 * |
| 29 * Extends NativeLibraryTestBase so that {@link UrlUtilities#getDomainAndRegistr
y} can access | 30 * Extends NativeLibraryTestBase so that {@link UrlUtilities#getDomainAndRegistr
y} can access |
| 30 * native GetDomainAndRegistry, when called by {@link RoundedIconGenerator#getIc
onTextForUrl} during | 31 * native GetDomainAndRegistry, when called by {@link RoundedIconGenerator#getIc
onTextForUrl} during |
| 31 * testEnsureNormalizedIconBehavior(). | 32 * testEnsureNormalizedIconBehavior(). |
| (...skipping 26 matching lines...) Expand all Loading... |
| 58 .getApplicationContext(); | 59 .getApplicationContext(); |
| 59 Resources resources = appContext.getResources(); | 60 Resources resources = appContext.getResources(); |
| 60 | 61 |
| 61 int largeIconWidthPx = | 62 int largeIconWidthPx = |
| 62 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_width); | 63 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_width); |
| 63 int largeIconHeightPx = | 64 int largeIconHeightPx = |
| 64 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_height); | 65 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_height); |
| 65 | 66 |
| 66 String origin = "https://example.com"; | 67 String origin = "https://example.com"; |
| 67 | 68 |
| 68 NotificationBuilderBase notificationBuilder = new NotificationBuilderBas
e(resources) { | 69 NotificationBuilderBase notificationBuilder = new NotificationBuilderBas
e( |
| 70 resources, ChannelDefinitions.CHANNEL_ID_SITES) { |
| 69 @Override | 71 @Override |
| 70 public Notification build() { | 72 public Notification build() { |
| 71 return null; | 73 return null; |
| 72 } | 74 } |
| 73 }; | 75 }; |
| 74 Bitmap fromNullIcon = notificationBuilder.ensureNormalizedIcon(null, ori
gin); | 76 Bitmap fromNullIcon = notificationBuilder.ensureNormalizedIcon(null, ori
gin); |
| 75 Assert.assertNotNull(fromNullIcon); | 77 Assert.assertNotNull(fromNullIcon); |
| 76 Assert.assertEquals(largeIconWidthPx, fromNullIcon.getWidth()); | 78 Assert.assertEquals(largeIconWidthPx, fromNullIcon.getWidth()); |
| 77 Assert.assertEquals(largeIconHeightPx, fromNullIcon.getHeight()); | 79 Assert.assertEquals(largeIconHeightPx, fromNullIcon.getHeight()); |
| 78 | 80 |
| 79 Bitmap largeIcon = Bitmap.createBitmap( | 81 Bitmap largeIcon = Bitmap.createBitmap( |
| 80 largeIconWidthPx * 2, largeIconHeightPx * 2, Bitmap.Config.ALPHA
_8); | 82 largeIconWidthPx * 2, largeIconHeightPx * 2, Bitmap.Config.ALPHA
_8); |
| 81 | 83 |
| 82 Bitmap fromLargeIcon = notificationBuilder.ensureNormalizedIcon(largeIco
n, origin); | 84 Bitmap fromLargeIcon = notificationBuilder.ensureNormalizedIcon(largeIco
n, origin); |
| 83 Assert.assertNotNull(fromLargeIcon); | 85 Assert.assertNotNull(fromLargeIcon); |
| 84 Assert.assertEquals(largeIconWidthPx, fromLargeIcon.getWidth()); | 86 Assert.assertEquals(largeIconWidthPx, fromLargeIcon.getWidth()); |
| 85 Assert.assertEquals(largeIconHeightPx, fromLargeIcon.getHeight()); | 87 Assert.assertEquals(largeIconHeightPx, fromLargeIcon.getHeight()); |
| 86 | 88 |
| 87 Bitmap smallIcon = Bitmap.createBitmap( | 89 Bitmap smallIcon = Bitmap.createBitmap( |
| 88 largeIconWidthPx / 2, largeIconHeightPx / 2, Bitmap.Config.ALPHA
_8); | 90 largeIconWidthPx / 2, largeIconHeightPx / 2, Bitmap.Config.ALPHA
_8); |
| 89 | 91 |
| 90 Bitmap fromSmallIcon = notificationBuilder.ensureNormalizedIcon(smallIco
n, origin); | 92 Bitmap fromSmallIcon = notificationBuilder.ensureNormalizedIcon(smallIco
n, origin); |
| 91 Assert.assertNotNull(fromSmallIcon); | 93 Assert.assertNotNull(fromSmallIcon); |
| 92 Assert.assertEquals(smallIcon, fromSmallIcon); | 94 Assert.assertEquals(smallIcon, fromSmallIcon); |
| 93 } | 95 } |
| 94 } | 96 } |
| OLD | NEW |