Browse Source

test: add a test

alice 5 months ago
parent
commit
eb621e7c9c
1 changed files with 19 additions and 0 deletions
  1. 19 0
      spec/api-shell-spec.ts

+ 19 - 0
spec/api-shell-spec.ts

@@ -76,6 +76,25 @@ describe('shell module', () => {
         requestReceived
       ]);
     });
+
+    it('should focus the external app when opening the URL on macOS', async () => {
+      const testUrl = 'http://127.0.0.1';
+      const mainWindow = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true, contextIsolation: false } });
+      await mainWindow.loadURL('about:blank');
+
+      mainWindow.webContents.on('will-navigate', (event, rawTarget) => {
+        event.preventDefault();
+        shell.openExternal(rawTarget);
+      });
+
+      if (process.platform === 'darwin') {
+        const blurPromise = once(mainWindow, 'blur');
+        expect(mainWindow.isFocused()).to.be.true();
+        await mainWindow.webContents.executeJavaScript(`window.location.href = '${testUrl}'`);
+        await blurPromise;
+        expect(mainWindow.isFocused()).to.be.false();
+      }
+    });
   });
 
   describe('shell.trashItem()', () => {