Modifying setting suggestion logging to only log the shown items.

Previously if there was three suggestions in the suggestions view, all
three would be logged as shown, although by default only two of them are
shown and the third one is shown only if the view is expanded. Now, only
the actual shown items will be logged.

Test: RunSettingsRoboTests
Fixes: b/35348496

Change-Id: Ic3af7961b4713f48e63c51ac599cb55bf69975ff
This commit is contained in:
Soroosh Mariooryad
2017-02-10 11:12:31 -08:00
parent 0f76385e13
commit 25d8049bb2
3 changed files with 114 additions and 34 deletions

View File

@@ -15,20 +15,34 @@
*/
package com.android.settings.dashboard;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.view.View;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.dashboard.conditional.Condition;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.Tile;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -42,6 +56,12 @@ public class DashboardAdapterTest {
private Condition mCondition;
@Mock
private MetricsFeatureProvider mMetricsFeatureProvider;
@Mock
private TypedArray mTypedArray;
@Captor
private ArgumentCaptor<Integer> mActionCategoryCaptor = ArgumentCaptor.forClass(Integer.class);
@Captor
private ArgumentCaptor<String> mActionPackageCaptor = ArgumentCaptor.forClass(String.class);
private DashboardAdapter mDashboardAdapter;
@Before
@@ -59,4 +79,35 @@ public class DashboardAdapterTest {
mDashboardAdapter.setConditions(null);
assertThat(mDashboardAdapter.mDashboardData.getExpandedCondition()).isNull();
}
@Test
public void testSuggestionsLogs() {
when(mTypedArray.getColor(any(int.class), any(int.class))).thenReturn(0);
when(mContext.obtainStyledAttributes(any(int[].class))).thenReturn(mTypedArray);
List<Tile> suggestions = new ArrayList<Tile>();
suggestions.add(makeSuggestion("pkg1", "cls1"));
suggestions.add(makeSuggestion("pkg2", "cls2"));
suggestions.add(makeSuggestion("pkg3", "cls3"));
mDashboardAdapter.setCategoriesAndSuggestions(
new ArrayList<DashboardCategory>(), suggestions);
mDashboardAdapter.onPause();
verify(mMetricsFeatureProvider, times(4)).action(
any(Context.class), mActionCategoryCaptor.capture(), mActionPackageCaptor.capture());
String[] expectedPackages = new String[] {"pkg1", "pkg2", "pkg1", "pkg2"};
Integer[] expectedActions = new Integer[] {
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION,
MetricsEvent.ACTION_HIDE_SETTINGS_SUGGESTION};
assertThat(mActionPackageCaptor.getAllValues().toArray()).isEqualTo(expectedPackages);
assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
}
private Tile makeSuggestion(String pkgName, String className) {
Tile suggestion = new Tile();
suggestion.intent = new Intent("action");
suggestion.intent.setComponent(new ComponentName(pkgName, className));
return suggestion;
}
}