Commit ea1af4b6 authored by Tom Lukaszewicz's avatar Tom Lukaszewicz Committed by Josip Sokcevic

Tab Search: Notify the backend when the UI is ready

This change updates the Tab Search UI code to call ShowUI() on its
BrowserProxy object when the necessary DOM changes have occurred and
have become visible.

This allows us to show the UI only when ready, preventing the UI from
stuttering as it resizes while the list items load in.

Bug: 1099917
Change-Id: Ia60f5ce1e0e30abd0dc1857344d880eb083356b8
Reviewed-on: https://chrome-internal-review.googlesource.com/c/chrome/browser/resources/tab_search/+/3245003Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819588}
parent fe77d241
...@@ -93,9 +93,15 @@ export class TabSearchAppElement extends PolymerElement { ...@@ -93,9 +93,15 @@ export class TabSearchAppElement extends PolymerElement {
const event = /** @type {!CustomEvent<!{value: number}>} */ (e); const event = /** @type {!CustomEvent<!{value: number}>} */ (e);
// Ensure that the full list of tabs has been rendered. // Ensure that the full list of tabs has been rendered.
assert(event.detail.value === this.filteredOpenTabs_.length); assert(event.detail.value === this.filteredOpenTabs_.length);
chrome.metricsPrivate.recordTime(
// Push showUI() to the event loop to allow reflow to occur following
// the DOM update.
setTimeout(() => {
this.apiProxy_.showUI();
chrome.metricsPrivate.recordTime(
'Tabs.TabSearch.WebUI.InitialTabsRenderTime', 'Tabs.TabSearch.WebUI.InitialTabsRenderTime',
Math.round(window.performance.now())); Math.round(window.performance.now()));
}, 0);
}); });
} }
this.openTabs_ = profileTabs.windows; this.openTabs_ = profileTabs.windows;
......
...@@ -33,6 +33,8 @@ export class TabSearchApiProxy { ...@@ -33,6 +33,8 @@ export class TabSearchApiProxy {
/** @return {!tabSearch.mojom.PageCallbackRouter} */ /** @return {!tabSearch.mojom.PageCallbackRouter} */
getCallbackRouter() {} getCallbackRouter() {}
showUI() {}
} }
/** @implements {TabSearchApiProxy} */ /** @implements {TabSearchApiProxy} */
...@@ -74,6 +76,11 @@ export class TabSearchApiProxyImpl { ...@@ -74,6 +76,11 @@ export class TabSearchApiProxyImpl {
getCallbackRouter() { getCallbackRouter() {
return this.callbackRouter; return this.callbackRouter;
} }
/** @override */
showUI() {
this.handler.showUI();
}
} }
addSingletonGetter(TabSearchApiProxyImpl); addSingletonGetter(TabSearchApiProxyImpl);
...@@ -352,4 +352,30 @@ suite('TabSearchAppTest', () => { ...@@ -352,4 +352,30 @@ suite('TabSearchAppTest', () => {
assertTrue(withSearch); assertTrue(withSearch);
}); });
}); });
test('Verify showUI() is called correctly.', async () => {
assertEquals(0, testProxy.getCallCount('showUI'));
await setupTest(sampleData());
await waitAfterNextRender(tabSearchApp);
// Make sure that tab data has been received.
verifyTabIds(queryRows(), [ 1, 5, 6, 2, 3, 4 ]);
// Ensure that showUI() has been called once after initial data has been
// rendered.
assertEquals(1, testProxy.getCallCount('showUI'));
// Force a change to filtered tab data that would result in a
// re-render.
const searchField = /** @type {!TabSearchSearchField} */
(tabSearchApp.shadowRoot.querySelector('#searchField'));
searchField.setValue('bing');
await flushTasks();
await waitAfterNextRender(tabSearchApp);
verifyTabIds(queryRows(), [ 2 ]);
// |showUI()| should still have only been called once.
assertEquals(1, testProxy.getCallCount('showUI'));
});
}); });
...@@ -12,6 +12,7 @@ export class TestTabSearchApiProxy extends TestBrowserProxy { ...@@ -12,6 +12,7 @@ export class TestTabSearchApiProxy extends TestBrowserProxy {
'closeTab', 'closeTab',
'getProfileTabs', 'getProfileTabs',
'switchToTab', 'switchToTab',
'showUI',
]); ]);
/** @type {!tabSearch.mojom.PageCallbackRouter} */ /** @type {!tabSearch.mojom.PageCallbackRouter} */
...@@ -41,6 +42,11 @@ export class TestTabSearchApiProxy extends TestBrowserProxy { ...@@ -41,6 +42,11 @@ export class TestTabSearchApiProxy extends TestBrowserProxy {
this.methodCalled('switchToTab', [ tabInfo, withSearch ]); this.methodCalled('switchToTab', [ tabInfo, withSearch ]);
} }
/** @override */
showUI() {
this.methodCalled('showUI');
}
/** @override */ /** @override */
getCallbackRouter() { getCallbackRouter() {
return this.callbackRouter; return this.callbackRouter;
......
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