Commit f96a690f authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Fix for the Assistant voice search service being null

Returning early from the function if the service is null to guard
against a potential race condition affecting beta.

Bug: 1055274
Change-Id: Ibb419037e67b2bce7cc31b3f0371ed1264ca01fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2070823
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744450}
parent ddab13b0
...@@ -979,6 +979,9 @@ public class NewTabPageLayout extends LinearLayout implements TileGroup.Observer ...@@ -979,6 +979,9 @@ public class NewTabPageLayout extends LinearLayout implements TileGroup.Observer
@Override @Override
public void onAssistantVoiceSearchServiceChanged() { public void onAssistantVoiceSearchServiceChanged() {
// Potential race condition between destroy and the observer, see crbug.com/1055274.
if (mAssistantVoiceSearchService == null) return;
Drawable drawable = mAssistantVoiceSearchService.getCurrentMicDrawable(); Drawable drawable = mAssistantVoiceSearchService.getCurrentMicDrawable();
mVoiceSearchButton.setImageDrawable(drawable); mVoiceSearchButton.setImageDrawable(drawable);
......
...@@ -9,13 +9,13 @@ import android.content.Intent; ...@@ -9,13 +9,13 @@ import android.content.Intent;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.annotation.VisibleForTesting;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.ColorRes; import androidx.annotation.ColorRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.LocaleUtils; import org.chromium.base.LocaleUtils;
import org.chromium.base.SysUtils; import org.chromium.base.SysUtils;
...@@ -72,6 +72,7 @@ public class AssistantVoiceSearchService implements TemplateUrlService.TemplateU ...@@ -72,6 +72,7 @@ public class AssistantVoiceSearchService implements TemplateUrlService.TemplateU
new Locale("ml", "in"), new Locale("gu", "in"), new Locale("ur", "in"))); new Locale("ml", "in"), new Locale("gu", "in"), new Locale("ur", "in")));
private static final boolean DEFAULT_ASSISTANT_COLORFUL_MIC_ENABLED = false; private static final boolean DEFAULT_ASSISTANT_COLORFUL_MIC_ENABLED = false;
// TODO(wylieb): Convert this to an ObserverList and add #addObserver, #removeObserver.
private final Observer mObserver; private final Observer mObserver;
private final Context mContext; private final Context mContext;
private final ExternalAuthUtils mExternalAuthUtils; private final ExternalAuthUtils mExternalAuthUtils;
...@@ -260,5 +261,6 @@ public class AssistantVoiceSearchService implements TemplateUrlService.TemplateU ...@@ -260,5 +261,6 @@ public class AssistantVoiceSearchService implements TemplateUrlService.TemplateU
/** Enable the colorful mic for testing purposes. */ /** Enable the colorful mic for testing purposes. */
void setColorfulMicEnabledForTesting(boolean enabled) { void setColorfulMicEnabledForTesting(boolean enabled) {
mIsColorfulMicEnabled = enabled; mIsColorfulMicEnabled = enabled;
mShouldShowColorfulMic = enabled;
} }
} }
...@@ -8,10 +8,12 @@ import static org.mockito.ArgumentMatchers.any; ...@@ -8,10 +8,12 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
...@@ -21,7 +23,9 @@ import org.junit.Test; ...@@ -21,7 +23,9 @@ import org.junit.Test;
import org.junit.rules.TestRule; import org.junit.rules.TestRule;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.chromium.base.SysUtils; import org.chromium.base.SysUtils;
...@@ -55,8 +59,6 @@ public class AssistantVoiceSearchServiceUnitTest { ...@@ -55,8 +59,6 @@ public class AssistantVoiceSearchServiceUnitTest {
@Mock @Mock
GSAState mGsaState; GSAState mGsaState;
@Mock @Mock
Context mContext;
@Mock
PackageManager mPackageManager; PackageManager mPackageManager;
@Mock @Mock
TemplateUrlService mTemplateUrlService; TemplateUrlService mTemplateUrlService;
...@@ -64,11 +66,14 @@ public class AssistantVoiceSearchServiceUnitTest { ...@@ -64,11 +66,14 @@ public class AssistantVoiceSearchServiceUnitTest {
ExternalAuthUtils mExternalAuthUtils; ExternalAuthUtils mExternalAuthUtils;
PackageInfo mPackageInfo; PackageInfo mPackageInfo;
Context mContext;
@Before @Before
public void setUp() throws NameNotFoundException { public void setUp() throws NameNotFoundException {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = Mockito.spy(Robolectric.buildActivity(Activity.class).setup().get());
doReturn(true).when(mExternalAuthUtils).isChromeGoogleSigned(); doReturn(true).when(mExternalAuthUtils).isChromeGoogleSigned();
doReturn(true).when(mExternalAuthUtils).isGoogleSigned(IntentHandler.PACKAGE_GSA); doReturn(true).when(mExternalAuthUtils).isGoogleSigned(IntentHandler.PACKAGE_GSA);
...@@ -182,4 +187,14 @@ public class AssistantVoiceSearchServiceUnitTest { ...@@ -182,4 +187,14 @@ public class AssistantVoiceSearchServiceUnitTest {
mAssistantVoiceSearchService.setColorfulMicEnabledForTesting(true); mAssistantVoiceSearchService.setColorfulMicEnabledForTesting(true);
Assert.assertNull(mAssistantVoiceSearchService.getMicButtonColorStateList(0, mContext)); Assert.assertNull(mAssistantVoiceSearchService.getMicButtonColorStateList(0, mContext));
} }
@Test
@Feature("OmniboxAssistantVoiceSearch")
public void getCurrentMicDrawable() {
Drawable greyMic = mAssistantVoiceSearchService.getCurrentMicDrawable();
mAssistantVoiceSearchService.setColorfulMicEnabledForTesting(true);
Drawable colorfulMic = mAssistantVoiceSearchService.getCurrentMicDrawable();
Assert.assertNotEquals(greyMic, colorfulMic);
}
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment