Fix race condition and optimize categoryUpdater refresh
- In SettingsActivity, do not call updateCategories() if nothing changed. - In SummaryLoader, create a mapping between tile key and summary. This is necessary to handle a race condition where category is refreshed after summary load. - In DashboardSummary, refresh Tile's summary to latest cache value everytime category is refreshed. Change-Id: I61389b8ba614ba7e34939325bada6e1bd6fa6709 Fix: 63149109 Test: robotests
This commit is contained in:
@@ -17,13 +17,21 @@
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.app.Activity;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
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.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@@ -31,18 +39,27 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SummaryLoaderTest {
|
||||
|
||||
private static final String SUMMARY_1 = "summary1";
|
||||
private static final String SUMMARY_2 = "summary2";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private SummaryLoader mSummaryLoader;
|
||||
private boolean mCallbackInvoked;
|
||||
private Tile mTile;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void SetUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
|
||||
|
||||
mTile = new Tile();
|
||||
mTile.summary = SUMMARY_1;
|
||||
mCallbackInvoked = false;
|
||||
@@ -71,4 +88,23 @@ public class SummaryLoaderTest {
|
||||
|
||||
assertThat(mCallbackInvoked).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSummaryToCache_hasCache_shouldUpdate() {
|
||||
|
||||
final String testSummary = "test_summary";
|
||||
final DashboardCategory category = new DashboardCategory();
|
||||
final Tile tile = new Tile();
|
||||
tile.key = "123";
|
||||
tile.intent = new Intent();
|
||||
category.addTile(tile);
|
||||
when(mFeatureFactory.dashboardFeatureProvider.getDashboardKeyForTile(tile))
|
||||
.thenReturn(tile.key);
|
||||
|
||||
mSummaryLoader.updateSummaryIfNeeded(tile, testSummary);
|
||||
tile.summary = null;
|
||||
mSummaryLoader.updateSummaryToCache(category);
|
||||
|
||||
assertThat(tile.summary).isEqualTo(testSummary);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user