Commit 4a2af52e authored by Yuheng Huang's avatar Yuheng Huang Committed by Josip Sokcevic

Tab Search: tests initial commit

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

Bug: 1099917
Change-Id: I45fb78b7013b46b5ac3c00f905631fc63d871c87
Reviewed-on: https://chrome-internal-review.googlesource.com/c/chrome/browser/resources/tab_search/+/3164617Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarTom Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819569}
parent e3c0ef01
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
</div> </div>
<div id="content"> <div id="content">
<template is="dom-repeat" items="[[filteredOpenTabs_]]"> <template is="dom-repeat" items="[[filteredOpenTabs_]]">
<div id="[[item.tabId]]" on-click="onItemClick_"> <div class="row" id="[[item.tabId]]" on-click="onItemClick_">
<div> <div>
<img src="[[item.favIconUrl]]"> <img src="[[item.favIconUrl]]">
</div> </div>
......
...@@ -6,7 +6,7 @@ import 'chrome://resources/cr_elements/icons.m.js'; ...@@ -6,7 +6,7 @@ import 'chrome://resources/cr_elements/icons.m.js';
import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js'; import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {TabSearchApiProxy} from './tab_search_api_proxy.js'; import {TabSearchApiProxy, TabSearchApiProxyImpl} from './tab_search_api_proxy.js';
/** /**
* @param {string} searchText * @param {string} searchText
...@@ -17,7 +17,7 @@ function filterFunc(searchText, item) { ...@@ -17,7 +17,7 @@ function filterFunc(searchText, item) {
return item.title.toLowerCase().includes(searchText.toLowerCase()); return item.title.toLowerCase().includes(searchText.toLowerCase());
}; };
class TabSearchElement extends PolymerElement { export class TabSearchAppElement extends PolymerElement {
static get is() { static get is() {
return 'tab-search-app'; return 'tab-search-app';
} }
...@@ -48,7 +48,7 @@ class TabSearchElement extends PolymerElement { ...@@ -48,7 +48,7 @@ class TabSearchElement extends PolymerElement {
constructor() { constructor() {
super(); super();
/** @private {!TabSearchApiProxy} */ /** @private {!TabSearchApiProxy} */
this.apiProxy_ = TabSearchApiProxy.getInstance(); this.apiProxy_ = TabSearchApiProxyImpl.getInstance();
} }
/** @override */ /** @override */
...@@ -94,6 +94,13 @@ class TabSearchElement extends PolymerElement { ...@@ -94,6 +94,13 @@ class TabSearchElement extends PolymerElement {
} }
return result; return result;
} }
/**
* @param {string} text
*/
setSearchText(text) {
this.searchText_ = text;
}
} }
customElements.define(TabSearchElement.is, TabSearchElement); customElements.define(TabSearchAppElement.is, TabSearchAppElement);
...@@ -7,7 +7,17 @@ import './tab_search.mojom-lite.js'; ...@@ -7,7 +7,17 @@ import './tab_search.mojom-lite.js';
import {addSingletonGetter} from 'chrome://resources/js/cr.m.js'; import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';
/** @interface */
export class TabSearchApiProxy { export class TabSearchApiProxy {
/** @return {Promise<{profileTabs: tabSearch.mojom.ProfileTabs}>} */
getProfileTabs() {}
/** @param {!tabSearch.mojom.SwitchToTabInfo} info */
switchToTab(info) {}
}
/** @implements {TabSearchApiProxy} */
export class TabSearchApiProxyImpl {
constructor() { constructor() {
/** @type {!tabSearch.mojom.PageCallbackRouter} */ /** @type {!tabSearch.mojom.PageCallbackRouter} */
this.callbackRouter = new tabSearch.mojom.PageCallbackRouter(); this.callbackRouter = new tabSearch.mojom.PageCallbackRouter();
...@@ -21,15 +31,15 @@ export class TabSearchApiProxy { ...@@ -21,15 +31,15 @@ export class TabSearchApiProxy {
this.handler.$.bindNewPipeAndPassReceiver()); this.handler.$.bindNewPipeAndPassReceiver());
} }
/** @return {Promise<{profileTabs: tabSearch.mojom.ProfileTabs}>} */ /** override */
getProfileTabs() { getProfileTabs() {
return this.handler.getProfileTabs(); return this.handler.getProfileTabs();
} }
/** @param {!tabSearch.mojom.SwitchToTabInfo} info */ /** override */
switchToTab(info) { switchToTab(info) {
this.handler.switchToTab(info); this.handler.switchToTab(info);
} }
} }
addSingletonGetter(TabSearchApiProxy); addSingletonGetter(TabSearchApiProxyImpl);
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni")
js_type_check("closure_compile") {
is_polymer3 = true
closure_flags = default_closure_args + [
"browser_resolver_prefix_replacements=\"chrome://tab-search/=../../chrome/browser/resources/tab-search/\"",
"js_module_root=../../chrome/test/data/webui/",
"js_module_root=./gen/chrome/test/data/webui/",
]
deps = [ ":tab_search_app_test" ]
}
js_library("tab_search_app_test") {
deps = [
":test_tab_search_api_proxy",
"../..:chai_assert",
"//chrome/browser/resources/tab_search:app",
]
externs_list = [ "$externs_path/mocha-2.5.js" ]
}
js_library("test_tab_search_api_proxy") {
deps = [
"//chrome/browser/resources/tab_search:tab_search_api_proxy",
"//chrome/browser/ui/webui/tab_search:mojo_bindings_js_library_for_compile",
"//chrome/test/data/webui:test_browser_proxy.m",
]
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {TabSearchAppElement} from 'chrome://tab-search/app.js';
import {TabSearchApiProxy, TabSearchApiProxyImpl} from 'chrome://tab-search/tab_search_api_proxy.js'
import {assertEquals} from '../../chai_assert.js';
import {flushTasks} from '../../test_util.m.js';
import {TestTabSearchApiProxy} from './test_tab_search_api_proxy.js';
suite('TabSearchAppTest', () => {
/** @type {!TabSearchAppElement} */
let tabSearchApp;
/** @type {!TestTabSearchApiProxy} */
let testProxy;
/**
* @param {!NodeList<!Element>} rows
* @param {!Array<number>} ids
*/
function verifyTabIds(rows, ids) {
assertEquals(ids.length, rows.length);
rows.forEach((row, index) => {
assertEquals(ids[index].toString(), row.getAttribute('id'));
});
}
/**
* @return {!NodeList<!Element>}
*/
function queryRows() {
return tabSearchApp.shadowRoot.querySelectorAll('.row');
}
function setupData() {
const profileTabs = {
windows: [
{
active: true,
tabs: [{
index: 0,
tabId: 1,
favIconUrl: '',
title: 'Google',
url: 'https://www.google.com',
}],
},
{
active: false,
tabs: [
{
index: 0,
tabId: 2,
favIconUrl: '',
title: 'Bing',
url: 'https://www.bing.com/',
},
{
index: 1,
tabId: 3,
favIconUrl: '',
title: 'Yahoo',
url: 'https://www.yahoo.com',
},
{
index: 2,
tabId: 4,
favIconUrl: '',
title: 'Apple',
url: 'https://www.apple.com/',
},
]
}
]
};
testProxy.setProfileTabs(profileTabs);
}
setup(() => {
testProxy = new TestTabSearchApiProxy();
TabSearchApiProxyImpl.instance_ = testProxy;
setupData();
tabSearchApp = /** @type {!TabSearchAppElement} */
(document.createElement('tab-search-app'));
document.body.appendChild(tabSearchApp);
});
test('return all tabs', async () => {
await flushTasks();
verifyTabIds(queryRows(), [1, 2, 3, 4]);
});
test('return filtered tabs', async () => {
tabSearchApp.setSearchText('bing');
await flushTasks();
verifyTabIds(queryRows(), [2]);
});
});
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/** @fileoverview Test suite for the WebUI tab search. */
GEN_INCLUDE(['//chrome/test/data/webui/polymer_browser_test_base.js']);
GEN('#include "chrome/browser/ui/ui_features.h"');
GEN('#include "content/public/test/browser_test.h"');
GEN('#include "services/network/public/cpp/features.h"');
class TabSearchBrowserTest extends PolymerTest {
/** @override */
get browsePreload() {
throw 'this is abstract and should be overriden by subclasses';
}
get extraLibraries() {
return [
'//third_party/mocha/mocha.js',
'//chrome/test/data/webui/mocha_adapter.js',
];
}
/** @override */
get featureList() {
return {
enabled: [
'network::features::kOutOfBlinkCors',
'features::kTabSearch',
]
};
}
}
// eslint-disable-next-line no-var
var TabSearchAppTest = class extends TabSearchBrowserTest {
/** @override */
get browsePreload() {
return 'chrome://tab-search/test_loader.html?module=tab_search/test/tab_search_app_test.js';
}
};
TEST_F('TabSearchAppTest', 'All', function() {
mocha.run();
});
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {TabSearchApiProxy} from 'chrome://tab-search/tab_search_api_proxy.js';
import {TestBrowserProxy} from '../../test_browser_proxy.m.js';
/** @implements {TabSearchApiProxy} */
export class TestTabSearchApiProxy extends TestBrowserProxy {
constructor() {
super([
'getProfileTabs',
'switchToTab',
]);
/** @private {tabSearch.mojom.ProfileTabs} */
this.profileTabs_;
}
/** override */
getProfileTabs() {
this.methodCalled('getProfileTabs');
return Promise.resolve({profileTabs: this.profileTabs_});
}
/** override */
switchToTab(tabInfo) {
this.methodCalled('swtichToTab');
}
/** @param {tabSearch.mojom.ProfileTabs} profileTabs */
setProfileTabs(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