DO NOT MERGE Disable changing lock when device is not provisioned.

When the device is not yet provisioned and settings is launched:
- disable the entry point for changing device lock
- set display search menu to false
- disallow update to display the search menu

Bug: 110034419
Test: make RunSettingsRoboTests
Change-Id: Ieb7eb0e8699229ec0824ccc19d7b958ac44965a2
Merged-In: Ieb7eb0e8699229ec0824ccc19d7b958ac44965a2
This commit is contained in:
Doris Ling
2018-08-01 17:24:34 -07:00
parent 0e1393ae8c
commit cb68db7d4f
5 changed files with 141 additions and 3 deletions

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2018 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.settings;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.app.FragmentHostCallback;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings.Global;
import com.android.settings.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class
})
public class ChooseLockGenericTest {
@Mock
private ChooseLockGeneric mActivity;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
when(mActivity.getContentResolver()).thenReturn(mContext.getContentResolver());
when(mActivity.getTheme()).thenReturn(mContext.getTheme());
when(mActivity.getResources()).thenReturn(mContext.getResources());
}
@After
public void tearDown() {
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 1);
}
@Test
public void onCreate_deviceNotProvisioned_shouldFinishActivity() {
Global.putInt(mContext.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
final ChooseLockGenericFragment fragment = spy(new ChooseLockGenericFragment());
when(fragment.getActivity()).thenReturn(mActivity);
ReflectionHelpers.setField(fragment, "mHost", new TestHostCallbacks());
fragment.onCreate(Bundle.EMPTY);
verify(mActivity).finish();
}
public class TestHostCallbacks extends FragmentHostCallback<Activity> {
public TestHostCallbacks() {
super(mActivity, null /* handler */, 0 /* windowAnimations */);
}
@Override
public Activity onGetHost() {
return mActivity;
}
}
}

View File

@@ -25,6 +25,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.Settings.Global;
import android.view.Menu;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -80,11 +81,39 @@ public class SettingsActivityTest {
when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
doReturn(RuntimeEnvironment.application.getClassLoader()).when(mActivity).getClassLoader();
final Context context = RuntimeEnvironment.application;
doReturn(context.getClassLoader()).when(mActivity).getClassLoader();
doReturn(context.getContentResolver()).when(mActivity).getContentResolver();
mActivity.launchSettingFragment(null, true, mock(Intent.class));
}
@Test
public void launchSettingFragment_deviceNotProvisioned_shouldNotShowSearch() {
final Context context = RuntimeEnvironment.application;
Global.putInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
doReturn(context.getClassLoader()).when(mActivity).getClassLoader();
doReturn(context.getContentResolver()).when(mActivity).getContentResolver();
mActivity.launchSettingFragment(null, true, mock(Intent.class));
assertThat(mActivity.mDisplaySearch).isFalse();
}
@Test
public void setDisplaySearchMenu_deviceNotProvisioned_shouldNotUpdate() {
final Context context = RuntimeEnvironment.application;
Global.putInt(context.getContentResolver(), Global.DEVICE_PROVISIONED, 0);
doReturn(context.getContentResolver()).when(mActivity).getContentResolver();
mActivity.mDisplaySearch = false;
mActivity.setDisplaySearchMenu(true);
assertThat(mActivity.mDisplaySearch).isFalse();
}
@Test
public void testSetTaskDescription_IconChanged() {
mActivity.setTaskDescription(mTaskDescription);