Improve localization tests

This commit is contained in:
Dirk Baeumer 2021-07-06 13:15:43 +02:00
parent 7a0714a6e5
commit ae52915f0c
No known key found for this signature in database
GPG key ID: DD95715335E91385
9 changed files with 63 additions and 7 deletions

View file

@ -5,8 +5,9 @@
import { getTopLeftOffset, getClientArea } from 'vs/base/browser/dom';
import { coalesce } from 'vs/base/common/arrays';
import { IElement, ILocalizedStrings, IWindowDriver } from 'vs/platform/driver/common/driver';
import { IElement, ILocaleInfo, ILocalizedStrings, IWindowDriver } from 'vs/platform/driver/common/driver';
import localizedStrings from 'vs/platform/localizations/common/localizedStrings';
import { locale, language } from 'vs/base/common/platform';
function serializeElement(element: Element, recursive: boolean): IElement {
const attributes = Object.create(null);
@ -162,6 +163,13 @@ export abstract class BaseWindowDriver implements IWindowDriver {
xterm._core._coreService.triggerDataEvent(text);
}
getLocaleInfo(): Promise<ILocaleInfo> {
return Promise.resolve({
language: language,
locale: locale
});
}
getLocalizedStrings(): Promise<ILocalizedStrings> {
return Promise.resolve({
open: localizedStrings.open,

View file

@ -18,6 +18,18 @@ export interface IElement {
left: number;
}
export interface ILocaleInfo {
/**
* The UI language used.
*/
language: string;
/**
* The requested locale
*/
locale?: string;
}
export interface ILocalizedStrings {
open: string;
close: string;
@ -42,7 +54,8 @@ export interface IDriver {
typeInEditor(windowId: number, selector: string, text: string): Promise<void>;
getTerminalBuffer(windowId: number, selector: string): Promise<string[]>;
writeInTerminal(windowId: number, selector: string, text: string): Promise<void>;
getLocalizedStrings(windowId: number): Promise<ILocalizedStrings>
getLocaleInfo(windowId: number): Promise<ILocaleInfo>;
getLocalizedStrings(windowId: number): Promise<ILocalizedStrings>;
}
//*END
@ -60,6 +73,7 @@ export interface IWindowDriver {
typeInEditor(selector: string, text: string): Promise<void>;
getTerminalBuffer(selector: string): Promise<string[]>;
writeInTerminal(selector: string, text: string): Promise<void>;
getLocaleInfo(): Promise<ILocaleInfo>;
getLocalizedStrings(): Promise<ILocalizedStrings>
}

View file

@ -5,7 +5,7 @@
import { Event } from 'vs/base/common/event';
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
import { IDriverOptions, IElement, ILocalizedStrings as ILocalizedStrings, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
import { IDriverOptions, IElement, ILocaleInfo, ILocalizedStrings as ILocalizedStrings, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
export class WindowDriverChannel implements IServerChannel {
@ -27,6 +27,7 @@ export class WindowDriverChannel implements IServerChannel {
case 'typeInEditor': return this.driver.typeInEditor(arg[0], arg[1]);
case 'getTerminalBuffer': return this.driver.getTerminalBuffer(arg);
case 'writeInTerminal': return this.driver.writeInTerminal(arg[0], arg[1]);
case 'getLocaleInfo': return this.driver.getLocaleInfo();
case 'getLocalizedStrings': return this.driver.getLocalizedStrings();
}
@ -80,6 +81,10 @@ export class WindowDriverChannelClient implements IWindowDriver {
return this.channel.call('writeInTerminal', [selector, text]);
}
getLocaleInfo(): Promise<ILocaleInfo> {
return this.channel.call('getLocaleInfo');
}
getLocalizedStrings(): Promise<ILocalizedStrings> {
return this.channel.call('getLocalizedStrings');
}

View file

@ -18,7 +18,7 @@ import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/e
import { ScanCodeBinding } from 'vs/base/common/scanCode';
import { KeybindingParser } from 'vs/base/common/keybindingParser';
import { timeout } from 'vs/base/common/async';
import { IDriver, IDriverOptions, IElement, ILocalizedStrings, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
import { IDriver, IDriverOptions, IElement, ILocaleInfo, ILocalizedStrings, IWindowDriver, IWindowDriverRegistry } from 'vs/platform/driver/common/driver';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService';
@ -189,6 +189,11 @@ export class Driver implements IDriver, IWindowDriverRegistry {
await windowDriver.writeInTerminal(selector, text);
}
async getLocaleInfo(windowId: number): Promise<ILocaleInfo> {
const windowDriver = await this.getWindowDriver(windowId);
return await windowDriver.getLocaleInfo();
}
async getLocalizedStrings(windowId: number): Promise<ILocalizedStrings> {
const windowDriver = await this.getWindowDriver(windowId);
return await windowDriver.getLocalizedStrings();

View file

@ -7,7 +7,7 @@ import { Client } from 'vs/base/parts/ipc/common/ipc.net';
import { connect as connectNet } from 'vs/base/parts/ipc/node/ipc.net';
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
import { Event } from 'vs/base/common/event';
import { IDriver, IElement, IWindowDriverRegistry, ILocalizedStrings } from 'vs/platform/driver/common/driver';
import { IDriver, IElement, IWindowDriverRegistry, ILocalizedStrings, ILocaleInfo } from 'vs/platform/driver/common/driver';
export class DriverChannel implements IServerChannel {
@ -34,6 +34,7 @@ export class DriverChannel implements IServerChannel {
case 'typeInEditor': return this.driver.typeInEditor(arg[0], arg[1], arg[2]);
case 'getTerminalBuffer': return this.driver.getTerminalBuffer(arg[0], arg[1]);
case 'writeInTerminal': return this.driver.writeInTerminal(arg[0], arg[1], arg[2]);
case 'getLocaleInfo': return this.driver.getLocaleInfo(arg);
case 'getLocalizedStrings': return this.driver.getLocalizedStrings(arg);
}
@ -107,6 +108,10 @@ export class DriverChannelClient implements IDriver {
return this.channel.call('writeInTerminal', [windowId, selector, text]);
}
getLocaleInfo(windowId: number): Promise<ILocaleInfo> {
return this.channel.call('getLocaleInfo', windowId);
}
getLocalizedStrings(windowId: number): Promise<ILocalizedStrings> {
return this.channel.call('getLocalizedStrings', windowId);
}

View file

@ -9,7 +9,7 @@ import * as os from 'os';
import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import { tmpName } from 'tmp';
import { IDriver, connect as connectElectronDriver, IDisposable, IElement, Thenable, ILocalizedStrings } from './driver';
import { IDriver, connect as connectElectronDriver, IDisposable, IElement, Thenable, ILocalizedStrings, ILocaleInfo } from './driver';
import { connect as connectPlaywrightDriver, launch } from './playwrightDriver';
import { Logger } from './logger';
import { ncp } from 'ncp';
@ -360,6 +360,11 @@ export class Code {
await poll(() => this.driver.writeInTerminal(windowId, selector, value), () => true, `writeInTerminal '${selector}'`);
}
async getLocaleInfo(): Promise<ILocaleInfo> {
const windowId = await this.getActiveWindowId();
return await this.driver.getLocaleInfo(windowId);
}
async getLocalizedStrings(): Promise<ILocalizedStrings> {
const windowId = await this.getActiveWindowId();
return await this.driver.getLocalizedStrings(windowId);

View file

@ -4,11 +4,15 @@
*--------------------------------------------------------------------------------------------*/
import { Code } from './code';
import { ILocalizedStrings } from './driver';
import { ILocalizedStrings, ILocaleInfo } from './driver';
export class Localization {
constructor(private code: Code) { }
async getLocaleInfo(): Promise<ILocaleInfo> {
return this.code.getLocaleInfo();
}
async getLocalizedStrings(): Promise<ILocalizedStrings> {
return this.code.getLocalizedStrings();
}

View file

@ -82,6 +82,7 @@ function buildDriver(browser: playwright.Browser, page: playwright.Page): IDrive
typeInEditor: (windowId, selector, text) => page.evaluate(`window.driver.typeInEditor('${selector}', '${text}')`),
getTerminalBuffer: (windowId, selector) => page.evaluate(`window.driver.getTerminalBuffer('${selector}')`),
writeInTerminal: (windowId, selector, text) => page.evaluate(`window.driver.writeInTerminal('${selector}', '${text}')`),
getLocaleInfo: (windowId) => page.evaluate(`window.driver.getLocaleInfo()`),
getLocalizedStrings: (windowId) => page.evaluate(`window.driver.getLocalizedStrings()`)
};
return driver;

View file

@ -37,6 +37,15 @@ export function setup(opts: minimist.ParsedArgs) {
}
return;
} else {
const localeInfo = await app.workbench.localization.getLocaleInfo();
if (localeInfo.locale === undefined || localeInfo.locale.toLowerCase() !== 'de') {
throw new Error(`The requested locale for VS Code was not German. The received value is: ${localeInfo.locale === undefined ? 'not set' : localeInfo.locale}`);
}
if (localeInfo.language.toLowerCase() !== 'de') {
throw new Error(`The UI language is not German. It is ${localeInfo.language}`);
}
if (result.open.toLowerCase() !== 'öffnen' || result.close.toLowerCase() !== 'schließen' || result.find.toLowerCase() !== 'finden') {
throw new Error(`Received wrong German localized strings: ${JSON.stringify(result, undefined, 0)}`);
}