OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 (function() { |
| 6 |
| 7 'use strict'; |
| 8 |
| 9 /** @type {remoting.WindowShape} */ |
| 10 var windowShape; |
| 11 /** @type {HTMLElement} */ |
| 12 var elementToPosition; |
| 13 /** @type {sinon.TestStub} */ |
| 14 var currentWindowStub; |
| 15 /** @type {sinon.TestStub} */ |
| 16 var isAppsV2Stub; |
| 17 |
| 18 QUnit.module('WindowShape', { |
| 19 beforeEach: function() { |
| 20 windowShape = new remoting.WindowShape(); |
| 21 elementToPosition = |
| 22 /** @type {HTMLElement} */ (document.createElement('div')); |
| 23 sinon.stub(elementToPosition, 'getBoundingClientRect') |
| 24 .returns({left: -50, top: -50, width: 50, height: 50}); |
| 25 |
| 26 isAppsV2Stub = sinon.stub(base, 'isAppsV2', function() { return true; }); |
| 27 currentWindowStub = sinon.stub(chrome.app.window, 'current', function() { |
| 28 return { |
| 29 setShape: base.doNothing |
| 30 }; |
| 31 }); |
| 32 }, |
| 33 afterEach: function() { |
| 34 windowShape = null; |
| 35 elementToPosition = null; |
| 36 currentWindowStub.restore(); |
| 37 isAppsV2Stub.restore(); |
| 38 } |
| 39 }); |
| 40 |
| 41 QUnit.test('centerToDesktop() handles no desktop window', |
| 42 function(assert) { |
| 43 var originalInnerWidth = window.innerWidth; |
| 44 var originalInnerHeight = window.innerHeight; |
| 45 window.innerHeight = 100; |
| 46 window.innerWidth = 100; |
| 47 |
| 48 windowShape.centerToDesktop(elementToPosition); |
| 49 assert.equal(elementToPosition.style.left, '25px'); |
| 50 assert.equal(elementToPosition.style.top, '25px'); |
| 51 |
| 52 window.innerWidth = originalInnerWidth; |
| 53 window.innerHeight = originalInnerHeight; |
| 54 }); |
| 55 |
| 56 QUnit.test('centerToDesktop() handles single desktop window', |
| 57 function(assert) { |
| 58 windowShape.setDesktopRects([{left: 0, width: 100, top: 0, height: 100}]); |
| 59 windowShape.centerToDesktop(elementToPosition); |
| 60 assert.equal(elementToPosition.style.left, '25px'); |
| 61 assert.equal(elementToPosition.style.top, '25px'); |
| 62 }); |
| 63 |
| 64 QUnit.test('centerToDesktop() handles multiple desktop window', |
| 65 function(assert) { |
| 66 windowShape.setDesktopRects([ |
| 67 {left: 0, width: 10, top: 0, height: 10}, |
| 68 {left: 90, width: 10, top: 90, height: 10} |
| 69 ]); |
| 70 |
| 71 windowShape.centerToDesktop(elementToPosition); |
| 72 assert.equal(elementToPosition.style.left, '25px'); |
| 73 assert.equal(elementToPosition.style.top, '25px'); |
| 74 }); |
| 75 |
| 76 })(); |
OLD | NEW |