]> khamidou — GitHub mirrors - electron.git/commitdiff
spec: Test the -able methods
authorCheng Zhao <zcbenz@gmail.com>
Sat, 23 Jan 2016 11:35:30 +0000 (03:35 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 24 Jan 2016 06:31:37 +0000 (14:31 +0800)
atom/browser/native_window.cc
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
spec/api-browser-window-spec.js

index 73370d24c41ccc6745206e098e5f5095b96cedaa..732fc6301e2e791da63fb1c708b80946e65af694 100644 (file)
@@ -122,7 +122,7 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
   }
 #endif
   bool movable;
-  if (options.Get(options::kMovable, &movable) && movable) {
+  if (options.Get(options::kMovable, &movable)) {
     SetMovable(movable);
   }
   bool has_shadow;
index bd47fef914b781a815de6517c9b0135b218f4ad7..d109a8c3a1ad4630a216a017d6de78f12ac1766a 100644 (file)
@@ -489,9 +489,7 @@ NativeWindowMac::NativeWindowMac(
   bool fullscreen = false;
   if (options.Get(options::kFullscreen, &fullscreen) && !fullscreen)
     fullscreenable = false;
-  if (!fullscreenable) {
-    SetFullScreenable(false);
-  }
+  SetFullScreenable(fullscreenable);
 
   // Disable zoom button if window is not resizable
   if (!maximizable) {
index 9244a327d1b0e76ffe82491ea540d1154c579591..910a0c782b606ebb7f7115e0fe68b287ea482510 100644 (file)
@@ -465,9 +465,9 @@ void NativeWindowViews::SetMinimizable(bool minimizable) {
 
 bool NativeWindowViews::IsMinimizable() {
 #if defined(OS_WIN)
-  return CanMinimize();
+  return ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_MINIMIZEBOX;
 #else
-  return true;  // CanMinimize() Not implemented on Linux.
+  return true;  // Not implemented on Linux.
 #endif
 }
 
@@ -480,9 +480,9 @@ void NativeWindowViews::SetMaximizable(bool maximizable) {
 
 bool NativeWindowViews::IsMaximizable() {
 #if defined(OS_WIN)
-  return CanMaximize();
+  return ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_MAXIMIZEBOX;
 #else
-  return true;  // CanMaximize() Not implemented on Linux.
+  return true;  // Not implemented on Linux.
 #endif
 }
 
index 92f69d17bcacddd9e938692eed04f00bd4f65d6a..0cd0422afbbbd6c1473a85c0d1afd04602535f1b 100644 (file)
@@ -1,3 +1,5 @@
+'use strict';
+
 const assert = require('assert');
 const fs = require('fs');
 const path = require('path');
@@ -306,6 +308,7 @@ describe('browser-window module', function() {
       return assert.equal(after[1], size.height);
     });
   });
+
   describe('"web-preferences" option', function() {
     afterEach(function() {
       return ipcMain.removeAllListeners('answer');
@@ -491,4 +494,108 @@ describe('browser-window module', function() {
       return assert.equal(size[1], 600);
     });
   });
+
+  describe('window states', function() {
+    // Not implemented on Linux.
+    if (process.platform == 'linux')
+      return;
+
+    describe('movable state', function() {
+      it('can be changed with movable option', function() {
+        w.destroy();
+        w = new BrowserWindow({show: false, movable: false});
+        assert.equal(w.isMovable(), false);
+      });
+
+      it('can be changed with setMovable method', function() {
+        assert.equal(w.isMovable(), true);
+        w.setMovable(false);
+        assert.equal(w.isMovable(), false);
+        w.setMovable(true);
+        assert.equal(w.isMovable(), true);
+      });
+    });
+
+    describe('minimizable state', function() {
+      it('can be changed with minimizable option', function() {
+        w.destroy();
+        w = new BrowserWindow({show: false, minimizable: false});
+        assert.equal(w.isMinimizable(), false);
+      });
+
+      it('can be changed with setMinimizable method', function() {
+        assert.equal(w.isMinimizable(), true);
+        w.setMinimizable(false);
+        assert.equal(w.isMinimizable(), false);
+        w.setMinimizable(true);
+        assert.equal(w.isMinimizable(), true);
+      });
+    });
+
+    describe('maximizable state', function() {
+      it('can be changed with maximizable option', function() {
+        w.destroy();
+        w = new BrowserWindow({show: false, maximizable: false});
+        assert.equal(w.isMaximizable(), false);
+      });
+
+      it('can be changed with setMaximizable method', function() {
+        assert.equal(w.isMaximizable(), true);
+        w.setMaximizable(false);
+        assert.equal(w.isMaximizable(), false);
+        w.setMaximizable(true);
+        assert.equal(w.isMaximizable(), true);
+      });
+
+      it('is not affected when changing other states', function() {
+        w.setMaximizable(false);
+        assert.equal(w.isMaximizable(), false);
+        w.setMinimizable(false);
+        assert.equal(w.isMaximizable(), false);
+        w.setClosable(false);
+        assert.equal(w.isMaximizable(), false);
+      });
+    });
+
+    describe('fullscreenable state', function() {
+      // Only implemented on OS X.
+      if (process.platform != 'darwin')
+        return;
+
+      it('can be changed with fullscreenable option', function() {
+        w.destroy();
+        w = new BrowserWindow({show: false, fullscreenable: false});
+        assert.equal(w.isFullScreenable(), false);
+      });
+
+      it('can be changed with setFullScreenable method', function() {
+        assert.equal(w.isFullScreenable(), true);
+        w.setFullScreenable(false);
+        assert.equal(w.isFullScreenable(), false);
+        w.setFullScreenable(true);
+        assert.equal(w.isFullScreenable(), true);
+      });
+    });
+
+    describe('closable state', function() {
+      // Only implemented on OS X.
+      if (process.platform != 'darwin')
+        return;
+
+      it('can be changed with closable option', function() {
+        w.destroy();
+        w = new BrowserWindow({show: false, closable: false});
+        assert.equal(w.isClosable(), false);
+      });
+
+      it('can be changed with setClosable method', function() {
+        assert.equal(w.isClosable(), true);
+        w.setClosable(false);
+        assert.equal(w.isClosable(), false);
+        w.setClosable(true);
+        assert.equal(w.isClosable(), true);
+      });
+    });
+
+  });
 });