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

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java

Issue 2396063002: Add Notification images (Android pre-N standard layout) (Closed)
Patch Set: Add test and move comment Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java
index 338a684073520811cdcc25fedf6f24e1e3b87767..2bb84bc738b82baaae2d6c1911180f051f70f20d 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java
@@ -5,23 +5,80 @@
package org.chromium.chrome.browser.notifications;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import android.app.Notification;
+import android.os.Build;
-import org.chromium.base.test.util.Feature;
+import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.junit.runners.BlockJUnit4ClassRunner;
+
+import org.robolectric.annotation.Config;
+
+import org.chromium.base.CommandLine;
+import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.ChromeSwitches;
+import org.chromium.testing.local.LocalRobolectricTestRunner;
import java.util.Arrays;
/**
* Unit tests for NotificationPlatformBridge.
*/
-@RunWith(BlockJUnit4ClassRunner.class)
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
public class NotificationPlatformBridgeUnitTest {
+ @After
+ public void tearDown() {
+ // Clean up static state for subsequent tests.
+ CommandLine.reset();
+ }
+
+ @Test
+ @Feature({"Browser", "Notifications"})
+ public void testUseCustomLayouts() {
+ CommandLine.init(null);
+ CommandLine.getInstance().appendSwitch(
+ ChromeSwitches.ENABLE_WEB_NOTIFICATION_CUSTOM_LAYOUTS);
+ assertTrue(NotificationPlatformBridge.useCustomLayouts(false /* hasImage */));
+ assertTrue(NotificationPlatformBridge.useCustomLayouts(true /* hasImage */));
+ CommandLine.reset();
+
+ CommandLine.init(null);
+ CommandLine.getInstance().appendSwitch(
+ ChromeSwitches.DISABLE_WEB_NOTIFICATION_CUSTOM_LAYOUTS);
+ assertFalse(NotificationPlatformBridge.useCustomLayouts(false /* hasImage */));
+ assertFalse(NotificationPlatformBridge.useCustomLayouts(true /* hasImage */));
+ CommandLine.reset();
+
+ // Enable flag takes precedence over disable flag (arbitrarily).
+ CommandLine.init(null);
+ CommandLine.getInstance().appendSwitch(
+ ChromeSwitches.ENABLE_WEB_NOTIFICATION_CUSTOM_LAYOUTS);
+ CommandLine.getInstance().appendSwitch(
+ ChromeSwitches.DISABLE_WEB_NOTIFICATION_CUSTOM_LAYOUTS);
+ assertTrue(NotificationPlatformBridge.useCustomLayouts(false /* hasImage */));
+ assertTrue(NotificationPlatformBridge.useCustomLayouts(true /* hasImage */));
+ CommandLine.reset();
+
+ CommandLine.init(null);
+ boolean isNougatOrNewer = Build.VERSION.CODENAME.equals("N")
+ || Build.VERSION.SDK_INT > 23 /* Build.VERSION_CODES.M */;
+ if (isNougatOrNewer) {
+ // Without comand line flags, custom layouts are always disabled on Nougat+.
+ assertFalse(NotificationPlatformBridge.useCustomLayouts(false /* hasImage */));
+ assertFalse(NotificationPlatformBridge.useCustomLayouts(true /* hasImage */));
+ } else {
+ // On older versions of Android, custom layouts are enabled unless an image is provided.
+ assertTrue(NotificationPlatformBridge.useCustomLayouts(false /* hasImage */));
+ assertFalse(NotificationPlatformBridge.useCustomLayouts(true /* hasImage */));
+ }
+ CommandLine.reset();
+ }
+
/**
* Verifies that the getOriginFromTag method returns the origin for valid input, and null for
* invalid input.
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698