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

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

Issue 421433002: Implement bump-scroll browser-test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implementation Created 6 years, 4 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
(Empty)
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.
4
5 /**
6 * @fileoverview
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.
11 */
12
13 'use strict';
14
15 /** @constructor */
16 browserTest.FakeClientSession = function() {
17 this.pluginPosition = {
18 top: 0,
19 left: 0
20 };
21 this.defineEvents(Object.keys(remoting.ClientSession.Events));
22 };
23
24 base.extend(browserTest.FakeClientSession, base.EventSource);
25
26 browserTest.FakeClientSession.prototype.getPluginPositionForTesting =
27 function() {
28 return this.pluginPosition;
29 };
30
31
32 /** @constructor */
33 browserTest.Bump_Scroll = function() {};
34
35 browserTest.Bump_Scroll.prototype.run = function(data) {
36 browserTest.expect(typeof data.pin == 'string');
37
38 if (!remoting.isAppsV2) {
39 browserTest.fail(
40 'Bump-scroll requires full-screen, which can only be activated ' +
41 'programmatically in apps v2.')
42 }
43
44 this.testVerifyScroll().then(function() {
45 return browserTest.connectMe2Me();
46 }).then(function() {
47 return browserTest.enterPIN(data.pin);
48 }).then(
49 this.noScrollWindowed.bind(this)
kelvinp 2014/08/04 16:31:47 Nit: Indent
Jamie 2014/08/05 19:54:18 Done.
50 ).then(
51 this.activateFullscreen.bind(this)
52 ).then(
53 this.noScrollSmaller.bind(this)
54 // The order of these operations is important. Because the plugin starts
55 // scrolled to the top-left, it needs to be scrolled right and down first.
56 ).then(
57 this.scrollDirection.bind(this, 1.0, 0.5) // Right edge
58 ).then(
59 this.scrollDirection.bind(this, 0.5, 1.0) // Bottom edge
60 ).then(
61 this.scrollDirection.bind(this, 0.0, 0.5) // Left edge
62 ).then(
63 this.scrollDirection.bind(this, 0.5, 0.0) // Top edge
64 ).then(
65 function(value) {
66 browserTest.disconnect();
67 return browserTest.pass(value);
68 },
69 function(error) {
70 browserTest.disconnect();
71 return browserTest.fail(error);
72 }
73 );
74 };
75
76 browserTest.Bump_Scroll.prototype.noScrollWindowed = function() {
77 remoting.clientSession.pluginWidthForBumpScrollTesting =
78 window.innerWidth + 10;
kelvinp 2014/08/04 16:31:47 Where does 10px come from? Does it represent the
Jamie 2014/08/05 19:54:18 It's arbitrary, but positive. The idea is to fake
79 remoting.clientSession.pluginHeightForBumpScrollTesting =
80 window.innerHeight + 10;
81 this.moveMouseTo(0, 0);
82 return base.Promise.negate(this.verifyScroll(undefined, undefined));
83 };
84
85 browserTest.Bump_Scroll.prototype.noScrollSmaller = function() {
86 remoting.clientSession.pluginWidthForBumpScrollTesting =
87 window.innerWidth - 10;
88 remoting.clientSession.pluginHeightForBumpScrollTesting =
89 window.innerHeight - 10;
90 this.moveMouseTo(0, 0);
91 return base.Promise.negate(this.verifyScroll(undefined, undefined));
92 };
93
94 browserTest.Bump_Scroll.prototype.scrollDirection =
95 function(widthFraction, heightFraction) {
96 remoting.clientSession.pluginWidthForBumpScrollTesting = screen.width + 10;
97 remoting.clientSession.pluginHeightForBumpScrollTesting = screen.height + 10;
98 var expectedTop = heightFraction == 0.0 ? 0 :
kelvinp 2014/08/04 16:31:47 I am a bit confused about how this work. Say if w
Jamie 2014/08/05 19:54:18 undefined means "I don't care what value this has"
99 heightFraction == 1.0 ? -10 : undefined;
100 var expectedLeft = widthFraction == 0.0 ? 0 :
101 widthFraction == 1.0 ? -10 : undefined;
102 var result = this.verifyScroll(expectedTop, expectedLeft);
103 this.moveMouseTo(widthFraction * screen.width,
104 heightFraction * screen.height);
105 return result;
106 };
107
108 browserTest.Bump_Scroll.prototype.activateFullscreen = function() {
109 return new Promise(function(fulfill, reject) {
110 remoting.fullscreen.activate(true, function() {
111 // The onFullscreen callback is invoked before the window has
112 // resized, so defer fulfilling the promise so that innerWidth
113 // and innerHeight are correct.
114 base.Promise.sleep(1000).then(fulfill);
115 });
116 base.Promise.sleep(5000).then(function(){
117 reject('Timed out waiting for full-screen');
118 });
119 });
120 };
121
122 browserTest.Bump_Scroll.prototype.moveMouseTo = function(x, y) {
123 var e = {
124 bubbles: true,
125 cancelable: false,
126 view: window,
127 detail: 0,
128 screenX: x,
129 screenY: y,
130 clientX: x,
131 clientY: y,
132 ctrlKey: false,
133 altKey: false,
134 shiftKey: false,
135 metaKey: false,
136 button: 0,
137 relatedTarget: undefined
138 };
139 var event = document.createEvent('MouseEvents');
140 event.initMouseEvent('mousemove',
141 e.bubbles, e.cancelable, e.view, e.detail,
142 e.screenX, e.screenY, e.clientX, e.clientY,
143 e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
144 e.button, document.documentElement);
145 document.documentElement.dispatchEvent(event);
146 };
147
148 // verifyScroll is complicated enough to warrant a test
149 browserTest.Bump_Scroll.prototype.testVerifyScroll = function() {
150 var STARTED = remoting.ClientSession.Events.bumpScrollStarted;
151 var STOPPED = remoting.ClientSession.Events.bumpScrollStopped;
152 var fakeSession = new browserTest.FakeClientSession;
153 var that = this;
154
155 // No events raised (e.g. windowed mode).
156 var result = base.Promise.negate(
157 this.verifyScroll(undefined, undefined, fakeSession)
158
159 ).then(function() {
160 // Start and end events raised, but no scrolling (e.g. full-screen mode
161 // with host desktop <= window size).
162 fakeSession = new browserTest.FakeClientSession;
163 var result = base.Promise.negate(
164 that.verifyScroll(undefined, undefined, fakeSession));
165 fakeSession.raiseEvent(STARTED, {});
166 fakeSession.raiseEvent(STOPPED, {});
167 return result;
168
169 }).then(function() {
170 // Start and end events raised, with any scrolling.
171 fakeSession = new browserTest.FakeClientSession;
172 var result = that.verifyScroll(undefined, undefined, fakeSession);
173 fakeSession.raiseEvent(STARTED, {});
174 fakeSession.pluginPosition.top = 1;
175 fakeSession.pluginPosition.left = 1;
176 fakeSession.raiseEvent(STOPPED, {});
177 return result;
178
179 }).then(function() {
180 // Start and end events raised, with incorrect scrolling.
181 fakeSession = new browserTest.FakeClientSession;
182 var result = base.Promise.negate(
183 that.verifyScroll(2, 2, fakeSession));
184 fakeSession.raiseEvent(STARTED, {});
185 fakeSession.pluginPosition.top = 1;
186 fakeSession.pluginPosition.left = 1;
187 fakeSession.raiseEvent(STOPPED, {});
188 return result;
189
190 }).then(function() {
191 // Start and end events raised, with correct scrolling.
192 fakeSession = new browserTest.FakeClientSession;
193 var result = that.verifyScroll(2, 2, fakeSession);
194 fakeSession.raiseEvent(STARTED, {});
195 fakeSession.pluginPosition.top = 2;
196 fakeSession.pluginPosition.left = 2;
197 fakeSession.raiseEvent(STOPPED, {});
198 return result;
199 });
200
201 return result;
202 };
203
204 browserTest.Bump_Scroll.prototype.verifyScroll =
205 function (expectedTop, expectedLeft, opt_clientSession) {
206 var clientSession = opt_clientSession || remoting.clientSession;
207 base.debug.assert(clientSession != null);
208 var STARTED = remoting.ClientSession.Events.bumpScrollStarted;
209 var STOPPED = remoting.ClientSession.Events.bumpScrollStopped;
210
211 var initialPosition = clientSession.getPluginPositionForTesting();
212 var initialTop = initialPosition.top;
213 var initialLeft = initialPosition.left;
214 var verifyPluginPosition = function(fulfill, reject) {
215 var position = clientSession.getPluginPositionForTesting();
216 if (position.top == initialTop &&
217 position.left == initialLeft) {
218 reject(Error('No scroll detected: (' +
219 position.left + ',' + position.top + ')'));
220 } else if ((expectedTop !== undefined && position.top != expectedTop) ||
221 (expectedLeft !== undefined && position.left != expectedLeft)) {
222 reject(Error('Incorrect scroll detected: (' +
kelvinp 2014/08/04 16:31:47 Practically, Error and new Error has the same effe
Jamie 2014/08/05 19:54:18 Done.
223 position.left + ',' + position.top + ' instead of ' +
224 expectedLeft + ',' + expectedTop + ')'));
225 } else {
226 fulfill();
227 }
228 };
229
230 var started = browserTest.expectEvent(clientSession, STARTED, 1000);
231 var stopped = browserTest.expectEvent(clientSession, STOPPED, 5000);
232 return started.then(function(){
233 return stopped;
234 }).then(function() {
235 return new Promise(verifyPluginPosition);
kelvinp 2014/08/04 16:31:47 Since verifyPluginPosition doesn't have any async
Jamie 2014/08/05 19:54:18 Done.
236 });
237 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698