Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: remoting/webapp/browser_test/bump_scroll_browser_test.js

Issue 918783002: CRD Viewport Management refactor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + plumbing remoting.Host into clientSession Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /** @constructor */ 15 /** @constructor */
16 browserTest.FakeDesktopConnectedView = function() { 16 browserTest.FakeDesktopViewport = function() {
17 this.pluginPosition = { 17 this.pluginPosition = {
18 top: 0, 18 top: 0,
19 left: 0 19 left: 0
20 }; 20 };
21 this.defineEvents(Object.keys(remoting.DesktopConnectedView.Events)); 21 this.bumpScroller = new base.EventSourceImpl();
22 this.bumpScroller.defineEvents(Object.keys(remoting.BumpScroller.Events));
22 }; 23 };
23 24
24 base.extend(browserTest.FakeDesktopConnectedView, base.EventSourceImpl); 25 browserTest.FakeDesktopViewport.prototype.getPluginPositionForTesting =
25
26 browserTest.FakeDesktopConnectedView.prototype.getPluginPositionForTesting =
27 function() { 26 function() {
28 return this.pluginPosition; 27 return this.pluginPosition;
29 }; 28 };
30 29
30 browserTest.FakeDesktopViewport.prototype.getBumpScrollerForTesting =
31 function() {
32 return this.bumpScroller;
33 };
34
35 browserTest.FakeDesktopViewport.prototype.raiseEvent =
36 function() {
37 return this.bumpScroller.raiseEvent.apply(this.bumpScroller, arguments);
38 };
39
31 40
32 /** @constructor */ 41 /** @constructor */
33 browserTest.Bump_Scroll = function() { 42 browserTest.Bump_Scroll = function() {
34 // To aviod dependencies on the actual host desktop size, we simulate a 43 // To aviod dependencies on the actual host desktop size, we simulate a
35 // desktop larger or smaller than the client window. The exact value is 44 // desktop larger or smaller than the client window. The exact value is
36 // arbitrary, but must be positive. 45 // arbitrary, but must be positive.
37 this.kHostDesktopSizeDelta = 10; 46 this.kHostDesktopSizeDelta = 10;
38 }; 47 };
39 48
40 browserTest.Bump_Scroll.prototype.run = function(data) { 49 browserTest.Bump_Scroll.prototype.run = function(data) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return browserTest.pass(value); 81 return browserTest.pass(value);
73 }, 82 },
74 function(error) { 83 function(error) {
75 browserTest.disconnect(); 84 browserTest.disconnect();
76 return browserTest.fail(error); 85 return browserTest.fail(error);
77 } 86 }
78 ); 87 );
79 }; 88 };
80 89
81 browserTest.Bump_Scroll.prototype.noScrollWindowed = function() { 90 browserTest.Bump_Scroll.prototype.noScrollWindowed = function() {
82 remoting.desktopConnectedView.pluginWidthForBumpScrollTesting = 91 var viewport = remoting.desktopConnectedView.getViewportForTesting();
92 viewport.pluginWidthForBumpScrollTesting =
83 window.innerWidth + this.kHostDesktopSizeDelta; 93 window.innerWidth + this.kHostDesktopSizeDelta;
84 remoting.desktopConnectedView.pluginHeightForBumpScrollTesting = 94 viewport.pluginHeightForBumpScrollTesting =
85 window.innerHeight + this.kHostDesktopSizeDelta; 95 window.innerHeight + this.kHostDesktopSizeDelta;
86 this.moveMouseTo(0, 0); 96 this.moveMouseTo(0, 0);
87 return this.verifyScroll(undefined, undefined); 97 return this.verifyScroll(undefined, undefined);
88 }; 98 };
89 99
90 browserTest.Bump_Scroll.prototype.noScrollSmaller = function() { 100 browserTest.Bump_Scroll.prototype.noScrollSmaller = function() {
91 remoting.desktopConnectedView.pluginWidthForBumpScrollTesting = 101 var viewport = remoting.desktopConnectedView.getViewportForTesting();
102 viewport.pluginWidthForBumpScrollTesting =
92 window.innerWidth - this.kHostDesktopSizeDelta; 103 window.innerWidth - this.kHostDesktopSizeDelta;
93 remoting.desktopConnectedView.pluginHeightForBumpScrollTesting = 104 viewport.pluginHeightForBumpScrollTesting =
94 window.innerHeight - this.kHostDesktopSizeDelta; 105 window.innerHeight - this.kHostDesktopSizeDelta;
95 this.moveMouseTo(0, 0); 106 this.moveMouseTo(0, 0);
96 return this.verifyScroll(undefined, undefined); 107 return this.verifyScroll(undefined, undefined);
97 }; 108 };
98 109
99 browserTest.Bump_Scroll.prototype.scrollDirection = 110 browserTest.Bump_Scroll.prototype.scrollDirection =
100 function(widthFraction, heightFraction) { 111 function(widthFraction, heightFraction) {
101 remoting.desktopConnectedView.pluginWidthForBumpScrollTesting = 112 var viewport = remoting.desktopConnectedView.getViewportForTesting();
113 viewport.pluginWidthForBumpScrollTesting =
102 screen.width + this.kHostDesktopSizeDelta; 114 screen.width + this.kHostDesktopSizeDelta;
103 remoting.desktopConnectedView.pluginHeightForBumpScrollTesting = 115 viewport.pluginHeightForBumpScrollTesting =
104 screen.height + this.kHostDesktopSizeDelta; 116 screen.height + this.kHostDesktopSizeDelta;
105 var expectedTop = heightFraction == 0.0 ? 0 : 117 var expectedTop = heightFraction == 0.0 ? 0 :
106 heightFraction == 1.0 ? -this.kHostDesktopSizeDelta : 118 heightFraction == 1.0 ? -this.kHostDesktopSizeDelta :
107 undefined; 119 undefined;
108 var expectedLeft = widthFraction == 0.0 ? 0 : 120 var expectedLeft = widthFraction == 0.0 ? 0 :
109 widthFraction == 1.0 ? -this.kHostDesktopSizeDelta : 121 widthFraction == 1.0 ? -this.kHostDesktopSizeDelta :
110 undefined; 122 undefined;
111 var result = this.verifyScroll(expectedTop, expectedLeft); 123 var result = this.verifyScroll(expectedTop, expectedLeft);
112 this.moveMouseTo(widthFraction * screen.width, 124 this.moveMouseTo(widthFraction * screen.width,
113 heightFraction * screen.height); 125 heightFraction * screen.height);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 event.initMouseEvent('mousemove', 161 event.initMouseEvent('mousemove',
150 e.bubbles, e.cancelable, e.view, e.detail, 162 e.bubbles, e.cancelable, e.view, e.detail,
151 e.screenX, e.screenY, e.clientX, e.clientY, 163 e.screenX, e.screenY, e.clientX, e.clientY,
152 e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 164 e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
153 e.button, document.documentElement); 165 e.button, document.documentElement);
154 document.documentElement.dispatchEvent(event); 166 document.documentElement.dispatchEvent(event);
155 }; 167 };
156 168
157 // verifyScroll is complicated enough to warrant a test 169 // verifyScroll is complicated enough to warrant a test
158 browserTest.Bump_Scroll.prototype.testVerifyScroll = function() { 170 browserTest.Bump_Scroll.prototype.testVerifyScroll = function() {
159 var STARTED = remoting.DesktopConnectedView.Events.bumpScrollStarted; 171 var STARTED = remoting.BumpScroller.Events.bumpScrollStarted;
160 var STOPPED = remoting.DesktopConnectedView.Events.bumpScrollStopped; 172 var STOPPED = remoting.BumpScroller.Events.bumpScrollStopped;
161 var fakeSession = new browserTest.FakeDesktopConnectedView; 173 var fakeViewport = new browserTest.FakeDesktopViewport;
162 var that = this; 174 var that = this;
163 175
164 // No events raised (e.g. windowed mode). 176 // No events raised (e.g. windowed mode).
165 var result = this.verifyScroll(undefined, undefined, fakeSession) 177 var result = this.verifyScroll(undefined, undefined, fakeViewport)
166 178
167 .then(function() { 179 .then(function() {
168 // Start and end events raised, but no scrolling (e.g. full-screen mode 180 // Start and end events raised, but no scrolling (e.g. full-screen mode
169 // with host desktop <= window size). 181 // with host desktop <= window size).
170 fakeSession = new browserTest.FakeDesktopConnectedView; 182 fakeViewport = new browserTest.FakeDesktopViewport;
171 var result = that.verifyScroll(undefined, undefined, fakeSession); 183 var result = that.verifyScroll(undefined, undefined, fakeViewport);
172 fakeSession.raiseEvent(STARTED, {}); 184 fakeViewport.raiseEvent(STARTED, {});
173 fakeSession.raiseEvent(STOPPED, {}); 185 fakeViewport.raiseEvent(STOPPED, {});
174 return result; 186 return result;
175 187
176 }).then(function() { 188 }).then(function() {
177 // Start and end events raised, with incorrect scrolling. 189 // Start and end events raised, with incorrect scrolling.
178 fakeSession = new browserTest.FakeDesktopConnectedView; 190 fakeViewport = new browserTest.FakeDesktopViewport;
179 var result = base.Promise.negate( 191 var result = base.Promise.negate(
180 that.verifyScroll(2, 2, fakeSession)); 192 that.verifyScroll(2, 2, fakeViewport));
181 fakeSession.raiseEvent(STARTED, {}); 193 fakeViewport.raiseEvent(STARTED, {});
182 fakeSession.pluginPosition.top = 1; 194 fakeViewport.pluginPosition.top = 1;
183 fakeSession.pluginPosition.left = 1; 195 fakeViewport.pluginPosition.left = 1;
184 fakeSession.raiseEvent(STOPPED, {}); 196 fakeViewport.raiseEvent(STOPPED, {});
185 return result; 197 return result;
186 198
187 }).then(function() { 199 }).then(function() {
188 // Start event raised, but not end event. 200 // Start event raised, but not end event.
189 fakeSession = new browserTest.FakeDesktopConnectedView; 201 fakeViewport = new browserTest.FakeDesktopViewport;
190 var result = base.Promise.negate( 202 var result = base.Promise.negate(
191 that.verifyScroll(2, 2, fakeSession)); 203 that.verifyScroll(2, 2, fakeViewport));
192 fakeSession.raiseEvent(STARTED, {}); 204 fakeViewport.raiseEvent(STARTED, {});
193 fakeSession.pluginPosition.top = 2; 205 fakeViewport.pluginPosition.top = 2;
194 fakeSession.pluginPosition.left = 2; 206 fakeViewport.pluginPosition.left = 2;
195 return result; 207 return result;
196 208
197 }).then(function() { 209 }).then(function() {
198 // Start and end events raised, with correct scrolling. 210 // Start and end events raised, with correct scrolling.
199 fakeSession = new browserTest.FakeDesktopConnectedView; 211 fakeViewport = new browserTest.FakeDesktopViewport;
200 var result = that.verifyScroll(2, 2, fakeSession); 212 var result = that.verifyScroll(2, 2, fakeViewport);
201 fakeSession.raiseEvent(STARTED, {}); 213 fakeViewport.raiseEvent(STARTED, {});
202 fakeSession.pluginPosition.top = 2; 214 fakeViewport.pluginPosition.top = 2;
203 fakeSession.pluginPosition.left = 2; 215 fakeViewport.pluginPosition.left = 2;
204 fakeSession.raiseEvent(STOPPED, {}); 216 fakeViewport.raiseEvent(STOPPED, {});
205 return result; 217 return result;
206 }); 218 });
207 219
208 return result; 220 return result;
209 }; 221 };
210 222
211 /** 223 /**
212 * Verify that a bump scroll operation takes place and that the top-left corner 224 * Verify that a bump scroll operation takes place and that the top-left corner
213 * of the plugin is as expected when it completes. 225 * of the plugin is as expected when it completes.
214 * @param {number|undefined} expectedTop The expected vertical position of the 226 * @param {number|undefined} expectedTop The expected vertical position of the
215 * plugin, or undefined if it is not expected to change. 227 * plugin, or undefined if it is not expected to change.
216 * @param {number|undefined} expectedLeft The expected horizontal position of 228 * @param {number|undefined} expectedLeft The expected horizontal position of
217 * the plugin, or undefined if it is not expected to change. 229 * the plugin, or undefined if it is not expected to change.
218 * @param {browserTest.FakeDesktopConnectedView=} opt_desktopConnectedView 230 * @param {browserTest.FakeDesktopViewport=} opt_desktopViewport
219 * DesktopConnectedView fake, for testing. 231 * DesktopViewport fake, for testing.
220 */ 232 */
221 browserTest.Bump_Scroll.prototype.verifyScroll = 233 browserTest.Bump_Scroll.prototype.verifyScroll =
222 function (expectedTop, expectedLeft, opt_desktopConnectedView) { 234 function (expectedTop, expectedLeft, opt_desktopViewport) {
223 var desktopConnectedView = opt_desktopConnectedView || 235 var desktopViewport = opt_desktopViewport ||
224 remoting.desktopConnectedView; 236 remoting.desktopConnectedView.getViewportForTesting();
225 base.debug.assert(desktopConnectedView != null); 237 base.debug.assert(desktopViewport != null);
226 var STARTED = remoting.DesktopConnectedView.Events.bumpScrollStarted; 238 var STARTED = remoting.BumpScroller.Events.bumpScrollStarted;
227 var STOPPED = remoting.DesktopConnectedView.Events.bumpScrollStopped; 239 var STOPPED = remoting.BumpScroller.Events.bumpScrollStopped;
228 240
229 var initialPosition = desktopConnectedView.getPluginPositionForTesting(); 241 var initialPosition = desktopViewport.getPluginPositionForTesting();
230 var initialTop = initialPosition.top; 242 var initialTop = initialPosition.top;
231 var initialLeft = initialPosition.left; 243 var initialLeft = initialPosition.left;
232 244
233 var verifyPluginPosition = function() { 245 var verifyPluginPosition = function() {
234 var position = desktopConnectedView.getPluginPositionForTesting(); 246 var position = desktopViewport.getPluginPositionForTesting();
235 if (expectedLeft === undefined) { 247 if (expectedLeft === undefined) {
236 expectedLeft = initialLeft; 248 expectedLeft = initialLeft;
237 } 249 }
238 if (expectedTop === undefined) { 250 if (expectedTop === undefined) {
239 expectedTop = initialTop; 251 expectedTop = initialTop;
240 } 252 }
241 if (position.top != expectedTop || position.left != expectedLeft) { 253 if (position.top != expectedTop || position.left != expectedLeft) {
242 return Promise.reject( 254 return Promise.reject(
243 new Error('No or incorrect scroll detected: (' + 255 new Error('No or incorrect scroll detected: (' +
244 position.left + ',' + position.top + ' instead of ' + 256 position.left + ',' + position.top + ' instead of ' +
245 expectedLeft + ',' + expectedTop + ')')); 257 expectedLeft + ',' + expectedTop + ')'));
246 } else { 258 } else {
247 return Promise.resolve(); 259 return Promise.resolve();
248 } 260 }
249 }; 261 };
250 262
251 var started = browserTest.expectEvent(desktopConnectedView, STARTED, 1000); 263 var bumpScroller = desktopViewport.getBumpScrollerForTesting();
252 var stopped = browserTest.expectEvent(desktopConnectedView, STOPPED, 5000); 264 var started = browserTest.expectEvent(bumpScroller, STARTED, 1000);
253 return started.then(function() { 265 var stopped = browserTest.expectEvent(bumpScroller, STOPPED, 5000);
254 return stopped.then(function() { 266 return Promise.all([started, stopped]).then(function() {
Jamie 2015/02/18 00:33:10 Promise.all is not order-dependent, right? So I th
kelvinp 2015/02/20 23:24:16 Done.
255 return verifyPluginPosition(); 267 return verifyPluginPosition();
256 });
257 }, function() { 268 }, function() {
258 // If no started event is raised, the test might still pass if it asserted 269 // If no started event is raised, the test might still pass if it asserted
259 // no scrolling. 270 // no scrolling.
260 if (expectedTop == undefined && expectedLeft == undefined) { 271 if (expectedTop === undefined && expectedLeft === undefined) {
261 return Promise.resolve(); 272 return Promise.resolve();
262 } else { 273 } else {
263 return Promise.reject( 274 return Promise.reject(
264 new Error('Scroll expected but no start event fired.')); 275 new Error('Scroll expected but no start event fired.'));
265 } 276 }
266 }); 277 });
267 }; 278 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698