Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1aebd107 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5351881 from 66bcff6e to qt-release

Change-Id: I03619f01dab618b675ebf46668a9aef7362666fb
parents 1e76cfa3 66bcff6e
Loading
Loading
Loading
Loading
+0 −154
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.documentsui;

import android.graphics.Color;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Locale;

/**
 * To help the image verification by using RGB, HSV, and HSL color space to make sure whether the
 * pixels in the image over the threshold or not. Not only to use color ARGB match but also to
 * fuzzy color match(RGB, HSV, HSL).
 */
public class FuzzyColor {
    public static class Threshold {
        public int getColor() {
            return 20;
        }

        public float getHue() {
            return 8f;
        }

        public float getSaturation() {
            return 0.25f;
        }

        public float getValue() {
            return 0.25f;
        }

        public float getLuminance() {
            return 0.1f;
        }
    }

    private static Threshold sThreshold = new Threshold();

    /**
     * To set the threshold adjust the verify algorithm.
     *
     * @param threshold the threshold that want to set
     */
    public static synchronized void setThreshold(Threshold threshold) {
        if (threshold == null) {
            return;
        }
        sThreshold = threshold;
    }

    private final int mColor;
    private final float [] mHsv;
    private final float mLuminance;
    private final int mRed;
    private final int mGreen;
    private final int mBlue;
    private int mCount;

    /**
     * To initial a FuzzyColor according to color parameter.
     *
     * @param color the ARGB color for the pixel in the image
     */
    public FuzzyColor(int color) {
        mColor = color;

        mRed = Color.red(color);
        mGreen = Color.green(color);
        mBlue = Color.blue(color);
        mHsv = new float[3];
        mLuminance = Color.luminance(color);
        Color.RGBToHSV(Color.red(color), Color.green(color), Color.blue(color), mHsv);
    }

    public void add(int count) {
        mCount += count;
    }

    public int getCount() {
        return mCount;
    }

    public int getColor() {
        return mColor;
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (obj instanceof FuzzyColor) {
            FuzzyColor other = (FuzzyColor) obj;
            return compare(this, other);
        } else if (obj instanceof Integer) {
            int color = (int) obj;
            return compare(this, new FuzzyColor(color));
        } else {
            return false;
        }
    }

    private static boolean compare(FuzzyColor c1, FuzzyColor c2) {
        if (Math.abs(c1.mRed - c2.mRed) < sThreshold.getColor()
                && Math.abs(c1.mGreen - c2.mGreen) < sThreshold.getColor()
                && Math.abs(c1.mBlue - c2.mBlue) < sThreshold.getColor()) {
            return true;
        }

        float hueDiff = Math.abs(c1.mHsv[0] - c2.mHsv[0]);
        if (hueDiff > sThreshold.getHue() && hueDiff < (360f - sThreshold.getHue())) {
            return false;
        }

        float saturationDiff = Math.abs(c1.mHsv[1] - c2.mHsv[1]);
        if (saturationDiff > sThreshold.getSaturation()) {
            return false;
        }

        float valueDiff = Math.abs(c1.mHsv[2] - c2.mHsv[2]);
        if (valueDiff > sThreshold.getValue()) {
            return false;
        }

        float luminanceDiff = Math.abs(c1.mLuminance - c2.mLuminance);
        if (luminanceDiff > sThreshold.getLuminance()) {
            return false;
        }

        return true;
    }

    @NonNull
    @Override
    public String toString() {
        return String.format(Locale.ENGLISH,
                "[#%08x] count = %d, hue = %f, saturation = %f, value = %f, luminance = %f",
                mColor, mCount, mHsv[0], mHsv[1],  mHsv[2], mLuminance);
    }
}
+49 −0
Original line number Diff line number Diff line
@@ -15,39 +15,35 @@
 *
 */

package com.android.documentsui;

import android.graphics.Bitmap;
import android.util.Log;

import androidx.test.runner.screenshot.BasicScreenCaptureProcessor;
import androidx.test.runner.screenshot.ScreenCapture;
import androidx.test.runner.screenshot.Screenshot;
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.IOException;
package com.android.documentsui.filters;

import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * When the test fail happen, the screen capture will help the developer to judge
 * what does the UI looks like, where is the asserted view, and why test fail.
 * Marks a test that should run as part of the Huge and take a long time tests.
 *
 * Please mark the test whose duration is larger than 10 seconds.
 */
public class ScreenshotCaptureRule extends TestWatcher {
    private static final String TAG = ScreenshotCaptureRule.class.getSimpleName();

