From e00d3d4b3790f8f5447f52192d8c24d6c4929ea4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 29 Aug 2013 11:40:07 +0800 Subject: [PATCH] Add spec for #70. --- spec/api/window.coffee | 33 +++++++++++++++++++++++++++++++++ spec/fixtures/api/close.html | 10 ++++++++++ spec/fixtures/api/unload.html | 9 +++++++++ 3 files changed, 52 insertions(+) create mode 100644 spec/api/window.coffee create mode 100644 spec/fixtures/api/close.html create mode 100644 spec/fixtures/api/unload.html diff --git a/spec/api/window.coffee b/spec/api/window.coffee new file mode 100644 index 00000000..a0c5e795 --- /dev/null +++ b/spec/api/window.coffee @@ -0,0 +1,33 @@ +assert = require 'assert' +fs = require 'fs' +path = require 'path' +remote = require 'remote' +BrowserWindow = remote.require 'browser-window' + +fixtures = path.resolve __dirname, '..', 'fixtures' + +describe 'window module', -> + describe 'BrowserWindow.close()', -> + it 'should emit unload handler', (done) -> + w = new BrowserWindow(show: false) + w.on 'loading-state-changed', (event, isLoading) -> + if (!isLoading) + w.close() + w.on 'destroyed', -> + test = path.join(fixtures, 'api', 'test') + content = fs.readFileSync(test) + fs.unlinkSync(test) + assert.equal String(content), 'unload' + done() + w.loadUrl 'file://' + path.join(fixtures, 'api', 'unload.html') + + describe 'window.close()', -> + it 'should emit unload handler', (done) -> + w = new BrowserWindow(show: false) + w.on 'destroyed', -> + test = path.join(fixtures, 'api', 'close') + content = fs.readFileSync(test) + fs.unlinkSync(test) + assert.equal String(content), 'close' + done() + w.loadUrl 'file://' + path.join(fixtures, 'api', 'close.html') diff --git a/spec/fixtures/api/close.html b/spec/fixtures/api/close.html new file mode 100644 index 00000000..0b6e4f36 --- /dev/null +++ b/spec/fixtures/api/close.html @@ -0,0 +1,10 @@ + + + + + diff --git a/spec/fixtures/api/unload.html b/spec/fixtures/api/unload.html new file mode 100644 index 00000000..9490c56d --- /dev/null +++ b/spec/fixtures/api/unload.html @@ -0,0 +1,9 @@ + + + + + -- 2.43.0