| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.util; | 5 package org.chromium.chrome.browser.util; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
| 8 | 8 |
| 9 import org.chromium.base.test.util.Feature; | |
| 10 import org.chromium.content.browser.test.NativeLibraryTestBase; | 9 import org.chromium.content.browser.test.NativeLibraryTestBase; |
| 11 | 10 |
| 12 import java.net.URI; | |
| 13 | |
| 14 /** Tests for {@link UrlUtilities}. */ | 11 /** Tests for {@link UrlUtilities}. */ |
| 15 public class UrlUtilitiesTest extends NativeLibraryTestBase { | 12 public class UrlUtilitiesTest extends NativeLibraryTestBase { |
| 16 | 13 |
| 17 @Override | 14 @Override |
| 18 public void setUp() throws Exception { | 15 public void setUp() throws Exception { |
| 19 super.setUp(); | 16 super.setUp(); |
| 20 loadNativeLibraryNoBrowserProcess(); | 17 loadNativeLibraryNoBrowserProcess(); |
| 21 } | 18 } |
| 22 | 19 |
| 23 @SmallTest | 20 @SmallTest |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 public void testIsValidForIntentFallbackUrl() { | 68 public void testIsValidForIntentFallbackUrl() { |
| 72 assertTrue(UrlUtilities.isValidForIntentFallbackNavigation( | 69 assertTrue(UrlUtilities.isValidForIntentFallbackNavigation( |
| 73 "https://user:pass@awesome.com:9000/bad-scheme:#fake:")); | 70 "https://user:pass@awesome.com:9000/bad-scheme:#fake:")); |
| 74 assertTrue(UrlUtilities.isValidForIntentFallbackNavigation("http://aweso
me.example.com/")); | 71 assertTrue(UrlUtilities.isValidForIntentFallbackNavigation("http://aweso
me.example.com/")); |
| 75 assertFalse(UrlUtilities.isValidForIntentFallbackNavigation("inline:skat
es.co.uk")); | 72 assertFalse(UrlUtilities.isValidForIntentFallbackNavigation("inline:skat
es.co.uk")); |
| 76 assertFalse(UrlUtilities.isValidForIntentFallbackNavigation("javascript:
alert(1)")); | 73 assertFalse(UrlUtilities.isValidForIntentFallbackNavigation("javascript:
alert(1)")); |
| 77 assertFalse(UrlUtilities.isValidForIntentFallbackNavigation("")); | 74 assertFalse(UrlUtilities.isValidForIntentFallbackNavigation("")); |
| 78 } | 75 } |
| 79 | 76 |
| 80 @SmallTest | 77 @SmallTest |
| 81 @Feature({"Webapps"}) | |
| 82 public void testFormatUrlForSecurityDisplay() { | |
| 83 URI uri; | |
| 84 | |
| 85 uri = URI.create("http://chopped.com/is/awesome"); | |
| 86 assertEquals("http://chopped.com", UrlUtilities.formatUrlForSecurityDisp
lay(uri, true)); | |
| 87 assertEquals("chopped.com", UrlUtilities.formatUrlForSecurityDisplay(uri
, false)); | |
| 88 | |
| 89 uri = URI.create("http://lopped.com"); | |
| 90 assertEquals("http://lopped.com", UrlUtilities.formatUrlForSecurityDispl
ay(uri, true)); | |
| 91 assertEquals("lopped.com", UrlUtilities.formatUrlForSecurityDisplay(uri,
false)); | |
| 92 | |
| 93 uri = URI.create("http://dropped.com?things"); | |
| 94 assertEquals("http://dropped.com", UrlUtilities.formatUrlForSecurityDisp
lay(uri, true)); | |
| 95 assertEquals("dropped.com", UrlUtilities.formatUrlForSecurityDisplay(uri
, false)); | |
| 96 | |
| 97 uri = URI.create("http://dfalcant@stopped.com:1234"); | |
| 98 assertEquals( | |
| 99 "http://stopped.com:1234", UrlUtilities.formatUrlForSecurityDisp
lay(uri, true)); | |
| 100 assertEquals("stopped.com:1234", UrlUtilities.formatUrlForSecurityDispla
y(uri, false)); | |
| 101 | |
| 102 uri = URI.create("http://dfalcant:secret@stopped.com:9999"); | |
| 103 assertEquals( | |
| 104 "http://stopped.com:9999", UrlUtilities.formatUrlForSecurityDisp
lay(uri, true)); | |
| 105 assertEquals("stopped.com:9999", UrlUtilities.formatUrlForSecurityDispla
y(uri, false)); | |
| 106 | |
| 107 uri = URI.create("chrome://settings:443"); | |
| 108 assertEquals("chrome://settings:443", UrlUtilities.formatUrlForSecurityD
isplay(uri, true)); | |
| 109 assertEquals("chrome://settings:443", UrlUtilities.formatUrlForSecurityD
isplay(uri, false)); | |
| 110 | |
| 111 uri = URI.create("about:blank"); | |
| 112 assertEquals("about:blank", UrlUtilities.formatUrlForSecurityDisplay(uri
, true)); | |
| 113 assertEquals("about:blank", UrlUtilities.formatUrlForSecurityDisplay(uri
, false)); | |
| 114 } | |
| 115 | |
| 116 @SmallTest | |
| 117 public void testValidateIntentUrl() { | 78 public void testValidateIntentUrl() { |
| 118 // Valid action, hostname, and (empty) path. | 79 // Valid action, hostname, and (empty) path. |
| 119 assertTrue(UrlUtilities.validateIntentUrl( | 80 assertTrue(UrlUtilities.validateIntentUrl( |
| 120 "intent://10010#Intent;scheme=tel;action=com.google.android.apps
." | 81 "intent://10010#Intent;scheme=tel;action=com.google.android.apps
." |
| 121 + "authenticator.AUTHENTICATE;end")); | 82 + "authenticator.AUTHENTICATE;end")); |
| 122 // Valid package, scheme, hostname, and path. | 83 // Valid package, scheme, hostname, and path. |
| 123 assertTrue(UrlUtilities.validateIntentUrl( | 84 assertTrue(UrlUtilities.validateIntentUrl( |
| 124 "intent://scan/#Intent;package=com.google.zxing.client.android;" | 85 "intent://scan/#Intent;package=com.google.zxing.client.android;" |
| 125 + "scheme=zxing;end;")); | 86 + "scheme=zxing;end;")); |
| 126 // Valid package, scheme, component, hostname, and path. | 87 // Valid package, scheme, component, hostname, and path. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 url + "#fragment", "http://example.com:443/path#fragment")); | 155 url + "#fragment", "http://example.com:443/path#fragment")); |
| 195 } | 156 } |
| 196 | 157 |
| 197 @SmallTest | 158 @SmallTest |
| 198 public void testUrlsFragmentsDiffer() { | 159 public void testUrlsFragmentsDiffer() { |
| 199 String url = "http://www.example.com/path"; | 160 String url = "http://www.example.com/path"; |
| 200 assertFalse(UrlUtilities.urlsFragmentsDiffer(url, url)); | 161 assertFalse(UrlUtilities.urlsFragmentsDiffer(url, url)); |
| 201 assertTrue(UrlUtilities.urlsFragmentsDiffer(url + "#fragment", url)); | 162 assertTrue(UrlUtilities.urlsFragmentsDiffer(url + "#fragment", url)); |
| 202 } | 163 } |
| 203 } | 164 } |
| OLD | NEW |