Add in-app browser tabs (#430)

This commit is contained in:
Jinwoo Hong
2026-04-10 00:04:42 -07:00
committed by GitHub
parent fee1165747
commit c6ff6da3a8
45 changed files with 3953 additions and 345 deletions
+53 -3
View File
@@ -1,8 +1,9 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const { browserWindowMock, openExternalMock } = vi.hoisted(() => ({
const { browserWindowMock, openExternalMock, attachGuestPoliciesMock } = vi.hoisted(() => ({
browserWindowMock: vi.fn(),
openExternalMock: vi.fn()
openExternalMock: vi.fn(),
attachGuestPoliciesMock: vi.fn()
}))
vi.mock('electron', () => ({
@@ -24,12 +25,19 @@ vi.mock('../../../resources/icon-dev.png?asset', () => ({
default: 'icon-dev'
}))
vi.mock('../browser/browser-manager', () => ({
browserManager: {
attachGuestPolicies: attachGuestPoliciesMock
}
}))
import { createMainWindow } from './createMainWindow'
describe('createMainWindow', () => {
beforeEach(() => {
browserWindowMock.mockReset()
openExternalMock.mockReset()
attachGuestPoliciesMock.mockReset()
})
it('enables renderer sandboxing and opens external links safely', () => {
@@ -39,6 +47,8 @@ describe('createMainWindow', () => {
windowHandlers[event] = handler
}),
setZoomLevel: vi.fn(),
setBackgroundThrottling: vi.fn(),
invalidate: vi.fn(),
setWindowOpenHandler: vi.fn((handler) => {
windowHandlers.windowOpen = handler
}),
@@ -47,6 +57,11 @@ describe('createMainWindow', () => {
const browserWindowInstance = {
webContents,
on: vi.fn(),
isDestroyed: vi.fn(() => false),
isMaximized: vi.fn(() => true),
isFullScreen: vi.fn(() => false),
getSize: vi.fn(() => [1200, 800]),
setSize: vi.fn(),
maximize: vi.fn(),
show: vi.fn(),
loadFile: vi.fn(),
@@ -70,7 +85,7 @@ describe('createMainWindow', () => {
expect(windowHandlers.windowOpen({ url: 'not a url' })).toEqual({ action: 'deny' })
expect(openExternalMock).toHaveBeenCalledTimes(2)
expect(openExternalMock).toHaveBeenCalledWith('https://example.com')
expect(openExternalMock).toHaveBeenCalledWith('https://example.com/')
expect(openExternalMock).toHaveBeenCalledWith('http://localhost:3000/')
const preventDefault = vi.fn()
@@ -95,6 +110,27 @@ describe('createMainWindow', () => {
)
expect(fileNavigationPreventDefault).toHaveBeenCalledTimes(1)
expect(openExternalMock).toHaveBeenCalledTimes(4)
const allowBlankEvent = { preventDefault: vi.fn() }
const allowBlankPrefs = { partition: 'persist:orca-browser' }
windowHandlers['will-attach-webview'](
allowBlankEvent as never,
allowBlankPrefs as never,
{ src: 'data:text/html,' } as never
)
expect(allowBlankEvent.preventDefault).not.toHaveBeenCalled()
const denyInlineHtmlEvent = { preventDefault: vi.fn() }
windowHandlers['will-attach-webview'](
denyInlineHtmlEvent as never,
{ partition: 'persist:orca-browser' } as never,
{ src: 'data:text/html,<script>alert(1)</script>' } as never
)
expect(denyInlineHtmlEvent.preventDefault).toHaveBeenCalledTimes(1)
const guest = { marker: 'guest' }
windowHandlers['did-attach-webview']({} as never, guest as never)
expect(attachGuestPoliciesMock).toHaveBeenCalledWith(guest)
})
it('supports all minus key variants for terminal zoom out', () => {
@@ -104,12 +140,19 @@ describe('createMainWindow', () => {
windowHandlers[event] = handler
}),
setZoomLevel: vi.fn(),
setBackgroundThrottling: vi.fn(),
invalidate: vi.fn(),
setWindowOpenHandler: vi.fn(),
send: vi.fn()
}
const browserWindowInstance = {
webContents,
on: vi.fn(),
isDestroyed: vi.fn(() => false),
isMaximized: vi.fn(() => true),
isFullScreen: vi.fn(() => false),
getSize: vi.fn(() => [1200, 800]),
setSize: vi.fn(),
maximize: vi.fn(),
show: vi.fn(),
loadFile: vi.fn(),
@@ -152,12 +195,19 @@ describe('createMainWindow', () => {
windowHandlers[event] = handler
}),
setZoomLevel: vi.fn(),
setBackgroundThrottling: vi.fn(),
invalidate: vi.fn(),
setWindowOpenHandler: vi.fn(),
send: vi.fn()
}
const browserWindowInstance = {
webContents,
on: vi.fn(),
isDestroyed: vi.fn(() => false),
isMaximized: vi.fn(() => true),
isFullScreen: vi.fn(() => false),
getSize: vi.fn(() => [1200, 800]),
setSize: vi.fn(),
maximize: vi.fn(),
show: vi.fn(),
loadFile: vi.fn(),