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

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

Issue 1788873003: [Offline pages] Making offline page bridge testable by junit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing feedback Created 4 years, 9 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/offlinepages/OfflinePageBridge.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/offlinepages/OfflinePageBridgeTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridgeTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridgeTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..5f2d216b42bba747cd6683b453a1fe9995cae11b
--- /dev/null
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridgeTest.java
@@ -0,0 +1,73 @@
+// 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.offlinepages;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import org.chromium.base.BaseChromiumApplication;
+import org.chromium.base.test.util.Feature;
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+import java.util.Set;
+
+/**
+ * Unit tests for OfflinePageUtils.
+ */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE, application = BaseChromiumApplication.class)
+public class OfflinePageBridgeTest {
+ private OfflinePageBridge mBridge;
+
+ private static final String TEST_NAMESPACE = "TEST_NAMESPACE";
+ private static final String TEST_ID = "TEST_ID";
+
+ @Before
+ public void setUp() throws Exception {
+ OfflinePageBridge bridge = new OfflinePageBridge(0);
+ // Using the spy to automatically marshal all the calls to the original methods if they are
+ // not mocked explicitly.
+ mBridge = spy(bridge);
+ }
+
+ /**
+ * Tests OfflinePageBridge#getPageByClientId() method in a scenario where a model was loaded.
+ */
+ @Test
+ @Feature({"OfflinePages"})
+ public void testGetPageByClientId() {
+ doReturn(new long[] {123, 456})
+ .when(mBridge)
+ .nativeGetOfflineIdsForClientId(anyLong(), eq(TEST_NAMESPACE), eq(TEST_ID));
+
+ mBridge.offlinePageModelLoaded();
+
+ ClientId testClientId = new ClientId(TEST_NAMESPACE, TEST_ID);
+ Set<Long> result = mBridge.getOfflineIdsForClientId(testClientId);
+ assertEquals(2, result.size());
+ assertTrue(result.contains(123L));
+ assertTrue(result.contains(456L));
+ verify(mBridge, times(1))
+ .nativeGetOfflineIdsForClientId(anyLong(), anyString(), anyString());
+ }
+
+ @Test(expected = AssertionError.class)
+ @Feature({"OfflinePages"})
+ public void testGetPageByClientId_ModelNotLoaded() {
+ ClientId testClientId = new ClientId("TEST_NAMESPACE", "TEST_ID");
+ Set<Long> result = mBridge.getOfflineIdsForClientId(testClientId);
+ }
+}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridge.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698