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

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

Issue 2568843003: Allow deferred intent when the screen is locked (Closed)
Patch Set: Allow deferred 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
« no previous file with comments | « chrome/android/java_sources.gni ('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/DelayedScreenLockIntentHandlerTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/DelayedScreenLockIntentHandlerTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/DelayedScreenLockIntentHandlerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..8f0b91946997ceef3fa3ca0d7f3afd4cc1e7686b
--- /dev/null
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/DelayedScreenLockIntentHandlerTest.java
@@ -0,0 +1,100 @@
+// 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.mockito.Mockito.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+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.base.ContextUtils;
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+
+/**
+ * Unit tests for the DelayedScreenLockIntentHandlerTest class.
+ */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class DelayedScreenLockIntentHandlerTest {
+ @Mock private Context mContextMock;
+
+ private DelayedScreenLockIntentHandler mIntentHandler;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mIntentHandler = new DelayedScreenLockIntentHandler();
+ ContextUtils.initApplicationContextForTests(mContextMock);
+ }
+
+ @Test
+ public void testReceiveBroadcast() {
+ final Intent deferredIntent = new Intent();
+ final Intent intent = new Intent(Intent.ACTION_USER_PRESENT);
+
+ mIntentHandler.updateDeferredIntent(deferredIntent);
+ mIntentHandler.onReceive(mContextMock, intent);
+
+ verify(mContextMock).registerReceiver(eq(mIntentHandler), any(IntentFilter.class));
+ verify(mContextMock).startActivity(deferredIntent);
+ verify(mContextMock).unregisterReceiver(mIntentHandler);
+ }
+
+ @Test
+ public void testReceiveBroadcastTwice() {
+ final Intent deferredIntent = new Intent();
+ final Intent intent = new Intent(Intent.ACTION_USER_PRESENT);
+
+ mIntentHandler.updateDeferredIntent(deferredIntent);
+ mIntentHandler.onReceive(mContextMock, intent);
+ mIntentHandler.onReceive(mContextMock, intent);
+
+ verify(mContextMock).registerReceiver(eq(mIntentHandler), any(IntentFilter.class));
+ verify(mContextMock).startActivity(deferredIntent);
+ verify(mContextMock).unregisterReceiver(mIntentHandler);
+ }
+
+ @Test
+ public void testSecondDeferredIntentAction() {
+ final Intent deferredIntent1 = new Intent();
+ final Intent deferredIntent2 = new Intent();
+ final Intent intent = new Intent(Intent.ACTION_USER_PRESENT);
+
+ mIntentHandler.updateDeferredIntent(deferredIntent1);
+ mIntentHandler.updateDeferredIntent(deferredIntent2);
+ mIntentHandler.onReceive(mContextMock, intent);
+
+ verify(mContextMock).registerReceiver(eq(mIntentHandler), any(IntentFilter.class));
+ verify(mContextMock).startActivity(deferredIntent2);
+ verify(mContextMock).unregisterReceiver(mIntentHandler);
+ }
+
+ @Test
+ public void testNonExpectedIntentAction() {
+ mIntentHandler.updateDeferredIntent(new Intent());
+ try {
+ mIntentHandler.onReceive(mContextMock, new Intent());
+ } catch (AssertionError assertError) {
+ // Ignore AssertErrors
+ }
+
+ verify(mContextMock).registerReceiver(eq(mIntentHandler), any(IntentFilter.class));
+ verify(mContextMock, never()).startActivity(any(Intent.class));
+ verify(mContextMock, never()).unregisterReceiver(mIntentHandler);
+ }
+}
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698