Commit cb2479d0 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Fix URL bar scrolling logic for about: URLs.

BUG=992838

Change-Id: Idc6ab38c6f40224188312f9f6804857fcf48828f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757299
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarEnder <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#688290}
parent 466e43ed
......@@ -26,8 +26,9 @@ public class UrlBarData {
* The URL schemes that should be displayed complete with path.
*/
public static final HashSet<String> UNSUPPORTED_SCHEMES_TO_SPLIT =
CollectionUtil.newHashSet(UrlConstants.FILE_SCHEME, UrlConstants.JAVASCRIPT_SCHEME,
UrlConstants.DATA_SCHEME, UrlConstants.CONTENT_SCHEME);
CollectionUtil.newHashSet(ContentUrlConstants.ABOUT_SCHEME, UrlConstants.DATA_SCHEME,
UrlConstants.FILE_SCHEME, UrlConstants.FTP_SCHEME, UrlConstants.INLINE_SCHEME,
UrlConstants.JAVASCRIPT_SCHEME, UrlConstants.CHROME_SCHEME);
/**
* URI schemes that ContentView can handle.
*
......
......@@ -9,7 +9,6 @@ import static org.chromium.chrome.test.util.OmniboxTestUtils.buildSuggestionMap;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
......@@ -724,58 +723,6 @@ public class OmniboxTest {
}
}
// TODO(bauerb): Move this to a Robolectric test.
@Test
@SmallTest
@SkipCommandLineParameterization
public void testOriginSpan() {
verifyOriginSpan("", null, "");
verifyOriginSpan("https:", null, "https:");
verifyOriginSpan("about:blank", null, "about:blank");
verifyOriginSpan("chrome://flags", null, "chrome://flags");
verifyOriginSpan("chrome://flags", "/?egads", "chrome://flags/?egads");
verifyOriginSpan("www.google.com", null, "www.google.com");
verifyOriginSpan("www.google.com", null, "www.google.com/");
verifyOriginSpan("www.google.com", "/?q=blah", "www.google.com/?q=blah");
verifyOriginSpan("https://www.google.com", null, "https://www.google.com");
verifyOriginSpan("https://www.google.com", null, "https://www.google.com/");
verifyOriginSpan("https://www.google.com", "/?q=blah", "https://www.google.com/?q=blah");
// crbug.com/414990
String testUrl = "https://disneyworld.disney.go.com/special-offers/"
+ "?CMP=KNC-WDW_FY15_DOM_Q1RO_BR_Gold_SpOffer|G|4141300.RR.AM.01.47"
+ "&keyword_id=s6JyxRifG_dm|walt%20disney%20world|37174067873|e|1540wwa14043";
verifyOriginSpan("https://disneyworld.disney.go.com",
"/special-offers/?CMP=KNC-WDW_FY15_DOM_Q1RO_BR_Gold_SpOffer|G|4141300.RR.AM.01.47"
+ "&keyword_id=s6JyxRifG_dm|walt%20disney%20world|37174067873|e|"
+ "1540wwa14043",
testUrl);
// crbug.com/415387
verifyOriginSpan("ftp://example.com", "/ftp.html", "ftp://example.com/ftp.html");
// crbug.com/447416
verifyOriginSpan("file:///dev/blah", null, "file:///dev/blah");
verifyOriginSpan(
"javascript:window.alert('hello');", null, "javascript:window.alert('hello');");
verifyOriginSpan("data:text/html;charset=utf-8,Page%201", null,
"data:text/html;charset=utf-8,Page%201");
}
private void verifyOriginSpan(
String expectedOrigin, @Nullable String expectedOriginSuffix, String url) {
UrlBarData urlBarData = UrlBarData.forUrl(url);
String displayText = urlBarData.displayText.toString();
Assert.assertEquals(expectedOriginSuffix == null ? expectedOrigin
: expectedOrigin + expectedOriginSuffix,
displayText);
Assert.assertEquals(expectedOrigin,
displayText.substring(urlBarData.originStartIndex, urlBarData.originEndIndex));
}
@Test
@MediumTest
@Feature({"Omnibox"})
......
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.omnibox;
import android.support.annotation.Nullable;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -18,7 +20,7 @@ import org.chromium.base.test.BaseRobolectricTestRunner;
@Config(manifest = Config.NONE)
public class UrlBarDataTest {
@Test
public void forUrlAndText_nonHttpOrHttps() {
public void forUrlAndText_nonHttpOrHttps_DisplayTextDiffersFromUrl() {
UrlBarData data =
UrlBarData.forUrlAndText("data:text/html,blah,blah", "data:text/html,blah", "BLAH");
Assert.assertEquals("data:text/html,blah,blah", data.url);
......@@ -27,4 +29,76 @@ public class UrlBarDataTest {
// Ensure that the end index is the length of the display text and not the URL.
Assert.assertEquals(data.displayText.length(), data.originEndIndex);
}
@Test
public void forUrlAndText_aboutUri_NoSlashes() {
final String aboutUrl = "about:blank#verylongurl.totallylegit.notsuspicious.url.com";
UrlBarData data = UrlBarData.forUrlAndText(aboutUrl, aboutUrl);
Assert.assertEquals(aboutUrl, data.url);
Assert.assertEquals(aboutUrl, data.displayText);
Assert.assertEquals(0, data.originStartIndex);
// Ensure that the end index is the length of the display text and not the URL.
Assert.assertEquals(aboutUrl.length(), data.originEndIndex);
}
@Test
public void forUrlAndText_aboutUri_WithSlashes() {
final String aboutUrl = "about://blank#verylongurl.totallylegit.notsuspicious.url.com";
UrlBarData data = UrlBarData.forUrlAndText(aboutUrl, aboutUrl);
Assert.assertEquals(aboutUrl, data.url);
Assert.assertEquals(aboutUrl, data.displayText);
Assert.assertEquals(0, data.originStartIndex);
// Ensure that the end index is the length of the display text and not the URL.
Assert.assertEquals(aboutUrl.length(), data.originEndIndex);
}
@Test
public void originSpans() {
verifyOriginSpan("", null, "");
verifyOriginSpan("https:", null, "https:");
verifyOriginSpan("about:blank", null, "about:blank");
verifyOriginSpan("chrome://flags", null, "chrome://flags");
verifyOriginSpan("chrome://flags/?egads", null, "chrome://flags/?egads");
verifyOriginSpan("www.google.com", null, "www.google.com");
verifyOriginSpan("www.google.com", null, "www.google.com/");
verifyOriginSpan("www.google.com", "/?q=blah", "www.google.com/?q=blah");
verifyOriginSpan("https://www.google.com", null, "https://www.google.com");
verifyOriginSpan("https://www.google.com", null, "https://www.google.com/");
verifyOriginSpan("https://www.google.com", "/?q=blah", "https://www.google.com/?q=blah");
// crbug.com/414990
String testUrl = "https://disneyworld.disney.go.com/special-offers/"
+ "?CMP=KNC-WDW_FY15_DOM_Q1RO_BR_Gold_SpOffer|G|4141300.RR.AM.01.47"
+ "&keyword_id=s6JyxRifG_dm|walt%20disney%20world|37174067873|e|1540wwa14043";
verifyOriginSpan("https://disneyworld.disney.go.com",
"/special-offers/?CMP=KNC-WDW_FY15_DOM_Q1RO_BR_Gold_SpOffer|G|4141300.RR.AM.01.47"
+ "&keyword_id=s6JyxRifG_dm|walt%20disney%20world|37174067873|e|"
+ "1540wwa14043",
testUrl);
// crbug.com/415387
verifyOriginSpan("ftp://example.com/ftp.html", null, "ftp://example.com/ftp.html");
// crbug.com/447416
verifyOriginSpan("file:///dev/blah", null, "file:///dev/blah");
verifyOriginSpan(
"javascript:window.alert('hello');", null, "javascript:window.alert('hello');");
verifyOriginSpan("data:text/html;charset=utf-8,Page%201", null,
"data:text/html;charset=utf-8,Page%201");
}
private void verifyOriginSpan(
String expectedOrigin, @Nullable String expectedOriginSuffix, String url) {
UrlBarData urlBarData = UrlBarData.forUrl(url);
String displayText = urlBarData.displayText.toString();
Assert.assertEquals(expectedOriginSuffix == null ? expectedOrigin
: expectedOrigin + expectedOriginSuffix,
displayText);
Assert.assertEquals("Origina start index, end index did not generate expected origin",
expectedOrigin,
displayText.substring(urlBarData.originStartIndex, urlBarData.originEndIndex));
}
}
......@@ -82,7 +82,7 @@ public class UrlBarMediatorUnitTest {
}
@Test
public void setUrlData_ScrollStateForNonHttpOrHttps() {
public void setUrlData_ScrollStateForDataUrl() {
PropertyModel model = new PropertyModel(UrlBarProperties.ALL_KEYS);
UrlBarMediator mediator = new UrlBarMediator(model);
......@@ -97,6 +97,22 @@ public class UrlBarMediatorUnitTest {
model.get(UrlBarProperties.TEXT_STATE).scrollType);
}
@Test
public void setUrlData_ScrollStateForAboutUrl() {
PropertyModel model = new PropertyModel(UrlBarProperties.ALL_KEYS);
UrlBarMediator mediator = new UrlBarMediator(model);
String displayText = "about:blank#verylongurl.totallylegit.notsuspicious.url.com";
UrlBarData data = UrlBarData.create(
displayText, spannable(displayText), 0, displayText.length(), null);
Assert.assertTrue(mediator.setUrlBarData(data, UrlBar.ScrollType.SCROLL_TO_TLD,
UrlBarCoordinator.SelectionState.SELECT_ALL));
// The scroll state should be overridden to SCROLL_TO_BEGINNING for file-type schemes.
Assert.assertEquals(UrlBar.ScrollType.SCROLL_TO_BEGINNING,
model.get(UrlBarProperties.TEXT_STATE).scrollType);
}
@Test
public void urlDataComparison_equals() {
Assert.assertTrue(UrlBarMediator.isNewTextEquivalentToExistingText(null, null));
......
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