refactor: use WidgetDelegate::SetAccessibleTitle()
(#46765)
* refactor: use WidgetDelegate::SetAccessibleTitle() * test: add window.accessibleTitle tests
This commit is contained in:
parent
c16ea8d54e
commit
924a8da940
3 changed files with 33 additions and 14 deletions
|
@ -781,14 +781,6 @@ const views::Widget* NativeWindow::GetWidget() const {
|
||||||
return widget();
|
return widget();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::u16string NativeWindow::GetAccessibleWindowTitle() const {
|
|
||||||
if (accessible_title_.empty()) {
|
|
||||||
return views::WidgetDelegate::GetAccessibleWindowTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
return accessible_title_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string NativeWindow::GetTitle() const {
|
std::string NativeWindow::GetTitle() const {
|
||||||
return base::UTF16ToUTF8(WidgetDelegate::GetWindowTitle());
|
return base::UTF16ToUTF8(WidgetDelegate::GetWindowTitle());
|
||||||
}
|
}
|
||||||
|
@ -802,11 +794,11 @@ void NativeWindow::SetTitle(const std::string_view title) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::SetAccessibleTitle(const std::string& title) {
|
void NativeWindow::SetAccessibleTitle(const std::string& title) {
|
||||||
accessible_title_ = base::UTF8ToUTF16(title);
|
WidgetDelegate::SetAccessibleTitle(base::UTF8ToUTF16(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string NativeWindow::GetAccessibleTitle() {
|
std::string NativeWindow::GetAccessibleTitle() {
|
||||||
return base::UTF16ToUTF8(accessible_title_);
|
return base::UTF16ToUTF8(GetAccessibleWindowTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::HandlePendingFullscreenTransitions() {
|
void NativeWindow::HandlePendingFullscreenTransitions() {
|
||||||
|
|
|
@ -447,7 +447,6 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
// views::WidgetDelegate:
|
// views::WidgetDelegate:
|
||||||
views::Widget* GetWidget() override;
|
views::Widget* GetWidget() override;
|
||||||
const views::Widget* GetWidget() const override;
|
const views::Widget* GetWidget() const override;
|
||||||
std::u16string GetAccessibleWindowTitle() const override;
|
|
||||||
|
|
||||||
void set_content_view(views::View* view) { content_view_ = view; }
|
void set_content_view(views::View* view) { content_view_ = view; }
|
||||||
|
|
||||||
|
@ -532,9 +531,6 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
absl::flat_hash_set<BackgroundThrottlingSource*>
|
absl::flat_hash_set<BackgroundThrottlingSource*>
|
||||||
background_throttling_sources_;
|
background_throttling_sources_;
|
||||||
|
|
||||||
// Accessible title.
|
|
||||||
std::u16string accessible_title_;
|
|
||||||
|
|
||||||
std::string vibrancy_;
|
std::string vibrancy_;
|
||||||
std::string background_material_;
|
std::string background_material_;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { setTimeout } from 'node:timers/promises';
|
||||||
import * as nodeUrl from 'node:url';
|
import * as nodeUrl from 'node:url';
|
||||||
|
|
||||||
import { emittedUntil, emittedNTimes } from './lib/events-helpers';
|
import { emittedUntil, emittedNTimes } from './lib/events-helpers';
|
||||||
|
import { randomString } from './lib/net-helpers';
|
||||||
import { HexColors, hasCapturableScreen, ScreenCapture } from './lib/screen-helpers';
|
import { HexColors, hasCapturableScreen, ScreenCapture } from './lib/screen-helpers';
|
||||||
import { ifit, ifdescribe, defer, listen, waitUntil } from './lib/spec-helpers';
|
import { ifit, ifdescribe, defer, listen, waitUntil } from './lib/spec-helpers';
|
||||||
import { closeWindow, closeAllWindows } from './lib/window-helpers';
|
import { closeWindow, closeAllWindows } from './lib/window-helpers';
|
||||||
|
@ -232,6 +233,36 @@ describe('BrowserWindow module', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('window.accessibleTitle', () => {
|
||||||
|
const title = 'Window Title';
|
||||||
|
let w: BrowserWindow;
|
||||||
|
beforeEach(() => {
|
||||||
|
w = new BrowserWindow({ show: false, title, webPreferences: { nodeIntegration: true, contextIsolation: false } });
|
||||||
|
});
|
||||||
|
afterEach(async () => {
|
||||||
|
await closeWindow(w);
|
||||||
|
w = null as unknown as BrowserWindow;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should default to the window title', async () => {
|
||||||
|
expect(w.accessibleTitle).to.equal(title);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be mutable', async () => {
|
||||||
|
const accessibleTitle = randomString(20);
|
||||||
|
w.accessibleTitle = accessibleTitle;
|
||||||
|
expect(w.accessibleTitle).to.equal(accessibleTitle);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be clearable', async () => {
|
||||||
|
const accessibleTitle = randomString(20);
|
||||||
|
w.accessibleTitle = accessibleTitle;
|
||||||
|
expect(w.accessibleTitle).to.equal(accessibleTitle);
|
||||||
|
w.accessibleTitle = '';
|
||||||
|
expect(w.accessibleTitle).to.equal(title);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('window.close()', () => {
|
describe('window.close()', () => {
|
||||||
let w: BrowserWindow;
|
let w: BrowserWindow;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue