Skip to content

Commit

Permalink
Removes errors after a manual refresh (#4004)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/414730916066338/1206139108436193/f

### Description
This task removes errors from a site after a manual refresh has been
triggered. It also fixes the yeti screen stuck even after a successul
refresh of the page. It doesn't add the pull to refresh capability
though. Comming soon.

### Steps to test this PR

- [x] Go to www.pacopatata.es
- [x] Web shouldn't load
- [x] Filter logcat by epbf
- [x] Send a broken site report
- [x] Pixel should contain an errorDescription
- [x] Now go to https://client-cert-missing.badssl.com/
- [x] Send a broken site report
- [x] Pixel should not have an errorDescription but an httpErrorCode
instead.
- [x] Go to cnn.com
- [x] Put the phone in airplane mode and refresh
- [x] You should see the yeti screen
- [x] Send a broken site report
- [x] Pixel should have an errorDescription
- [x] Remove airplane mode and refresh the page
- [x] Yeti screen should disappear
- [x] Send a broken site report
- [x] Pixel should not contain an errorDescription or httpErrorCode
  • Loading branch information
marcosholgado authored Dec 15, 2023
1 parent 3b2e096 commit 0700f71
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import com.duckduckgo.app.browser.BrowserTabViewModel.NavigationCommand
import com.duckduckgo.app.browser.BrowserTabViewModel.NavigationCommand.Navigate
import com.duckduckgo.app.browser.LongPressHandler.RequiredAction.DownloadFile
import com.duckduckgo.app.browser.LongPressHandler.RequiredAction.OpenInNewTab
import com.duckduckgo.app.browser.WebViewErrorResponse.LOADING
import com.duckduckgo.app.browser.WebViewErrorResponse.OMITTED
import com.duckduckgo.app.browser.addtohome.AddToHomeCapabilityDetector
import com.duckduckgo.app.browser.applinks.AppLinksHandler
import com.duckduckgo.app.browser.camera.CameraHardwareChecker
Expand Down Expand Up @@ -4554,6 +4556,15 @@ class BrowserTabViewModelTest {
assertCommandIssued<Command.ShowFileChooser>()
}

@Test
fun whenWebViewRefreshedThenBrowserErrorStateChangedToLoading() {
assertEquals(OMITTED, browserViewState().browserError)

testee.onWebViewRefreshed()

assertEquals(LOADING, browserViewState().browserError)
}

private fun aCredential(): LoginCredentials {
return LoginCredentials(domain = null, username = null, password = null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import com.duckduckgo.app.browser.BrowserTabViewModel.OmnibarViewState
import com.duckduckgo.app.browser.BrowserTabViewModel.PrivacyShieldViewState
import com.duckduckgo.app.browser.BrowserTabViewModel.SavedSiteChangedViewState
import com.duckduckgo.app.browser.DownloadConfirmationFragment.DownloadConfirmationDialogListener
import com.duckduckgo.app.browser.WebViewErrorResponse.LOADING
import com.duckduckgo.app.browser.WebViewErrorResponse.OMITTED
import com.duckduckgo.app.browser.autocomplete.BrowserAutoCompleteSuggestionsAdapter
import com.duckduckgo.app.browser.cookies.ThirdPartyCookieManager
Expand Down Expand Up @@ -1118,6 +1119,7 @@ class BrowserTabFragment :
fun refresh() {
webView?.reload()
viewModel.onWebViewRefreshed()
viewModel.resetErrors()
}

private fun processCommand(it: Command?) {
Expand Down Expand Up @@ -3287,6 +3289,9 @@ class BrowserTabFragment :
lastSeenLoadingViewState = viewState

if (viewState.progress == MAX_PROGRESS) {
if (lastSeenBrowserViewState?.browserError == LOADING) {
showBrowser()
}
webView?.setBottomMatchingBehaviourEnabled(true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.duckduckgo.app.browser.BrowserTabViewModel.HighlightableButton.Visibl
import com.duckduckgo.app.browser.LongPressHandler.RequiredAction
import com.duckduckgo.app.browser.SpecialUrlDetector.UrlType.AppLink
import com.duckduckgo.app.browser.SpecialUrlDetector.UrlType.NonHttpAppLink
import com.duckduckgo.app.browser.WebViewErrorResponse.LOADING
import com.duckduckgo.app.browser.WebViewErrorResponse.OMITTED
import com.duckduckgo.app.browser.addtohome.AddToHomeCapabilityDetector
import com.duckduckgo.app.browser.applinks.AppLinksHandler
Expand Down Expand Up @@ -2889,7 +2890,12 @@ class BrowserTabViewModel @Inject constructor(
}
}

fun resetErrors() {
site?.resetErrors()
}

fun onWebViewRefreshed() {
browserViewState.value = currentBrowserViewState().copy(browserError = LOADING)
accessibilityViewState.value = currentAccessibilityViewState().copy(refreshWebView = false)
canAutofillSelectCredentialsDialogCanAutomaticallyShow = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,5 +502,6 @@ enum class WebViewErrorResponse(@StringRes val errorId: Int) {
BAD_URL(R.string.webViewErrorBadUrl),
CONNECTION(R.string.webViewErrorNoConnection),
OMITTED(R.string.webViewErrorNoConnection),
LOADING(R.string.webViewErrorNoConnection),
SSL_PROTOCOL_ERROR(R.string.webViewErrorSslProtocol),
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class SiteMonitor(
return HttpsStatus.NONE
}

override fun resetErrors() {
errorCodeEvents.clear()
httpErrorCodeEvents.clear()
}

override fun surrogateDetected(surrogate: SurrogateResponse) {
surrogates.add(surrogate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface Site {
fun trackerDetected(event: TrackingEvent)
fun onHttpErrorDetected(errorCode: Int)
fun onErrorDetected(error: String)
fun resetErrors()
fun updatePrivacyData(sitePrivacyData: SitePrivacyData)
fun surrogateDetected(surrogate: SurrogateResponse)

Expand Down

0 comments on commit 0700f71

Please sign in to comment.