Merge "Log source with visibility change"
This commit is contained in:
committed by
Android (Google) Code Review
commit
3a399f5eb4
@@ -79,7 +79,8 @@ public class DevelopmentSettingsTest {
|
||||
doReturn(mActivity).when(mSettings).getActivity();
|
||||
when(mPreferenceManager.getContext()).thenReturn(mContext);
|
||||
when(mFeatureFactory.dashboardFeatureProvider.getPreferencesForCategory(
|
||||
mActivity, mContext, CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT))
|
||||
mActivity, mContext, mSettings.getMetricsCategory(),
|
||||
CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT))
|
||||
.thenReturn(preferences);
|
||||
|
||||
mSettings.onAttach(mContext);
|
||||
|
@@ -24,6 +24,7 @@ import android.content.pm.PackageManager;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
@@ -57,18 +58,20 @@ public class AppInfoWithHeaderTest {
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
|
||||
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
|
||||
when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
|
||||
.thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
|
||||
mAppInfoWithHeader = new TestFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAppHeaderIsAdded() {
|
||||
final AppHeaderController appHeaderController = new AppHeaderController(
|
||||
ShadowApplication.getInstance().getApplicationContext(),
|
||||
mAppInfoWithHeader,
|
||||
null);
|
||||
when(mFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
|
||||
when(mFactory.applicationFeatureProvider.newAppHeaderController(mAppInfoWithHeader, null))
|
||||
.thenReturn(new AppHeaderController(
|
||||
ShadowApplication.getInstance().getApplicationContext(),
|
||||
mAppInfoWithHeader,
|
||||
null));
|
||||
.thenReturn(appHeaderController);
|
||||
mAppInfoWithHeader.onActivityCreated(null);
|
||||
|
||||
verify(mAppInfoWithHeader.mScreen).addPreference(any(LayoutPreference.class));
|
||||
|
@@ -21,9 +21,11 @@ import android.os.UserManager;
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources.SettingsShadowTheme;
|
||||
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -46,7 +48,8 @@ import static org.mockito.Mockito.when;
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowTheme.class,
|
||||
ShadowDynamicIndexableContentMonitor.class
|
||||
ShadowDynamicIndexableContentMonitor.class,
|
||||
ShadowEventLogWriter.class
|
||||
})
|
||||
public class ManageApplicationsTest {
|
||||
|
||||
@@ -55,8 +58,8 @@ public class ManageApplicationsTest {
|
||||
@Mock private UserManager mUserManager;
|
||||
|
||||
private Looper mBgLooper;
|
||||
|
||||
private ManageApplications mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -67,6 +70,7 @@ public class ManageApplicationsTest {
|
||||
when(mState.getBackgroundLooper()).thenReturn(mBgLooper);
|
||||
|
||||
mFragment = new ManageApplications();
|
||||
ReflectionHelpers.setField(mFragment, "mLifecycle", new Lifecycle());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -15,9 +15,15 @@
|
||||
*/
|
||||
package com.android.settings.core.instrumentation;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -29,9 +35,11 @@ import static com.android.settings.core.instrumentation.Instrumentable.METRICS_C
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -54,7 +62,23 @@ public class VisibilityLoggerMixinTest {
|
||||
mMixin.onResume();
|
||||
|
||||
verify(mMetricsFeature, times(1))
|
||||
.visible(any(Context.class), eq(TestInstrumentable.TEST_METRIC));
|
||||
.visible(any(Context.class), eq(MetricsProto.MetricsEvent.VIEW_UNKNOWN),
|
||||
eq(TestInstrumentable.TEST_METRIC));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLogVisibleWithSource() {
|
||||
final Intent sourceIntent = new Intent()
|
||||
.putExtra(SettingsActivity.EXTRA_SOURCE_METRICS_CATEGORY,
|
||||
MetricsProto.MetricsEvent.SETTINGS_GESTURES);
|
||||
final Activity activity = mock(Activity.class);
|
||||
when(activity.getIntent()).thenReturn(sourceIntent);
|
||||
mMixin.setSourceMetricsCategory(activity);
|
||||
mMixin.onResume();
|
||||
|
||||
verify(mMetricsFeature, times(1))
|
||||
.visible(any(Context.class), eq(MetricsProto.MetricsEvent.SETTINGS_GESTURES),
|
||||
eq(TestInstrumentable.TEST_METRIC));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -98,7 +98,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
tile.metaData = new Bundle();
|
||||
tile.metaData.putString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS, "HI");
|
||||
tile.priority = 10;
|
||||
mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getTitle()).isEqualTo(tile.title);
|
||||
assertThat(preference.getSummary()).isEqualTo(tile.summary);
|
||||
@@ -118,7 +119,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
tile.intent = new Intent();
|
||||
tile.intent.setComponent(new ComponentName("pkg", "class"));
|
||||
|
||||
mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getFragment()).isNull();
|
||||
assertThat(preference.getOnPreferenceClickListener()).isNotNull();
|
||||
@@ -140,7 +142,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE))
|
||||
.thenReturn(mUserManager);
|
||||
|
||||
mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.getOnPreferenceClickListener().onPreferenceClick(null);
|
||||
|
||||
verify(mActivity).getFragmentManager();
|
||||
@@ -160,7 +163,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE))
|
||||
.thenReturn(mUserManager);
|
||||
|
||||
mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.getOnPreferenceClickListener().onPreferenceClick(null);
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(
|
||||
any(Context.class),
|
||||
@@ -177,8 +181,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Tile tile = new Tile();
|
||||
tile.intent = new Intent();
|
||||
tile.intent.setComponent(new ComponentName("pkg", "class"));
|
||||
mImpl.bindPreferenceToTile(mActivity, preference, tile, null /* key */
|
||||
, Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
|
||||
preference, tile, null /*key */, Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getKey()).isNotNull();
|
||||
assertThat(preference.getOrder()).isEqualTo(Preference.DEFAULT_ORDER);
|
||||
@@ -192,8 +196,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
tile.key = "key";
|
||||
tile.intent = new Intent();
|
||||
tile.intent.setComponent(new ComponentName("pkg", "class"));
|
||||
mImpl.bindPreferenceToTile(mActivity, preference, tile, null /* key */
|
||||
, Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
|
||||
preference, tile, null /* key */, Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(tile.key);
|
||||
}
|
||||
@@ -206,7 +210,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Tile tile = new Tile();
|
||||
tile.metaData = new Bundle();
|
||||
tile.priority = 10;
|
||||
mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", baseOrder);
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
|
||||
preference, tile, "123", baseOrder);
|
||||
|
||||
assertThat(preference.getOrder()).isEqualTo(-tile.priority + baseOrder);
|
||||
}
|
||||
@@ -223,12 +228,16 @@ public class DashboardFeatureProviderImplTest {
|
||||
tile.metaData = new Bundle();
|
||||
tile.metaData.putString("com.android.settings.intent.action", "TestAction");
|
||||
tile.userHandle = null;
|
||||
mImpl.bindPreferenceToTile(activity, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.performClick();
|
||||
ShadowActivity shadowActivity = shadowOf(activity);
|
||||
|
||||
assertThat(shadowActivity.getNextStartedActivityForResult().intent.getAction())
|
||||
final Intent launchIntent = shadowActivity.getNextStartedActivityForResult().intent;
|
||||
assertThat(launchIntent.getAction())
|
||||
.isEqualTo("TestAction");
|
||||
assertThat(launchIntent.getIntExtra(SettingsActivity.EXTRA_SOURCE_METRICS_CATEGORY, 0))
|
||||
.isEqualTo(MetricsProto.MetricsEvent.SETTINGS_GESTURES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -236,7 +245,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
final DashboardFeatureProviderImpl mSpy = spy(mImpl);
|
||||
when(mSpy.isEnabled()).thenReturn(false);
|
||||
|
||||
assertThat(mSpy.getPreferencesForCategory(null, null, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
assertThat(mSpy.getPreferencesForCategory(null, null,
|
||||
MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@@ -248,7 +258,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
.thenReturn(null);
|
||||
|
||||
assertThat(mSpy.getPreferencesForCategory(null, null, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
assertThat(mSpy.getPreferencesForCategory(null, null,
|
||||
MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@@ -260,7 +271,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
.thenReturn(new DashboardCategory());
|
||||
|
||||
assertThat(mSpy.getPreferencesForCategory(null, null, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
assertThat(mSpy.getPreferencesForCategory(null, null,
|
||||
MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@@ -277,6 +289,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
|
||||
assertThat(mSpy.getPreferencesForCategory(mActivity,
|
||||
ShadowApplication.getInstance().getApplicationContext(),
|
||||
MetricsProto.MetricsEvent.SETTINGS_GESTURES,
|
||||
CategoryKey.CATEGORY_HOMEPAGE).isEmpty())
|
||||
.isFalse();
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import android.support.v7.preference.PreferenceScreen;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
@@ -37,6 +38,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -186,6 +188,8 @@ public class DashboardFragmentTest {
|
||||
mControllers = new ArrayList<>();
|
||||
|
||||
when(mPreferenceManager.getContext()).thenReturn(mContext);
|
||||
ReflectionHelpers.setField(
|
||||
this, "mVisibilityLoggerMixin", mock(VisibilityLoggerMixin.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.testutils.shadow;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.instrumentation.EventLogWriter;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@Implements(value = EventLogWriter.class, callThroughByDefault = false)
|
||||
public class ShadowEventLogWriter {
|
||||
@Implementation
|
||||
public void visible(Context context, int source, int category) {
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user