diff options
author | mvanouwerkerk <mvanouwerkerk@chromium.org> | 2016-01-15 03:15:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-15 11:17:01 +0000 |
commit | d45b6e9cb6f38e4132a171ed018674d4fd24f93d (patch) | |
tree | 5d7321454bdd6f6c0dae37e12c4b260759c6ab07 /chrome/android/junit | |
parent | ff895e295978e346b3003df6cffabf5cf1d69c5a (diff) | |
download | chromium_src-d45b6e9cb6f38e4132a171ed018674d4fd24f93d.zip chromium_src-d45b6e9cb6f38e4132a171ed018674d4fd24f93d.tar.gz chromium_src-d45b6e9cb6f38e4132a171ed018674d4fd24f93d.tar.bz2 |
Notifications: move instrumentation unit tests to simpler junit tests.
Review URL: https://codereview.chromium.org/1585233002
Cr-Commit-Position: refs/heads/master@{#369727}
Diffstat (limited to 'chrome/android/junit')
-rw-r--r-- | chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationUIManagerUnitTest.java | 84 | ||||
-rw-r--r-- | chrome/android/junit/src/org/chromium/chrome/browser/notifications/OWNERS | 1 |
2 files changed, 85 insertions, 0 deletions
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationUIManagerUnitTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationUIManagerUnitTest.java new file mode 100644 index 0000000..a957f48 --- /dev/null +++ b/chrome/android/junit/src/org/chromium/chrome/browser/notifications/NotificationUIManagerUnitTest.java @@ -0,0 +1,84 @@ +// Copyright 2016 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import android.app.Notification; + +import org.chromium.base.test.util.Feature; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +import java.util.Arrays; + +/** + * Unit tests for NotificationUIManager. + */ +@RunWith(BlockJUnit4ClassRunner.class) +public class NotificationUIManagerUnitTest { + /** + * Verifies that the getOriginFromTag method returns the origin for valid input, and null for + * invalid input. + */ + @Test + @Feature({"Browser", "Notifications"}) + public void testGetOriginFromTag() throws Exception { + // The common case. + assertEquals( + "https://example.com", NotificationUIManager.getOriginFromTag( + "NotificationUIManager;https://example.com;42")); + + // An tag that includes the separator. Probably a bit unusual, but valid. + assertEquals("https://example.com", NotificationUIManager.getOriginFromTag( + "NotificationUIManager;https://example.com;this;tag;contains;the;separator")); + + // Some invalid input. + assertNull(NotificationUIManager.getOriginFromTag("SystemDownloadNotifier")); + assertNull(NotificationUIManager.getOriginFromTag(null)); + assertNull(NotificationUIManager.getOriginFromTag("")); + assertNull(NotificationUIManager.getOriginFromTag(";")); + assertNull(NotificationUIManager.getOriginFromTag(";;;;;;;")); + assertNull(NotificationUIManager.getOriginFromTag( + "SystemDownloadNotifier;NotificationUIManager;42")); + assertNull(NotificationUIManager.getOriginFromTag( + "SystemDownloadNotifier;https://example.com;42")); + assertNull(NotificationUIManager.getOriginFromTag( + "NotificationUIManager;SystemDownloadNotifier;42")); + } + + /** + * Verifies that the makeDefaults method returns the generated notification defaults. + */ + @Test + @Feature({"Browser", "Notifications"}) + public void testMakeDefaults() throws Exception { + // 0 should be returned if silent is true and vibration's length is 0. + assertEquals(0, NotificationUIManager.makeDefaults(0, true)); + + // Notification.DEFAULT_ALL should be returned if silent is false and + // vibration's length is 0. + assertEquals(Notification.DEFAULT_ALL, NotificationUIManager.makeDefaults(0, false)); + + // Notification.DEFAULT_ALL & ~Notification.DEFAULT_VIBRATE should be returned + // if silent is false and vibration's length is greater than 0. + assertEquals(Notification.DEFAULT_ALL & ~Notification.DEFAULT_VIBRATE, + NotificationUIManager.makeDefaults(10, false)); + } + + /** + * Verifies that the makeVibrationPattern method returns vibration pattern used + * in Android notification. + */ + @Test + @Feature({"Browser", "Notifications"}) + public void testMakeVibrationPattern() throws Exception { + assertTrue(Arrays.equals(new long[] {0, 100, 200, 300}, + NotificationUIManager.makeVibrationPattern(new int[] {100, 200, 300}))); + } +} diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/notifications/OWNERS b/chrome/android/junit/src/org/chromium/chrome/browser/notifications/OWNERS new file mode 100644 index 0000000..83754a0 --- /dev/null +++ b/chrome/android/junit/src/org/chromium/chrome/browser/notifications/OWNERS @@ -0,0 +1 @@ +file://chrome/android/java/src/org/chromium/chrome/browser/notifications/OWNERS
\ No newline at end of file |