Commit 706a9dd9 authored by fgorski's avatar fgorski Committed by Commit bot

[Offline pages] Fixing client ID from bookmark generation

Adding a check for a null bookmark ID and tests.

BUG=594896
TBR=nyquist@chromium.org

Review URL: https://codereview.chromium.org/1804213002

Cr-Commit-Position: refs/heads/master@{#381597}
parent ea80a420
...@@ -279,6 +279,7 @@ junit_binary("chrome_junit_tests") { ...@@ -279,6 +279,7 @@ junit_binary("chrome_junit_tests") {
"junit/src/org/chromium/chrome/browser/media/router/cast/TestUtils.java", "junit/src/org/chromium/chrome/browser/media/router/cast/TestUtils.java",
"junit/src/org/chromium/chrome/browser/notifications/NotificationUIManagerUnitTest.java", "junit/src/org/chromium/chrome/browser/notifications/NotificationUIManagerUnitTest.java",
"junit/src/org/chromium/chrome/browser/ntp/NativePageFactoryTest.java", "junit/src/org/chromium/chrome/browser/ntp/NativePageFactoryTest.java",
"junit/src/org/chromium/chrome/browser/offlinepages/ClientIdTest.java",
"junit/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridgeTest.java", "junit/src/org/chromium/chrome/browser/offlinepages/OfflinePageBridgeTest.java",
"junit/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java", "junit/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java",
"junit/src/org/chromium/chrome/browser/omaha/ResponseParserTest.java", "junit/src/org/chromium/chrome/browser/omaha/ResponseParserTest.java",
......
...@@ -46,6 +46,7 @@ public class ClientId { ...@@ -46,6 +46,7 @@ public class ClientId {
* @return A {@link ClientId} that represents this BookmarkId. * @return A {@link ClientId} that represents this BookmarkId.
*/ */
public static ClientId createClientIdForBookmarkId(BookmarkId id) { public static ClientId createClientIdForBookmarkId(BookmarkId id) {
if (id == null) return null;
return new ClientId(OfflinePageBridge.BOOKMARK_NAMESPACE, id.toString()); return new ClientId(OfflinePageBridge.BOOKMARK_NAMESPACE, id.toString());
} }
} }
// 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.assertNotNull;
import static org.junit.Assert.assertNull;
import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.test.util.Feature;
import org.chromium.components.bookmarks.BookmarkId;
import org.chromium.components.bookmarks.BookmarkType;
import org.chromium.testing.local.LocalRobolectricTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
/**
* Unit tests for ClientId.
*/
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE, application = BaseChromiumApplication.class)
public class ClientIdTest {
private static final long INVALID_BOOKMARK_ID = -1;
private static final long TEST_BOOKMARK_ID = 42;
private static final String TEST_NAMESPACE = "TEST_NAMESPACE";
private static final String TEST_ID = "TEST_ID";
/**
* Tests ClientId#createClientIdForBookmarkId() method in cases with valid, invalid and null
* bookmark ID.
*/
@Test
@Feature({"OfflinePages"})
public void testCreateClientIdForBookmarkId() {
ClientId clientId = ClientId.createClientIdForBookmarkId(
new BookmarkId(TEST_BOOKMARK_ID, BookmarkType.NORMAL));
assertNotNull(clientId);
assertEquals(OfflinePageBridge.BOOKMARK_NAMESPACE, clientId.getNamespace());
assertEquals(Long.toString(TEST_BOOKMARK_ID), clientId.getId());
clientId = ClientId.createClientIdForBookmarkId(
new BookmarkId(INVALID_BOOKMARK_ID, BookmarkType.NORMAL));
assertNotNull(clientId);
assertEquals(OfflinePageBridge.BOOKMARK_NAMESPACE, clientId.getNamespace());
assertEquals(Long.toString(INVALID_BOOKMARK_ID), clientId.getId());
clientId = ClientId.createClientIdForBookmarkId(null);
assertNull(clientId);
}
/**
* Ensure that ClientId works properly.
*/
@Test
@Feature({"OfflinePages"})
public void testClientIdConstructor() {
ClientId clientId = new ClientId(TEST_NAMESPACE, TEST_ID);
assertEquals(TEST_NAMESPACE, clientId.getNamespace());
assertEquals(TEST_ID, clientId.getId());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment