Commit 57bd38de authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Android] Record keyboard accessory bar metrics up to once

Before this CL, the accessory bar wouldn't add impressions to delayed
appearing actions. This CL ensures this is done once (per new set of
actions) while keeping the constraint that every bar impression happens
exactly once.

Bug: 873143
Change-Id: I4de6c8f8e95321176d9bca19459d6e9d2cdae746
Reviewed-on: https://chromium-review.googlesource.com/1171227
Commit-Queue: Friedrich Horschig <fhorschig@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582881}
parent b5fb1284
......@@ -56,8 +56,7 @@ public class AutofillKeyboardAccessoryBridge
@Override
public void suggestionSelected(int listIndex) {
KeyboardAccessoryMetricsRecorder.recordActionSelected(
AccessoryAction.GENERATE_PASSWORD_AUTOMATIC);
KeyboardAccessoryMetricsRecorder.recordActionSelected(AccessoryAction.AUTOFILL_SUGGESTION);
if (mManualFillingCoordinator != null) mManualFillingCoordinator.dismiss();
if (mNativeAutofillKeyboardAccessory == 0) return;
nativeSuggestionSelected(mNativeAutofillKeyboardAccessory, listIndex);
......
......@@ -40,7 +40,7 @@ public class AccessorySheetCoordinator {
model.addObserver(new PropertyModelChangeProcessor<>(model, stubHolder,
new LazyViewBinderAdapter<>(
new AccessorySheetViewBinder(), this::onViewInflated)));
KeyboardAccessoryMetricsRecorder.recordModelChanges(model);
KeyboardAccessoryMetricsRecorder.registerMetricsObserver(model);
mMediator = new AccessorySheetMediator(model);
}
......
......@@ -72,7 +72,7 @@ public class KeyboardAccessoryCoordinator {
model.addObserver(new PropertyModelChangeProcessor<>(model, mViewHolder,
new LazyViewBinderAdapter<>(
new KeyboardAccessoryViewBinder(), this::onViewInflated)));
KeyboardAccessoryMetricsRecorder.recordModelChanges(model);
KeyboardAccessoryMetricsRecorder.registerMetricsObserver(model);
}
/**
......
......@@ -368,30 +368,64 @@ public class KeyboardAccessoryControllerTest {
}
@Test
public void testRecordsContentImpressionsOnlyOnInitialShowing() {
public void testRecordsContentBarImpressionOnceAndContentsUpToOnce() {
assertThat(RecordHistogram.getHistogramTotalCountForTesting(
KeyboardAccessoryMetricsRecorder.UMA_KEYBOARD_ACCESSORY_BAR_SHOWN),
is(0));
// First showing contains actions only.
mModel.getActionList().add(new Action(null, 0, null));
mCoordinator.addTab(mTestTab);
mMediator.keyboardVisibilityChanged(true);
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_TABS), is(1));
assertThat(getShownMetricsCount(AccessoryBarContents.ANY_CONTENTS), is(1));
// Adding a tabs doesn't change the total impression count but the specific bucket.
mModel.getActionList().add(new Action(null, 0, null));
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_ACTIONS), is(1));
assertThat(getShownMetricsCount(AccessoryBarContents.ANY_CONTENTS), is(1));
// Adding a tabs or suggestions now doesn't change the impression count
KeyboardAccessoryData.PropertyProvider<Action> autofillSuggestionProvider =
new KeyboardAccessoryData.PropertyProvider<>(AUTOFILL_SUGGESTION);
Action suggestion = new Action("Suggestion", AUTOFILL_SUGGESTION, (a) -> {});
mCoordinator.registerActionListProvider(autofillSuggestionProvider);
autofillSuggestionProvider.notifyObservers(new Action[] {suggestion});
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_AUTOFILL_SUGGESTIONS), is(1));
// The other changes were not recorded again - just the changes.
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_ACTIONS), is(1));
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_TABS), is(1));
assertThat(getShownMetricsCount(AccessoryBarContents.NO_CONTENTS), is(0));
}
@Test
public void testRecordsAgainIfExistingItemsChange() {
assertThat(RecordHistogram.getHistogramTotalCountForTesting(
KeyboardAccessoryMetricsRecorder.UMA_KEYBOARD_ACCESSORY_BAR_SHOWN),
is(0));
// Add a tab and show, so the accessory is permanently visible.
mCoordinator.addTab(mTestTab);
mMediator.keyboardVisibilityChanged(true);
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_TABS), is(0));
// Adding an action fills the bar impression bucket and the actions set once.
mModel.getActionList().set(
new Action[] {new Action("One", AccessoryAction.GENERATE_PASSWORD_AUTOMATIC, null),
new Action("Two", AccessoryAction.GENERATE_PASSWORD_AUTOMATIC, null)});
assertThat(getActionImpressionCount(AccessoryAction.GENERATE_PASSWORD_AUTOMATIC), is(1));
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_ACTIONS), is(1));
assertThat(getShownMetricsCount(AccessoryBarContents.ANY_CONTENTS), is(1));
// Adding another action leaves bar impressions unchanged but affects the actions bucket.
mModel.getActionList().set(
new Action[] {new Action("Uno", AccessoryAction.GENERATE_PASSWORD_AUTOMATIC, null),
new Action("Dos", AccessoryAction.GENERATE_PASSWORD_AUTOMATIC, null)});
assertThat(getShownMetricsCount(AccessoryBarContents.WITH_ACTIONS), is(1));
assertThat(getActionImpressionCount(AccessoryAction.GENERATE_PASSWORD_AUTOMATIC), is(2));
}
private int getActionImpressionCount(@AccessoryAction int bucket) {
return RecordHistogram.getHistogramValueCountForTesting(
KeyboardAccessoryMetricsRecorder.UMA_KEYBOARD_ACCESSORY_ACTION_IMPRESSION, bucket);
}
private int getShownMetricsCount(@AccessoryBarContents int bucket) {
......
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