Commit 018e6784 authored by Roman Arora's avatar Roman Arora Committed by Chromium LUCI CQ

Decouple MWB styles from InfiniteList component

Fixed: 1147535
Change-Id: If8ad3df877d1baa5ce32c7199b50ff4d886555dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2585994
Commit-Queue: Roman Arora <romanarora@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Reviewed-by: default avatarThomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837884}
parent e9b1ca4a
...@@ -51,19 +51,19 @@ ...@@ -51,19 +51,19 @@
</defs> </defs>
</svg> </svg>
</iron-iconset-svg> </iron-iconset-svg>
<tab-search-search-field id="searchField" autofocus clear-label="$i18n{clearSearch}" <tab-search-search-field id="searchField" autofocus
label="$i18n{searchTabs}" on-focus="onSearchFocus_" clear-label="$i18n{clearSearch}" label="$i18n{searchTabs}"
on-keydown="onSearchKeyDown_" on-search-changed="onSearchChanged_" on-focus="onSearchFocus_" on-keydown="onSearchKeyDown_"
on-search-changed="onSearchChanged_"
search-result-text="[[searchResultText_]]"> search-result-text="[[searchResultText_]]">
</tab-search-search-field> </tab-search-search-field>
<div hidden="[[!filteredOpenTabs_.length]]"> <div hidden="[[!filteredOpenTabs_.length]]">
<infinite-list id="tabsList" items="[[filteredOpenTabs_]]" > <infinite-list id="tabsList" items="[[filteredOpenTabs_]]" >
<template> <template is="dom-repeat">
<tab-search-item id="[[item.tab.tabId]]" aria-label="[[ariaLabel_(item)]]" <tab-search-item id="[[item.tab.tabId]]" aria-label="[[ariaLabel_(item)]]"
class="mwb-list-item" data="[[item]]" class="mwb-list-item" data="[[item]]" on-click="onItemClick_"
on-click="onItemClick_" on-close="onItemClose_" on-close="onItemClose_" on-focus="onItemFocus_"
on-focus="onItemFocus_" on-keydown="onItemKeyDown_" tabindex="0" on-keydown="onItemKeyDown_" tabindex="0" role="option">
role="option">
</tab-search-item> </tab-search-item>
</template> </template>
</infinite-list> </infinite-list>
......
...@@ -266,9 +266,9 @@ export class TabSearchAppElement extends PolymerElement { ...@@ -266,9 +266,9 @@ export class TabSearchAppElement extends PolymerElement {
* @private * @private
*/ */
onItemClick_(e) { onItemClick_(e) {
const tabIndex = e.currentTarget.parentNode.indexOf(e.currentTarget);
const tabId = Number.parseInt(e.currentTarget.id, 10); const tabId = Number.parseInt(e.currentTarget.id, 10);
this.apiProxy_.switchToTab({tabId}, !!this.searchText_, tabIndex); this.apiProxy_.switchToTab(
{tabId}, !!this.searchText_, /** @type {number} */ (e.model.index));
} }
/** /**
...@@ -277,9 +277,9 @@ export class TabSearchAppElement extends PolymerElement { ...@@ -277,9 +277,9 @@ export class TabSearchAppElement extends PolymerElement {
*/ */
onItemClose_(e) { onItemClose_(e) {
performance.mark('close_tab:benchmark_begin'); performance.mark('close_tab:benchmark_begin');
const tabIndex = e.currentTarget.parentNode.indexOf(e.currentTarget);
const tabId = Number.parseInt(e.currentTarget.id, 10); const tabId = Number.parseInt(e.currentTarget.id, 10);
this.apiProxy_.closeTab(tabId, !!this.searchText_, tabIndex); this.apiProxy_.closeTab(
tabId, !!this.searchText_, /** @type {number} */ (e.model.index));
this.announceA11y_(loadTimeData.getString('a11yTabClosed')); this.announceA11y_(loadTimeData.getString('a11yTabClosed'));
listenOnce(this.$.tabsList, 'iron-items-changed', () => { listenOnce(this.$.tabsList, 'iron-items-changed', () => {
performance.mark('close_tab:benchmark_end'); performance.mark('close_tab:benchmark_end');
...@@ -328,7 +328,7 @@ export class TabSearchAppElement extends PolymerElement { ...@@ -328,7 +328,7 @@ export class TabSearchAppElement extends PolymerElement {
// Ensure that when a TabSearchItem receives focus, it becomes the selected // Ensure that when a TabSearchItem receives focus, it becomes the selected
// item in the list. // item in the list.
/** @type {!InfiniteList} */ (this.$.tabsList).selected = /** @type {!InfiniteList} */ (this.$.tabsList).selected =
e.currentTarget.parentNode.indexOf(e.currentTarget); /** @type {number} */ (e.model.index);
} }
/** @private */ /** @private */
......
<style include="mwb-shared-style"> <style>
:host { :host {
display: block; display: block;
}
#container {
max-height: var(--list-max-height); max-height: var(--list-max-height);
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;
position: relative; position: relative;
} }
</style> </style>
<div id="container" on-scroll="onScroll_"> <div id="items">
<div id="items">
<iron-selector id="selector" on-keydown="onKeyDown_" <iron-selector id="selector" on-keydown="onKeyDown_"
on-iron-items-changed="updateScrollerSize_" on-iron-items-changed="updateScrollerSize_"
on-iron-select="onSelectedChanged_" role="listbox" on-iron-select="onSelectedChanged_" role="listbox"
selected-class="selected"> selected-class="selected">
<slot></slot>
</iron-selector> </iron-selector>
</div>
</div> </div>
...@@ -17,12 +17,9 @@ ...@@ -17,12 +17,9 @@
* fill the view. * fill the view.
*/ */
/* TODO(crbug.com/1147535): Decouple MWB style from component */
import 'chrome://resources/cr_elements/mwb_shared_style.js';
import 'chrome://resources/cr_elements/mwb_shared_vars.js';
import 'chrome://resources/polymer/v3_0/iron-selector/iron-selector.js'; import 'chrome://resources/polymer/v3_0/iron-selector/iron-selector.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert, assertInstanceof} from 'chrome://resources/js/assert.m.js';
import {listenOnce} from 'chrome://resources/js/util.m.js'; import {listenOnce} from 'chrome://resources/js/util.m.js';
import {afterNextRender, DomRepeat, html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {afterNextRender, DomRepeat, html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
...@@ -85,7 +82,12 @@ export class InfiniteList extends PolymerElement { ...@@ -85,7 +82,12 @@ export class InfiniteList extends PolymerElement {
/** @override */ /** @override */
ready() { ready() {
super.ready(); super.ready();
this.ensureTemplatized_();
this.domRepeat_ = assertInstanceof(
this.firstChild, DomRepeat,
'infinite-list requires a dom-repeat child to be provided in light-dom');
this.addEventListener('scroll', () => this.onScroll_());
} }
/** @private */ /** @private */
...@@ -137,35 +139,16 @@ export class InfiniteList extends PolymerElement { ...@@ -137,35 +139,16 @@ export class InfiniteList extends PolymerElement {
} }
} }
/**
* Verifies a light-dom template has been provided and initializes a DomRepeat
* component with the given template.
* @private
*/
ensureTemplatized_() {
// The user provided light-dom template to use when stamping DOM items.
const template =
/** @type {!HTMLTemplateElement} */ (this.querySelector('template'));
assert(
template,
'infinite-list requires a template to be provided in light-dom');
this.domRepeat_ = new DomRepeat();
this.domRepeat_.appendChild(template);
this.$.selector.appendChild(this.domRepeat_);
}
/** /**
* Adds additional DOM items as needed to fill the view based on user scroll * Adds additional DOM items as needed to fill the view based on user scroll
* interactions. * interactions.
* @private * @private
*/ */
onScroll_() { onScroll_() {
if (this.$.container.scrollTop > 0 && if (this.scrollTop > 0 &&
this.domRepeat_.items.length !== this.items.length) { this.domRepeat_.items.length !== this.items.length) {
const aboveScrollTopItemCount = const aboveScrollTopItemCount =
Math.round(this.$.container.scrollTop / this.domItemAverageHeight_()); Math.round(this.scrollTop / this.domItemAverageHeight_());
// Ensure we have sufficient items to fill the current scroll position and // Ensure we have sufficient items to fill the current scroll position and
// a full view following our current position. // a full view following our current position.
...@@ -225,7 +208,7 @@ export class InfiniteList extends PolymerElement { ...@@ -225,7 +208,7 @@ export class InfiniteList extends PolymerElement {
if (this.domRepeat_ && this.items) { if (this.domRepeat_ && this.items) {
const domItemAvgHeight = this.domItemAverageHeight_(); const domItemAvgHeight = this.domItemAverageHeight_();
const aboveScrollTopItemCount = domItemAvgHeight !== 0 ? const aboveScrollTopItemCount = domItemAvgHeight !== 0 ?
Math.round(this.$.container.scrollTop / domItemAvgHeight) : Math.round(this.scrollTop / domItemAvgHeight) :
0; 0;
this.domRepeat_.set('items', []); this.domRepeat_.set('items', []);
...@@ -274,7 +257,7 @@ export class InfiniteList extends PolymerElement { ...@@ -274,7 +257,7 @@ export class InfiniteList extends PolymerElement {
} }
const previousItem = selector.items[selector.selected - 1]; const previousItem = selector.items[selector.selected - 1];
if (previousItem.offsetTop < this.$.container.scrollTop) { if (previousItem.offsetTop < this.scrollTop) {
/** @type {!Element} */ (previousItem) /** @type {!Element} */ (previousItem)
.scrollIntoView({behavior: 'smooth', block: 'nearest'}); .scrollIntoView({behavior: 'smooth', block: 'nearest'});
return; return;
...@@ -283,7 +266,7 @@ export class InfiniteList extends PolymerElement { ...@@ -283,7 +266,7 @@ export class InfiniteList extends PolymerElement {
const nextItem = const nextItem =
selector.items[/** @type {number} */ (selector.selected) + 1]; selector.items[/** @type {number} */ (selector.selected) + 1];
if (nextItem.offsetTop + nextItem.offsetHeight > if (nextItem.offsetTop + nextItem.offsetHeight >
this.$.container.scrollTop + this.offsetHeight) { this.scrollTop + this.offsetHeight) {
/** @type {!Element} */ (nextItem).scrollIntoView( /** @type {!Element} */ (nextItem).scrollIntoView(
{behavior: 'smooth', block: 'nearest'}); {behavior: 'smooth', block: 'nearest'});
} }
......
...@@ -61,7 +61,7 @@ class TabSearchUIBrowserTest : public InProcessBrowserTest { ...@@ -61,7 +61,7 @@ class TabSearchUIBrowserTest : public InProcessBrowserTest {
IN_PROC_BROWSER_TEST_F(TabSearchUIBrowserTest, InitialTabItemsListed) { IN_PROC_BROWSER_TEST_F(TabSearchUIBrowserTest, InitialTabItemsListed) {
const std::string tab_items_js = const std::string tab_items_js =
"const tabItems = document.querySelector('tab-search-app').shadowRoot" "const tabItems = document.querySelector('tab-search-app').shadowRoot"
" .getElementById('tabsList').shadowRoot" " .getElementById('tabsList')"
" .querySelectorAll('tab-search-item');"; " .querySelectorAll('tab-search-item');";
int tab_item_count = int tab_item_count =
content::EvalJs(webui_contents_.get(), tab_items_js + "tabItems.length", content::EvalJs(webui_contents_.get(), tab_items_js + "tabItems.length",
...@@ -82,7 +82,8 @@ IN_PROC_BROWSER_TEST_F(TabSearchUIBrowserTest, SwitchToTabAction) { ...@@ -82,7 +82,8 @@ IN_PROC_BROWSER_TEST_F(TabSearchUIBrowserTest, SwitchToTabAction) {
const std::string tab_item_js = base::StringPrintf( const std::string tab_item_js = base::StringPrintf(
"document.querySelector('tab-search-app').shadowRoot" "document.querySelector('tab-search-app').shadowRoot"
" .getElementById('tabsList').shadowRoot.getElementById('%s')", " .getElementById('tabsList')"
" .querySelector('tab-search-item[id=\"%s\"]')",
base::NumberToString(tab_id).c_str()); base::NumberToString(tab_id).c_str());
ASSERT_TRUE(content::ExecJs(webui_contents_.get(), tab_item_js + ".click()", ASSERT_TRUE(content::ExecJs(webui_contents_.get(), tab_item_js + ".click()",
content::EXECUTE_SCRIPT_DEFAULT_OPTIONS, content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
...@@ -98,7 +99,8 @@ IN_PROC_BROWSER_TEST_F(TabSearchUIBrowserTest, CloseTabAction) { ...@@ -98,7 +99,8 @@ IN_PROC_BROWSER_TEST_F(TabSearchUIBrowserTest, CloseTabAction) {
const std::string tab_item_button_js = base::StringPrintf( const std::string tab_item_button_js = base::StringPrintf(
"document.querySelector('tab-search-app').shadowRoot" "document.querySelector('tab-search-app').shadowRoot"
" .getElementById('tabsList').shadowRoot.getElementById('%s')" " .getElementById('tabsList')"
" .querySelector('tab-search-item[id=\"%s\"]')"
" .shadowRoot.getElementById('closeButton')", " .shadowRoot.getElementById('closeButton')",
base::NumberToString(tab_id).c_str()); base::NumberToString(tab_id).c_str());
ASSERT_TRUE(content::ExecJs(webui_contents_.get(), ASSERT_TRUE(content::ExecJs(webui_contents_.get(),
......
...@@ -37,7 +37,10 @@ js_library("fuzzy_search_test") { ...@@ -37,7 +37,10 @@ js_library("fuzzy_search_test") {
} }
js_library("infinite_list_test") { js_library("infinite_list_test") {
deps = [ "..:chai_assert" ] deps = [
"..:chai_assert",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
]
externs_list = [ "$externs_path/mocha-2.5.js" ] externs_list = [ "$externs_path/mocha-2.5.js" ]
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {InfiniteList, TabSearchItem} from 'chrome://tab-search/tab_search.js'; import {InfiniteList, TabSearchItem} from 'chrome://tab-search/tab_search.js';
import {assertEquals, assertGT, assertNotEquals, assertTrue} from '../../chai_assert.js'; import {assertEquals, assertGT, assertNotEquals, assertTrue} from '../../chai_assert.js';
...@@ -10,8 +11,35 @@ import {flushTasks, waitAfterNextRender} from '../../test_util.m.js'; ...@@ -10,8 +11,35 @@ import {flushTasks, waitAfterNextRender} from '../../test_util.m.js';
import {generateSampleTabsFromSiteNames, sampleSiteNames} from './tab_search_test_data.js'; import {generateSampleTabsFromSiteNames, sampleSiteNames} from './tab_search_test_data.js';
import {assertTabItemAndNeighborsInViewBounds, disableScrollIntoViewAnimations} from './tab_search_test_helper.js'; import {assertTabItemAndNeighborsInViewBounds, disableScrollIntoViewAnimations} from './tab_search_test_helper.js';
suite('InfniteListTest', () => { const CHUNK_ITEM_COUNT = 7;
const CHUNK_ITEM_COUNT = 7;
class TestApp extends PolymerElement {
static get properties() {
return {
/** @private {number} */
chunkItemCount_: {
type: Number,
value: CHUNK_ITEM_COUNT
}
};
}
static get template() {
return html`
<infinite-list id="list" chunk-item-count="[[chunkItemCount_]]">
<template is="dom-repeat">
<tab-search-item id="[[item.tab.tabId]]"
style="display: flex;height: 56px" data="[[item]]" tabindex="0"
role="option">
</tab-search-item>
</template>
</infinite-list>`;
}
}
customElements.define('test-app', TestApp);
suite('InfiniteListTest', () => {
/** @type {!InfiniteList} */ /** @type {!InfiniteList} */
let infiniteList; let infiniteList;
...@@ -21,20 +49,19 @@ suite('InfniteListTest', () => { ...@@ -21,20 +49,19 @@ suite('InfniteListTest', () => {
* @param {!Array<!tabSearch.mojom.Tab>} sampleData * @param {!Array<!tabSearch.mojom.Tab>} sampleData
*/ */
async function setupTest(sampleData) { async function setupTest(sampleData) {
document.head.insertAdjacentHTML( document.head.insertAdjacentHTML('beforeend', `
'beforeend', `<style>html{--list-max-height: 280px}</style>`); <style>
html {
document.body.innerHTML = ` --list-max-height: 280px;
<infinite-list id="list" chunk-item-count="${CHUNK_ITEM_COUNT}"> }
<template> </style>`);
<tab-search-item id="[[item.tab.tabId]]" class="mwb-list-item"
data="[[item]]" tabindex="0" role="option"> const testApp = document.createElement('test-app');
</tab-search-item> document.body.innerHTML = '';
</template> document.body.appendChild(testApp);
</infinite-list>`;
infiniteList = infiniteList = /** @type {!InfiniteList} */ (
/** @type {!InfiniteList} */ (document.querySelector('#list')); testApp.shadowRoot.querySelector('#list'));
infiniteList.items = sampleData; infiniteList.items = sampleData;
await flushTasks(); await flushTasks();
} }
...@@ -44,7 +71,7 @@ suite('InfniteListTest', () => { ...@@ -44,7 +71,7 @@ suite('InfniteListTest', () => {
*/ */
function queryRows() { function queryRows() {
return /** @type {!NodeList<!HTMLElement>} */ ( return /** @type {!NodeList<!HTMLElement>} */ (
infiniteList.shadowRoot.querySelectorAll('tab-search-item')); infiniteList.querySelectorAll('tab-search-item'));
} }
/** /**
...@@ -61,8 +88,7 @@ suite('InfniteListTest', () => { ...@@ -61,8 +88,7 @@ suite('InfniteListTest', () => {
const tabItems = sampleTabItems(sampleSiteNames()); const tabItems = sampleTabItems(sampleSiteNames());
await setupTest(tabItems); await setupTest(tabItems);
const container = infiniteList.shadowRoot.getElementById('container'); assertEquals(0, infiniteList.scrollTop);
assertEquals(0, container.scrollTop);
const itemHeightStyle = const itemHeightStyle =
getComputedStyle(document.head).getPropertyValue('--mwb-item-height'); getComputedStyle(document.head).getPropertyValue('--mwb-item-height');
...@@ -70,7 +96,7 @@ suite('InfniteListTest', () => { ...@@ -70,7 +96,7 @@ suite('InfniteListTest', () => {
const tabItemHeight = Number.parseInt( const tabItemHeight = Number.parseInt(
itemHeightStyle.substring(0, itemHeightStyle.length - 2), 10); itemHeightStyle.substring(0, itemHeightStyle.length - 2), 10);
assertEquals(tabItemHeight * tabItems.length, container.scrollHeight); assertEquals(tabItemHeight * tabItems.length, infiniteList.scrollHeight);
}); });
test('SelectedIndex', async () => { test('SelectedIndex', async () => {
...@@ -78,8 +104,7 @@ suite('InfniteListTest', () => { ...@@ -78,8 +104,7 @@ suite('InfniteListTest', () => {
const tabItems = sampleTabItems(siteNames); const tabItems = sampleTabItems(siteNames);
await setupTest(tabItems); await setupTest(tabItems);
const container = infiniteList.shadowRoot.getElementById('container'); assertEquals(0, infiniteList.scrollTop);
assertEquals(0, container.scrollTop);
assertEquals(CHUNK_ITEM_COUNT, queryRows().length); assertEquals(CHUNK_ITEM_COUNT, queryRows().length);
// Assert that upon changing the selected index to a non previously rendered // Assert that upon changing the selected index to a non previously rendered
...@@ -93,7 +118,7 @@ suite('InfniteListTest', () => { ...@@ -93,7 +118,7 @@ suite('InfniteListTest', () => {
assertEquals(2 * CHUNK_ITEM_COUNT, domTabItems.length); assertEquals(2 * CHUNK_ITEM_COUNT, domTabItems.length);
// Assert that the view scrolled to show the selected item. // Assert that the view scrolled to show the selected item.
const afterSelectionScrollTop = container.scrollTop; const afterSelectionScrollTop = infiniteList.scrollTop;
assertNotEquals(0, afterSelectionScrollTop); assertNotEquals(0, afterSelectionScrollTop);
// Assert that on replacing the list items, the currently selected index // Assert that on replacing the list items, the currently selected index
...@@ -105,15 +130,14 @@ suite('InfniteListTest', () => { ...@@ -105,15 +130,14 @@ suite('InfniteListTest', () => {
assertNotEquals(null, theSelectedTabItem); assertNotEquals(null, theSelectedTabItem);
// Assert the selected item is still visible in the view. // Assert the selected item is still visible in the view.
assertEquals(afterSelectionScrollTop, container.scrollTop); assertEquals(afterSelectionScrollTop, infiniteList.scrollTop);
}); });
test('NavigateDownShowsPreviousAndFollowingListItems', async () => { test('NavigateDownShowsPreviousAndFollowingListItems', async () => {
const tabItems = sampleTabItems(sampleSiteNames()); const tabItems = sampleTabItems(sampleSiteNames());
await setupTest(tabItems); await setupTest(tabItems);
const tabsDiv = /** @type {!HTMLElement} */ const tabsDiv = /** @type {!HTMLElement} */ (infiniteList);
(infiniteList.shadowRoot.querySelector('#container'));
// Assert that the tabs are in a overflowing state. // Assert that the tabs are in a overflowing state.
assertGT(tabsDiv.scrollHeight, tabsDiv.clientHeight); assertGT(tabsDiv.scrollHeight, tabsDiv.clientHeight);
...@@ -133,8 +157,7 @@ suite('InfniteListTest', () => { ...@@ -133,8 +157,7 @@ suite('InfniteListTest', () => {
const tabItems = sampleTabItems(sampleSiteNames()); const tabItems = sampleTabItems(sampleSiteNames());
await setupTest(tabItems); await setupTest(tabItems);
const tabsDiv = /** @type {!HTMLElement} */ const tabsDiv = /** @type {!HTMLElement} */ (infiniteList);
(infiniteList.shadowRoot.querySelector('#container'));
// Assert that the tabs are in a overflowing state. // Assert that the tabs are in a overflowing state.
assertGT(tabsDiv.scrollHeight, tabsDiv.clientHeight); assertGT(tabsDiv.scrollHeight, tabsDiv.clientHeight);
......
...@@ -52,7 +52,7 @@ suite('TabSearchAppFocusTest', () => { ...@@ -52,7 +52,7 @@ suite('TabSearchAppFocusTest', () => {
const tabSearchItems = /** @type {!NodeList<!HTMLElement>} */ const tabSearchItems = /** @type {!NodeList<!HTMLElement>} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelectorAll('tab-search-item')); .querySelectorAll('tab-search-item'));
tabSearchItems[0].focus(); tabSearchItems[0].focus();
// Once an item is focused, arrow keys should change focus too. // Once an item is focused, arrow keys should change focus too.
...@@ -86,7 +86,7 @@ suite('TabSearchAppFocusTest', () => { ...@@ -86,7 +86,7 @@ suite('TabSearchAppFocusTest', () => {
const tabSearchItem = /** @type {!HTMLElement} */ const tabSearchItem = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelector('tab-search-item')); .querySelector('tab-search-item'));
tabSearchItem.focus(); tabSearchItem.focus();
keyDownOn(tabSearchItem, 0, [], 'Enter'); keyDownOn(tabSearchItem, 0, [], 'Enter');
...@@ -103,14 +103,13 @@ suite('TabSearchAppFocusTest', () => { ...@@ -103,14 +103,13 @@ suite('TabSearchAppFocusTest', () => {
await setupTest(generateSampleDataFromSiteNames(sampleSiteNames())); await setupTest(generateSampleDataFromSiteNames(sampleSiteNames()));
const tabsDiv = /** @type {!HTMLElement} */ const tabsDiv = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList'));
.shadowRoot.querySelector('#container'));
// Assert that the tabs are in a overflowing state. // Assert that the tabs are in a overflowing state.
assertGT(tabsDiv.scrollHeight, tabsDiv.clientHeight); assertGT(tabsDiv.scrollHeight, tabsDiv.clientHeight);
const tabItems = /** @type {!NodeList<HTMLElement>} */ const tabItems = /** @type {!NodeList<HTMLElement>} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelectorAll('tab-search-item')); .querySelectorAll('tab-search-item'));
for (let i = 0; i < tabItems.length; i++) { for (let i = 0; i < tabItems.length; i++) {
tabItems[i].focus(); tabItems[i].focus();
......
...@@ -34,7 +34,7 @@ suite('TabSearchAppTest', () => { ...@@ -34,7 +34,7 @@ suite('TabSearchAppTest', () => {
*/ */
function queryRows() { function queryRows() {
return tabSearchApp.shadowRoot.querySelector('#tabsList') return tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelectorAll('tab-search-item'); .querySelectorAll('tab-search-item');
} }
/** /**
...@@ -98,7 +98,7 @@ suite('TabSearchAppTest', () => { ...@@ -98,7 +98,7 @@ suite('TabSearchAppTest', () => {
const tabSearchItem = /** @type {!HTMLElement} */ const tabSearchItem = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelector('tab-search-item')); .querySelector('tab-search-item'));
tabSearchItem.click(); tabSearchItem.click();
const [tabInfo] = await testProxy.whenCalled('switchToTab'); const [tabInfo] = await testProxy.whenCalled('switchToTab');
assertEquals(tabData.tabId, tabInfo.tabId); assertEquals(tabData.tabId, tabInfo.tabId);
...@@ -229,7 +229,7 @@ suite('TabSearchAppTest', () => { ...@@ -229,7 +229,7 @@ suite('TabSearchAppTest', () => {
verifyTabIds(queryRows(), [1, 5, 6, 2, 3, 4]); verifyTabIds(queryRows(), [1, 5, 6, 2, 3, 4]);
let tabSearchItem = /** @type {!HTMLElement} */ let tabSearchItem = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelector('tab-search-item[id="1"]')); .querySelector('tab-search-item[id="1"]'));
assertEquals('Google', tabSearchItem.data.tab.title); assertEquals('Google', tabSearchItem.data.tab.title);
assertEquals('https://www.google.com', tabSearchItem.data.tab.url); assertEquals('https://www.google.com', tabSearchItem.data.tab.url);
const updatedTab = /** @type {!Tab} */ ({ const updatedTab = /** @type {!Tab} */ ({
...@@ -245,7 +245,7 @@ suite('TabSearchAppTest', () => { ...@@ -245,7 +245,7 @@ suite('TabSearchAppTest', () => {
verifyTabIds(queryRows(), [1, 5, 6, 2, 3, 4]); verifyTabIds(queryRows(), [1, 5, 6, 2, 3, 4]);
tabSearchItem = /** @type {!HTMLElement} */ tabSearchItem = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelector('tab-search-item[id="1"]')); .querySelector('tab-search-item[id="1"]'));
assertEquals(updatedTab.title, tabSearchItem.data.tab.title); assertEquals(updatedTab.title, tabSearchItem.data.tab.title);
assertEquals(updatedTab.url, tabSearchItem.data.tab.url); assertEquals(updatedTab.url, tabSearchItem.data.tab.url);
assertEquals('example.com', tabSearchItem.data.hostname); assertEquals('example.com', tabSearchItem.data.hostname);
...@@ -305,7 +305,7 @@ suite('TabSearchAppTest', () => { ...@@ -305,7 +305,7 @@ suite('TabSearchAppTest', () => {
// Click the first element with tabId 1. // Click the first element with tabId 1.
let tabSearchItem = /** @type {!HTMLElement} */ let tabSearchItem = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelector('tab-search-item[id="1"]')); .querySelector('tab-search-item[id="1"]'));
tabSearchItem.click(); tabSearchItem.click();
// Assert switchToTab() was called appropriately for an unfiltered tab list. // Assert switchToTab() was called appropriately for an unfiltered tab list.
...@@ -320,7 +320,7 @@ suite('TabSearchAppTest', () => { ...@@ -320,7 +320,7 @@ suite('TabSearchAppTest', () => {
// Click the first element with tabId 6. // Click the first element with tabId 6.
tabSearchItem = /** @type {!HTMLElement} */ tabSearchItem = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelector('tab-search-item[id="6"]')); .querySelector('tab-search-item[id="6"]'));
tabSearchItem.click(); tabSearchItem.click();
// Assert switchToTab() was called appropriately for an unfiltered tab list. // Assert switchToTab() was called appropriately for an unfiltered tab list.
...@@ -343,7 +343,7 @@ suite('TabSearchAppTest', () => { ...@@ -343,7 +343,7 @@ suite('TabSearchAppTest', () => {
// Click the only remaining element with tabId 2. // Click the only remaining element with tabId 2.
tabSearchItem = /** @type {!HTMLElement} */ tabSearchItem = /** @type {!HTMLElement} */
(tabSearchApp.shadowRoot.querySelector('#tabsList') (tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelector('tab-search-item[id="2"]')); .querySelector('tab-search-item[id="2"]'));
tabSearchItem.click(); tabSearchItem.click();
// Assert switchToTab() was called appropriately for a tab list fitlered by // Assert switchToTab() was called appropriately for a tab list fitlered by
...@@ -437,7 +437,7 @@ suite('TabSearchAppTest', () => { ...@@ -437,7 +437,7 @@ suite('TabSearchAppTest', () => {
tabSearchApp.shadowRoot.querySelector('#searchField'), tabSearchApp.shadowRoot.querySelector('#searchField'),
tabSearchApp.shadowRoot.querySelector('#tabsList'), tabSearchApp.shadowRoot.querySelector('#tabsList'),
tabSearchApp.shadowRoot.querySelector('#tabsList') tabSearchApp.shadowRoot.querySelector('#tabsList')
.shadowRoot.querySelector('tab-search-item'), .querySelector('tab-search-item'),
tabSearchApp.shadowRoot.querySelector('#feedback-footer'), tabSearchApp.shadowRoot.querySelector('#feedback-footer'),
]; ];
......
...@@ -231,7 +231,6 @@ class TabSearchStoryScrollUpAndDown(TabSearchStory): ...@@ -231,7 +231,6 @@ class TabSearchStoryScrollUpAndDown(TabSearchStory):
SCROLL_ELEMENT_FUNCTION = ''' SCROLL_ELEMENT_FUNCTION = '''
document.querySelector('tab-search-app').shadowRoot.getElementById('tabsList') document.querySelector('tab-search-app').shadowRoot.getElementById('tabsList')
.shadowRoot.getElementById('container')
''' '''
MEASURE_FRAME_TIME_SCRIPT = ''' MEASURE_FRAME_TIME_SCRIPT = '''
......
<template> <template>
<style> <style>
::-webkit-scrollbar-thumb { ::-webkit-scrollbar-thumb {
background: var(--google-grey-refresh-300); background-color: var(--mwb-scrollbar-thumb-color);
}
/* TODO(crbug.com/1110109): Add WCAG compliant dark mode support. */
@media (prefers-color-scheme: dark) {
::-webkit-scrollbar-thumb {
background: var(--google-grey-refresh-500);
}
} }
::-webkit-scrollbar-thumb:hover { ::-webkit-scrollbar-thumb:hover {
background: var(--google-grey-refresh-500); background-color: var(--mwb-scrollbar-thumb-hover-color);
}
@media (prefers-color-scheme: dark) {
::-webkit-scrollbar-thumb:hover {
background: var(--google-grey-refresh-300);
}
} }
::-webkit-scrollbar-track { ::-webkit-scrollbar-track {
background: var(--mwb-background-color); background-color: var(--mwb-scrollbar-track-color);
} }
::-webkit-scrollbar { ::-webkit-scrollbar {
width: 4px; width: var(--mwb-scrollbar-width);
} }
.mwb-list-item { .mwb-list-item {
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
--mwb-list-item-hover-background-color: rgba(var(--google-grey-900-rgb), 0.1); --mwb-list-item-hover-background-color: rgba(var(--google-grey-900-rgb), 0.1);
--mwb-list-item-selected-background-color: rgba(var(--google-grey-900-rgb), 0.14); --mwb-list-item-selected-background-color: rgba(var(--google-grey-900-rgb), 0.14);
--mwb-primary-text-font-size: 13px; --mwb-primary-text-font-size: 13px;
--mwb-scrollbar-thumb-color: var(--google-grey-refresh-300);
--mwb-scrollbar-thumb-hover-color: var(--google-grey-refresh-500);
--mwb-scrollbar-track-color: var(--mwb-background-color);
--mwb-scrollbar-width: 4px;
--mwb-secondary-text-font-size: 12px; --mwb-secondary-text-font-size: 12px;
} }
...@@ -21,6 +25,8 @@ ...@@ -21,6 +25,8 @@
--mwb-icon-button-hover-background-color: rgba(255, 255, 255, 0.1); --mwb-icon-button-hover-background-color: rgba(255, 255, 255, 0.1);
--mwb-list-item-hover-background-color: rgb(55, 56, 58); /* #37383a */ --mwb-list-item-hover-background-color: rgb(55, 56, 58); /* #37383a */
--mwb-list-item-selected-background-color: rgb(68, 69, 71); /* #444547 */ --mwb-list-item-selected-background-color: rgb(68, 69, 71); /* #444547 */
--mwb-scrollbar-thumb-color: var(--google-grey-refresh-500);
--mwb-scrollbar-thumb-hover-color: var(--google-grey-refresh-300);
} }
} }
</style> </style>
......
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