Skip to content

Commit

Permalink
[Start] Build histogram for click rates of Single tab card on Start S…
Browse files Browse the repository at this point in the history
…urface

In this CL, we completed the histogram "StartSurface.Module.Click" by recording the clicking actions on the Single tab card on Start Surface and adding the test for it. The histogram is recorded when the user clicks on the single tab card.

(cherry picked from commit ab1e45e)

Bug: 1384156
Change-Id: I76fd60a9d955a366de8371ddab285cedd5f3edb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4198966
Commit-Queue: Xinyi Ji <[email protected]>
Reviewed-by: Weilun Shi <[email protected]>
Reviewed-by: Xi Han <[email protected]>
Cr-Original-Commit-Position: refs/heads/main@{#1098132}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4219037
Commit-Queue: Xi Han <[email protected]>
Cr-Commit-Position: refs/branch-heads/5563@{chromium#154}
Cr-Branched-From: 3ac59a6-refs/heads/main@{#1097615}
  • Loading branch information
Xinyi Ji authored and Chromium LUCI CQ committed Feb 3, 2023
1 parent ecb64ff commit 4e070d6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher.TabSwitcherViewObserver;
import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.chrome.browser.util.BrowserUiUtils;
import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration;
import org.chromium.chrome.features.start_surface.StartSurfaceUserData;
import org.chromium.ui.modelutil.PropertyModel;
Expand Down Expand Up @@ -78,6 +79,8 @@ public class SingleTabSwitcherMediator implements TabSwitcher.Controller {
&& mTabModelSelector.getCurrentTabId() != TabList.INVALID_TAB_INDEX) {
StartSurfaceUserData.setOpenedFromStart(mTabModelSelector.getCurrentTab());
selectTheCurrentTab();
BrowserUiUtils.recordModuleClickHistogram(BrowserUiUtils.HostSurface.START_SURFACE,
BrowserUiUtils.ModuleTypeOnStartAndNTP.SINGLE_TAB_CARD);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;

import static org.chromium.chrome.features.tasks.SingleTabViewProperties.CLICK_LISTENER;
Expand All @@ -34,8 +35,14 @@
import org.robolectric.Robolectric;
import org.robolectric.annotation.Config;

import org.chromium.base.ContextUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tasks.tab_management.TabListFaviconProvider;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
import org.chromium.chrome.browser.util.BrowserUiUtils;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
Expand All @@ -45,6 +52,8 @@
@Config(manifest = Config.NONE)
public class SingleTabViewBinderUnitTest {
private static final String TEST_TITLE = "test";
private final int mTabId = 1;
private static final String HISTOGRAM_START_SURFACE_MODULE_CLICK = "StartSurface.Module.Click";

private Activity mActivity;
private SingleTabView mSingleTabView;
Expand All @@ -54,6 +63,12 @@ public class SingleTabViewBinderUnitTest {

@Mock
private View.OnClickListener mClickListener;
@Mock
private TabModelSelector mTabModelSelector;
@Mock
private TabSwitcher.OnTabSelectingListener mOnTabSelectingListener;
@Mock
private TabListFaviconProvider mTabListFaviconProvider;

@Before
public void setUp() throws Exception {
Expand Down Expand Up @@ -124,4 +139,22 @@ public void testClickListener() {
mPropertyModel.set(IS_VISIBLE, false);
assertFalse(isViewVisible(R.id.single_tab_view));
}

@Test
@SmallTest
public void testRecordHistogramSingleTabCardClick_StartSurface() {
doReturn(mTabId).when(mTabModelSelector).getCurrentTabId();
doReturn(false).when(mTabModelSelector).isIncognitoSelected();
SingleTabSwitcherMediator mediator =
new SingleTabSwitcherMediator(ContextUtils.getApplicationContext(), mPropertyModel,
mTabModelSelector, mTabListFaviconProvider);
mediator.setOnTabSelectingListener(mOnTabSelectingListener);
mSingleTabView.performClick();
assertEquals(HISTOGRAM_START_SURFACE_MODULE_CLICK
+ " is not recorded correctly when clicking on the single tab card.",
1,
RecordHistogram.getHistogramValueCountForTesting(
HISTOGRAM_START_SURFACE_MODULE_CLICK,
BrowserUiUtils.ModuleTypeOnStartAndNTP.SINGLE_TAB_CARD));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ [email protected].
or check about this source and topic; 3) click the learn more button on the
top of the feeds section. For omnibox: is recorded every time when user uses
Omnibox or voice search on Omnibox to navigate. This is consistent with
MobileOmniboxUse. The histogram is logged on Start surface and is
Android-only.
MobileOmniboxUse. For single tab card: is recorded every time when user
clicks on the single tab card. The histogram is logged on Start surface and
is Android-only.
</summary>
</histogram>

Expand Down

0 comments on commit 4e070d6

Please sign in to comment.