Commit 8dee606f authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Fix omnibox scroll handling for data: URIs.

BUG=966393

Change-Id: If8e1a066d327f32f7922cd7694a296ff7e2e3b9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635203
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664401}
parent 8081952c
......@@ -145,6 +145,7 @@ chrome_junit_test_java_sources = [
"junit/src/org/chromium/chrome/browser/omnibox/AutocompleteStateUnitTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/KeyboardHideHelperUnitTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/SpannableAutocompleteEditTextModelUnitTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/UrlBarDataTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/UrlBarMediatorUnitTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeaderUnitTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/geo/PlatformNetworksManagerTest.java",
......
......@@ -78,7 +78,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
}
// Do not scroll to the end of the host for URLs such as data:, javascript:, etc...
if (data.url != null && data.originEndIndex == data.url.length()) {
if (data.url != null && data.originEndIndex == data.displayText.length()) {
Uri uri = Uri.parse(data.url);
String scheme = uri.getScheme();
if (!TextUtils.isEmpty(scheme)
......
// Copyright 2019 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.omnibox;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.chromium.base.test.BaseRobolectricTestRunner;
/**
* Unit tests for {@link UrlBarData}.
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class UrlBarDataTest {
@Test
public void forUrlAndText_nonHttpOrHttps() {
UrlBarData data =
UrlBarData.forUrlAndText("data:text/html,blah,blah", "data:text/html,blah", "BLAH");
Assert.assertEquals("data:text/html,blah,blah", data.url);
Assert.assertEquals("data:text/html,blah", 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(data.displayText.length(), data.originEndIndex);
}
}
......@@ -22,6 +22,9 @@ import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyObservable.PropertyObserver;
/**
* Unit tests for {@link UrlBarMediator}.
*/
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class UrlBarMediatorUnitTest {
......@@ -78,6 +81,22 @@ public class UrlBarMediatorUnitTest {
Mockito.verifyZeroInteractions(observer);
}
@Test
public void setUrlData_ScrollStateForNonHttpOrHttps() {
PropertyModel model = new PropertyModel(UrlBarProperties.ALL_KEYS);
UrlBarMediator mediator = new UrlBarMediator(model);
String displayText = "data:text/html,blah";
UrlBarData data = UrlBarData.create(
"data:text/html,blah,blah", 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