summaryrefslogtreecommitdiff
path: root/chromium/components/autofill/android/provider/junit
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/components/autofill/android/provider/junit
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/autofill/android/provider/junit')
-rw-r--r--chromium/components/autofill/android/provider/junit/BUILD.gn23
-rw-r--r--chromium/components/autofill/android/provider/junit/src/org/chromium/components/autofill/AutofillProviderTest.java115
2 files changed, 138 insertions, 0 deletions
diff --git a/chromium/components/autofill/android/provider/junit/BUILD.gn b/chromium/components/autofill/android/provider/junit/BUILD.gn
new file mode 100644
index 00000000000..95cea50bf90
--- /dev/null
+++ b/chromium/components/autofill/android/provider/junit/BUILD.gn
@@ -0,0 +1,23 @@
+# Copyright 2020 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/config/android/config.gni")
+import("//build/config/android/rules.gni")
+
+java_library("components_autofill_junit_tests") {
+ # Platform checks are broken for Robolectric. See https://crbug.com/1071638.
+ bypass_platform_checks = true
+ testonly = true
+ sources = [ "src/org/chromium/components/autofill/AutofillProviderTest.java" ]
+ deps = [
+ "//base:base_java_test_support",
+ "//base:base_junit_test_support",
+ "//components/autofill/android/provider:java",
+ "//content/public/android:content_java",
+ "//third_party/android_deps:robolectric_all_java",
+ "//third_party/junit",
+ "//third_party/mockito:mockito_java",
+ "//ui/android:ui_java",
+ ]
+}
diff --git a/chromium/components/autofill/android/provider/junit/src/org/chromium/components/autofill/AutofillProviderTest.java b/chromium/components/autofill/android/provider/junit/src/org/chromium/components/autofill/AutofillProviderTest.java
new file mode 100644
index 00000000000..e4b12cec808
--- /dev/null
+++ b/chromium/components/autofill/android/provider/junit/src/org/chromium/components/autofill/AutofillProviderTest.java
@@ -0,0 +1,115 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.autofill;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.view.ViewGroup;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.robolectric.annotation.Config;
+
+import org.chromium.base.test.BaseRobolectricTestRunner;
+import org.chromium.content_public.browser.WebContents;
+import org.chromium.ui.base.WindowAndroid;
+import org.chromium.ui.display.DisplayAndroid;
+
+import java.util.ArrayList;
+
+/**
+ * The unit tests for AutofillProvider.
+ */
+@RunWith(BaseRobolectricTestRunner.class)
+@Config(manifest = Config.NONE)
+public class AutofillProviderTest {
+ private static final float EXPECTED_DIP_SCALE = 2;
+ private static final int SCROLL_X = 15;
+ private static final int SCROLL_Y = 155;
+ private static final int LOCATION_X = 25;
+ private static final int LOCATION_Y = 255;
+
+ private Context mContext;
+ private WindowAndroid mWindowAndroid;
+ private WebContents mWebContents;
+ private ViewGroup mContainerView;
+ private AutofillProvider mAutofillProvider;
+ private DisplayAndroid mDisplayAndroid;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = Mockito.mock(Context.class);
+ mWindowAndroid = Mockito.mock(WindowAndroid.class);
+ mDisplayAndroid = Mockito.mock(DisplayAndroid.class);
+ mWebContents = Mockito.mock(WebContents.class);
+ mContainerView = Mockito.mock(ViewGroup.class);
+ mAutofillProvider = new AutofillProvider(mContext, mContainerView, "AutofillProviderTest");
+ mAutofillProvider.setWebContents(mWebContents);
+
+ when(mWebContents.getTopLevelNativeWindow()).thenReturn(mWindowAndroid);
+ when(mWindowAndroid.getDisplay()).thenReturn(mDisplayAndroid);
+ when(mDisplayAndroid.getDipScale()).thenReturn(EXPECTED_DIP_SCALE);
+ when(mContainerView.getScrollX()).thenReturn(SCROLL_X);
+ when(mContainerView.getScrollY()).thenReturn(SCROLL_Y);
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ int[] location = (int[]) args[0];
+ location[0] = LOCATION_X;
+ location[1] = LOCATION_Y;
+ return null;
+ }
+ })
+ .when(mContainerView)
+ .getLocationOnScreen(ArgumentMatchers.any());
+ }
+
+ @Test
+ public void testTransformFormFieldToContainViewCoordinates() {
+ ArrayList<FormFieldData> fields = new ArrayList<FormFieldData>(1);
+ fields.add(FormFieldData.createFormFieldData(null, null, null, null, false, null, null,
+ null, null, null, false, false, 0, null, 10 /* left */, 20 /* top */,
+ 300 /* right */, 60 /*bottom*/, null, null));
+ fields.add(FormFieldData.createFormFieldData(null, null, null, null, false, null, null,
+ null, null, null, false, false, 0, null, 20 /* left */, 100 /* top */,
+ 400 /* right */, 200 /*bottom*/, null, null));
+ FormData formData = new FormData(null, null, fields);
+ mAutofillProvider.transformFormFieldToContainViewCoordinates(formData);
+ RectF result = formData.mFields.get(0).getBoundsInContainerViewCoordinates();
+ assertEquals(10 * EXPECTED_DIP_SCALE + SCROLL_X, result.left, 0);
+ assertEquals(20 * EXPECTED_DIP_SCALE + SCROLL_Y, result.top, 0);
+ assertEquals(300 * EXPECTED_DIP_SCALE + SCROLL_X, result.right, 0);
+ assertEquals(60 * EXPECTED_DIP_SCALE + SCROLL_Y, result.bottom, 0);
+
+ result = formData.mFields.get(1).getBoundsInContainerViewCoordinates();
+ assertEquals(20 * EXPECTED_DIP_SCALE + SCROLL_X, result.left, 0);
+ assertEquals(100 * EXPECTED_DIP_SCALE + SCROLL_Y, result.top, 0);
+ assertEquals(400 * EXPECTED_DIP_SCALE + SCROLL_X, result.right, 0);
+ assertEquals(200 * EXPECTED_DIP_SCALE + SCROLL_Y, result.bottom, 0);
+ }
+
+ @Test
+ public void testTransformToWindowBounds() {
+ RectF source = new RectF(10, 20, 300, 400);
+ Rect result = mAutofillProvider.transformToWindowBounds(source);
+ assertEquals(10 * EXPECTED_DIP_SCALE + LOCATION_X, result.left, 0);
+ assertEquals(20 * EXPECTED_DIP_SCALE + LOCATION_Y, result.top, 0);
+ assertEquals(300 * EXPECTED_DIP_SCALE + LOCATION_X, result.right, 0);
+ assertEquals(400 * EXPECTED_DIP_SCALE + LOCATION_Y, result.bottom, 0);
+ }
+}