Commit bcfea980 authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Tab Search: Add metrics to track switched tab position

This CL adds metrics to track the position of a switched tab from
both filtered and unfiltered lists.

Bug: 1099917
Change-Id: I4cb7822240bd78b228906b0fd86eaf364b4cdb33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2529692
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Reviewed-by: default avatarYuheng Huang <yuhengh@chromium.org>
Reviewed-by: default avatarJesse Doherty <jwd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826869}
parent 4a88f427
......@@ -281,8 +281,9 @@ export class TabSearchAppElement extends PolymerElement {
* @private
*/
onItemClick_(e) {
const tabIndex = e.currentTarget.parentNode.indexOf(e.currentTarget);
const tabId = Number.parseInt(e.currentTarget.id, 10);
this.apiProxy_.switchToTab({tabId}, !!this.searchText_);
this.apiProxy_.switchToTab({tabId}, !!this.searchText_, tabIndex);
}
/**
......@@ -371,7 +372,8 @@ export class TabSearchAppElement extends PolymerElement {
e.preventDefault();
} else if (e.key === 'Enter' || e.key === ' ') {
this.apiProxy_.switchToTab(
{tabId: this.getSelectedTab_().tabId}, !!this.searchText_);
{tabId: this.getSelectedTab_().tabId}, !!this.searchText_,
this.getSelectedIndex());
e.stopPropagation();
}
}
......@@ -424,7 +426,8 @@ export class TabSearchAppElement extends PolymerElement {
this.ariaLabel_(this.filteredOpenTabs_[this.getSelectedIndex()]));
} else if (e.key === 'Enter') {
this.apiProxy_.switchToTab(
{tabId: this.getSelectedTab_().tabId}, !!this.searchText_);
{tabId: this.getSelectedTab_().tabId}, !!this.searchText_,
this.getSelectedIndex());
e.stopPropagation();
}
}
......
......@@ -29,8 +29,9 @@ export class TabSearchApiProxy {
/**
* @param {!SwitchToTabInfo} info
* @param {boolean} withSearch
* @param {number} switchedTabIndex
*/
switchToTab(info, withSearch) {}
switchToTab(info, withSearch, switchedTabIndex) {}
/** @return {!PageCallbackRouter} */
getCallbackRouter() {}
......@@ -71,12 +72,17 @@ export class TabSearchApiProxyImpl {
}
/** @override */
switchToTab(info, withSearch) {
switchToTab(info, withSearch, switchedTabIndex) {
chrome.metricsPrivate.recordEnumerationValue(
'Tabs.TabSearch.WebUI.TabSwitchAction',
withSearch ? TabSwitchAction.WITH_SEARCH
: TabSwitchAction.WITHOUT_SEARCH,
Object.keys(TabSwitchAction).length);
chrome.metricsPrivate.recordSmallCount(
withSearch ? 'Tabs.TabSearch.WebUI.IndexOfSwitchTabInFilteredList' :
'Tabs.TabSearch.WebUI.IndexOfSwitchTabInUnfilteredList',
switchedTabIndex);
this.handler.switchToTab(info);
}
......
......@@ -286,9 +286,24 @@ suite('TabSearchAppTest', () => {
// Assert switchToTab() was called appropriately for an unfiltered tab list.
await testProxy.whenCalled('switchToTab')
.then(([ tabInfo, withSearch ]) => {
.then(([tabInfo, withSearch, switchedTabIndex]) => {
assertEquals(1, tabInfo.tabId);
assertFalse(withSearch);
assertEquals(0, switchedTabIndex);
});
testProxy.reset();
// Click the first element with tabId 6.
tabSearchItem = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('tab-search-item[id="6"]'));
tabSearchItem.click();
// Assert switchToTab() was called appropriately for an unfiltered tab list.
await testProxy.whenCalled('switchToTab')
.then(([tabInfo, withSearch, switchedTabIndex]) => {
assertEquals(6, tabInfo.tabId);
assertFalse(withSearch);
assertEquals(2, switchedTabIndex);
});
// Force a change to filtered tab data that would result in a
......@@ -308,9 +323,10 @@ suite('TabSearchAppTest', () => {
// Assert switchToTab() was called appropriately for a tab list fitlered by
// the search query.
await testProxy.whenCalled('switchToTab')
.then(([ tabInfo, withSearch ]) => {
.then(([tabInfo, withSearch, switchedTabIndex]) => {
assertEquals(2, tabInfo.tabId);
assertTrue(withSearch);
assertEquals(0, switchedTabIndex);
});
});
......
......@@ -46,8 +46,8 @@ export class TestTabSearchApiProxy extends TestBrowserProxy {
}
/** @override */
switchToTab(tabInfo, withSearch) {
this.methodCalled('switchToTab', [ tabInfo, withSearch ]);
switchToTab(tabInfo, withSearch, switchedTabIndex) {
this.methodCalled('switchToTab', [tabInfo, withSearch, switchedTabIndex]);
}
/** @override */
......
......@@ -2048,6 +2048,29 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>
<histogram name="Tabs.TabSearch.WebUI.IndexOf{Action}TabIn{State}List"
units="tabs" expires_after="M90">
<owner>tluk@chromium.org</owner>
<owner>robliao@chromium.org</owner>
<owner>yuhengh@chromium.org</owner>
<owner>romanarora@chromium.org</owner>
<summary>
Tab Search is a feature that allows users to better search their browsers
for their desired tabs and close any currently open tabs.
This records the index at which a {Action} has been performed on a tab in
Tab Search's tab list in a {State} state.
</summary>
<token key="Action">
<variant name="Close"/>
<variant name="Switch"/>
</token>
<token key="State">
<variant name="Filtered" summary="Filtered by user search query."/>
<variant name="Unfiltered" summary="Unfiltered by user search query."/>
</token>
</histogram>
<histogram name="Tabs.TabSearch.WebUI.InitialTabsRenderTime" units="ms"
expires_after="M90">
<owner>tluk@chromium.org</owner>
......
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