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

Issue #9838: Introduce CreditCardValidationDelegate and implement onCreditCardSave in GeckoCreditCardsAddressesStorageDelegate #9875

Closed
wants to merge 507 commits into from

Conversation

gabrielluong
Copy link
Member

@gabrielluong gabrielluong commented Mar 11, 2021

Fixes #9838

  • Introduces CreditCardValidationDelegate and a default implementation in DefaultCreditCardValidationDelegate
  • Adds a wipeLocal() to CreditCardsAddressesStorage to clear out local state in between tests
  • Implements onCreditCardSave in GeckoCreditCardsAddressesStorageDelegate

Pull Request checklist

  • Quality: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry or does not need one
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features

After merge

  • Milestone: Make sure issues closed by this pull request are added to the milestone of the version currently in development.
  • Breaking Changes: If this is a breaking change, please push a draft PR on Reference Browser to address the breaking issues.

@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #9875 (719b601) into main (57e8d7b) will decrease coverage by 7.47%.
The diff coverage is 26.53%.

❗ Current head 719b601 differs from pull request most recent head b8be7e9. Consider uploading reports for the commit b8be7e9 to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##               main    #9875      +/-   ##
============================================
- Coverage     74.15%   66.67%   -7.48%     
+ Complexity     6240      768    -5472     
============================================
  Files           835      119     -716     
  Lines         31562     3712   -27850     
  Branches       5268      590    -4678     
============================================
- Hits          23405     2475   -20930     
+ Misses         5465      903    -4562     
+ Partials       2692      334    -2358     
Impacted Files Coverage Δ
...tofill/GeckoCreditCardsAddressesStorageDelegate.kt 5.88% <0.00%> (ø)
.../mozilla/components/service/sync/autofill/Types.kt 71.64% <0.00%> (ø)
...nc/autofill/AutofillCreditCardsAddressesStorage.kt 64.00% <75.00%> (ø)
...nc/autofill/DefaultCreditCardValidationDelegate.kt 77.77% <77.77%> (ø)
...eature/awesomebar/provider/SearchActionProvider.kt 63.15% <0.00%> (-1.85%) ⬇️
...a/mozilla/components/browser/storage/sync/Types.kt 80.43% <0.00%> (-1.66%) ⬇️
.../components/concept/engine/prompt/PromptRequest.kt 78.09% <0.00%> (-1.00%) ⬇️
...re/awesomebar/provider/SearchSuggestionProvider.kt 76.31% <0.00%> (-0.61%) ⬇️
...java/mozilla/components/concept/engine/Settings.kt 100.00% <0.00%> (ø)
...components/feature/awesomebar/AwesomeBarFeature.kt 89.33% <0.00%> (ø)
... and 729 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 57e8d7b...b8be7e9. Read the comment docs.

Copy link
Contributor

@grigoryk grigoryk left a comment

Choose a reason for hiding this comment

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

This is pretty close! A few questions throughout, and some specific suggestions.

data class CanBeUpdated(val foundCreditCard: CreditCard) : Result()

