OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * @suppress {checkTypes} | 7 * @suppress {checkTypes} |
8 * Browser test for the scenario below: | 8 * Browser test for the scenario below: |
9 * 1. Enter full-screen mode | 9 * 1. Enter full-screen mode |
10 * 2. Move the mouse to each edge; verify that the desktop bump-scrolls. | 10 * 2. Move the mouse to each edge; verify that the desktop bump-scrolls. |
11 */ | 11 */ |
12 | 12 |
13 'use strict'; | 13 'use strict'; |
14 | 14 |
15 /** | 15 /** @constructor */ |
16 * @constructor | 16 browserTest.FakeDesktopViewport = function() { |
17 * @extends {base.EventSourceImpl} | 17 /** @private */ |
18 */ | 18 this.pluginPosition_ = { |
19 browserTest.FakeDesktopConnectedView = function() { | |
20 this.pluginPosition = { | |
21 top: 0, | 19 top: 0, |
22 left: 0 | 20 left: 0 |
23 }; | 21 }; |
24 this.defineEvents(Object.keys(remoting.DesktopConnectedView.Events)); | 22 /** @private */ |
| 23 this.bumpScroller_ = new base.EventSourceImpl(); |
| 24 this.bumpScroller_.defineEvents(Object.keys(remoting.BumpScroller.Events)); |
25 }; | 25 }; |
26 | 26 |
27 base.extend(browserTest.FakeDesktopConnectedView, base.EventSourceImpl); | 27 /** |
| 28 * @param {number} top |
| 29 * @param {number} left |
| 30 * @return {void} nothing. |
| 31 */ |
| 32 browserTest.FakeDesktopViewport.prototype.setPluginPositionForTesting = |
| 33 function(top, left) { |
| 34 this.pluginPosition_ = { |
| 35 top: top, |
| 36 left: left |
| 37 }; |
| 38 }; |
28 | 39 |
29 /** | 40 /** |
30 * @return {{top: number, left:number}} The top-left corner of the plugin. | 41 * @return {{top: number, left:number}} The top-left corner of the plugin. |
31 */ | 42 */ |
32 browserTest.FakeDesktopConnectedView.prototype.getPluginPositionForTesting = | 43 browserTest.FakeDesktopViewport.prototype.getPluginPositionForTesting = |
33 function() { | 44 function() { |
34 return this.pluginPosition; | 45 return this.pluginPosition_; |
| 46 }; |
| 47 |
| 48 /** @return {base.EventSource} */ |
| 49 browserTest.FakeDesktopViewport.prototype.getBumpScrollerForTesting = |
| 50 function() { |
| 51 return this.bumpScroller_; |
| 52 }; |
| 53 |
| 54 browserTest.FakeDesktopViewport.prototype.raiseEvent = |
| 55 function() { |
| 56 return this.bumpScroller_.raiseEvent.apply(this.bumpScroller_, arguments); |
35 }; | 57 }; |
36 | 58 |
37 | 59 |
38 /** @constructor */ | 60 /** @constructor */ |
39 browserTest.Bump_Scroll = function() { | 61 browserTest.Bump_Scroll = function() { |
40 // To avoid dependencies on the actual host desktop size, we simulate a | 62 // To avoid dependencies on the actual host desktop size, we simulate a |
41 // desktop larger or smaller than the client window. The exact value is | 63 // desktop larger or smaller than the client window. The exact value is |
42 // arbitrary, but must be positive. | 64 // arbitrary, but must be positive. |
43 /** @type {number} */ | 65 /** @type {number} */ |
44 this.kHostDesktopSizeDelta = 10; | 66 this.kHostDesktopSizeDelta = 10; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 browserTest.disconnect(); | 107 browserTest.disconnect(); |
86 return browserTest.fail(error); | 108 return browserTest.fail(error); |
87 } | 109 } |
88 ); | 110 ); |
89 }; | 111 }; |
90 | 112 |
91 /** | 113 /** |
92 * @return {Promise} | 114 * @return {Promise} |
93 */ | 115 */ |
94 browserTest.Bump_Scroll.prototype.noScrollWindowed = function() { | 116 browserTest.Bump_Scroll.prototype.noScrollWindowed = function() { |
95 remoting.desktopConnectedView.setPluginSizeForBumpScrollTesting( | 117 var viewport = remoting.desktopConnectedView.getViewportForTesting(); |
| 118 viewport.setPluginSizeForBumpScrollTesting( |
96 window.innerWidth + this.kHostDesktopSizeDelta, | 119 window.innerWidth + this.kHostDesktopSizeDelta, |
97 window.innerHeight + this.kHostDesktopSizeDelta); | 120 window.innerHeight + this.kHostDesktopSizeDelta); |
98 this.moveMouseTo(0, 0); | 121 this.moveMouseTo(0, 0); |
99 return this.verifyScroll(undefined, undefined); | 122 return this.verifyScroll(undefined, undefined); |
100 }; | 123 }; |
101 | 124 |
102 /** | 125 /** |
103 * @return {Promise} | 126 * @return {Promise} |
104 */ | 127 */ |
105 browserTest.Bump_Scroll.prototype.noScrollSmaller = function() { | 128 browserTest.Bump_Scroll.prototype.noScrollSmaller = function() { |
106 remoting.desktopConnectedView.setPluginSizeForBumpScrollTesting( | 129 var viewport = remoting.desktopConnectedView.getViewportForTesting(); |
| 130 viewport.setPluginSizeForBumpScrollTesting( |
107 window.innerWidth - this.kHostDesktopSizeDelta, | 131 window.innerWidth - this.kHostDesktopSizeDelta, |
108 window.innerHeight - this.kHostDesktopSizeDelta); | 132 window.innerHeight - this.kHostDesktopSizeDelta); |
109 this.moveMouseTo(0, 0); | 133 this.moveMouseTo(0, 0); |
110 return this.verifyScroll(undefined, undefined); | 134 return this.verifyScroll(undefined, undefined); |
111 }; | 135 }; |
112 | 136 |
113 /** | 137 /** |
114 * @param {number} widthFraction | 138 * @param {number} widthFraction |
115 * @param {number} heightFraction | 139 * @param {number} heightFraction |
116 * @return {Promise} | 140 * @return {Promise} |
117 */ | 141 */ |
118 browserTest.Bump_Scroll.prototype.scrollDirection = | 142 browserTest.Bump_Scroll.prototype.scrollDirection = |
119 function(widthFraction, heightFraction) { | 143 function(widthFraction, heightFraction) { |
120 remoting.desktopConnectedView.setPluginSizeForBumpScrollTesting( | 144 var viewport = remoting.desktopConnectedView.getViewportForTesting(); |
| 145 viewport.setPluginSizeForBumpScrollTesting( |
121 screen.width + this.kHostDesktopSizeDelta, | 146 screen.width + this.kHostDesktopSizeDelta, |
122 screen.height + this.kHostDesktopSizeDelta); | 147 screen.height + this.kHostDesktopSizeDelta); |
123 /** @type {number} */ | 148 /** @type {number} */ |
124 var expectedTop = heightFraction == 0.0 ? 0 : | 149 var expectedTop = heightFraction === 0.0 ? 0 : |
125 heightFraction == 1.0 ? -this.kHostDesktopSizeDelta : | 150 heightFraction == 1.0 ? -this.kHostDesktopSizeDelta : |
126 undefined; | 151 undefined; |
127 /** @type {number} */ | 152 /** @type {number} */ |
128 var expectedLeft = widthFraction == 0.0 ? 0 : | 153 var expectedLeft = widthFraction === 0.0 ? 0 : |
129 widthFraction == 1.0 ? -this.kHostDesktopSizeDelta : | 154 widthFraction === 1.0 ? -this.kHostDesktopSizeDelta : |
130 undefined; | 155 undefined; |
131 var result = this.verifyScroll(expectedTop, expectedLeft); | 156 var result = this.verifyScroll(expectedTop, expectedLeft); |
132 this.moveMouseTo(widthFraction * screen.width, | 157 this.moveMouseTo(widthFraction * screen.width, |
133 heightFraction * screen.height); | 158 heightFraction * screen.height); |
134 return result; | 159 return result; |
135 }; | 160 }; |
136 | 161 |
137 /** | 162 /** |
138 * @return {Promise} | 163 * @return {Promise} |
139 */ | 164 */ |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, | 204 e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, |
180 e.button, document.documentElement); | 205 e.button, document.documentElement); |
181 document.documentElement.dispatchEvent(event); | 206 document.documentElement.dispatchEvent(event); |
182 }; | 207 }; |
183 | 208 |
184 /** | 209 /** |
185 * verifyScroll() is complicated enough to warrant a test. | 210 * verifyScroll() is complicated enough to warrant a test. |
186 * @return {Promise} | 211 * @return {Promise} |
187 */ | 212 */ |
188 browserTest.Bump_Scroll.prototype.testVerifyScroll = function() { | 213 browserTest.Bump_Scroll.prototype.testVerifyScroll = function() { |
189 var STARTED = remoting.DesktopConnectedView.Events.bumpScrollStarted; | 214 var STARTED = remoting.BumpScroller.Events.bumpScrollStarted; |
190 var STOPPED = remoting.DesktopConnectedView.Events.bumpScrollStopped; | 215 var STOPPED = remoting.BumpScroller.Events.bumpScrollStopped; |
191 var fakeSession = new browserTest.FakeDesktopConnectedView; | 216 var fakeViewport = new browserTest.FakeDesktopViewport; |
192 var that = this; | 217 var that = this; |
193 | 218 |
194 // No events raised (e.g. windowed mode). | 219 // No events raised (e.g. windowed mode). |
195 var result = this.verifyScroll(undefined, undefined, fakeSession) | 220 var result = this.verifyScroll(undefined, undefined, fakeViewport) |
196 | 221 |
197 .then(function() { | 222 .then(function() { |
198 // Start and end events raised, but no scrolling (e.g. full-screen mode | 223 // Start and end events raised, but no scrolling (e.g. full-screen mode |
199 // with host desktop <= window size). | 224 // with host desktop <= window size). |
200 fakeSession = new browserTest.FakeDesktopConnectedView; | 225 fakeViewport = new browserTest.FakeDesktopViewport; |
201 var result = that.verifyScroll(undefined, undefined, fakeSession); | 226 var result = that.verifyScroll(undefined, undefined, fakeViewport); |
202 fakeSession.raiseEvent(STARTED, {}); | 227 fakeViewport.raiseEvent(STARTED, {}); |
203 fakeSession.raiseEvent(STOPPED, {}); | 228 fakeViewport.raiseEvent(STOPPED, {}); |
204 return result; | 229 return result; |
205 | 230 |
206 }).then(function() { | 231 }).then(function() { |
207 // Start and end events raised, with incorrect scrolling. | 232 // Start and end events raised, with incorrect scrolling. |
208 fakeSession = new browserTest.FakeDesktopConnectedView; | 233 fakeViewport = new browserTest.FakeDesktopViewport; |
209 var result = base.Promise.negate( | 234 var result = base.Promise.negate( |
210 that.verifyScroll(2, 2, fakeSession)); | 235 that.verifyScroll(2, 2, fakeViewport)); |
211 fakeSession.raiseEvent(STARTED, {}); | 236 fakeViewport.raiseEvent(STARTED, {}); |
212 fakeSession.pluginPosition.top = 1; | 237 fakeViewport.setPluginPositionForTesting(1, 1); |
213 fakeSession.pluginPosition.left = 1; | 238 fakeViewport.raiseEvent(STOPPED, {}); |
214 fakeSession.raiseEvent(STOPPED, {}); | |
215 return result; | 239 return result; |
216 | 240 |
217 }).then(function() { | 241 }).then(function() { |
218 // Start event raised, but not end event. | 242 // Start event raised, but not end event. |
219 fakeSession = new browserTest.FakeDesktopConnectedView; | 243 fakeViewport = new browserTest.FakeDesktopViewport; |
220 var result = base.Promise.negate( | 244 var result = base.Promise.negate( |
221 that.verifyScroll(2, 2, fakeSession)); | 245 that.verifyScroll(2, 2, fakeViewport)); |
222 fakeSession.raiseEvent(STARTED, {}); | 246 fakeViewport.raiseEvent(STARTED, {}); |
223 fakeSession.pluginPosition.top = 2; | 247 fakeViewport.setPluginPositionForTesting(2, 2); |
224 fakeSession.pluginPosition.left = 2; | |
225 return result; | 248 return result; |
226 | 249 |
227 }).then(function() { | 250 }).then(function() { |
228 // Start and end events raised, with correct scrolling. | 251 // Start and end events raised, with correct scrolling. |
229 fakeSession = new browserTest.FakeDesktopConnectedView; | 252 fakeViewport = new browserTest.FakeDesktopViewport; |
230 var result = that.verifyScroll(2, 2, fakeSession); | 253 var result = that.verifyScroll(2, 2, fakeViewport); |
231 fakeSession.raiseEvent(STARTED, {}); | 254 fakeViewport.raiseEvent(STARTED, {}); |
232 fakeSession.pluginPosition.top = 2; | 255 fakeViewport.setPluginPositionForTesting(2, 2); |
233 fakeSession.pluginPosition.left = 2; | 256 fakeViewport.raiseEvent(STOPPED, {}); |
234 fakeSession.raiseEvent(STOPPED, {}); | |
235 return result; | 257 return result; |
236 }); | 258 }); |
237 | 259 |
238 return result; | 260 return result; |
239 }; | 261 }; |
240 | 262 |
241 /** | 263 /** |
242 * Verify that a bump scroll operation takes place and that the top-left corner | 264 * Verify that a bump scroll operation takes place and that the top-left corner |
243 * of the plugin is as expected when it completes. | 265 * of the plugin is as expected when it completes. |
244 * @param {number|undefined} expectedTop The expected vertical position of the | 266 * @param {number|undefined} expectedTop The expected vertical position of the |
245 * plugin, or undefined if it is not expected to change. | 267 * plugin, or undefined if it is not expected to change. |
246 * @param {number|undefined} expectedLeft The expected horizontal position of | 268 * @param {number|undefined} expectedLeft The expected horizontal position of |
247 * the plugin, or undefined if it is not expected to change. | 269 * the plugin, or undefined if it is not expected to change. |
248 * @param {browserTest.FakeDesktopConnectedView=} opt_desktopConnectedView | 270 * @param {browserTest.FakeDesktopViewport=} opt_desktopViewport |
249 * DesktopConnectedView fake, for testing. | 271 * DesktopViewport fake, for testing. |
250 * @return {Promise} | 272 * @return {Promise} |
251 */ | 273 */ |
252 browserTest.Bump_Scroll.prototype.verifyScroll = | 274 browserTest.Bump_Scroll.prototype.verifyScroll = |
253 function (expectedTop, expectedLeft, opt_desktopConnectedView) { | 275 function (expectedTop, expectedLeft, opt_desktopViewport) { |
254 /** @type {browserTest.FakeDesktopConnectedView} */ | 276 var desktopViewport = opt_desktopViewport || |
255 var desktopConnectedView = opt_desktopConnectedView || | 277 remoting.desktopConnectedView.getViewportForTesting(); |
256 remoting.desktopConnectedView; | 278 base.debug.assert(desktopViewport != null); |
257 base.debug.assert(desktopConnectedView != null); | 279 var STARTED = remoting.BumpScroller.Events.bumpScrollStarted; |
258 var STARTED = remoting.DesktopConnectedView.Events.bumpScrollStarted; | 280 var STOPPED = remoting.BumpScroller.Events.bumpScrollStopped; |
259 var STOPPED = remoting.DesktopConnectedView.Events.bumpScrollStopped; | |
260 | 281 |
261 var initialPosition = desktopConnectedView.getPluginPositionForTesting(); | 282 var initialPosition = desktopViewport.getPluginPositionForTesting(); |
262 var initialTop = initialPosition.top; | 283 var initialTop = initialPosition.top; |
263 var initialLeft = initialPosition.left; | 284 var initialLeft = initialPosition.left; |
264 | 285 |
265 /** @return {Promise} */ | 286 /** @return {Promise} */ |
266 var verifyPluginPosition = function() { | 287 var verifyPluginPosition = function() { |
267 var position = desktopConnectedView.getPluginPositionForTesting(); | 288 var position = desktopViewport.getPluginPositionForTesting(); |
268 if (expectedLeft === undefined) { | 289 if (expectedLeft === undefined) { |
269 expectedLeft = initialLeft; | 290 expectedLeft = initialLeft; |
270 } | 291 } |
271 if (expectedTop === undefined) { | 292 if (expectedTop === undefined) { |
272 expectedTop = initialTop; | 293 expectedTop = initialTop; |
273 } | 294 } |
274 if (position.top != expectedTop || position.left != expectedLeft) { | 295 if (position.top != expectedTop || position.left != expectedLeft) { |
275 return Promise.reject( | 296 return Promise.reject( |
276 new Error('No or incorrect scroll detected: (' + | 297 new Error('No or incorrect scroll detected: (' + |
277 position.left + ',' + position.top + ' instead of ' + | 298 position.left + ',' + position.top + ' instead of ' + |
278 expectedLeft + ',' + expectedTop + ')')); | 299 expectedLeft + ',' + expectedTop + ')')); |
279 } else { | 300 } else { |
280 return Promise.resolve(); | 301 return Promise.resolve(); |
281 } | 302 } |
282 }; | 303 }; |
283 | 304 |
284 var started = browserTest.expectEvent(desktopConnectedView, STARTED, 1000); | 305 var bumpScroller = desktopViewport.getBumpScrollerForTesting(); |
285 var stopped = browserTest.expectEvent(desktopConnectedView, STOPPED, 5000); | 306 var started = browserTest.expectEvent(bumpScroller, STARTED, 1000); |
| 307 var stopped = browserTest.expectEvent(bumpScroller, STOPPED, 5000); |
286 return started.then(function() { | 308 return started.then(function() { |
287 return stopped.then(function() { | 309 return stopped; |
288 return verifyPluginPosition(); | |
289 }); | |
290 }, function() { | 310 }, function() { |
291 // If no started event is raised, the test might still pass if it asserted | 311 // If no started event is raised, the test might still pass if it asserted |
292 // no scrolling. | 312 // no scrolling. |
293 if (expectedTop == undefined && expectedLeft == undefined) { | 313 if (expectedTop === undefined && expectedLeft === undefined) { |
294 return Promise.resolve(); | 314 return Promise.resolve(); |
295 } else { | 315 } else { |
296 return Promise.reject( | 316 return Promise.reject( |
297 new Error('Scroll expected but no start event fired.')); | 317 new Error('Scroll expected but no start event fired.')); |
298 } | 318 } |
| 319 }).then(function() { |
| 320 return verifyPluginPosition(); |
299 }); | 321 }); |
300 }; | 322 }; |
OLD | NEW |