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
3 // found in the LICENSE file.
7 * @suppress {checkTypes}
8 * Browser test for the scenario below:
9 * 1. Enter full-screen mode
10 * 2. Move the mouse to each edge; verify that the desktop bump-scrolls.
16 browserTest.FakeClientSession = function() {
17 this.pluginPosition = {
21 this.defineEvents(Object.keys(remoting.ClientSession.Events));
24 base.extend(browserTest.FakeClientSession, base.EventSource);
26 browserTest.FakeClientSession.prototype.getPluginPositionForTesting =
28 return this.pluginPosition;
33 browserTest.Bump_Scroll = function() {
34 // 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
36 // arbitrary, but must be positive.
37 this.kHostDesktopSizeDelta = 10;
40 browserTest.Bump_Scroll.prototype.run = function(data) {
41 browserTest.expect(typeof data.pin == 'string');
43 if (!base.isAppsV2()) {
45 'Bump-scroll requires full-screen, which can only be activated ' +
46 'programmatically in apps v2.')
49 this.testVerifyScroll().then(function() {
50 return browserTest.connectMe2Me();
52 return browserTest.enterPIN(data.pin);
54 this.noScrollWindowed.bind(this)
56 this.activateFullscreen.bind(this)
58 this.noScrollSmaller.bind(this)
59 // The order of these operations is important. Because the plugin starts
60 // scrolled to the top-left, it needs to be scrolled right and down first.
62 this.scrollDirection.bind(this, 1.0, 0.5) // Right edge
64 this.scrollDirection.bind(this, 0.5, 1.0) // Bottom edge
66 this.scrollDirection.bind(this, 0.0, 0.5) // Left edge
68 this.scrollDirection.bind(this, 0.5, 0.0) // Top edge
71 browserTest.disconnect();
72 return browserTest.pass(value);
75 browserTest.disconnect();
76 return browserTest.fail(error);
81 browserTest.Bump_Scroll.prototype.noScrollWindowed = function() {
82 remoting.clientSession.pluginWidthForBumpScrollTesting =
83 window.innerWidth + this.kHostDesktopSizeDelta;
84 remoting.clientSession.pluginHeightForBumpScrollTesting =
85 window.innerHeight + this.kHostDesktopSizeDelta;
86 this.moveMouseTo(0, 0);
87 return this.verifyScroll(undefined, undefined);
90 browserTest.Bump_Scroll.prototype.noScrollSmaller = function() {
91 remoting.clientSession.pluginWidthForBumpScrollTesting =
92 window.innerWidth - this.kHostDesktopSizeDelta;
93 remoting.clientSession.pluginHeightForBumpScrollTesting =
94 window.innerHeight - this.kHostDesktopSizeDelta;
95 this.moveMouseTo(0, 0);
96 return this.verifyScroll(undefined, undefined);
99 browserTest.Bump_Scroll.prototype.scrollDirection =
100 function(widthFraction, heightFraction) {
101 remoting.clientSession.pluginWidthForBumpScrollTesting =
102 screen.width + this.kHostDesktopSizeDelta;
103 remoting.clientSession.pluginHeightForBumpScrollTesting =
104 screen.height + this.kHostDesktopSizeDelta;
105 var expectedTop = heightFraction == 0.0 ? 0 :
106 heightFraction == 1.0 ? -this.kHostDesktopSizeDelta :
108 var expectedLeft = widthFraction == 0.0 ? 0 :
109 widthFraction == 1.0 ? -this.kHostDesktopSizeDelta :
111 var result = this.verifyScroll(expectedTop, expectedLeft);
112 this.moveMouseTo(widthFraction * screen.width,
113 heightFraction * screen.height);
117 browserTest.Bump_Scroll.prototype.activateFullscreen = function() {
118 return new Promise(function(fulfill, reject) {
119 remoting.fullscreen.activate(true, function() {
120 // The onFullscreen callback is invoked before the window has
121 // resized, so defer fulfilling the promise so that innerWidth
122 // and innerHeight are correct.
123 base.Promise.sleep(1000).then(fulfill);
125 base.Promise.sleep(5000).then(function(){
126 reject('Timed out waiting for full-screen');
131 browserTest.Bump_Scroll.prototype.moveMouseTo = function(x, y) {
146 relatedTarget: undefined
148 var event = document.createEvent('MouseEvents');
149 event.initMouseEvent('mousemove',
150 e.bubbles, e.cancelable, e.view, e.detail,
151 e.screenX, e.screenY, e.clientX, e.clientY,
152 e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
153 e.button, document.documentElement);
154 document.documentElement.dispatchEvent(event);
157 // verifyScroll is complicated enough to warrant a test
158 browserTest.Bump_Scroll.prototype.testVerifyScroll = function() {
159 var STARTED = remoting.ClientSession.Events.bumpScrollStarted;
160 var STOPPED = remoting.ClientSession.Events.bumpScrollStopped;
161 var fakeSession = new browserTest.FakeClientSession;
164 // No events raised (e.g. windowed mode).
165 var result = this.verifyScroll(undefined, undefined, fakeSession)
168 // Start and end events raised, but no scrolling (e.g. full-screen mode
169 // with host desktop <= window size).
170 fakeSession = new browserTest.FakeClientSession;
171 var result = that.verifyScroll(undefined, undefined, fakeSession);
172 fakeSession.raiseEvent(STARTED, {});
173 fakeSession.raiseEvent(STOPPED, {});
177 // Start and end events raised, with incorrect scrolling.
178 fakeSession = new browserTest.FakeClientSession;
179 var result = base.Promise.negate(
180 that.verifyScroll(2, 2, fakeSession));
181 fakeSession.raiseEvent(STARTED, {});
182 fakeSession.pluginPosition.top = 1;
183 fakeSession.pluginPosition.left = 1;
184 fakeSession.raiseEvent(STOPPED, {});
188 // Start event raised, but not end event.
189 fakeSession = new browserTest.FakeClientSession;
190 var result = base.Promise.negate(
191 that.verifyScroll(2, 2, fakeSession));
192 fakeSession.raiseEvent(STARTED, {});
193 fakeSession.pluginPosition.top = 2;
194 fakeSession.pluginPosition.left = 2;
198 // Start and end events raised, with correct scrolling.
199 fakeSession = new browserTest.FakeClientSession;
200 var result = that.verifyScroll(2, 2, fakeSession);
201 fakeSession.raiseEvent(STARTED, {});
202 fakeSession.pluginPosition.top = 2;
203 fakeSession.pluginPosition.left = 2;
204 fakeSession.raiseEvent(STOPPED, {});
212 * Verify that a bump scroll operation takes place and that the top-left corner
213 * of the plugin is as expected when it completes.
214 * @param {number|undefined} expectedTop The expected vertical position of the
215 * plugin, or undefined if it is not expected to change.
216 * @param {number|undefined} expectedLeft The expected horizontal position of
217 * the plugin, or undefined if it is not expected to change.
218 * @param {browserTest.FakeClientSession=} opt_clientSession ClientSession-like
221 browserTest.Bump_Scroll.prototype.verifyScroll =
222 function (expectedTop, expectedLeft, opt_clientSession) {
223 var clientSession = opt_clientSession || remoting.clientSession;
224 base.debug.assert(clientSession != null);
225 var STARTED = remoting.ClientSession.Events.bumpScrollStarted;
226 var STOPPED = remoting.ClientSession.Events.bumpScrollStopped;
228 var initialPosition = clientSession.getPluginPositionForTesting();
229 var initialTop = initialPosition.top;
230 var initialLeft = initialPosition.left;
232 var verifyPluginPosition = function() {
233 var position = clientSession.getPluginPositionForTesting();
234 if (expectedLeft === undefined) {
235 expectedLeft = initialLeft;
237 if (expectedTop === undefined) {
238 expectedTop = initialTop;
240 if (position.top != expectedTop || position.left != expectedLeft) {
241 return Promise.reject(
242 new Error('No or incorrect scroll detected: (' +
243 position.left + ',' + position.top + ' instead of ' +
244 expectedLeft + ',' + expectedTop + ')'));
246 return Promise.resolve();
250 var started = browserTest.expectEvent(clientSession, STARTED, 1000);
251 var stopped = browserTest.expectEvent(clientSession, STOPPED, 5000);
252 return started.then(function() {
253 return stopped.then(function() {
254 return verifyPluginPosition();
257 // If no started event is raised, the test might still pass if it asserted
259 if (expectedTop == undefined && expectedLeft == undefined) {
260 return Promise.resolve();
262 return Promise.reject(
263 new Error('Scroll expected but no start event fired.'));