/**
* The [CreditCard] cannot be saved.
Copy link
Contributor

Choose a reason for hiding this comment

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

"saved or updated", right?

Also - do we get anything from the API we can use as a "reason" here?

)
}
is CreditCardValidationDelegate.Result.Error -> {
// Do nothing since an error occurred and the credit card cannot be saved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not return any results to GV?

@@ -8,8 +8,10 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this class should probably be called DefaultCreditCardsAddressesStorageDelegate if there's nothing gecko-specific going on here.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is kinda of Gecko specific. It is only consumed by the GeckoAutocompleteStorageDelegate. Its respective Login counterpart also uses the Gecko prefix. If we want to rename this, I would suggest we do it for both, and note that it will be a breaking change.

@@ -38,6 +40,22 @@ class GeckoCreditCardsAddressesStorageDelegate(
}

override fun onCreditCardSave(creditCard: CreditCard) {
TODO("Not yet implemented")
val validationDelegate = DefaultCreditCardValidationDelegate(storage)
Copy link
Contributor

Choose a reason for hiding this comment

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

If this method is called in a quick succession (and you're not in control of its consumers, so you don't know if it'll be called in this fashion or not), it's possible that one of the add/update calls to storage below will fail (and we'll crash) with a SQL_LOCKED exception coming out of storage.

That's because sqlite doesn't support consequent writers, and within AutofillCreditCardsAddressesStorage you only have a single connection instance to the storage that's shared for both reading and writing. And, the coroutineContext use there is defined over Dispatchers.IO. That means you call addCreditCard and then very quickly an updateCreditCard while first operation is still running, it's possible for things to crash - we'll end up using a different thread for the update operation, and will try to talk to the storage while it's busy.

For comparison, PlacesStorage defines two scopes - readScope and writeScope. The former uses a thread pool to make sure reads are quick, while the latter uses a single threaded executor to make sure write operations are sequential and never overlap.

Just to avoid this class of errors and not have to worry about what's possible here and what's not, this is the kind of split I'd introduce here as well.


assertEquals(Result.CanBeCreated, result)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Note how your tests assume that weird/bad things won't happen (they don't test for them). See my comment in the validate method.

@grigoryk grigoryk added ✏️ needs changes PRs that need some changes/fixes before they can land and removed 🕵️‍♀️ needs review PRs that need to be reviewed labels Mar 23, 2021
@mergify
Copy link
Contributor

mergify bot commented Apr 8, 2021

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

@mergify
Copy link
Contributor

mergify bot commented Apr 20, 2021

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Apr 29, 2021

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

@mergify
Copy link
Contributor

mergify bot commented May 19, 2021

This pull request has conflicts when rebasing. Could you fix it @gabrielluong? 🙏

@pocmo
Copy link
Contributor

pocmo commented Aug 11, 2021

Looking through old PRs... Is this something we still want to get landed?

@grigoryk
Copy link
Contributor

@pocmo yup, definitely worth landing this - and the pieces on the GV side to call into this delegate. I'll rebase/clean this up and will land it.

Mugurell and others added 7 commits September 10, 2021 17:54
…of InputResultDetail

We need to wait until having a response from GeckoView on how it handled the
touch only after which we'll know whether to animate the toolbar or not.

The edgecase scenario of having pull to refresh enabled even before having a
response from GeckoView will still work because "canOverscrollTop()" only
checks for the touch to not be handled by the browser to pan the page.
The previous implementation was affected by the fact that the class has 3
integer properties, all with values [0..4] (-1 was added recently) and it
would just add those value to compute the hashcode.
Collisions were a given.

By using decimal places for each property the new implementation should avoid
collisions while allowing for all the other expected guarantees.
This commented method seems to be a leftover from the previous refactoring.
"behavior.forceExpand(..)" now calls "expandWithAnimation" for which we already
have a test at line 450.
pocmo and others added 18 commits September 10, 2021 17:55
This version of A-S included breaking changes around the history
metadata API, which this patch resolves.
…lla-mobile#10913)

* Ensure we notice and repair a missing or expired push endpoint.

The core problem is that the device constellation's observer is registered
after we've updated the devices, so the code that checks if re-subscribing is
necessary is never hit.

The easiest way of fixing this was to move the `refreshDevices` call to the
account state state-machine, rather than the authentication state-machine,
meaning we can ensure the `onAuthenticated` notification is delivered before
we refresh the devices.

Note that I also removed the special-case for "SEND_TAB" devices - push is
also used for account-related notifications, such as being disconnected.

* Address CI failures (hopefully!)

* Update comments about push renewal

* Tweak suggested by Grisha for when to call refreshDevices

* More CI failures

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…ozilla-mobile#9827)

* Accounts: Make webchannel work with custom fxa server

* Accounts: Send overrideFxAServer message only to custom fxa server

* Accounts: make webchannel background message name constant

Co-authored-by: Grisha Kruglov <gkruglov@mozilla.com>
@grigoryk
Copy link
Contributor

Ummm. Yeah, that didn't go quite as planned... Going to close this in favour of #10964

@grigoryk grigoryk closed this Sep 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✏️ needs changes PRs that need some changes/fixes before they can land
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement onCreditCardSave in GeckoCreditCardsAddressesStorageDelegate