    @Override
    protected void failed(Throwable e, Description description) {
        super.failed(e, description);

        ScreenCapture capture = Screenshot.capture();
        capture.setFormat(Bitmap.CompressFormat.PNG);
        capture.setName(description.getMethodName());

        try {
            new BasicScreenCaptureProcessor().process(capture);
        } catch (IOException e1) {
            Log.e(TAG, "Can't handle the capture. " + e1.getMessage());
        }
    }
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface HugeLongTest {
}
+5 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.util.Log;
import androidx.test.filters.LargeTest;

import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.filters.HugeLongTest;
import com.android.documentsui.services.TestNotificationService;

import java.util.concurrent.CountDownLatch;
@@ -141,6 +142,7 @@ public class CancelFromNotificationUiTest extends ActivityTest<FilesActivity> {
        }
    }

    @HugeLongTest
    public void testCopyDocument_Cancel() throws Exception {
        bots.roots.openRoot(ROOT_0_ID);

@@ -159,6 +161,7 @@ public class CancelFromNotificationUiTest extends ActivityTest<FilesActivity> {
        bots.directory.waitForDocument(TARGET_FILE);
    }

    @HugeLongTest
    public void testCopyDocument_CancelFromNotification() throws Exception {
        bots.roots.openRoot(ROOT_0_ID);
        bots.directory.findDocument(TARGET_FILE);
@@ -191,6 +194,7 @@ public class CancelFromNotificationUiTest extends ActivityTest<FilesActivity> {
        assertTrue(bots.directory.hasDocuments(TARGET_FILE));
    }

    @HugeLongTest
    public void testMoveDocument_Cancel() throws Exception {
        bots.roots.openRoot(ROOT_0_ID);

@@ -209,6 +213,7 @@ public class CancelFromNotificationUiTest extends ActivityTest<FilesActivity> {
        bots.directory.waitForDocument(TARGET_FILE);
    }

    @HugeLongTest
    public void testMoveDocument_CancelFromNotification() throws Exception {
        bots.roots.openRoot(ROOT_0_ID);
        bots.directory.findDocument(TARGET_FILE);
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.documentsui;
import androidx.test.filters.LargeTest;

import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.filters.HugeLongTest;

@LargeTest
public class DirectoryMessagesUiTest extends ActivityTest<FilesActivity> {
@@ -45,12 +46,14 @@ public class DirectoryMessagesUiTest extends ActivityTest<FilesActivity> {
        bots.directory.assertHasMessageButtonText("SIGN IN");
    }

    @HugeLongTest
    public void testInfoMessage_visible() throws Exception {
        bots.directory.openDocument(DemoProvider.DIR_INFO);
        bots.directory.assertHasMessage(DemoProvider.MSG_INFO);
        bots.directory.assertHasMessageButtonText("DISMISS");
    }

    @HugeLongTest
    public void testInfoMessage_dismissable() throws Exception {
        bots.directory.openDocument(DemoProvider.DIR_INFO);
        bots.directory.assertHasMessage(true);
@@ -58,12 +61,14 @@ public class DirectoryMessagesUiTest extends ActivityTest<FilesActivity> {
        bots.directory.assertHasMessage(false);
    }

    @HugeLongTest
    public void testErrorMessage_visible() throws Exception {
        bots.directory.openDocument(DemoProvider.DIR_ERROR);
        bots.directory.assertHasMessage(DemoProvider.MSG_ERROR);
        bots.directory.assertHasMessageButtonText("DISMISS");
    }

    @HugeLongTest
    public void testErrorMessage_dismissable() throws Exception {
        bots.directory.openDocument(DemoProvider.DIR_ERROR);
        bots.directory.assertHasMessage(true);
@@ -71,6 +76,7 @@ public class DirectoryMessagesUiTest extends ActivityTest<FilesActivity> {
        bots.directory.assertHasMessage(false);
    }

    @HugeLongTest
    public void testErrorMessage_supercedesInfoMessage() throws Exception {
        // When both error and info are returned in Directory, only show the error.
        bots.directory.openDocument(DemoProvider.DIR_ERROR_AND_INFO);
+5 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.State;
import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.filters.HugeLongTest;
import com.android.documentsui.services.TestNotificationService;

import java.util.HashMap;
@@ -371,6 +372,7 @@ public class FileCopyUiTest extends ActivityTest<FilesActivity> {
    }

    // Copy Internal Storage -> Internal Storage //
    @HugeLongTest
    public void testCopyDocuments_InternalStorage() throws Exception {
        createDocuments(StubProvider.ROOT_0_ID, rootDir0, mDocsHelper);
        copyFiles(StubProvider.ROOT_0_ID, StubProvider.ROOT_1_ID);
@@ -384,6 +386,7 @@ public class FileCopyUiTest extends ActivityTest<FilesActivity> {
    }

    // Copy SD Card -> Internal Storage //
    @HugeLongTest
    public void testCopyDocuments_FromSdCard() throws Exception {
        createDocuments(mSdCardLabel, mSdCardRoot, mStorageDocsHelper);
        copyFiles(mSdCardLabel, Build.MODEL);
@@ -397,6 +400,7 @@ public class FileCopyUiTest extends ActivityTest<FilesActivity> {
    }

    // Copy Internal Storage -> SD Card //
    @HugeLongTest
    public void testCopyDocuments_ToSdCard() throws Exception {
        createDocuments(Build.MODEL, mPrimaryRoot, mStorageDocsHelper);
        copyFiles(Build.MODEL, mSdCardLabel);
@@ -409,6 +413,7 @@ public class FileCopyUiTest extends ActivityTest<FilesActivity> {
        assertFilesCopied(mSdCardLabel, mSdCardRoot, mStorageDocsHelper);
    }

    @HugeLongTest
    public void testCopyDocuments_documentsDisabled() throws Exception {
        mDocsHelper.createDocument(rootDir0, "text/plain", fileName1);
        bots.roots.openRoot(StubProvider.ROOT_0_ID);
Loading