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

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

Issue 2162653003: Extract TitleUtil from NewTabPageView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Address bauerb's comments. Add unit test. Created 4 years, 5 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/junit/src/org/chromium/chrome/browser/ntp/OWNERS ('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/ntp/TitleUtilTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/TitleUtilTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/TitleUtilTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e27710a5f880d125fd5671225efdeafe2dcbb4f5
--- /dev/null
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/TitleUtilTest.java
@@ -0,0 +1,44 @@
+// 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.ntp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.testing.local.LocalRobolectricTestRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+/**
+ * Unit tests for TitleUtil.
+ */
+@RunWith(LocalRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class TitleUtilTest {
+ /**
+ * Tests for the getTitleForDisplay method.
+ */
+ @Test
+ @Feature({"Ntp"})
+ public void testGetTitleForDisplay() throws Exception {
+ // If the title is not null or empty it is simply returned.
+ assertEquals("title", TitleUtil.getTitleForDisplay("title", "https://example.com/path"));
+ assertEquals("title", TitleUtil.getTitleForDisplay("title", ""));
+ assertEquals("title", TitleUtil.getTitleForDisplay("title", null));
+
+ // If the url is null or empty the title is simply returned.
+ assertNull(TitleUtil.getTitleForDisplay(null, null));
+ assertEquals("", TitleUtil.getTitleForDisplay("", null));
+
+ // If the title is null or empty but not the url, a shortened form of the url is returned.
+ assertEquals("example.com/foo/bar",
+ TitleUtil.getTitleForDisplay(null, "https://example.com/foo/bar"));
+ assertEquals("example.com", TitleUtil.getTitleForDisplay(null, "https://example.com/"));
+ assertEquals("foo/bar", TitleUtil.getTitleForDisplay(null, "foo/bar"));
+ assertEquals("", TitleUtil.getTitleForDisplay(null, "/"));
+ }
+}
« no previous file with comments | « chrome/android/junit/src/org/chromium/chrome/browser/ntp/OWNERS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698