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

Commit de54cb8f authored by vadimt's avatar vadimt
Browse files

Adding a rule for analyzing view capture data

For now, the rule is basically empty, to start with. In the following CLs it will
invoke the search for anomalies in the data collected by ViewCaptureRule
after the test succeeds and fail the test if an anomaly is found.

Bug: 286251603
Test: presubmit
Flag: N/A
Change-Id: I373ea0d7ee85206101fb15584889ea5933e7d7b8
parent fde9d30f
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import com.android.launcher3.util.rule.FailureWatcher;
import com.android.launcher3.util.rule.SamplerRule;
import com.android.launcher3.util.rule.ScreenRecordRule;
import com.android.launcher3.util.rule.TestStabilityRule;
import com.android.launcher3.util.rule.ViewCaptureAnalysisRule;
import com.android.launcher3.util.rule.ViewCaptureRule;
import com.android.quickstep.views.RecentsView;

@@ -121,7 +122,8 @@ public class FallbackRecentsTest {
                .outerRule(new SamplerRule())
                .around(new NavigationModeSwitchRule(mLauncher))
                .around(viewCaptureRule)
                .around(new FailureWatcher(mDevice, mLauncher, viewCaptureRule.getViewCapture()));
                .around(new FailureWatcher(mDevice, mLauncher, viewCaptureRule.getViewCapture()))
                .around(new ViewCaptureAnalysisRule(viewCaptureRule.getViewCapture()));

        mOtherLauncherActivity = context.getPackageManager().queryIntentActivities(
                getHomeIntentInPackage(context),
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ filegroup {
      "src/com/android/launcher3/util/rule/SimpleActivityRule.java",
      "src/com/android/launcher3/util/rule/TestStabilityRule.java",
      "src/com/android/launcher3/util/rule/TISBindRule.java",
      "src/com/android/launcher3/util/rule/ViewCaptureAnalysisRule.java",
      "src/com/android/launcher3/testcomponent/BaseTestingActivity.java",
      "src/com/android/launcher3/testcomponent/OtherBaseTestingActivity.java",
      "src/com/android/launcher3/testcomponent/CustomShortcutConfigActivity.java",
+3 −1
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import com.android.launcher3.util.rule.SamplerRule;
import com.android.launcher3.util.rule.ScreenRecordRule;
import com.android.launcher3.util.rule.ShellCommandRule;
import com.android.launcher3.util.rule.TestStabilityRule;
import com.android.launcher3.util.rule.ViewCaptureAnalysisRule;
import com.android.launcher3.util.rule.ViewCaptureRule;

import org.junit.After;
@@ -210,7 +211,8 @@ public abstract class AbstractLauncherUiTest {
        final RuleChain inner = RuleChain
                .outerRule(new PortraitLandscapeRunner(this))
                .around(viewCaptureRule)
                .around(new FailureWatcher(mDevice, mLauncher, viewCaptureRule.getViewCapture()));
                .around(new FailureWatcher(mDevice, mLauncher, viewCaptureRule.getViewCapture()))
                .around(new ViewCaptureAnalysisRule(viewCaptureRule.getViewCapture()));

        return TestHelpers.isInLauncherProcess()
                ? RuleChain.outerRule(ShellCommandRule.setDefaultLauncher()).around(inner)
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.launcher3.util.rule;

import androidx.annotation.NonNull;
import androidx.test.InstrumentationRegistry;

import com.android.app.viewcapture.ViewCapture;
import com.android.app.viewcapture.data.ExportedData;

import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

import java.util.concurrent.ExecutionException;

/**
 * After the test succeeds, the rule looks for anomalies in the data accumulated by ViewCapture
 * that's passed as a parameter. If anomalies are detected, throws an exception and fails the test.
 */
public class ViewCaptureAnalysisRule extends TestWatcher {
    @NonNull
    private final ViewCapture mViewCapture;

    public ViewCaptureAnalysisRule(@NonNull ViewCapture viewCapture) {
        mViewCapture = viewCapture;
    }

    @Override
    protected void succeeded(Description description) {
        super.succeeded(description);
        try {
            analyzeViewCaptureData(mViewCapture.getExportedData(
                    InstrumentationRegistry.getTargetContext()));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }

    private static void analyzeViewCaptureData(ExportedData viewCaptureData) {
    }
}