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
fenix
Commits
b6ac5079
Commit
b6ac5079
authored
Feb 18, 2021
by
Arturo Mejia
Committed by
Christian Sadilek
Feb 18, 2021
Browse files
For issue #18049 Download complete dialog is not showing in custom tab.
parent
6270c8da
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt
View file @
b6ac5079
...
...
@@ -458,9 +458,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
downloadFeature
.
onDownloadStopped
=
{
downloadState
,
_
,
downloadJobStatus
->
// If the download is just paused, don't show any in-app notification
if
(
downloadJobStatus
==
DownloadState
.
Status
.
COMPLETED
||
downloadJobStatus
==
DownloadState
.
Status
.
FAILED
)
{
if
(
shouldShowCompletedDownloadDialog
(
downloadState
,
downloadJobStatus
))
{
saveDownloadDialogState
(
downloadState
.
sessionId
,
...
...
@@ -488,16 +486,13 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
onDismiss
=
{
sharedViewModel
.
downloadDialogState
.
remove
(
downloadState
.
sessionId
)
}
)
// Don't show the dialog if we aren't in the tab that started the download
if
(
downloadState
.
sessionId
==
sessionManager
.
selectedSession
?.
id
)
{
dynamicDownloadDialog
.
show
()
browserToolbarView
.
expand
()
}
dynamicDownloadDialog
.
show
()
browserToolbarView
.
expand
()
}
}
resumeDownloadDialogState
(
sessionManager
.
selectedSession
?.
id
,
getCurrentTab
()
?.
id
,
store
,
view
,
context
,
toolbarHeight
)
...
...
@@ -1152,7 +1147,8 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
}
}
private
fun
getCurrentTab
():
SessionState
?
{
@VisibleForTesting
internal
fun
getCurrentTab
():
SessionState
?
{
return
requireComponents
.
core
.
store
.
state
.
findCustomTabOrSelectedTab
(
customTabSessionId
)
}
...
...
@@ -1358,4 +1354,16 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
*/
@VisibleForTesting
internal
fun
getSwipeRefreshLayout
()
=
swipeRefresh
@VisibleForTesting
internal
fun
shouldShowCompletedDownloadDialog
(
downloadState
:
DownloadState
,
status
:
DownloadState
.
Status
):
Boolean
{
val
isValidStatus
=
status
in
listOf
(
DownloadState
.
Status
.
COMPLETED
,
DownloadState
.
Status
.
FAILED
)
val
isSameTab
=
downloadState
.
sessionId
==
getCurrentTab
()
?.
id
?:
false
return
isValidStatus
&&
isSameTab
}
}
app/src/test/java/org/mozilla/fenix/browser/BaseBrowserFragmentTest.kt
View file @
b6ac5079
...
...
@@ -12,8 +12,12 @@ import io.mockk.mockk
import
io.mockk.slot
import
io.mockk.spyk
import
io.mockk.verify
import
junit.framework.TestCase.assertFalse
import
junit.framework.TestCase.assertTrue
import
kotlinx.coroutines.ExperimentalCoroutinesApi
import
mozilla.components.browser.state.state.SessionState
import
mozilla.components.browser.state.state.content.DownloadState
import
mozilla.components.browser.state.state.createTab
import
mozilla.components.concept.engine.EngineView
import
mozilla.components.feature.contextmenu.ContextMenuCandidate
import
mozilla.components.feature.session.behavior.EngineViewBrowserToolbarBehavior
...
...
@@ -111,6 +115,66 @@ class BaseBrowserFragmentTest {
verify
{
(
swipeRefreshLayout
.
layoutParams
as
CoordinatorLayout
.
LayoutParams
).
bottomMargin
=
13
}
}
@Test
fun
`WHEN
status
is
equals
to
FAILED
or
COMPLETED
and
it
is
the
same
tab
then
shouldShowCompletedDownloadDialog
will
be
true
`
()
{
every
{
fragment
.
getCurrentTab
()
}
returns
createTab
(
id
=
"1"
,
url
=
""
)
val
download
=
DownloadState
(
url
=
""
,
sessionId
=
"1"
)
val
status
=
DownloadState
.
Status
.
values
()
.
filter
{
it
==
DownloadState
.
Status
.
COMPLETED
&&
it
==
DownloadState
.
Status
.
FAILED
}
status
.
forEach
{
val
result
=
fragment
.
shouldShowCompletedDownloadDialog
(
download
,
it
)
assertTrue
(
result
)
}
}
@Test
fun
`WHEN
status
is
different
from
FAILED
or
COMPLETED
then
shouldShowCompletedDownloadDialog
will
be
false
`
()
{
every
{
fragment
.
getCurrentTab
()
}
returns
createTab
(
id
=
"1"
,
url
=
""
)
val
download
=
DownloadState
(
url
=
""
,
sessionId
=
"1"
)
val
status
=
DownloadState
.
Status
.
values
()
.
filter
{
it
!=
DownloadState
.
Status
.
COMPLETED
&&
it
!=
DownloadState
.
Status
.
FAILED
}
status
.
forEach
{
val
result
=
fragment
.
shouldShowCompletedDownloadDialog
(
download
,
it
)
assertFalse
(
result
)
}
}
@Test
fun
`WHEN
the
tab
is
different
from
the
initial
one
then
shouldShowCompletedDownloadDialog
will
be
false
`
()
{
every
{
fragment
.
getCurrentTab
()
}
returns
createTab
(
id
=
"1"
,
url
=
""
)
val
download
=
DownloadState
(
url
=
""
,
sessionId
=
"2"
)
val
status
=
DownloadState
.
Status
.
values
()
.
filter
{
it
!=
DownloadState
.
Status
.
COMPLETED
&&
it
!=
DownloadState
.
Status
.
FAILED
}
status
.
forEach
{
val
result
=
fragment
.
shouldShowCompletedDownloadDialog
(
download
,
it
)
assertFalse
(
result
)
}
}
}
@ExperimentalCoroutinesApi
...
...
Write
Preview
Markdown
is supported
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