]> khamidou — GitHub mirrors - electron.git/commitdiff
Add spec for #70.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 29 Aug 2013 03:40:07 +0000 (11:40 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 29 Aug 2013 03:40:07 +0000 (11:40 +0800)
spec/api/window.coffee [new file with mode: 0644]
spec/fixtures/api/close.html [new file with mode: 0644]
spec/fixtures/api/unload.html [new file with mode: 0644]

diff --git a/spec/api/window.coffee b/spec/api/window.coffee
new file mode 100644 (file)
index 0000000..a0c5e79
--- /dev/null
@@ -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 (file)
index 0000000..0b6e4f3
--- /dev/null
@@ -0,0 +1,10 @@
+<html>
+<body>
+<script type="text/javascript" charset="utf-8">
+  window.addEventListener('unload', function (e) {
+    require('fs').writeFileSync(__dirname + '/test', 'close');
+  }, false);
+  window.close();
+</script>
+</body>
+</html>
diff --git a/spec/fixtures/api/unload.html b/spec/fixtures/api/unload.html
new file mode 100644 (file)
index 0000000..9490c56
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<body>
+<script type="text/javascript" charset="utf-8">
+  window.addEventListener('unload', function (e) {
+    require('fs').writeFileSync(__dirname + '/test', 'unload');
+  }, false);
+</script>
+</body>
+</html>