Commit 2f3baa76 authored by John Lee's avatar John Lee Committed by Commit Bot

WebUI Tab Strip: Add placeholder title when a tab does not have one

To mimic the native tab strip, the title of the tab will now either
have a placeholder title indicating the tab is still loading or one
indicating that the tab is untitled.

Bug: 989131
Change-Id: I30acc3b973c573fd8b6721093c52fa31efc49c3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1907565
Commit-Queue: John Lee <johntlee@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714605}
parent 6fbb3fdd
...@@ -121,8 +121,15 @@ export class TabElement extends CustomElement { ...@@ -121,8 +121,15 @@ export class TabElement extends CustomElement {
this.setAttribute('draggable', true); this.setAttribute('draggable', true);
this.toggleAttribute('crashed_', tab.crashed); this.toggleAttribute('crashed_', tab.crashed);
if (!this.tab_ || this.tab_.title !== tab.title) { if (tab.title) {
this.titleTextEl_.textContent = tab.title; this.titleTextEl_.textContent = tab.title;
} else if (
!tab.shouldHideThrobber &&
(tab.networkState === TabNetworkState.WAITING ||
tab.networkState === TabNetworkState.LOADING)) {
this.titleTextEl_.textContent = loadTimeData.getString('loadingTab');
} else {
this.titleTextEl_.textContent = loadTimeData.getString('defaultTabTitle');
} }
this.titleTextEl_.setAttribute('aria-label', getAccessibleTitle(tab)); this.titleTextEl_.setAttribute('aria-label', getAccessibleTitle(tab));
......
...@@ -472,6 +472,8 @@ TabStripUI::TabStripUI(content::WebUI* web_ui) ...@@ -472,6 +472,8 @@ TabStripUI::TabStripUI(content::WebUI* web_ui)
static constexpr LocalizedString kStrings[] = { static constexpr LocalizedString kStrings[] = {
{"tabListTitle", IDS_ACCNAME_TAB_LIST}, {"tabListTitle", IDS_ACCNAME_TAB_LIST},
{"closeTab", IDS_ACCNAME_CLOSE}, {"closeTab", IDS_ACCNAME_CLOSE},
{"defaultTabTitle", IDS_DEFAULT_TAB_TITLE},
{"loadingTab", IDS_TAB_LOADING_TITLE},
{"tabCrashed", IDS_TAB_AX_LABEL_CRASHED_FORMAT}, {"tabCrashed", IDS_TAB_AX_LABEL_CRASHED_FORMAT},
{"tabNetworkError", IDS_TAB_AX_LABEL_NETWORK_ERROR_FORMAT}, {"tabNetworkError", IDS_TAB_AX_LABEL_NETWORK_ERROR_FORMAT},
{"audioPlaying", IDS_TAB_AX_LABEL_AUDIO_PLAYING_FORMAT}, {"audioPlaying", IDS_TAB_AX_LABEL_AUDIO_PLAYING_FORMAT},
......
...@@ -27,6 +27,7 @@ suite('Tab', function() { ...@@ -27,6 +27,7 @@ suite('Tab', function() {
const strings = { const strings = {
closeTab: 'Close tab', closeTab: 'Close tab',
loadingTab: 'Loading...',
tabCrashed: '$1 has crashed', tabCrashed: '$1 has crashed',
tabNetworkError: '$1 has a network error', tabNetworkError: '$1 has a network error',
}; };
...@@ -195,6 +196,18 @@ suite('Tab', function() { ...@@ -195,6 +196,18 @@ suite('Tab', function() {
tab.title, tabElement.shadowRoot.querySelector('#titleText').innerText); tab.title, tabElement.shadowRoot.querySelector('#titleText').innerText);
}); });
test('sets the loading title while loading', () => {
const loadingTabWithoutTitle = Object.assign({}, tab, {
networkState: TabNetworkState.WAITING,
shouldHideThrobber: false,
});
delete loadingTabWithoutTitle.title;
tabElement.tab = loadingTabWithoutTitle;
assertEquals(
strings['loadingTab'],
tabElement.shadowRoot.querySelector('#titleText').innerText);
});
test('exposes the tab ID to an attribute', () => { test('exposes the tab ID to an attribute', () => {
tabElement.tab = Object.assign({}, tab, {id: 1001}); tabElement.tab = Object.assign({}, tab, {id: 1001});
assertEquals('1001', tabElement.getAttribute('data-tab-id')); assertEquals('1001', tabElement.getAttribute('data-tab-id'));
......
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