Commit 0c827c9f authored by Yuheng Huang's avatar Yuheng Huang Committed by Josip Sokcevic

Tab Search: Implement TabsChanged API frontend

Related CL: https://chromium-review.googlesource.com/c/chromium/src/+/2290996

Bug: 1099917
Change-Id: Ic96dd27394ab8495d00a3a723c19e80239c99404
Reviewed-on: https://chrome-internal-review.googlesource.com/c/chrome/browser/resources/tab_search/+/3158203Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Reviewed-by: default avatarRoman Arora <romanarora@chromium.org>
Reviewed-by: default avatarTom Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819572}
parent e63fb2eb
...@@ -62,12 +62,29 @@ export class TabSearchAppElement extends PolymerElement { ...@@ -62,12 +62,29 @@ export class TabSearchAppElement extends PolymerElement {
/** @private {!TabSearchApiProxy} */ /** @private {!TabSearchApiProxy} */
this.apiProxy_ = TabSearchApiProxyImpl.getInstance(); this.apiProxy_ = TabSearchApiProxyImpl.getInstance();
/** @private {!Array<number>} */
this.listenerIds_ = [];
} }
/** @override */ /** @override */
ready() { ready() {
super.ready(); super.ready();
this.listenerIds_.push(
this.apiProxy_.getCallbackRouter().tabsChanged.addListener(
this.getTabs.bind(this)));
this.getTabs();
}
/** @override */
disconnectedCallback() {
this.listenerIds_.forEach(
id => this.apiProxy_.getCallbackRouter().removeListener(id));
}
/** @private */
getTabs() {
this.apiProxy_.getProfileTabs().then(({profileTabs}) => { this.apiProxy_.getProfileTabs().then(({profileTabs}) => {
if (profileTabs) { if (profileTabs) {
this.openTabs_ = profileTabs.windows; this.openTabs_ = profileTabs.windows;
......
...@@ -14,6 +14,9 @@ export class TabSearchApiProxy { ...@@ -14,6 +14,9 @@ export class TabSearchApiProxy {
/** @param {!tabSearch.mojom.SwitchToTabInfo} info */ /** @param {!tabSearch.mojom.SwitchToTabInfo} info */
switchToTab(info) {} switchToTab(info) {}
/** @return {!tabSearch.mojom.PageCallbackRouter} */
getCallbackRouter() {}
} }
/** @implements {TabSearchApiProxy} */ /** @implements {TabSearchApiProxy} */
...@@ -40,6 +43,11 @@ export class TabSearchApiProxyImpl { ...@@ -40,6 +43,11 @@ export class TabSearchApiProxyImpl {
switchToTab(info) { switchToTab(info) {
this.handler.switchToTab(info); this.handler.switchToTab(info);
} }
/** override */
getCallbackRouter() {
return this.callbackRouter;
}
} }
addSingletonGetter(TabSearchApiProxyImpl); addSingletonGetter(TabSearchApiProxyImpl);
...@@ -173,4 +173,13 @@ suite('TabSearchAppTest', () => { ...@@ -173,4 +173,13 @@ suite('TabSearchAppTest', () => {
keyDownOn(searchInput, 0, [], 'Home'); keyDownOn(searchInput, 0, [], 'Home');
assertEquals(0, tabSearchApp.getSelectedIndex()); assertEquals(0, tabSearchApp.getSelectedIndex());
}); });
test('refresh on tabs changed', async () => {
await setupTest(sampleData());
verifyTabIds(queryRows(), [1, 5, 6, 2, 3, 4]);
testProxy.setProfileTabs({windows: []});
testProxy.getCallbackRouterRemote().tabsChanged();
await flushTasks();
verifyTabIds(queryRows(), []);
});
}); });
...@@ -13,6 +13,13 @@ export class TestTabSearchApiProxy extends TestBrowserProxy { ...@@ -13,6 +13,13 @@ export class TestTabSearchApiProxy extends TestBrowserProxy {
'switchToTab', 'switchToTab',
]); ]);
/** @type {!tabSearch.mojom.PageCallbackRouter} */
this.callbackRouter = new tabSearch.mojom.PageCallbackRouter();
/** @type {!tabSearch.mojom.PageRemote} */
this.callbackRouterRemote =
this.callbackRouter.$.bindNewPipeAndPassRemote();
/** @private {tabSearch.mojom.ProfileTabs} */ /** @private {tabSearch.mojom.ProfileTabs} */
this.profileTabs_; this.profileTabs_;
} }
...@@ -28,6 +35,16 @@ export class TestTabSearchApiProxy extends TestBrowserProxy { ...@@ -28,6 +35,16 @@ export class TestTabSearchApiProxy extends TestBrowserProxy {
this.methodCalled('switchToTab'); this.methodCalled('switchToTab');
} }
/** override */
getCallbackRouter() {
return this.callbackRouter;
}
/** return {!tabSearch.mojom.PageRemote} */
getCallbackRouterRemote() {
return this.callbackRouterRemote;
}
/** @param {tabSearch.mojom.ProfileTabs} profileTabs */ /** @param {tabSearch.mojom.ProfileTabs} profileTabs */
setProfileTabs(profileTabs) { setProfileTabs(profileTabs) {
this.profileTabs_ = profileTabs; this.profileTabs_ = profileTabs;
......
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