Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge branch 'main' into update-as-93.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarik Eshaq authored May 9, 2022
2 parents a2be093 + 9667ab6 commit 99ab397
Show file tree
Hide file tree
Showing 44 changed files with 1,125 additions and 11 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Gecko.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Gecko {
/**
* GeckoView Version.
*/
const val version = "102.0.20220505094230"
const val version = "102.0.20220509094710"

/**
* GeckoView channel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Description for the button to accept the search suggestion and continue editing the search. -->
<string name="mozac_browser_awesomebar_edit_suggestion">تجویز کوں قبول کرو تے تبدیلی کرو</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.browser.engine.gecko.ext

import mozilla.components.concept.storage.Address
import org.mozilla.geckoview.Autocomplete

/**
* Converts a GeckoView [Autocomplete.Address] to an Android Components [Address].
*/
fun Autocomplete.Address.toAddress() = Address(
guid = guid ?: "",
givenName = givenName,
additionalName = additionalName,
familyName = familyName,
organization = organization,
streetAddress = streetAddress,
addressLevel3 = addressLevel3,
addressLevel2 = addressLevel2,
addressLevel1 = addressLevel1,
postalCode = postalCode,
country = country,
tel = tel,
email = email
)

/**
* Converts an Android Components [Address] to a GeckoView [Autocomplete.Address].
*/
fun Address.toAutocompleteAddress() = Autocomplete.Address.Builder()
.guid(guid)
.givenName(givenName)
.additionalName(additionalName)
.familyName(familyName)
.organization(organization)
.streetAddress(streetAddress)
.addressLevel3(addressLevel3)
.addressLevel2(addressLevel2)
.addressLevel1(addressLevel1)
.postalCode(postalCode)
.country(country)
.tel(tel)
.email(email)
.build()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.content.Context
import android.net.Uri
import androidx.annotation.VisibleForTesting
import mozilla.components.browser.engine.gecko.GeckoEngineSession
import mozilla.components.browser.engine.gecko.ext.toAddress
import mozilla.components.browser.engine.gecko.ext.toAutocompleteAddress
import mozilla.components.browser.engine.gecko.ext.toAutocompleteCreditCard
import mozilla.components.browser.engine.gecko.ext.toCreditCardEntry
import mozilla.components.browser.engine.gecko.ext.toLoginEntry
Expand All @@ -17,6 +19,7 @@ import mozilla.components.concept.engine.prompt.PromptRequest.MenuChoice
import mozilla.components.concept.engine.prompt.PromptRequest.MultipleChoice
import mozilla.components.concept.engine.prompt.PromptRequest.SingleChoice
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.concept.storage.Address
import mozilla.components.concept.storage.CreditCardEntry
import mozilla.components.concept.storage.Login
import mozilla.components.concept.storage.LoginEntry
Expand Down Expand Up @@ -224,6 +227,39 @@ internal class GeckoPromptDelegate(private val geckoEngineSession: GeckoEngineSe
return geckoResult
}

override fun onAddressSelect(
session: GeckoSession,
request: AutocompleteRequest<Autocomplete.AddressSelectOption>
): GeckoResult<PromptResponse> {
val geckoResult = GeckoResult<PromptResponse>()

val onConfirm: (Address) -> Unit = { address ->
if (!request.isComplete) {
geckoResult.complete(
request.confirm(
Autocomplete.AddressSelectOption(address.toAutocompleteAddress())
)
)
}
}

val onDismiss: () -> Unit = {
request.dismissSafely(geckoResult)
}

geckoEngineSession.notifyObservers {
onPromptRequest(
PromptRequest.SelectAddress(
addresses = request.options.map { it.value.toAddress() },
onConfirm = onConfirm,
onDismiss = onDismiss
)
)
}

return geckoResult
}

override fun onAlertPrompt(
session: GeckoSession,
prompt: PromptDelegate.AlertPrompt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import android.net.Uri
import android.os.Looper.getMainLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.browser.engine.gecko.GeckoEngineSession
import mozilla.components.browser.engine.gecko.ext.toAutocompleteAddress
import mozilla.components.browser.engine.gecko.ext.toAutocompleteCreditCard
import mozilla.components.browser.engine.gecko.ext.toLoginEntry
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.prompt.Choice
import mozilla.components.concept.engine.prompt.PromptRequest
import mozilla.components.concept.engine.prompt.PromptRequest.MultipleChoice
import mozilla.components.concept.engine.prompt.PromptRequest.SingleChoice
import mozilla.components.concept.storage.Address
import mozilla.components.concept.storage.CreditCardEntry
import mozilla.components.concept.storage.Login
import mozilla.components.concept.storage.LoginEntry
Expand Down Expand Up @@ -1436,6 +1438,96 @@ class GeckoPromptDelegateTest {
verify(geckoResult, never()).complete(any())
}

@Test
fun `WHEN onAddressSelect is called THEN SelectAddress prompt request must be provided with the correct callbacks`() {
val mockSession = GeckoEngineSession(runtime)

var isOnConfirmCalled = false
var isOnDismissCalled = false

var selectAddressPrompt: PromptRequest.SelectAddress = mock()

val promptDelegate = spy(GeckoPromptDelegate(mockSession))

// Capture the SelectAddress prompt request
mockSession.register(object : EngineSession.Observer {
override fun onPromptRequest(promptRequest: PromptRequest) {
selectAddressPrompt = promptRequest as PromptRequest.SelectAddress
}
})

val address = Address(
guid = "1",
givenName = "Firefox",
additionalName = "-",
familyName = "-",
organization = "-",
streetAddress = "street",
addressLevel3 = "address3",
addressLevel2 = "address2",
addressLevel1 = "address1",
postalCode = "1",
country = "Country",
tel = "1",
email = "@"
)
val addressSelectOption =
Autocomplete.AddressSelectOption(address.toAutocompleteAddress())

var geckoPrompt =
geckoSelectAddressPrompt(arrayOf(addressSelectOption))

var geckoResult = promptDelegate.onAddressSelect(
mock(),
geckoPrompt
)

// Verify that the onDismiss callback was called
geckoResult.accept {
isOnDismissCalled = true
}

selectAddressPrompt.onDismiss()
shadowOf(getMainLooper()).idle()
assertTrue(isOnDismissCalled)

// Verify that the onConfirm callback was called
geckoPrompt =
geckoSelectAddressPrompt(arrayOf(addressSelectOption))

geckoResult = promptDelegate.onAddressSelect(
mock(),
geckoPrompt
)

geckoResult.accept {
isOnConfirmCalled = true
}

selectAddressPrompt.onConfirm(selectAddressPrompt.addresses.first())
shadowOf(getMainLooper()).idle()
assertTrue(isOnConfirmCalled)

// Verify that when the prompt request is already completed and onConfirm callback is called,
// then onConfirm callback is not executed
isOnConfirmCalled = false
geckoPrompt =
geckoSelectAddressPrompt(arrayOf(addressSelectOption), true)

geckoResult = promptDelegate.onAddressSelect(
mock(),
geckoPrompt
)

geckoResult.accept {
isOnConfirmCalled = true
}

selectAddressPrompt.onConfirm(selectAddressPrompt.addresses.first())
shadowOf(getMainLooper()).idle()
assertFalse(isOnConfirmCalled)
}

private fun geckoChoicePrompt(
title: String,
message: String,
Expand Down Expand Up @@ -1595,4 +1687,15 @@ class GeckoPromptDelegateTest {
ReflectionUtils.setField(prompt, "options", creditCards)
return prompt
}

private fun geckoSelectAddressPrompt(
addresses: Array<Autocomplete.AddressSelectOption>,
isComplete: Boolean = false
): GeckoSession.PromptDelegate.AutocompleteRequest<Autocomplete.AddressSelectOption> {
val prompt: GeckoSession.PromptDelegate.AutocompleteRequest<Autocomplete.AddressSelectOption> =
mock()
whenever(prompt.isComplete).thenReturn(isComplete)
ReflectionUtils.setField(prompt, "options", addresses)
return prompt
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Text for the title of an alert dialog displayed by a web page. %1$s will be replaced with the URL of the current page (displaying the dialog). -->
<string name="mozac_browser_engine_system_alert_title">%1$s تے ورقہ آہدے:</string>
<!-- Text for the message of an auth dialog displayed by a web page.
%1$s will be replaced by the hostname or a description of the protected area/site, %2$s will be replaced with the URL of the current page (displaying the dialog). -->
<string name="mozac_browser_engine_system_auth_message">%2$s ورتݨ ناں تے پاسورڈ دی ارداس کریندا پئے۔ سائٹ آہدی ہے: “%1$s”</string>
<!-- Text for the message of an auth dialog displayed by a web page. %1$s will be replaced with the URL of the current page (displaying the dialog). -->
<string name="mozac_browser_engine_system_auth_no_realm_message">%1$s تہاݙے ورتݨ ناں تے پاسورڈ دی ارداس کریندا پئے۔</string>
</resources>
Loading

1 comment on commit 99ab397

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

Failed to fetch task artifact public/github/customCheckRunText.md for GitHub integration.
Make sure the artifact exists on the worker or other location.

Please sign in to comment.