From c41de501cb3b230092ac931cf67e9fe37e05ecdf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 23 Jan 2016 03:35:30 -0800 Subject: [PATCH] spec: Test the -able methods --- atom/browser/native_window.cc | 2 +- atom/browser/native_window_mac.mm | 4 +- atom/browser/native_window_views.cc | 8 +-- spec/api-browser-window-spec.js | 107 ++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 8 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 73370d24c41c..732fc6301e2e 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index bd47fef914b7..d109a8c3a1ad 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -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) { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 9244a327d1b0..910a0c782b60 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -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 } diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 92f69d17bcac..0cd0422afbbb 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -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); + }); + }); + + }); });