Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
778a2052
Commit
778a2052
authored
Nov 18, 2019
by
Grisha Kruglov
Browse files
Pre: make sure to use the profile cache instead of always fetching it
parent
25a05146
Changes
2
Hide whitespace changes
Inline
Side-by-side
components/service/firefox-accounts/src/main/java/mozilla/components/service/fxa/manager/FxaAccountManager.kt
View file @
778a2052
...
...
@@ -734,7 +734,8 @@ open class FxaAccountManager(
// https://github.com/mozilla/application-services/issues/483
logger
.
info
(
"Fetching profile..."
)
profile
=
account
.
getProfileAsync
(
true
).
await
()
// `account` provides us with intelligent profile caching, so make sure to use it.
profile
=
account
.
getProfileAsync
(
ignoreCache
=
false
).
await
()
if
(
profile
==
null
)
{
return
Event
.
FailedToFetchProfile
}
...
...
components/service/firefox-accounts/src/test/java/mozilla/components/service/fxa/FxaAccountManagerTest.kt
View file @
778a2052
...
...
@@ -917,7 +917,7 @@ class FxaAccountManagerTest {
val
constellation
:
DeviceConstellation
=
mock
()
val
profile
=
Profile
(
"testUid"
,
"test@example.com"
,
null
,
"Test Profile"
)
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
thenReturn
(
CompletableDeferred
(
profile
))
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
thenReturn
(
CompletableDeferred
(
profile
))
// We have an account at the start.
`when`
(
accountStorage
.
read
()).
thenReturn
(
mockAccount
)
`when`
(
mockAccount
.
getCurrentDeviceId
()).
thenReturn
(
"testDeviceId"
)
...
...
@@ -1046,7 +1046,7 @@ class FxaAccountManagerTest {
val
mockAccount
:
OAuthAccount
=
mock
()
val
profile
=
Profile
(
uid
=
"testUID"
,
avatar
=
null
,
email
=
"test@example.com"
,
displayName
=
"test profile"
)
val
accountStorage
=
mock
<
AccountStorage
>()
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
thenReturn
(
CompletableDeferred
(
profile
))
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
thenReturn
(
CompletableDeferred
(
profile
))
val
fxaPanic
=
CompletableDeferred
<
AuthFlowUrl
>()
fxaPanic
.
completeExceptionally
(
FxaPanicException
(
"panic!"
))
...
...
@@ -1295,7 +1295,7 @@ class FxaAccountManagerTest {
`when`
(
mockAccount
.
deviceConstellation
()).
thenReturn
(
constellation
)
`when`
(
mockAccount
.
getCurrentDeviceId
()).
thenReturn
(
"testDeviceId"
)
`when`
(
constellation
.
initDeviceAsync
(
any
(),
any
(),
any
())).
thenReturn
(
CompletableDeferred
(
true
))
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
thenReturn
(
CompletableDeferred
(
value
=
null
))
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
thenReturn
(
CompletableDeferred
(
value
=
null
))
`when`
(
mockAccount
.
beginOAuthFlowAsync
(
any
())).
thenReturn
(
CompletableDeferred
(
AuthFlowUrl
(
EXPECTED_AUTH_STATE
,
"auth://url"
)))
`when`
(
mockAccount
.
completeOAuthFlowAsync
(
anyString
(),
anyString
())).
thenReturn
(
CompletableDeferred
(
true
))
// There's no account at the start.
...
...
@@ -1340,7 +1340,7 @@ class FxaAccountManagerTest {
val
profile
=
Profile
(
uid
=
"testUID"
,
avatar
=
null
,
email
=
"test@example.com"
,
displayName
=
"test profile"
)
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
thenReturn
(
CompletableDeferred
(
profile
))
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
thenReturn
(
CompletableDeferred
(
profile
))
manager
.
updateProfileAsync
().
await
()
...
...
@@ -1376,7 +1376,7 @@ class FxaAccountManagerTest {
mockAccount
}
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
then
{
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
then
{
// Hit an auth error.
CoroutineScope
(
coroutineContext
).
launch
{
manager
.
encounteredAuthError
()
}
CompletableDeferred
(
value
=
null
)
...
...
@@ -1433,7 +1433,7 @@ class FxaAccountManagerTest {
mockAccount
}
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
then
{
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
then
{
// Hit an auth error.
CoroutineScope
(
coroutineContext
).
launch
{
manager
.
encounteredAuthError
()
}
CompletableDeferred
(
value
=
null
)
...
...
@@ -1495,7 +1495,7 @@ class FxaAccountManagerTest {
}
var
didFailProfileFetch
=
false
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
then
{
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
then
{
// Hit an auth error, but only once. As we recover from it, we'll attempt to fetch a profile
// again. At that point, we'd like to succeed.
if
(!
didFailProfileFetch
)
{
...
...
@@ -1552,7 +1552,7 @@ class FxaAccountManagerTest {
`when`
(
mockAccount
.
getCurrentDeviceId
()).
thenReturn
(
"testDeviceId"
)
`when`
(
mockAccount
.
deviceConstellation
()).
thenReturn
(
constellation
)
`when`
(
constellation
.
initDeviceAsync
(
any
(),
any
(),
any
())).
thenReturn
(
CompletableDeferred
(
true
))
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
thenReturn
(
exceptionalProfile
)
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
thenReturn
(
exceptionalProfile
)
`when`
(
mockAccount
.
beginOAuthFlowAsync
(
any
())).
thenReturn
(
CompletableDeferred
(
AuthFlowUrl
(
EXPECTED_AUTH_STATE
,
"auth://url"
)))
`when`
(
mockAccount
.
completeOAuthFlowAsync
(
anyString
(),
anyString
())).
thenReturn
(
CompletableDeferred
(
true
))
// There's no account at the start.
...
...
@@ -1630,7 +1630,7 @@ class FxaAccountManagerTest {
coroutineContext
:
CoroutineContext
):
FxaAccountManager
{
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
thenReturn
(
CompletableDeferred
(
profile
))
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
thenReturn
(
CompletableDeferred
(
profile
))
`when`
(
mockAccount
.
beginOAuthFlowAsync
(
any
())).
thenReturn
(
CompletableDeferred
(
AuthFlowUrl
(
EXPECTED_AUTH_STATE
,
"auth://url"
)))
`when`
(
mockAccount
.
beginPairingFlowAsync
(
anyString
(),
any
())).
thenReturn
(
CompletableDeferred
(
AuthFlowUrl
(
EXPECTED_AUTH_STATE
,
"auth://url"
)))
`when`
(
mockAccount
.
completeOAuthFlowAsync
(
anyString
(),
anyString
())).
thenReturn
(
CompletableDeferred
(
true
))
...
...
@@ -1661,7 +1661,7 @@ class FxaAccountManagerTest {
accountObserver
:
AccountObserver
,
coroutineContext
:
CoroutineContext
):
FxaAccountManager
{
`when`
(
mockAccount
.
getProfileAsync
(
anyBoolean
()
)).
thenReturn
(
CompletableDeferred
(
profile
))
`when`
(
mockAccount
.
getProfileAsync
(
ignoreCache
=
false
)).
thenReturn
(
CompletableDeferred
(
profile
))
`when`
(
mockAccount
.
beginOAuthFlowAsync
(
any
())).
thenReturn
(
CompletableDeferred
(
value
=
null
))
`when`
(
mockAccount
.
beginPairingFlowAsync
(
anyString
(),
any
())).
thenReturn
(
CompletableDeferred
(
value
=
null
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment