diff --git a/app/screenshots/gplay/debug/com.owncloud.android.ui.dialog.DialogFragmentIT_testSslUntrustedCertDialog.png b/app/screenshots/gplay/debug/com.owncloud.android.ui.dialog.DialogFragmentIT_testSslUntrustedCertDialog.png new file mode 100644 index 0000000000..655039e83e Binary files /dev/null and b/app/screenshots/gplay/debug/com.owncloud.android.ui.dialog.DialogFragmentIT_testSslUntrustedCertDialog.png differ diff --git a/app/src/androidTest/java/com/owncloud/android/ui/dialog/DialogFragmentIT.java b/app/src/androidTest/java/com/owncloud/android/ui/dialog/DialogFragmentIT.java index 0583e46052..368f26143f 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/dialog/DialogFragmentIT.java +++ b/app/src/androidTest/java/com/owncloud/android/ui/dialog/DialogFragmentIT.java @@ -25,9 +25,12 @@ package com.owncloud.android.ui.dialog; import android.accounts.Account; import android.accounts.AccountManager; import android.content.Intent; +import android.net.http.SslCertificate; +import android.net.http.SslError; import android.os.Looper; import android.view.View; import android.view.ViewGroup; +import android.webkit.SslErrorHandler; import android.widget.TextView; import com.google.android.material.bottomsheet.BottomSheetBehavior; @@ -59,7 +62,6 @@ import com.owncloud.android.lib.resources.users.Status; import com.owncloud.android.lib.resources.users.StatusType; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.fragment.OCFileListBottomSheetActions; -import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog; import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialogFragment; import com.owncloud.android.ui.fragment.ProfileBottomSheetDialog; import com.owncloud.android.utils.MimeTypeUtil; @@ -69,6 +71,7 @@ import com.owncloud.android.utils.theme.CapabilityUtils; import org.junit.After; import org.junit.Rule; import org.junit.Test; +import org.mockito.Mockito; import java.net.URI; import java.util.ArrayList; @@ -464,6 +467,23 @@ public class DialogFragmentIT extends AbstractIT { screenshot(sut.getWindow().getDecorView()); } + + @Test + @ScreenshotTest + public void testSslUntrustedCertDialog() { + if (Looper.myLooper() == null) { + Looper.prepare(); + } + + final SslCertificate certificate = new SslCertificate("foo", "bar", "2022/01/10", "2022/01/30"); + final SslError sslError = new SslError(SslError.SSL_UNTRUSTED, certificate); + final SslErrorHandler handler = Mockito.mock(SslErrorHandler.class); + + + SslUntrustedCertDialog sut = SslUntrustedCertDialog.newInstanceForEmptySslError(sslError, handler); + showDialog(sut); + } + private FileDisplayActivity showDialog(DialogFragment dialog) { Intent intent = new Intent(targetContext, FileDisplayActivity.class); diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/SslUntrustedCertDialog.java b/app/src/main/java/com/owncloud/android/ui/dialog/SslUntrustedCertDialog.java index 3046976902..1fa774010c 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/SslUntrustedCertDialog.java +++ b/app/src/main/java/com/owncloud/android/ui/dialog/SslUntrustedCertDialog.java @@ -24,10 +24,8 @@ import android.app.Activity; import android.app.Dialog; import android.net.http.SslError; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; -import android.view.ViewGroup; import android.view.Window; import android.webkit.SslErrorHandler; import android.widget.Button; @@ -135,17 +133,14 @@ public class SslUntrustedCertDialog extends DialogFragment implements Injectable binding = null; } + @NonNull @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - Log_OC.d(TAG, "onCreateView, savedInsanceState is " + savedInstanceState); - // Create a view by inflating desired layout - if (binding == null) { - binding = SslUntrustedCertLayoutBinding.inflate(inflater, container, false); - binding.detailsScroll.setVisibility(View.GONE); - mErrorViewAdapter.updateErrorView(binding); - } else { - ((ViewGroup) binding.getRoot().getParent()).removeView(binding.getRoot()); - } + public Dialog onCreateDialog(Bundle savedInstanceState) { + Log_OC.d(TAG, "onCreateDialog, savedInstanceState is " + savedInstanceState); + + binding = SslUntrustedCertLayoutBinding.inflate(getLayoutInflater(), null, false); + binding.detailsScroll.setVisibility(View.GONE); + mErrorViewAdapter.updateErrorView(binding); binding.ok.setOnClickListener(new OnCertificateTrusted()); @@ -163,13 +158,7 @@ public class SslUntrustedCertDialog extends DialogFragment implements Injectable } }); - return binding.getRoot(); - } - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - Log_OC.d(TAG, "onCreateDialog, savedInstanceState is " + savedInstanceState); MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(binding.getRoot().getContext()); builder.setView(binding.getRoot());