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

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

Issue 927373005: [Chromoting] Enable jscompile for browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments 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 /**
16 * @constructor
17 * @extends {base.EventSourceImpl}
18 */
16 browserTest.FakeDesktopConnectedView = function() { 19 browserTest.FakeDesktopConnectedView = function() {
17 this.pluginPosition = { 20 this.pluginPosition = {
18 top: 0, 21 top: 0,
19 left: 0 22 left: 0
20 }; 23 };
21 this.defineEvents(Object.keys(remoting.DesktopConnectedView.Events)); 24 this.defineEvents(Object.keys(remoting.DesktopConnectedView.Events));
22 }; 25 };
23 26
24 base.extend(browserTest.FakeDesktopConnectedView, base.EventSourceImpl); 27 base.extend(browserTest.FakeDesktopConnectedView, base.EventSourceImpl);
25 28
29 /**
30 * @return {{top: number, left:number}} The top-left corner of the plugin.
31 */
26 browserTest.FakeDesktopConnectedView.prototype.getPluginPositionForTesting = 32 browserTest.FakeDesktopConnectedView.prototype.getPluginPositionForTesting =
27 function() { 33 function() {
28 return this.pluginPosition; 34 return this.pluginPosition;
29 }; 35 };
30 36
31 37
32 /** @constructor */ 38 /** @constructor */
33 browserTest.Bump_Scroll = function() { 39 browserTest.Bump_Scroll = function() {
34 // To aviod dependencies on the actual host desktop size, we simulate a 40 // To avoid dependencies on the actual host desktop size, we simulate a
35 // desktop larger or smaller than the client window. The exact value is 41 // desktop larger or smaller than the client window. The exact value is
36 // arbitrary, but must be positive. 42 // arbitrary, but must be positive.
43 /** @type {number} */
37 this.kHostDesktopSizeDelta = 10; 44 this.kHostDesktopSizeDelta = 10;
38 }; 45 };
39 46
47 /**
48 * @param {{pin: string}} data
kelvinp 2015/02/18 18:41:29 Nit: No space before string
garykac 2015/02/19 01:48:45 Done.
49 */
40 browserTest.Bump_Scroll.prototype.run = function(data) { 50 browserTest.Bump_Scroll.prototype.run = function(data) {
41 browserTest.expect(typeof data.pin == 'string'); 51 browserTest.expect(typeof data.pin == 'string');
42 52
43 if (!base.isAppsV2()) { 53 if (!base.isAppsV2()) {
44 browserTest.fail( 54 browserTest.fail(
45 'Bump-scroll requires full-screen, which can only be activated ' + 55 'Bump-scroll requires full-screen, which can only be activated ' +
46 'programmatically in apps v2.') 56 'programmatically in apps v2.')
47 } 57 }
48 58
49 this.testVerifyScroll().then(function() { 59 this.testVerifyScroll().then(function() {
(...skipping 21 matching lines...) Expand all
71 browserTest.disconnect(); 81 browserTest.disconnect();
72 return browserTest.pass(value); 82 return browserTest.pass(value);
73 }, 83 },
74 function(error) { 84 function(error) {
75 browserTest.disconnect(); 85 browserTest.disconnect();
76 return browserTest.fail(error); 86 return browserTest.fail(error);
77 } 87 }
78 ); 88 );
79 }; 89 };
80 90
91 /**
92 * @return {Promise}
93 */
81 browserTest.Bump_Scroll.prototype.noScrollWindowed = function() { 94 browserTest.Bump_Scroll.prototype.noScrollWindowed = function() {
82 remoting.desktopConnectedView.pluginWidthForBumpScrollTesting = 95 remoting.desktopConnectedView.setPluginSizeForBumpScrollTesting(
83 window.innerWidth + this.kHostDesktopSizeDelta; 96 window.innerWidth + this.kHostDesktopSizeDelta,
84 remoting.desktopConnectedView.pluginHeightForBumpScrollTesting = 97 window.innerHeight + this.kHostDesktopSizeDelta);
85 window.innerHeight + this.kHostDesktopSizeDelta;
86 this.moveMouseTo(0, 0); 98 this.moveMouseTo(0, 0);
87 return this.verifyScroll(undefined, undefined); 99 return this.verifyScroll(undefined, undefined);
88 }; 100 };
89 101
102 /**
103 * @return {Promise}
104 */
90 browserTest.Bump_Scroll.prototype.noScrollSmaller = function() { 105 browserTest.Bump_Scroll.prototype.noScrollSmaller = function() {
91 remoting.desktopConnectedView.pluginWidthForBumpScrollTesting = 106 remoting.desktopConnectedView.setPluginSizeForBumpScrollTesting(
92 window.innerWidth - this.kHostDesktopSizeDelta; 107 window.innerWidth - this.kHostDesktopSizeDelta,
93 remoting.desktopConnectedView.pluginHeightForBumpScrollTesting = 108 window.innerHeight - this.kHostDesktopSizeDelta);
94 window.innerHeight - this.kHostDesktopSizeDelta;
95 this.moveMouseTo(0, 0); 109 this.moveMouseTo(0, 0);
96 return this.verifyScroll(undefined, undefined); 110 return this.verifyScroll(undefined, undefined);
97 }; 111 };
98 112
113 /**
114 * @param {number} widthFraction
115 * @param {number} heightFraction
116 * @return {Promise}
117 */
99 browserTest.Bump_Scroll.prototype.scrollDirection = 118 browserTest.Bump_Scroll.prototype.scrollDirection =
100 function(widthFraction, heightFraction) { 119 function(widthFraction, heightFraction) {
101 remoting.desktopConnectedView.pluginWidthForBumpScrollTesting = 120 remoting.desktopConnectedView.setPluginSizeForBumpScrollTesting(
102 screen.width + this.kHostDesktopSizeDelta; 121 screen.width + this.kHostDesktopSizeDelta,
103 remoting.desktopConnectedView.pluginHeightForBumpScrollTesting = 122 screen.height + this.kHostDesktopSizeDelta);
104 screen.height + this.kHostDesktopSizeDelta; 123 /** @type {number} */
105 var expectedTop = heightFraction == 0.0 ? 0 : 124 var expectedTop = heightFraction == 0.0 ? 0 :
106 heightFraction == 1.0 ? -this.kHostDesktopSizeDelta : 125 heightFraction == 1.0 ? -this.kHostDesktopSizeDelta :
107 undefined; 126 undefined;
127 /** @type {number} */
108 var expectedLeft = widthFraction == 0.0 ? 0 : 128 var expectedLeft = widthFraction == 0.0 ? 0 :
109 widthFraction == 1.0 ? -this.kHostDesktopSizeDelta : 129 widthFraction == 1.0 ? -this.kHostDesktopSizeDelta :
110 undefined; 130 undefined;
111 var result = this.verifyScroll(expectedTop, expectedLeft); 131 var result = this.verifyScroll(expectedTop, expectedLeft);
112 this.moveMouseTo(widthFraction * screen.width, 132 this.moveMouseTo(widthFraction * screen.width,
113 heightFraction * screen.height); 133 heightFraction * screen.height);
114 return result; 134 return result;
115 }; 135 };
116 136
137 /**
138 * @return {Promise}
139 */
117 browserTest.Bump_Scroll.prototype.activateFullscreen = function() { 140 browserTest.Bump_Scroll.prototype.activateFullscreen = function() {
118 return new Promise(function(fulfill, reject) { 141 return new Promise(function(fulfill, reject) {
119 remoting.fullscreen.activate(true, function() { 142 remoting.fullscreen.activate(true, function() {
120 // The onFullscreen callback is invoked before the window has 143 // The onFullscreen callback is invoked before the window has
121 // resized, so defer fulfilling the promise so that innerWidth 144 // resized, so defer fulfilling the promise so that innerWidth
122 // and innerHeight are correct. 145 // and innerHeight are correct.
123 base.Promise.sleep(1000).then(fulfill); 146 base.Promise.sleep(1000).then(fulfill);
124 }); 147 });
125 base.Promise.sleep(5000).then(function(){ 148 base.Promise.sleep(5000).then(function(){
126 reject('Timed out waiting for full-screen'); 149 reject('Timed out waiting for full-screen');
127 }); 150 });
128 }); 151 });
129 }; 152 };
130 153
154 /**
155 * @param {number} x
156 * @param {number} y
157 */
131 browserTest.Bump_Scroll.prototype.moveMouseTo = function(x, y) { 158 browserTest.Bump_Scroll.prototype.moveMouseTo = function(x, y) {
132 var e = { 159 var e = {
133 bubbles: true, 160 bubbles: true,
134 cancelable: false, 161 cancelable: false,
135 view: window, 162 view: window,
136 detail: 0, 163 detail: 0,
137 screenX: x, 164 screenX: x,
138 screenY: y, 165 screenY: y,
139 clientX: x, 166 clientX: x,
140 clientY: y, 167 clientY: y,
141 ctrlKey: false, 168 ctrlKey: false,
142 altKey: false, 169 altKey: false,
143 shiftKey: false, 170 shiftKey: false,
144 metaKey: false, 171 metaKey: false,
145 button: 0, 172 button: 0,
146 relatedTarget: undefined 173 relatedTarget: undefined
147 }; 174 };
148 var event = document.createEvent('MouseEvents'); 175 var event = document.createEvent('MouseEvents');
149 event.initMouseEvent('mousemove', 176 event.initMouseEvent('mousemove',
150 e.bubbles, e.cancelable, e.view, e.detail, 177 e.bubbles, e.cancelable, e.view, e.detail,
151 e.screenX, e.screenY, e.clientX, e.clientY, 178 e.screenX, e.screenY, e.clientX, e.clientY,
152 e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 179 e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
153 e.button, document.documentElement); 180 e.button, document.documentElement);
154 document.documentElement.dispatchEvent(event); 181 document.documentElement.dispatchEvent(event);
155 }; 182 };
156 183
157 // verifyScroll is complicated enough to warrant a test 184 /**
185 * verifyScroll() is complicated enough to warrant a test.
186 * @return {Promise}
187 */
158 browserTest.Bump_Scroll.prototype.testVerifyScroll = function() { 188 browserTest.Bump_Scroll.prototype.testVerifyScroll = function() {
159 var STARTED = remoting.DesktopConnectedView.Events.bumpScrollStarted; 189 var STARTED = remoting.DesktopConnectedView.Events.bumpScrollStarted;
160 var STOPPED = remoting.DesktopConnectedView.Events.bumpScrollStopped; 190 var STOPPED = remoting.DesktopConnectedView.Events.bumpScrollStopped;
161 var fakeSession = new browserTest.FakeDesktopConnectedView; 191 var fakeSession = new browserTest.FakeDesktopConnectedView;
162 var that = this; 192 var that = this;
163 193
164 // No events raised (e.g. windowed mode). 194 // No events raised (e.g. windowed mode).
165 var result = this.verifyScroll(undefined, undefined, fakeSession) 195 var result = this.verifyScroll(undefined, undefined, fakeSession)
166 196
167 .then(function() { 197 .then(function() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 240
211 /** 241 /**
212 * Verify that a bump scroll operation takes place and that the top-left corner 242 * Verify that a bump scroll operation takes place and that the top-left corner
213 * of the plugin is as expected when it completes. 243 * of the plugin is as expected when it completes.
214 * @param {number|undefined} expectedTop The expected vertical position of the 244 * @param {number|undefined} expectedTop The expected vertical position of the
215 * plugin, or undefined if it is not expected to change. 245 * plugin, or undefined if it is not expected to change.
216 * @param {number|undefined} expectedLeft The expected horizontal position of 246 * @param {number|undefined} expectedLeft The expected horizontal position of
217 * the plugin, or undefined if it is not expected to change. 247 * the plugin, or undefined if it is not expected to change.
218 * @param {browserTest.FakeDesktopConnectedView=} opt_desktopConnectedView 248 * @param {browserTest.FakeDesktopConnectedView=} opt_desktopConnectedView
219 * DesktopConnectedView fake, for testing. 249 * DesktopConnectedView fake, for testing.
250 * @return {Promise}
220 */ 251 */
221 browserTest.Bump_Scroll.prototype.verifyScroll = 252 browserTest.Bump_Scroll.prototype.verifyScroll =
222 function (expectedTop, expectedLeft, opt_desktopConnectedView) { 253 function (expectedTop, expectedLeft, opt_desktopConnectedView) {
254 /** @type {browserTest.FakeDesktopConnectedView} */
223 var desktopConnectedView = opt_desktopConnectedView || 255 var desktopConnectedView = opt_desktopConnectedView ||
224 remoting.desktopConnectedView; 256 remoting.desktopConnectedView;
225 base.debug.assert(desktopConnectedView != null); 257 base.debug.assert(desktopConnectedView != null);
226 var STARTED = remoting.DesktopConnectedView.Events.bumpScrollStarted; 258 var STARTED = remoting.DesktopConnectedView.Events.bumpScrollStarted;
227 var STOPPED = remoting.DesktopConnectedView.Events.bumpScrollStopped; 259 var STOPPED = remoting.DesktopConnectedView.Events.bumpScrollStopped;
228 260
229 var initialPosition = desktopConnectedView.getPluginPositionForTesting(); 261 var initialPosition = desktopConnectedView.getPluginPositionForTesting();
230 var initialTop = initialPosition.top; 262 var initialTop = initialPosition.top;
231 var initialLeft = initialPosition.left; 263 var initialLeft = initialPosition.left;
232 264
265 /** @return {Promise} */
233 var verifyPluginPosition = function() { 266 var verifyPluginPosition = function() {
234 var position = desktopConnectedView.getPluginPositionForTesting(); 267 var position = desktopConnectedView.getPluginPositionForTesting();
235 if (expectedLeft === undefined) { 268 if (expectedLeft === undefined) {
236 expectedLeft = initialLeft; 269 expectedLeft = initialLeft;
237 } 270 }
238 if (expectedTop === undefined) { 271 if (expectedTop === undefined) {
239 expectedTop = initialTop; 272 expectedTop = initialTop;
240 } 273 }
241 if (position.top != expectedTop || position.left != expectedLeft) { 274 if (position.top != expectedTop || position.left != expectedLeft) {
242 return Promise.reject( 275 return Promise.reject(
(...skipping 15 matching lines...) Expand all
258 // If no started event is raised, the test might still pass if it asserted 291 // If no started event is raised, the test might still pass if it asserted
259 // no scrolling. 292 // no scrolling.
260 if (expectedTop == undefined && expectedLeft == undefined) { 293 if (expectedTop == undefined && expectedLeft == undefined) {
261 return Promise.resolve(); 294 return Promise.resolve();
262 } else { 295 } else {
263 return Promise.reject( 296 return Promise.reject(
264 new Error('Scroll expected but no start event fired.')); 297 new Error('Scroll expected but no start event fired.'));
265 } 298 }
266 }); 299 });
267 }; 300 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698