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

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

Issue 2568843003: Allow deferred intent when the screen is locked (Closed)
Patch Set: Allow deferred intent when the screen is locked Created 4 years 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
Index: chrome/android/junit/src/org/chromium/chrome/browser/IntentHandlerUnitTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/IntentHandlerUnitTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/IntentHandlerUnitTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..87e7bf5e13d973d77e118a5f24bd74349baf13b4
--- /dev/null
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/IntentHandlerUnitTest.java
@@ -0,0 +1,87 @@
+// 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;
+
+import static org.junit.Assert.assertTrue;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import org.robolectric.annotation.Config;
+
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+
+/**
+ * Unit tests for the IntentHandler class.
+ */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class IntentHandlerUnitTest {
+ private static final String TEST_URL = "http://test";
+
+ @Mock private IntentHandler mIntentHandlerMock;
+ @Mock private Context mContextMock;
+ @Mock private Intent mIntentMock;
+ @Mock private KeyguardBroadcastReceiver mKeyguardReceiverMock;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testRegisterKeyguardBroadcastReceiverOnDeferredIntent() {
+ doCallRealMethod().when(mIntentHandlerMock).shouldIgnoreIntent(mContextMock, mIntentMock);
+ when(mIntentHandlerMock.intentHasValidUrl(mIntentMock)).thenReturn(true);
+ when(mIntentHandlerMock.getUrlFromIntent(mIntentMock)).thenReturn(TEST_URL);
+ when(mIntentHandlerMock.isIntentUserVisible(mContextMock)).thenReturn(false);
+
+ assertTrue(mIntentHandlerMock.shouldIgnoreIntent(mContextMock, mIntentMock));
+ verify(mContextMock).registerReceiver(
+ any(KeyguardBroadcastReceiver.class), any(IntentFilter.class));
+ }
+
+ @Test
+ public void testUpdateDeferredIntent() {
+ doCallRealMethod().when(mIntentHandlerMock).shouldIgnoreIntent(mContextMock, mIntentMock);
+ doCallRealMethod().when(mIntentHandlerMock)
+ .setKeyguardBroadcastReceiverForTesting(mKeyguardReceiverMock);
+ when(mIntentHandlerMock.intentHasValidUrl(mIntentMock)).thenReturn(true);
+ when(mIntentHandlerMock.getUrlFromIntent(mIntentMock)).thenReturn(TEST_URL);
+ when(mIntentHandlerMock.isIntentUserVisible(mContextMock)).thenReturn(false);
+
+ mIntentHandlerMock.setKeyguardBroadcastReceiverForTesting(mKeyguardReceiverMock);
+ assertTrue(mIntentHandlerMock.shouldIgnoreIntent(mContextMock, mIntentMock));
+ verify(mContextMock, never()).registerReceiver(
+ any(KeyguardBroadcastReceiver.class), any(IntentFilter.class));
+ verify(mKeyguardReceiverMock).updateDeferredIntent(mIntentMock);
+ }
+
+ @Test
+ public void testUnregisterBroadcastReceiver() {
+ doCallRealMethod().when(mIntentHandlerMock)
+ .tryUnregisterLockscreenIntentReceiver(mContextMock, mIntentMock);
+ doCallRealMethod().when(mIntentHandlerMock)
+ .setKeyguardBroadcastReceiverForTesting(mKeyguardReceiverMock);
+
+ mIntentHandlerMock.setKeyguardBroadcastReceiverForTesting(mKeyguardReceiverMock);
+ mIntentHandlerMock.tryUnregisterLockscreenIntentReceiver(mContextMock, mIntentMock);
+ verify(mContextMock).unregisterReceiver(any(KeyguardBroadcastReceiver.class));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698