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

Commit 349305f1 authored by Hyundo Moon's avatar Hyundo Moon Committed by Gerrit Code Review
Browse files

Merge "Remove BluetoothPrefTest"

parents b2016c3c a9c93d7c
Loading
Loading
Loading
Loading
+0 −90
Original line number Diff line number Diff line
/*
 * Copyright 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.bluetooth;

import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
import static android.content.pm.PackageManager.DONT_KILL_APP;

import static androidx.test.espresso.intent.Intents.intended;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import androidx.test.core.app.ActivityScenario;
import androidx.test.espresso.intent.Intents;
import androidx.test.espresso.intent.matcher.IntentMatchers;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

@Ignore("b/265140063")
@LargeTest
@RunWith(AndroidJUnit4.class)
public class BluetoothPrefsTest {

    Context mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    Intent mIntent;

    ActivityScenario<BluetoothPrefs> mActivityScenario;

    @Before
    public void setUp() {
        Intents.init();
        enableActivity(true);

        mIntent = new Intent();
        mIntent.setClass(mTargetContext, BluetoothPrefs.class);

        mActivityScenario = ActivityScenario.launch(mIntent);
    }

    @After
    public void tearDown() throws Exception {
        if (mActivityScenario != null) {
            // Workaround for b/159805732. Without this, test hangs for 45 seconds.
            Thread.sleep(1_000);
            mActivityScenario.close();
        }

        enableActivity(false);
    }

    @Test
    public void initialize_launchesBluetoothSettingsActivity() {
        intended(IntentMatchers.hasAction(BluetoothPrefs.BLUETOOTH_SETTING_ACTION));
    }

    private void enableActivity(boolean enable) {
        int enabledState = enable ? COMPONENT_ENABLED_STATE_ENABLED
                : COMPONENT_ENABLED_STATE_DEFAULT;

        mTargetContext.getPackageManager().setApplicationEnabledSetting(
                mTargetContext.getPackageName(), enabledState, DONT_KILL_APP);

        ComponentName activityName = new ComponentName(mTargetContext, BluetoothPrefs.class);
        mTargetContext.getPackageManager().setComponentEnabledSetting(
                activityName, enabledState, DONT_KILL_APP);
    }
}
 No newline at end of file