Bug 1805616 - Expose datalist values in ColorPrompt. r=geckoview-reviewers,owlish,calu

Follow up bug 960984 for GeckoView.

Differential Revision: https://phabricator.services.mozilla.com/D164775
This commit is contained in:
Makoto Kato 2023-01-11 04:03:34 +00:00
Родитель 204bd3b7af
Коммит 5c9ad540a2
7 изменённых файлов: 71 добавлений и 3 удалений

Просмотреть файл

@ -25,6 +25,7 @@ class ColorPickerDelegate {
type: "color",
title: aTitle,
value: aInitialColor,
predefinedValues: aDefaultColors,
};
}

Просмотреть файл

@ -1363,9 +1363,10 @@ package org.mozilla.geckoview {
}
public static class GeckoSession.PromptDelegate.ColorPrompt extends GeckoSession.PromptDelegate.BasePrompt {
ctor protected ColorPrompt(@NonNull String, @Nullable String, @Nullable String, @NonNull GeckoSession.PromptDelegate.BasePrompt.Observer);
ctor protected ColorPrompt(@NonNull String, @Nullable String, @Nullable String, @Nullable String[], @NonNull GeckoSession.PromptDelegate.BasePrompt.Observer);
method @NonNull @UiThread public GeckoSession.PromptDelegate.PromptResponse confirm(@NonNull String);
field @Nullable public final String defaultValue;
field @Nullable public final String[] predefinedValues;
}
public static class GeckoSession.PromptDelegate.DateTimePrompt extends GeckoSession.PromptDelegate.BasePrompt {

Просмотреть файл

@ -22,5 +22,10 @@
<input type="color" id="colorexample" value="#ffffff" />
<input type="file" id="fileexample" accept="image/*,.pdf" capture="user" />
<datalist id="colorlist">
<option>#000000</option>
<option>#808080</option>
</datalist>
</body>
</html>

Просмотреть файл

@ -1,3 +1,7 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.geckoview.test
import androidx.test.ext.junit.runners.AndroidJUnit4
@ -578,6 +582,7 @@ class PromptDelegateTest : BaseSessionTest() {
@AssertCalled(count = 1)
override fun onColorPrompt(session: GeckoSession, prompt: PromptDelegate.ColorPrompt): GeckoResult<PromptDelegate.PromptResponse> {
assertThat("Value should match", "#ffffff", equalTo(prompt.defaultValue))
assertThat("Predefined values size", 0, equalTo(prompt.predefinedValues!!.size))
return GeckoResult.fromValue(prompt.confirm("#123456"))
}
})
@ -609,6 +614,49 @@ class PromptDelegateTest : BaseSessionTest() {
)
}
@Test fun colorTestWithDatalist() {
sessionRule.setPrefsUntilTestEnd(mapOf("dom.disable_open_during_load" to false))
mainSession.loadTestPath(PROMPT_HTML_PATH)
mainSession.waitForPageStop()
sessionRule.delegateDuringNextWait(object : PromptDelegate {
@AssertCalled(count = 1)
override fun onColorPrompt(session: GeckoSession, prompt: PromptDelegate.ColorPrompt): GeckoResult<PromptDelegate.PromptResponse> {
assertThat("Value should match", "#ffffff", equalTo(prompt.defaultValue))
assertThat("Predefined values size", 2, equalTo(prompt.predefinedValues!!.size))
assertThat("First predefined value", "#000000", equalTo(prompt.predefinedValues?.get(0)))
assertThat("Second predefined value", "#808080", equalTo(prompt.predefinedValues?.get(1)))
return GeckoResult.fromValue(prompt.confirm("#123456"))
}
})
mainSession.evaluateJS(
"""
this.c = document.getElementById('colorexample');
this.c.setAttribute('list', 'colorlist');
""".trimIndent()
)
val promise = mainSession.evaluatePromiseJS(
"""
new Promise((resolve, reject) => {
this.c.addEventListener(
'change',
event => resolve(event.target.value),
);
})
""".trimIndent()
)
mainSession.evaluateJS("this.c.click();")
assertThat(
"Value should match",
promise.value as String,
equalTo("#123456")
)
}
@WithDisplay(width = 100, height = 100)
@Test
fun dateTest() {

Просмотреть файл

@ -4680,13 +4680,18 @@ public class GeckoSession {
/** The default value supplied by content. */
public final @Nullable String defaultValue;
/** The predefined values by &lt;datalist&gt; element */
public final @Nullable String[] predefinedValues;
protected ColorPrompt(
@NonNull final String id,
@Nullable final String title,
@Nullable final String defaultValue,
@Nullable final String[] predefinedValues,
@NonNull final Observer observer) {
super(id, title, observer);
this.defaultValue = defaultValue;
this.predefinedValues = predefinedValues;
}
/**

Просмотреть файл

@ -295,7 +295,11 @@ import org.mozilla.geckoview.GeckoSession.PromptDelegate.TextPrompt;
@Override
public ColorPrompt newPrompt(final GeckoBundle info, final Observer observer) {
return new ColorPrompt(
info.getString("id"), info.getString("title"), info.getString("value"), observer);
info.getString("id"),
info.getString("title"),
info.getString("value"),
info.getStringArray("predefinedValues"),
observer);
}
@Override

Просмотреть файл

@ -20,6 +20,8 @@ exclude: true
- Added [`Autofill.Node.getScreenRect`][110.5] for fission compatible.
- ⚠️ Deprecated [`Autofill.Node.getDimensions`][110.6].
([bug 1803733]({{bugzilla}}1803733))
- Added [`ColorPrompt.predefinedValues`][110.7] to expose predefined values by [`datalist`][110.8] element in the color prompt.
([bug 1805616]({{bugzilla}}1805616))
[110.1]: {{javadoc_uri}}/GeckoSession.ContentDelegate.html#onCookieBannerDetected(org.mozilla.geckoview.GeckoSession)
[110.2]: {{javadoc_uri}}/GeckoSession.ContentDelegate.html#onCookieBannerHandled(org.mozilla.geckoview.GeckoSession)
@ -27,6 +29,8 @@ exclude: true
[110.4]: {{javadoc_uri}}/StorageController.html#setCookieBannerModeAndPersistInPrivateBrowsingForDomain(java.lang.String,int)
[110.5]: {{javadoc_uri}}/Autofill.Node.html#getScreenRect()
[110.6]: {{javadoc_uri}}/Autofill.Node.html#getDimensions()
[110.7]: {{javadoc_uri}}/GeckoSession.PromptDelegate.ColorPrompt.html#predefinedValues
[110.8]: https://developer.mozilla.org/en/docs/Web/HTML/Element/datalist
## v109
- Added [`SelectionActionDelegate.Selection.screenRect`][109.1] for fission compatible.
@ -1292,4 +1296,4 @@ to allow adding gecko profiler markers.
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport(android.content.Context,android.os.Bundle,java.lang.String)
[65.25]: {{javadoc_uri}}/GeckoResult.html
[api-version]: 83cff5df17e8f55a7f0faecbc0f0fa5c1c9555f0
[api-version]: a08a53cd6a57e5b698d1b74d82a7be789926754c