1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

feat(PlatformUtils): [Auth/PM-25817] New PlatformUtilsService.isChromium() method (#16468)

This commit is contained in:
Jared Snider
2025-09-18 14:36:35 -04:00
committed by GitHub
parent d6cd30cf54
commit 42ec956782
7 changed files with 75 additions and 0 deletions

View File

@@ -356,6 +356,33 @@ describe("Browser Utils Service", () => {
expect(result).toBe("");
});
});
describe("isChromium", () => {
const chromiumDevices: DeviceType[] = [
DeviceType.ChromeExtension,
DeviceType.EdgeExtension,
DeviceType.OperaExtension,
DeviceType.VivaldiExtension,
];
const nonChromiumDevices: DeviceType[] = [
DeviceType.FirefoxExtension,
DeviceType.SafariExtension,
];
afterEach(() => {
jest.restoreAllMocks();
});
test.each(chromiumDevices)("returns true when getDevice() is %s", (deviceType) => {
jest.spyOn(browserPlatformUtilsService, "getDevice").mockReturnValue(deviceType);
expect(browserPlatformUtilsService.isChromium()).toBe(true);
});
test.each(nonChromiumDevices)("returns false when getDevice() is %s", (deviceType) => {
jest.spyOn(browserPlatformUtilsService, "getDevice").mockReturnValue(deviceType);
expect(browserPlatformUtilsService.isChromium()).toBe(false);
});
});
});
describe("Safari Height Fix", () => {

View File

@@ -123,6 +123,10 @@ export abstract class BrowserPlatformUtilsService implements PlatformUtilsServic
return this.getDevice() === DeviceType.SafariExtension;
}
isChromium(): boolean {
return this.isChrome() || this.isEdge() || this.isOpera() || this.isVivaldi();
}
/**
* Safari previous to version 16.1 had a bug which caused artifacts on hover in large extension popups.
* https://bugs.webkit.org/show_bug.cgi?id=218704

View File

@@ -71,6 +71,10 @@ export class CliPlatformUtilsService implements PlatformUtilsService {
return false;
}
isChromium(): boolean {
return false;
}
isMacAppStore() {
return false;
}

View File

@@ -55,6 +55,10 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
return false;
}
isChromium(): boolean {
return true;
}
isMacAppStore(): boolean {
return ipc.platform.isMacAppStore;
}

View File

@@ -203,4 +203,35 @@ describe("Web Platform Utils Service", () => {
},
);
});
describe("isChromium", () => {
const chromiumDevices = [
DeviceType.ChromeBrowser,
DeviceType.EdgeBrowser,
DeviceType.OperaBrowser,
DeviceType.VivaldiBrowser,
];
const nonChromiumDevices = [
DeviceType.FirefoxBrowser,
DeviceType.SafariBrowser,
DeviceType.IEBrowser,
DeviceType.DuckDuckGoBrowser,
DeviceType.UnknownBrowser,
];
afterEach(() => {
jest.restoreAllMocks();
});
test.each(chromiumDevices)("returns true when getDevice() is %s", (deviceType) => {
jest.spyOn(webPlatformUtilsService, "getDevice").mockReturnValue(deviceType);
expect(webPlatformUtilsService.isChromium()).toBe(true);
});
test.each(nonChromiumDevices)("returns false when getDevice() is %s", (deviceType) => {
jest.spyOn(webPlatformUtilsService, "getDevice").mockReturnValue(deviceType);
expect(webPlatformUtilsService.isChromium()).toBe(false);
});
});
});

View File

@@ -90,6 +90,10 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
return this.getDevice() === DeviceType.SafariBrowser;
}
isChromium(): boolean {
return this.isChrome() || this.isEdge() || this.isOpera() || this.isVivaldi();
}
isWebKit(): boolean {
return true;
}

View File

@@ -21,6 +21,7 @@ export abstract class PlatformUtilsService {
abstract isOpera(): boolean;
abstract isVivaldi(): boolean;
abstract isSafari(): boolean;
abstract isChromium(): boolean;
abstract isMacAppStore(): boolean;
abstract isPopupOpen(): Promise<boolean>;
abstract launchUri(uri: string, options?: any): void;