From ff51e4033a720316a5762258cba7ea2a4e4c5d0a Mon Sep 17 00:00:00 2001 From: Robo Date: Sat, 19 Dec 2015 04:23:30 +0530 Subject: [PATCH 1/2] browser: fix value of document.hidden --- atom/renderer/lib/override.coffee | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index 7279b232a99d..15acbdd48bde 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -118,6 +118,12 @@ Object.defineProperty window.history, 'length', get: -> getHistoryOperation 'length' -# Make document.hidden return the correct value. +# Make document.hidden and document.visibilityState return the correct value. Object.defineProperty document, 'hidden', - get: -> !remote.getCurrentWindow().isVisible() + get: -> + currentWindow = remote.getCurrentWindow() + !currentWindow.isFocused() || !currentWindow.isVisible() + +Object.defineProperty document, 'visibilityState', + get: -> + if document.hidden then "hidden" else "visible" From cc7040d75f0ed7552622b93877043effdc0cf284 Mon Sep 17 00:00:00 2001 From: Robo Date: Mon, 21 Dec 2015 17:50:40 +0530 Subject: [PATCH 2/2] add test --- atom/renderer/lib/override.coffee | 2 +- spec/chromium-spec.coffee | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index 15acbdd48bde..5280f1927e80 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -122,7 +122,7 @@ Object.defineProperty window.history, 'length', Object.defineProperty document, 'hidden', get: -> currentWindow = remote.getCurrentWindow() - !currentWindow.isFocused() || !currentWindow.isVisible() + currentWindow.isMinimized() || !currentWindow.isVisible() Object.defineProperty document, 'visibilityState', get: -> diff --git a/spec/chromium-spec.coffee b/spec/chromium-spec.coffee index 5559c36eba89..d19933393f4f 100644 --- a/spec/chromium-spec.coffee +++ b/spec/chromium-spec.coffee @@ -45,6 +45,14 @@ describe 'chromium feature', -> done() w.loadURL url + it 'is set correctly when window is inactive', (done) -> + w = new BrowserWindow(show:false) + w.webContents.on 'ipc-message', (event, args) -> + assert.deepEqual args, ['hidden', false] + done() + w.showInactive() + w.loadURL url + xdescribe 'navigator.webkitGetUserMedia', -> it 'calls its callbacks', (done) -> @timeout 5000