summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordfalcantara@chromium.org <dfalcantara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-23 23:48:19 +0000
committerdfalcantara@chromium.org <dfalcantara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-23 23:48:19 +0000
commitd1a668fa2871b243fe669f705aa060ea32e341aa (patch)
tree82d2780c1127c3843cf81220fda206568c84cdcb
parentdec6812fe9a78eb3473c89f9d203ee76ec80442c (diff)
downloadchromium_src-d1a668fa2871b243fe669f705aa060ea32e341aa.zip
chromium_src-d1a668fa2871b243fe669f705aa060ea32e341aa.tar.gz
chromium_src-d1a668fa2871b243fe669f705aa060ea32e341aa.tar.bz2
Change UrlUtilities.getOriginForDisplay()
* Make the function return the original URL instead of null. * Allow chopping off the scheme. NOTRY=true TEST=UrlUtilities BUG=276709 Review URL: https://chromiumcodereview.appspot.com/23922010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224836 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/UrlUtilities.java30
-rw-r--r--chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java28
2 files changed, 43 insertions, 15 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/UrlUtilities.java b/chrome/android/java/src/org/chromium/chrome/browser/UrlUtilities.java
index 8f16003..f8b93ee 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/UrlUtilities.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/UrlUtilities.java
@@ -112,21 +112,35 @@ public class UrlUtilities {
/**
* Builds a String that strips down the URL to the its scheme, host, and port.
* @param uri URI to break down.
- * @return Stripped-down String containing the essential bits of the URL, or null if we fail
- * to strip it down.
+ * @param showScheme Whether or not to show the scheme. If the URL can't be parsed, this value
+ * is ignored.
+ * @return Stripped-down String containing the essential bits of the URL, or the original URL if
+ * it fails to parse it.
*/
- public static String getOriginForDisplay(URI uri) {
+ public static String getOriginForDisplay(URI uri, boolean showScheme) {
String scheme = uri.getScheme();
String host = uri.getHost();
int port = uri.getPort();
- if (TextUtils.isEmpty(scheme) || TextUtils.isEmpty(host)) return null;
- if (port == -1 || (port == 80 && "http".equals(scheme))
- || (port == 443 && "https".equals(scheme))) {
- return scheme + "://" + host;
+ String displayUrl;
+ if (TextUtils.isEmpty(scheme) || TextUtils.isEmpty(host)) {
+ displayUrl = uri.toString();
} else {
- return scheme + "://" + host + ":" + port;
+ if (showScheme) {
+ scheme += "://";
+ } else {
+ scheme = "";
+ }
+
+ if (port == -1 || (port == 80 && "http".equals(scheme))
+ || (port == 443 && "https".equals(scheme))) {
+ displayUrl = scheme + host;
+ } else {
+ displayUrl = scheme + host + ":" + port;
+ }
}
+
+ return displayUrl;
}
/**
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java
index 00b899f..7ee5b80 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java
@@ -89,20 +89,34 @@ public class UrlUtilitiesTest extends InstrumentationTestCase {
@Feature({"Webapps"})
public void testGetOriginForDisplay() {
URI uri;
+
uri = URI.create("http://chopped.com/is/awesome");
- assertEquals("http://chopped.com", UrlUtilities.getOriginForDisplay(uri));
+ assertEquals("http://chopped.com", UrlUtilities.getOriginForDisplay(uri, true));
+ assertEquals("chopped.com", UrlUtilities.getOriginForDisplay(uri, false));
+
uri = URI.create("http://lopped.com");
- assertEquals("http://lopped.com", UrlUtilities.getOriginForDisplay(uri));
+ assertEquals("http://lopped.com", UrlUtilities.getOriginForDisplay(uri, true));
+ assertEquals("lopped.com", UrlUtilities.getOriginForDisplay(uri, false));
+
uri = URI.create("http://dropped.com?things");
- assertEquals("http://dropped.com", UrlUtilities.getOriginForDisplay(uri));
+ assertEquals("http://dropped.com", UrlUtilities.getOriginForDisplay(uri, true));
+ assertEquals("dropped.com", UrlUtilities.getOriginForDisplay(uri, false));
+
uri = URI.create("http://dfalcant@stopped.com:1234");
- assertEquals("http://stopped.com:1234", UrlUtilities.getOriginForDisplay(uri));
+ assertEquals("http://stopped.com:1234", UrlUtilities.getOriginForDisplay(uri, true));
+ assertEquals("stopped.com:1234", UrlUtilities.getOriginForDisplay(uri, false));
+
uri = URI.create("http://dfalcant:secret@stopped.com:9999");
- assertEquals("http://stopped.com:9999", UrlUtilities.getOriginForDisplay(uri));
+ assertEquals("http://stopped.com:9999", UrlUtilities.getOriginForDisplay(uri, true));
+ assertEquals("stopped.com:9999", UrlUtilities.getOriginForDisplay(uri, false));
+
uri = URI.create("chrome://settings:443");
- assertEquals("chrome://settings:443", UrlUtilities.getOriginForDisplay(uri));
+ assertEquals("chrome://settings:443", UrlUtilities.getOriginForDisplay(uri, true));
+ assertEquals("settings:443", UrlUtilities.getOriginForDisplay(uri, false));
+
uri = URI.create("about:blank");
- assertEquals(null, UrlUtilities.getOriginForDisplay(uri));
+ assertEquals("about:blank", UrlUtilities.getOriginForDisplay(uri, true));
+ assertEquals("about:blank", UrlUtilities.getOriginForDisplay(uri, false));
}
}