Added autofill options on Developer Options screen.

Test: manual verification
Test: atest AutofillResetOptionsPreferenceControllerTest\
            AutofillLoggingLevelPreferenceControllerTest
Test: runtest --path packages/apps/Settings/tests/unit/src/com/android/settings/core/PreferenceControllerContractTest.java
Fixes: 65700540

Change-Id: I6b35fbf549529f4d97df164ce3fb6d641ee37650
This commit is contained in:
Felipe Leme
2018-07-24 17:24:40 -07:00
parent f24b749ec0
commit 9bf591b832
15 changed files with 839 additions and 0 deletions

View File

@@ -0,0 +1,144 @@
/*
* 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.development.autofill;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.os.RemoteException;
import android.view.autofill.AutofillManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.R;
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 androidx.preference.PreferenceScreen;
import androidx.preference.ListPreference;
@RunWith(SettingsRobolectricTestRunner.class)
public class AutofillLoggingLevelPreferenceControllerTest {
private static final int IDX_OFF = 0;
private static final int IDX_DEBUG = 1;
private static final int IDX_VERBOSE = 2;
@Mock
private ListPreference mPreference;
@Mock
private PreferenceScreen mPreferenceScreen;
private Context mContext;
private AutofillLoggingLevelPreferenceController mController;
private AutofillTestingHelper mHelper;
private String[] mListValues;
private String[] mListSummaries;
@Before
public void setup() {
MockitoAnnotations.initMocks(this); // TODO: use @Rule
mContext = RuntimeEnvironment.application;
mHelper = new AutofillTestingHelper(mContext);
final Resources resources = mContext.getResources();
mListValues = resources.getStringArray(R.array.autofill_logging_level_values);
mListSummaries = resources.getStringArray(R.array.autofill_logging_level_entries);
mController = new AutofillLoggingLevelPreferenceController(mContext);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mPreference);
mController.displayPreference(mPreferenceScreen);
}
@Test
public void handlePreferenceTreeClick_differentPreferenceKey_shouldNotTrigger()
throws Exception {
when(mPreference.getKey()).thenReturn("SomeRandomKey");
mHelper.setLoggingLevel(108);
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
assertThat(mHelper.getLoggingLevel()).isEqualTo(108);
}
@Test
public void onPreferenceChange_off() throws Exception {
mHelper.setLoggingLevel(108);
mController.onPreferenceChange(mPreference, mListValues[IDX_OFF]);
assertThat(mHelper.getLoggingLevel()).isEqualTo(AutofillManager.NO_LOGGING);
}
@Test
public void onPreferenceChange_debug() throws Exception {
mHelper.setLoggingLevel(108);
mController.onPreferenceChange(mPreference, mListValues[IDX_DEBUG]);
assertThat(mHelper.getLoggingLevel())
.isEqualTo(AutofillManager.FLAG_ADD_CLIENT_DEBUG);
}
@Test
public void onPreferenceChange_verbose() throws Exception {
mHelper.setLoggingLevel(108);
mController.onPreferenceChange(mPreference, mListValues[IDX_VERBOSE]);
assertThat(mHelper.getLoggingLevel())
.isEqualTo(AutofillManager.FLAG_ADD_CLIENT_VERBOSE);
}
@Test
public void onSettingsChange_off() throws Exception {
mHelper.setLoggingLevel(AutofillManager.NO_LOGGING);
mController.updateState(mPreference);
verify(mPreference).setValue(mListValues[IDX_OFF]);
verify(mPreference).setSummary(mListSummaries[IDX_OFF]);
}
@Test
public void onSettingsChange_debug() throws Exception {
mHelper.setLoggingLevel(AutofillManager.FLAG_ADD_CLIENT_DEBUG);
mController.updateState(mPreference);
verify(mPreference).setValue(mListValues[IDX_DEBUG]);
verify(mPreference).setSummary(mListSummaries[IDX_DEBUG]);
}
@Test
public void onSettingsChange_verbose() throws Exception {
mHelper.setLoggingLevel(AutofillManager.FLAG_ADD_CLIENT_VERBOSE);
mController.updateState(mPreference);
verify(mPreference).setValue(mListValues[IDX_VERBOSE]);
verify(mPreference).setSummary(mListSummaries[IDX_VERBOSE]);
}
}

View File

@@ -0,0 +1,94 @@
/*
* 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.development.autofill;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.RemoteException;
import android.view.autofill.AutofillManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
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 androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
@RunWith(SettingsRobolectricTestRunner.class)
public class AutofillResetOptionsPreferenceControllerTest {
@Mock
private SwitchPreference mPreference;
@Mock
private PreferenceScreen mPreferenceScreen;
private Context mContext;
private AutofillResetOptionsPreferenceController mController;
private AutofillTestingHelper mHelper;
@Before
public void setup() {
MockitoAnnotations.initMocks(this); // TODO: use @Rule
mContext = RuntimeEnvironment.application;
mHelper = new AutofillTestingHelper(mContext);
mController = new AutofillResetOptionsPreferenceController(mContext);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mPreference);
mController.displayPreference(mPreferenceScreen);
}
@Test
public void handlePreferenceTreeClick_differentPreferenceKey_shouldNotReset() throws Exception {
when(mPreference.getKey()).thenReturn("SomeRandomKey");
mHelper.setLoggingLevel(4);
mHelper.setMaxPartitionsSize(8);
mHelper.setMaxVisibleDatasets(15);
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
assertThat(mHelper.getLoggingLevel()).isEqualTo(4);
assertThat(mHelper.getMaxPartitionsSize()).isEqualTo(8);
assertThat(mHelper.getMaxVisibleDatasets()).isEqualTo(15);
}
@Test
public void handlePreferenceTreeClick_correctPreferenceKey_shouldReset() throws Exception {
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
mHelper.setMaxPartitionsSize(16);
mHelper.setMaxVisibleDatasets(23);
mHelper.setLoggingLevel(42);
assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
assertThat(mHelper.getLoggingLevel())
.isEqualTo(AutofillManager.DEFAULT_LOGGING_LEVEL);
assertThat(mHelper.getMaxPartitionsSize())
.isEqualTo(AutofillManager.DEFAULT_MAX_PARTITIONS_SIZE);
assertThat(mHelper.getMaxVisibleDatasets())
.isEqualTo(0);
}
}

View File

@@ -0,0 +1,62 @@
/*
* 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.development.autofill;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
final class AutofillTestingHelper {
private final ContentResolver mResolver;
public AutofillTestingHelper(Context context) {
mResolver = context.getContentResolver();
}
public void setLoggingLevel(int max) {
setGlobal(Settings.Global.AUTOFILL_LOGGING_LEVEL, max);
}
public void setMaxPartitionsSize(int max) {
setGlobal(Settings.Global.AUTOFILL_MAX_PARTITIONS_SIZE, max);
}
public void setMaxVisibleDatasets(int level) {
setGlobal(Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS, level);
}
public int getLoggingLevel() throws SettingNotFoundException {
return getGlobal(Settings.Global.AUTOFILL_LOGGING_LEVEL);
}
public int getMaxPartitionsSize() throws SettingNotFoundException {
return getGlobal(Settings.Global.AUTOFILL_MAX_PARTITIONS_SIZE);
}
public int getMaxVisibleDatasets() throws SettingNotFoundException {
return getGlobal(Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS);
}
private void setGlobal(String key, int value) {
Settings.Global.putInt(mResolver, key, value);
}
private int getGlobal(String key) throws SettingNotFoundException {
return Settings.Global.getInt(mResolver, key);
}
}