babylon.pointerInput.tests.ts 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940
  1. /**
  2. * Mock event interface used in place of real events when testing BaseCameraPointersInput
  3. * and derived classes.
  4. * Many PointerEvent properties are read-only so using real "new PointerEvent()"
  5. * is unpractical.
  6. */
  7. interface MockPointerEvent {
  8. target?: HTMLElement;
  9. type?: string;
  10. button?: number;
  11. pointerId?: number;
  12. pointerType?: string;
  13. clientX?: number;
  14. clientY?: number;
  15. movementX?: number;
  16. movementY?: number;
  17. altKey?: boolean;
  18. ctrlKey?: boolean;
  19. metaKey?: boolean;
  20. shiftKey?: boolean;
  21. buttons?: number[];
  22. [propName: string]: any;
  23. }
  24. /**
  25. * Make a mock PointerEvent.
  26. * Many PointerEvent properties are read-only so using real "new PointerEvent()"
  27. * is unpractical.
  28. */
  29. function eventTemplate(target: HTMLElement): MockPointerEvent {
  30. let returnVal = {
  31. target,
  32. button: 0,
  33. preventDefault: () => {},
  34. };
  35. return returnVal;
  36. }
  37. /**
  38. * Simulate PointerEvent in CameraPointersInput instance.
  39. */
  40. function simulateEvent(cameraInput: BABYLON.ICameraInput<BABYLON.Camera>,
  41. event: MockPointerEvent) {
  42. let pointerInfo = {};
  43. switch (event.type) {
  44. case "pointerdown":
  45. pointerInfo = {type: BABYLON.PointerEventTypes.POINTERDOWN, event};
  46. // Cast "camera" to <any> to relax "private" classification.
  47. (<any>cameraInput)._pointerInput(pointerInfo, undefined);
  48. break;
  49. case "pointerup":
  50. pointerInfo = {type: BABYLON.PointerEventTypes.POINTERUP, event};
  51. // Cast "camera" to <any> to relax "private" classification.
  52. (<any>cameraInput)._pointerInput(pointerInfo, undefined);
  53. break;
  54. case "pointermove":
  55. pointerInfo = {type: BABYLON.PointerEventTypes.POINTERMOVE, event};
  56. // Cast "camera" to <any> to relax "private" classification.
  57. (<any>cameraInput)._pointerInput(pointerInfo, undefined);
  58. break;
  59. case "blur":
  60. // Cast "camera" to <any> to relax "private" classification.
  61. (<any>cameraInput)._onLostFocus();
  62. break;
  63. case "POINTERDOUBLETAP":
  64. // Not a real DOM event. Just a shortcut to trigger
  65. // PointerEventTypes.POINTERMOVE on the Input class.
  66. pointerInfo = {type: BABYLON.PointerEventTypes.POINTERDOUBLETAP, event};
  67. // Cast "camera" to <any> to relax "private" classification.
  68. (<any>cameraInput)._pointerInput(pointerInfo, undefined);
  69. break;
  70. default:
  71. console.error("Invalid pointer event: " + event.type);
  72. }
  73. }
  74. /**
  75. * Override the methods of an existing camera to use when testing BaseCameraPointersInput.
  76. */
  77. function StubCameraInput() {
  78. let cameraInput: any = (<any>new BABYLON.ArcRotateCameraPointersInput());
  79. cameraInput.reset = ((): void => {
  80. cameraInput.countOnDoubleTap = 0;
  81. cameraInput.countOnTouch = 0;
  82. cameraInput.countOnMultiTouch = 0;
  83. cameraInput.countOnContextMenu = 0;
  84. cameraInput.countOnButtonDown = 0;
  85. cameraInput.countOnButtonUp = 0;
  86. cameraInput.countOnLostFocus = 0;
  87. cameraInput.lastOnDoubleTap = undefined;
  88. cameraInput.lastOnTouch = undefined;
  89. cameraInput.lastOnMultiTouch = undefined;
  90. cameraInput.lastOnContextMenu = undefined;
  91. cameraInput.lastOnButtonDown = undefined;
  92. cameraInput.lastOnButtonUp = undefined;
  93. });
  94. cameraInput.reset();
  95. cameraInput.onTouch =
  96. ((point: BABYLON.Nullable<BABYLON.PointerTouch>, offsetX: number, offsetY: number) => {
  97. cameraInput.countOnTouch++;
  98. cameraInput.lastOnTouch = {point, offsetX, offsetY};
  99. });
  100. cameraInput.onDoubleTap = ((type: string) => {
  101. cameraInput.countOnDoubleTap++;
  102. cameraInput.lastOnDoubleTap = type;
  103. });
  104. cameraInput.onMultiTouch = (
  105. (pointA: BABYLON.Nullable<BABYLON.PointerTouch>,
  106. pointB: BABYLON.Nullable<BABYLON.PointerTouch>,
  107. previousPinchSquaredDistance: number,
  108. pinchSquaredDistance: number,
  109. previousMultiTouchPanPosition: BABYLON.Nullable<BABYLON.PointerTouch>,
  110. multiTouchPanPosition: BABYLON.Nullable<BABYLON.PointerTouch>) =>
  111. {
  112. cameraInput.countOnMultiTouch++;
  113. cameraInput.lastOnMultiTouch = {
  114. pointA,
  115. pointB,
  116. previousPinchSquaredDistance,
  117. pinchSquaredDistance,
  118. previousMultiTouchPanPosition,
  119. multiTouchPanPosition,
  120. };
  121. });
  122. cameraInput.onButtonDown = ((evt: PointerEvent, buttonCount: number) => {
  123. cameraInput.countOnButtonDown++;
  124. cameraInput.lastOnButtonDown = {evt, buttonCount};
  125. });
  126. cameraInput.onButtonUp = ((evt: PointerEvent, buttonCount: number) => {
  127. cameraInput.countOnButtonUp++;
  128. cameraInput.lastOnButtonUp = {evt, buttonCount};
  129. });
  130. cameraInput.onContextMenu = ((evt: PointerEvent) => {
  131. cameraInput.countOnContextMenu++;
  132. cameraInput.lastOnContextMenu = evt;
  133. });
  134. cameraInput.onLostFocus = (() => {
  135. cameraInput.countOnLostFocus++;
  136. });
  137. return cameraInput;
  138. }
  139. /**
  140. * Test the things.
  141. */
  142. describe('BaseCameraPointersInput', function() {
  143. /**
  144. * Sets the timeout of all the tests to 10 seconds.
  145. */
  146. this.timeout(10000);
  147. before(function(done) {
  148. // runs before all tests in this block
  149. this.timeout(180000);
  150. (BABYLONDEVTOOLS).Loader
  151. .useDist()
  152. .testMode()
  153. .load(function() {
  154. // Force apply promise polyfill for consistent behavior between
  155. // PhantomJS, IE11, and other browsers.
  156. BABYLON.PromisePolyfill.Apply(true);
  157. done();
  158. });
  159. this._canvas = document.createElement("canvas");
  160. this._engine = new BABYLON.NullEngine();
  161. this._scene = new BABYLON.Scene(this._engine);
  162. // Set up an instance of a Camera with the ArcRotateCameraPointersInput.
  163. this.camera = new BABYLON.ArcRotateCamera(
  164. "StubCamera", 0, 0, 0, new BABYLON.Vector3(0, 0, 0), this._scene);
  165. this.cameraInput = StubCameraInput();
  166. this.cameraInput.camera = this.camera;
  167. this.cameraInput.attachControl(this._canvas);
  168. });
  169. beforeEach(function() {
  170. // runs before each test in this block
  171. this.cameraInput.reset();
  172. });
  173. describe('one button drag', function() {
  174. it('calls "onTouch" method', function() {
  175. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  176. // Button down.
  177. event.type = "pointerdown";
  178. event.clientX = 100;
  179. event.clientY = 200;
  180. event.button = 0;
  181. simulateEvent(this.cameraInput, event);
  182. // Button down but no movement events have fired yet.
  183. expect(this.cameraInput.countOnTouch).to.equal(0);
  184. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  185. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  186. // Start moving.
  187. event.type = "pointermove";
  188. event.button = 0;
  189. simulateEvent(this.cameraInput, event);
  190. expect(this.cameraInput.countOnTouch).to.equal(1);
  191. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  192. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  193. // Move just started; No value yet.
  194. expect(this.cameraInput.lastOnTouch.offsetX).to.equal(0);
  195. expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
  196. // Drag.
  197. event.type = "pointermove";
  198. event.clientX = 1000;
  199. event.button = 0;
  200. simulateEvent(this.cameraInput, event);
  201. expect(this.cameraInput.countOnTouch).to.equal(2);
  202. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  203. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  204. // Pointer dragged in X direction.
  205. expect(this.cameraInput.lastOnTouch.offsetX).to.above(0);
  206. expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
  207. // Button up.
  208. event.type = "pointerup";
  209. event.button = 0;
  210. simulateEvent(this.cameraInput, event);
  211. expect(this.cameraInput.countOnTouch).to.equal(2);
  212. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  213. expect(this.cameraInput.countOnButtonUp).to.equal(1);
  214. // These callbacks were never called.
  215. expect(this.cameraInput.countOnDoubleTap).to.equal(0);
  216. expect(this.cameraInput.countOnMultiTouch).to.equal(0);
  217. expect(this.cameraInput.countOnContextMenu).to.equal(0);
  218. expect(this.cameraInput.countOnLostFocus).to.equal(0);
  219. });
  220. it('leaves a clean state allowing repeat calls', function() {
  221. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  222. // Button down.
  223. event.type = "pointerdown";
  224. event.clientX = 100;
  225. event.clientY = 200;
  226. event.button = 0;
  227. simulateEvent(this.cameraInput, event);
  228. // Button down but no movement events have fired yet.
  229. expect(this.cameraInput.countOnTouch).to.equal(0);
  230. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  231. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  232. // Start moving.
  233. event.type = "pointermove";
  234. event.button = 0;
  235. simulateEvent(this.cameraInput, event);
  236. expect(this.cameraInput.countOnTouch).to.equal(1);
  237. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  238. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  239. // Move just started; No value yet.
  240. expect(this.cameraInput.lastOnTouch.offsetX).to.equal(0);
  241. expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
  242. // Drag.
  243. event.type = "pointermove";
  244. event.clientX = 1000;
  245. event.button = 0;
  246. simulateEvent(this.cameraInput, event);
  247. expect(this.cameraInput.countOnTouch).to.equal(2);
  248. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  249. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  250. // Pointer dragged in X direction.
  251. expect(this.cameraInput.lastOnTouch.offsetX).to.above(0);
  252. expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
  253. // Button up.
  254. event.type = "pointerup";
  255. event.button = 0;
  256. simulateEvent(this.cameraInput, event);
  257. expect(this.cameraInput.countOnTouch).to.equal(2);
  258. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  259. expect(this.cameraInput.countOnButtonUp).to.equal(1);
  260. // Button down for 2nd time.
  261. event.type = "pointerdown";
  262. event.clientX = 100;
  263. event.clientY = 200;
  264. event.button = 0;
  265. simulateEvent(this.cameraInput, event);
  266. // Button down but no movement events have fired yet.
  267. expect(this.cameraInput.countOnTouch).to.equal(2);
  268. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  269. expect(this.cameraInput.countOnButtonUp).to.equal(1);
  270. // Start moving.
  271. event.type = "pointermove";
  272. event.button = 0;
  273. simulateEvent(this.cameraInput, event);
  274. expect(this.cameraInput.countOnTouch).to.equal(3);
  275. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  276. expect(this.cameraInput.countOnButtonUp).to.equal(1);
  277. // Move just started; No value yet.
  278. expect(this.cameraInput.lastOnTouch.offsetX).to.equal(0);
  279. expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
  280. // Drag again.
  281. event.type = "pointermove";
  282. event.clientY = 2000;
  283. event.button = 0;
  284. simulateEvent(this.cameraInput, event);
  285. expect(this.cameraInput.countOnTouch).to.equal(4);
  286. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  287. expect(this.cameraInput.countOnButtonUp).to.equal(1);
  288. // Pointer dragged in Y direction.
  289. expect(this.cameraInput.lastOnTouch.offsetX).to.equal(0);
  290. expect(this.cameraInput.lastOnTouch.offsetY).to.above(0);
  291. // Button up.
  292. event.type = "pointerup";
  293. event.button = 0;
  294. simulateEvent(this.cameraInput, event);
  295. expect(this.cameraInput.countOnTouch).to.equal(4);
  296. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  297. expect(this.cameraInput.countOnButtonUp).to.equal(2);
  298. // These callbacks were never called.
  299. expect(this.cameraInput.countOnDoubleTap).to.equal(0);
  300. expect(this.cameraInput.countOnMultiTouch).to.equal(0);
  301. expect(this.cameraInput.countOnContextMenu).to.equal(0);
  302. expect(this.cameraInput.countOnLostFocus).to.equal(0);
  303. });
  304. });
  305. describe('two button drag', function() {
  306. it('calls "onMultiTouch" method', function() {
  307. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  308. // 1st button down.
  309. event.type = "pointerdown";
  310. event.pointerType = "touch";
  311. event.clientX = 1000;
  312. event.clientY = 200;
  313. event.button = 0;
  314. event.pointerId = 1;
  315. simulateEvent(this.cameraInput, event);
  316. // Button down but no movement events have fired yet.
  317. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  318. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  319. expect(this.cameraInput.countOnTouch).to.equal(0);
  320. expect(this.cameraInput.countOnMultiTouch).to.equal(0);
  321. // Start moving before 2nd button has been pressed.
  322. event.type = "pointermove";
  323. event.button = -1;
  324. event.pointerId = 1;
  325. simulateEvent(this.cameraInput, event);
  326. // Moving with one button down will start a drag.
  327. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  328. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  329. expect(this.cameraInput.countOnTouch).to.equal(1);
  330. expect(this.cameraInput.countOnMultiTouch).to.equal(0);
  331. // Move X coordinate.
  332. event.type = "pointermove";
  333. event.clientX = 1500;
  334. event.clientY = 200;
  335. event.button = -1;
  336. event.pointerId = 1;
  337. simulateEvent(this.cameraInput, event);
  338. // One button drag.
  339. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  340. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  341. expect(this.cameraInput.countOnTouch).to.equal(2);
  342. expect(this.cameraInput.countOnMultiTouch).to.equal(0);
  343. // 2nd button down. (Enter zoom mode.)
  344. event.type = "pointerdown";
  345. event.pointerType = "touch";
  346. event.button = 1;
  347. event.pointerId = 2;
  348. simulateEvent(this.cameraInput, event);
  349. // 2nd button down but hasn't moved yet.
  350. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  351. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  352. expect(this.cameraInput.countOnTouch).to.equal(2);
  353. expect(this.cameraInput.countOnMultiTouch).to.equal(0);
  354. // Start move of 2nd pointer.
  355. event.type = "pointermove";
  356. event.clientX = 2000;
  357. event.clientY = 2000;
  358. event.button = -1;
  359. event.pointerId = 2;
  360. simulateEvent(this.cameraInput, event);
  361. // Start of drag with 2 buttons down.
  362. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  363. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  364. expect(this.cameraInput.countOnTouch).to.equal(2);
  365. expect(this.cameraInput.countOnMultiTouch).to.equal(1);
  366. // First time onMultiTouch() is called for a new drag.
  367. expect(this.cameraInput.lastOnMultiTouch.pinchSquaredDistance).to.be.above(0);
  368. expect(this.cameraInput.lastOnMultiTouch.multiTouchPanPosition).to.not.be.null;
  369. // previousPinchSquaredDistance will be null.
  370. expect(this.cameraInput.lastOnMultiTouch.previousPinchSquaredDistance).to.be.equal(0);
  371. expect(this.cameraInput.lastOnMultiTouch.previousMultiTouchPanPosition).to.be.null;
  372. // Move Y coordinate. 2nd point is the one moving.
  373. event.type = "pointermove";
  374. event.clientX = 2000;
  375. event.clientY = 2500;
  376. event.button = -1;
  377. event.pointerId = 2;
  378. simulateEvent(this.cameraInput, event);
  379. // Moving two button drag.
  380. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  381. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  382. expect(this.cameraInput.countOnTouch).to.equal(2);
  383. expect(this.cameraInput.countOnMultiTouch).to.equal(2);
  384. // Neither first nor last event in a drag so everything populated.
  385. expect(this.cameraInput.lastOnMultiTouch.pinchSquaredDistance).to.be.above(0);
  386. expect(this.cameraInput.lastOnMultiTouch.multiTouchPanPosition).to.not.be.null;
  387. expect(this.cameraInput.lastOnMultiTouch.previousPinchSquaredDistance).to.be.above(0);
  388. expect(this.cameraInput.lastOnMultiTouch.previousMultiTouchPanPosition).to.not.be.null;
  389. // Move X and Y coordinate. 1st point is the one moving.
  390. event.type = "pointermove";
  391. event.clientX = 1700;
  392. event.clientY = 1700;
  393. event.button = -1;
  394. event.pointerId = 1;
  395. simulateEvent(this.cameraInput, event);
  396. // Moving two button drag.
  397. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  398. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  399. expect(this.cameraInput.countOnTouch).to.equal(2);
  400. expect(this.cameraInput.countOnMultiTouch).to.equal(3);
  401. // One of the buttons button up.
  402. event.type = "pointerup";
  403. event.pointerType = "touch";
  404. event.button = 0;
  405. event.pointerId = 1;
  406. simulateEvent(this.cameraInput, event);
  407. // Button up.
  408. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  409. expect(this.cameraInput.countOnButtonUp).to.equal(1);
  410. expect(this.cameraInput.countOnTouch).to.equal(2);
  411. expect(this.cameraInput.countOnMultiTouch).to.equal(4);
  412. // onMultiTouch() is called one last time when drag ends with null value for
  413. // multiTouchPanPosition.
  414. expect(this.cameraInput.lastOnMultiTouch.pinchSquaredDistance).to.equal(0);
  415. expect(this.cameraInput.lastOnMultiTouch.multiTouchPanPosition).to.be.null;
  416. // previousPinchSquaredDistance and previousMultiTouchPanPosition are
  417. // populated though.
  418. expect(this.cameraInput.lastOnMultiTouch.previousPinchSquaredDistance).to.be.above(0);
  419. expect(this.cameraInput.lastOnMultiTouch.previousMultiTouchPanPosition).to.not.be.null;
  420. // Move X and Y coordinate of remaining pressed point.
  421. event.type = "pointermove";
  422. event.clientX = 2000;
  423. event.clientY = 2700;
  424. event.button = -1;
  425. event.pointerId = 2;
  426. simulateEvent(this.cameraInput, event);
  427. // Back to one button drag.
  428. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  429. expect(this.cameraInput.countOnButtonUp).to.equal(1);
  430. expect(this.cameraInput.countOnTouch).to.equal(3);
  431. expect(this.cameraInput.countOnMultiTouch).to.equal(4);
  432. // Other button button up. (Now moves should have no affect.)
  433. event.type = "pointerup";
  434. event.pointerType = "touch";
  435. event.button = 1;
  436. event.pointerId = 2;
  437. simulateEvent(this.cameraInput, event);
  438. // Button up.
  439. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  440. expect(this.cameraInput.countOnButtonUp).to.equal(2);
  441. expect(this.cameraInput.countOnTouch).to.equal(3);
  442. expect(this.cameraInput.countOnMultiTouch).to.equal(4);
  443. // Move X and Y coordinate.
  444. event.type = "pointermove";
  445. event.clientX = 3000;
  446. event.clientY = 4000;
  447. event.button = -1;
  448. event.pointerId = 1;
  449. simulateEvent(this.cameraInput, event);
  450. // Not dragging anymore so no change in callbacks.
  451. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  452. expect(this.cameraInput.countOnButtonUp).to.equal(2);
  453. expect(this.cameraInput.countOnTouch).to.equal(3);
  454. expect(this.cameraInput.countOnMultiTouch).to.equal(4);
  455. // These callbacks were never called.
  456. expect(this.cameraInput.countOnDoubleTap).to.equal(0);
  457. expect(this.cameraInput.countOnContextMenu).to.equal(0);
  458. expect(this.cameraInput.countOnLostFocus).to.equal(0);
  459. });
  460. });
  461. describe('button down then up', function() {
  462. it('calls "onButtonDown" and "onButtonUp"', function() {
  463. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  464. // 1st button down.
  465. event.type = "pointerdown";
  466. event.pointerType = "touch";
  467. event.button = 0;
  468. event.pointerId = 1;
  469. simulateEvent(this.cameraInput, event);
  470. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  471. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  472. expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(1);
  473. // 2nd button down.
  474. event.type = "pointerdown";
  475. event.pointerType = "touch";
  476. event.button = 1;
  477. event.pointerId = 2;
  478. simulateEvent(this.cameraInput, event);
  479. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  480. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  481. expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(2);
  482. // One button up.
  483. event.type = "pointerup";
  484. event.pointerType = "touch";
  485. event.button = 1;
  486. event.pointerId = 2;
  487. simulateEvent(this.cameraInput, event);
  488. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  489. expect(this.cameraInput.countOnButtonUp).to.equal(1);
  490. expect(this.cameraInput.lastOnButtonUp.buttonCount).to.be.equal(1);
  491. // Other button up.
  492. event.type = "pointerup";
  493. event.pointerType = "touch";
  494. event.button = 0;
  495. event.pointerId = 1;
  496. simulateEvent(this.cameraInput, event);
  497. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  498. expect(this.cameraInput.countOnButtonUp).to.equal(2);
  499. expect(this.cameraInput.lastOnButtonUp.buttonCount).to.be.equal(0);
  500. // These callbacks were never called.
  501. expect(this.cameraInput.countOnTouch).to.equal(0);
  502. expect(this.cameraInput.countOnMultiTouch).to.equal(0);
  503. expect(this.cameraInput.countOnDoubleTap).to.equal(0);
  504. expect(this.cameraInput.countOnContextMenu).to.equal(0);
  505. expect(this.cameraInput.countOnLostFocus).to.equal(0);
  506. });
  507. it('pointerId of pointerup doesnt match', function() {
  508. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  509. // 1st button down.
  510. event.type = "pointerdown";
  511. event.pointerType = "touch";
  512. event.button = 0;
  513. event.pointerId = 1;
  514. simulateEvent(this.cameraInput, event);
  515. expect(this.cameraInput.countOnButtonDown).to.equal(1);
  516. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  517. expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(1);
  518. // 2nd button down.
  519. event.type = "pointerdown";
  520. event.pointerType = "touch";
  521. event.button = 1;
  522. event.pointerId = 2;
  523. simulateEvent(this.cameraInput, event);
  524. expect(this.cameraInput.countOnButtonDown).to.equal(2);
  525. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  526. expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(2);
  527. // 3rd button down.
  528. event.type = "pointerdown";
  529. event.pointerType = "touch";
  530. event.button = 2;
  531. event.pointerId = 3;
  532. simulateEvent(this.cameraInput, event);
  533. // Only 2 buttons are tracked.
  534. // onButtonDown() gets called but nothing else changes.
  535. expect(this.cameraInput.countOnButtonDown).to.equal(3);
  536. expect(this.cameraInput.countOnButtonUp).to.equal(0);
  537. expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(2);
  538. // One button up.
  539. event.type = "pointerup";
  540. event.pointerType = "touch";
  541. event.button = 1;
  542. event.pointerId = 99;
  543. simulateEvent(this.cameraInput, event);
  544. expect(this.cameraInput.countOnButtonDown).to.equal(3);
  545. expect(this.cameraInput.countOnButtonUp).to.equal(1);
  546. // Button state gets cleared. No buttons registered as being down.
  547. expect(this.cameraInput.lastOnButtonUp.buttonCount).to.be.equal(0);
  548. // These callbacks were never called.
  549. expect(this.cameraInput.countOnTouch).to.equal(0);
  550. expect(this.cameraInput.countOnMultiTouch).to.equal(0);
  551. expect(this.cameraInput.countOnDoubleTap).to.equal(0);
  552. expect(this.cameraInput.countOnContextMenu).to.equal(0);
  553. expect(this.cameraInput.countOnLostFocus).to.equal(0);
  554. });
  555. });
  556. });
  557. describe('ArcRotateCameraInput', function() {
  558. /**
  559. * Sets the timeout of all the tests to 10 seconds.
  560. */
  561. this.timeout(10000);
  562. enum ValChange {
  563. Increase,
  564. Same,
  565. Decrease,
  566. DontCare,
  567. }
  568. const interestingValues = [
  569. "inertialPanningX",
  570. "inertialPanningY",
  571. "inertialAlphaOffset",
  572. "inertialBetaOffset",
  573. "inertialRadiusOffset",
  574. ];
  575. function resetCameraPos(camera: BABYLON.ArcRotateCamera, cameraCachePos: {}) {
  576. camera.alpha = 10;
  577. camera.beta = 20;
  578. camera.radius = 30;
  579. camera.inertialPanningX = 0;
  580. camera.inertialPanningY = 0;
  581. camera.inertialAlphaOffset = 0;
  582. camera.inertialBetaOffset = 0;
  583. camera.inertialRadiusOffset = 0;
  584. camera._panningMouseButton = 2;
  585. camera.useInputToRestoreState = true;
  586. camera._useCtrlForPanning = true;
  587. interestingValues.forEach((key) => {
  588. cameraCachePos[key] = camera[key];
  589. });
  590. }
  591. function verifyChanges(
  592. camera: BABYLON.ArcRotateCamera,
  593. cameraCachePos: {},
  594. toCheck: {[key: string]: ValChange}): boolean {
  595. let result = true;
  596. interestingValues.forEach((key) => {
  597. if (toCheck[key] === undefined) {
  598. toCheck[key] = ValChange.Same;
  599. }
  600. let r = (
  601. toCheck[key] === ValChange.DontCare ||
  602. (toCheck[key] === ValChange.Decrease && camera[key] < cameraCachePos[key]) ||
  603. (toCheck[key] === ValChange.Same && camera[key] === cameraCachePos[key]) ||
  604. (toCheck[key] === ValChange.Increase && camera[key] > cameraCachePos[key])
  605. );
  606. if (!r) {
  607. console.log(
  608. `Incorrect value for ${key}, previous: ${cameraCachePos[key]}, current: ${camera[key]}`
  609. );
  610. }
  611. result = result && r;
  612. cameraCachePos[key] = camera[key];
  613. });
  614. if (!result) {
  615. displayCamera(camera);
  616. }
  617. return result;
  618. }
  619. function displayCamera(camera: BABYLON.ArcRotateCamera): void {
  620. let info = {
  621. inertialPanningX: camera.inertialPanningX,
  622. inertialPanningY: camera.inertialPanningY,
  623. inertialAlphaOffset: camera.inertialAlphaOffset,
  624. inertialBetaOffset: camera.inertialBetaOffset,
  625. inertialRadiusOffset: camera.inertialRadiusOffset
  626. };
  627. console.log(info);
  628. };
  629. before(function(done) {
  630. // runs before all tests in this block
  631. this.timeout(180000);
  632. (BABYLONDEVTOOLS).Loader
  633. .useDist()
  634. .testMode()
  635. .load(function() {
  636. // Force apply promise polyfill for consistent behavior between
  637. // PhantomJS, IE11, and other browsers.
  638. BABYLON.PromisePolyfill.Apply(true);
  639. done();
  640. });
  641. this._canvas = document.createElement("canvas");
  642. this._scene = new BABYLON.Scene(new BABYLON.NullEngine());
  643. // Set up an instance of a Camera with the ArcRotateCameraPointersInput.
  644. this.camera = new BABYLON.ArcRotateCamera(
  645. "Camera", 0, 0, 0, new BABYLON.Vector3(0, 0, 0), this._scene);
  646. this.cameraInput = new BABYLON.ArcRotateCameraPointersInput();
  647. this.cameraInput.camera = this.camera;
  648. this.cameraInput.attachControl(this._canvas);
  649. this.cameraCachePos = {};
  650. });
  651. beforeEach(function() {
  652. // runs before each test in this block
  653. resetCameraPos(this.camera, this.cameraCachePos);
  654. });
  655. describe('Test infrastructure', function() {
  656. it('verifyChanges checks Decrease', function() {
  657. this.camera.inertialAlphaOffset = 10;
  658. this.cameraCachePos.inertialAlphaOffset = 10.001;
  659. expect(
  660. verifyChanges(
  661. this.camera,
  662. this.cameraCachePos,
  663. {inertialAlphaOffset: ValChange.Decrease})
  664. ).to.be.true;
  665. this.camera.inertialAlphaOffset = 10;
  666. this.cameraCachePos.inertialAlphaOffset = 9.999;
  667. expect(
  668. verifyChanges(
  669. this.camera,
  670. this.cameraCachePos,
  671. {inertialAlphaOffset: ValChange.Decrease})
  672. ).to.be.false;
  673. });
  674. it('verifyChanges checks Same', function() {
  675. this.camera.inertialAlphaOffset = 10;
  676. this.cameraCachePos.inertialAlphaOffset = 10;
  677. expect(
  678. verifyChanges(
  679. this.camera,
  680. this.cameraCachePos,
  681. {inertialAlphaOffset: ValChange.Same})
  682. ).to.be.true;
  683. this.camera.inertialAlphaOffset = 10;
  684. this.cameraCachePos.inertialAlphaOffset = 10.001;
  685. expect(
  686. verifyChanges(
  687. this.camera,
  688. this.cameraCachePos,
  689. {inertialAlphaOffset: ValChange.Same})
  690. ).to.be.false;
  691. });
  692. it('verifyChanges checks undefined', function() {
  693. // If the 'toCheck' field is undefined, treat is as ValChange.Same.
  694. this.camera.inertialAlphaOffset = 10;
  695. this.cameraCachePos.inertialAlphaOffset = 10;
  696. expect(
  697. verifyChanges(
  698. this.camera,
  699. this.cameraCachePos,
  700. {})
  701. ).to.be.true;
  702. this.camera.inertialAlphaOffset = 10;
  703. this.cameraCachePos.inertialAlphaOffset = 10.001;
  704. expect(
  705. verifyChanges(
  706. this.camera,
  707. this.cameraCachePos,
  708. {})
  709. ).to.be.false;
  710. });
  711. it('verifyChanges checks DontCare', function() {
  712. this.camera.inertialAlphaOffset = 10;
  713. this.cameraCachePos.inertialAlphaOffset = 10;
  714. expect(
  715. verifyChanges(
  716. this.camera,
  717. this.cameraCachePos,
  718. {inertialAlphaOffset: ValChange.DontCare})
  719. ).to.be.true;
  720. this.camera.inertialAlphaOffset = 10;
  721. this.cameraCachePos.inertialAlphaOffset = 1001;
  722. expect(
  723. verifyChanges(
  724. this.camera,
  725. this.cameraCachePos,
  726. {inertialAlphaOffset: ValChange.DontCare})
  727. ).to.be.true;
  728. });
  729. it('verifyChanges checks Increase', function() {
  730. this.camera.inertialAlphaOffset = 10;
  731. this.cameraCachePos.inertialAlphaOffset = 9.999;
  732. expect(
  733. verifyChanges(
  734. this.camera,
  735. this.cameraCachePos,
  736. {inertialAlphaOffset: ValChange.Increase})
  737. ).to.be.true;
  738. this.camera.inertialAlphaOffset = 10;
  739. this.cameraCachePos.inertialAlphaOffset = 10.001;
  740. expect(
  741. verifyChanges(
  742. this.camera,
  743. this.cameraCachePos,
  744. {inertialAlphaOffset: ValChange.Increase})
  745. ).to.be.false;
  746. });
  747. });
  748. describe('one button drag', function() {
  749. it('changes inertialAlphaOffset', function() {
  750. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  751. // Button down.
  752. event.type = "pointerdown";
  753. event.clientX = 100;
  754. event.clientY = 200;
  755. event.button = 0;
  756. simulateEvent(this.cameraInput, event);
  757. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  758. // Start moving.
  759. event.type = "pointermove";
  760. event.button = 0;
  761. simulateEvent(this.cameraInput, event);
  762. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  763. // Move X coordinate. Drag camera.
  764. event.type = "pointermove";
  765. event.clientX = 1000;
  766. event.button = 0;
  767. simulateEvent(this.cameraInput, event);
  768. expect(verifyChanges(
  769. this.camera,
  770. this.cameraCachePos,
  771. {inertialAlphaOffset: ValChange.Decrease})
  772. ).to.be.true;
  773. // Button up. Primary button.
  774. event.type = "pointerup";
  775. event.button = 0;
  776. simulateEvent(this.cameraInput, event);
  777. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  778. });
  779. it('followed by another one button drag', function() {
  780. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  781. // Button down.
  782. event.type = "pointerdown";
  783. event.clientX = 100;
  784. event.clientY = 200;
  785. event.button = 0;
  786. simulateEvent(this.cameraInput, event);
  787. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  788. // Start moving.
  789. event.type = "pointermove";
  790. event.button = 0;
  791. simulateEvent(this.cameraInput, event);
  792. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  793. // Move X coordinate. Drag camera.
  794. event.type = "pointermove";
  795. event.clientX = 1000;
  796. event.button = 0;
  797. simulateEvent(this.cameraInput, event);
  798. expect(verifyChanges(
  799. this.camera,
  800. this.cameraCachePos,
  801. {inertialAlphaOffset: ValChange.Decrease})
  802. ).to.be.true;
  803. // Button up. Primary button.
  804. event.type = "pointerup";
  805. event.button = 0;
  806. simulateEvent(this.cameraInput, event);
  807. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  808. // 2nd drag.
  809. // Button down.
  810. event.type = "pointerdown";
  811. event.clientX = 100;
  812. event.clientY = 200;
  813. event.button = 0;
  814. simulateEvent(this.cameraInput, event);
  815. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  816. // Start moving.
  817. event.type = "pointermove";
  818. event.button = 0;
  819. simulateEvent(this.cameraInput, event);
  820. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  821. // Move Y coordinate. Drag camera.
  822. event.type = "pointermove";
  823. event.clientY = 1000;
  824. event.button = 0;
  825. simulateEvent(this.cameraInput, event);
  826. expect(verifyChanges(
  827. this.camera,
  828. this.cameraCachePos,
  829. {inertialBetaOffset: ValChange.Decrease})
  830. ).to.be.true;
  831. // Button up. Primary button.
  832. event.type = "pointerup";
  833. event.button = 0;
  834. simulateEvent(this.cameraInput, event);
  835. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  836. });
  837. it('with Ctrl key changes inertialPanningY', function() {
  838. this.cameraInput.panningSensibility = 3;
  839. this.cameraInput._useCtrlForPanning = true;
  840. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  841. // Button down.
  842. event.type = "pointerdown";
  843. event.clientX = 100;
  844. event.clientY = 200;
  845. event.button = 0;
  846. simulateEvent(this.cameraInput, event);
  847. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  848. // Start moving.
  849. event.type = "pointermove";
  850. event.button = 0;
  851. simulateEvent(this.cameraInput, event);
  852. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  853. // Move Y coordinate. Drag camera. (Not panning yet.)
  854. event.type = "pointermove";
  855. event.clientY = 1000;
  856. event.button = 0;
  857. simulateEvent(this.cameraInput, event);
  858. expect(verifyChanges(
  859. this.camera,
  860. this.cameraCachePos,
  861. {inertialBetaOffset: ValChange.Decrease})
  862. ).to.be.true;
  863. // Move X coordinate with Ctrl key depressed. Panning now.
  864. event.type = "pointermove";
  865. event.clientY = 2000;
  866. event.button = 0;
  867. event.ctrlKey = true; // Will cause pan motion.
  868. simulateEvent(this.cameraInput, event);
  869. expect(verifyChanges(
  870. this.camera,
  871. this.cameraCachePos,
  872. {inertialPanningY: ValChange.Increase})
  873. ).to.be.true;
  874. // Move X coordinate having released Ctrl.
  875. event.type = "pointermove";
  876. event.clientY = 3000;
  877. event.button = 0;
  878. event.ctrlKey = false; // Will cancel pan motion.
  879. simulateEvent(this.cameraInput, event);
  880. expect(verifyChanges(
  881. this.camera,
  882. this.cameraCachePos,
  883. {inertialBetaOffset: ValChange.Decrease})
  884. ).to.be.true;
  885. // Button up. Primary button.
  886. event.type = "pointerup";
  887. event.button = 0;
  888. simulateEvent(this.cameraInput, event);
  889. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  890. });
  891. it('with panningSensibility disabled', function() {
  892. this.cameraInput.panningSensibility = 0;
  893. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  894. // Button down.
  895. event.type = "pointerdown";
  896. event.clientX = 100;
  897. event.clientY = 200;
  898. event.button = 0;
  899. simulateEvent(this.cameraInput, event);
  900. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  901. // Start moving.
  902. event.type = "pointermove";
  903. event.button = 0;
  904. simulateEvent(this.cameraInput, event);
  905. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  906. // Move Y coordinate. Drag camera.
  907. event.type = "pointermove";
  908. event.clientY = 1000;
  909. event.button = 0;
  910. simulateEvent(this.cameraInput, event);
  911. expect(verifyChanges(
  912. this.camera,
  913. this.cameraCachePos,
  914. {inertialBetaOffset: ValChange.Decrease})
  915. ).to.be.true;
  916. // Move X coordinate with Ctrl key depressed.
  917. // Panning disabled so continue regular drag..
  918. event.type = "pointermove";
  919. event.clientY = 1500;
  920. event.button = 0;
  921. event.ctrlKey = true; // Will cause pan motion.
  922. simulateEvent(this.cameraInput, event);
  923. expect(verifyChanges(
  924. this.camera,
  925. this.cameraCachePos,
  926. {inertialBetaOffset: ValChange.Decrease})
  927. ).to.be.true;
  928. // Move X coordinate having released Ctrl.
  929. event.type = "pointermove";
  930. event.clientY = 3000;
  931. event.button = 0;
  932. event.ctrlKey = false;
  933. simulateEvent(this.cameraInput, event);
  934. expect(verifyChanges(
  935. this.camera,
  936. this.cameraCachePos,
  937. {inertialBetaOffset: ValChange.Decrease})
  938. ).to.be.true;
  939. // Button up. Primary button.
  940. event.type = "pointerup";
  941. event.button = 0;
  942. simulateEvent(this.cameraInput, event);
  943. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  944. });
  945. });
  946. describe('two button drag', function() {
  947. describe('multiTouchPanAndZoom enabled', function() {
  948. it('pinchDeltaPercentage enabled', function() {
  949. // Multiple button presses interpreted as "pinch" and "swipe".
  950. this.cameraInput.multiTouchPanAndZoom = true;
  951. // Zoom changes are a percentage of current value.
  952. this.cameraInput.pinchDeltaPercentage = 10;
  953. // Panning not enabled.
  954. this.cameraInput.panningSensibility = 0;
  955. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  956. // 1st button down.
  957. event.type = "pointerdown";
  958. event.pointerType = "touch";
  959. event.clientX = 1000;
  960. event.clientY = 200;
  961. event.button = 0;
  962. event.pointerId = 1;
  963. simulateEvent(this.cameraInput, event);
  964. // Start moving before 2nd button has been pressed.
  965. event.type = "pointermove";
  966. event.button = -1;
  967. event.pointerId = 1;
  968. simulateEvent(this.cameraInput, event);
  969. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  970. // Move X coordinate.
  971. event.type = "pointermove";
  972. event.clientX = 1500;
  973. event.clientY = 200;
  974. event.button = -1;
  975. event.pointerId = 1;
  976. simulateEvent(this.cameraInput, event);
  977. expect(verifyChanges(
  978. this.camera,
  979. this.cameraCachePos,
  980. {inertialAlphaOffset: ValChange.Decrease})
  981. ).to.be.true;
  982. // 2nd button down. (Enter zoom mode.)
  983. event.type = "pointerdown";
  984. event.pointerType = "touch";
  985. event.button = 1;
  986. event.pointerId = 2;
  987. simulateEvent(this.cameraInput, event);
  988. // Start move of 2nd pointer.
  989. event.type = "pointermove";
  990. event.clientX = 2000;
  991. event.clientY = 2000;
  992. event.button = -1;
  993. event.pointerId = 2;
  994. simulateEvent(this.cameraInput, event);
  995. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  996. // Move Y coordinate. 2nd point is the one moving.
  997. event.type = "pointermove";
  998. event.clientX = 2000;
  999. event.clientY = 2500;
  1000. event.button = -1;
  1001. event.pointerId = 2;
  1002. simulateEvent(this.cameraInput, event);
  1003. expect(verifyChanges(
  1004. this.camera,
  1005. this.cameraCachePos,
  1006. {inertialRadiusOffset: ValChange.Increase})
  1007. ).to.be.true;
  1008. // Move X + Y coordinate. 1st point is the one moving.
  1009. event.type = "pointermove";
  1010. event.clientX = 1700;
  1011. event.clientY = 1700;
  1012. event.button = -1;
  1013. event.pointerId = 1;
  1014. simulateEvent(this.cameraInput, event);
  1015. expect(verifyChanges(
  1016. this.camera,
  1017. this.cameraCachePos,
  1018. {inertialRadiusOffset: ValChange.Decrease})
  1019. ).to.be.true;
  1020. // One of the buttons button up. (Leave zoom mode.)
  1021. event.type = "pointerup";
  1022. event.pointerType = "touch";
  1023. event.button = 0;
  1024. event.pointerId = 1;
  1025. simulateEvent(this.cameraInput, event);
  1026. // Move X and Y coordinate of remaining pressed point.
  1027. event.type = "pointermove";
  1028. event.clientX = 2000;
  1029. event.clientY = 2700;
  1030. event.button = -1;
  1031. event.pointerId = 2;
  1032. simulateEvent(this.cameraInput, event);
  1033. expect(verifyChanges(
  1034. this.camera,
  1035. this.cameraCachePos,
  1036. {inertialBetaOffset: ValChange.Decrease})
  1037. ).to.be.true;
  1038. // Other button button up. (Now moves should have no affect.)
  1039. event.type = "pointerup";
  1040. event.pointerType = "touch";
  1041. event.button = 1;
  1042. event.pointerId = 2;
  1043. simulateEvent(this.cameraInput, event);
  1044. // Move X and Y coordinate.
  1045. event.type = "pointermove";
  1046. event.clientX = 3000;
  1047. event.clientY = 4000;
  1048. event.button = -1;
  1049. event.pointerId = 1;
  1050. simulateEvent(this.cameraInput, event);
  1051. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1052. });
  1053. it('pinchDeltaPercentage disabled', function() {
  1054. // Multiple button presses interpreted as "pinch" and "swipe".
  1055. this.cameraInput.multiTouchPanAndZoom = true;
  1056. // Zoom changes are not a percentage of current value.
  1057. this.cameraInput.pinchDeltaPercentage = 0;
  1058. // Panning not enabled.
  1059. this.cameraInput.panningSensibility = 0;
  1060. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  1061. // 1st button down.
  1062. event.type = "pointerdown";
  1063. event.pointerType = "touch";
  1064. event.clientX = 1000;
  1065. event.clientY = 200;
  1066. event.button = 0;
  1067. event.pointerId = 1;
  1068. simulateEvent(this.cameraInput, event);
  1069. // Start moving before 2nd button has been pressed.
  1070. event.type = "pointermove";
  1071. event.button = -1;
  1072. event.pointerId = 1;
  1073. simulateEvent(this.cameraInput, event);
  1074. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1075. // Move X coordinate.
  1076. event.type = "pointermove";
  1077. event.clientX = 1500;
  1078. event.clientY = 200;
  1079. event.button = -1;
  1080. event.pointerId = 1;
  1081. simulateEvent(this.cameraInput, event);
  1082. expect(verifyChanges(
  1083. this.camera,
  1084. this.cameraCachePos,
  1085. {inertialAlphaOffset: ValChange.Decrease})
  1086. ).to.be.true;
  1087. // 2nd button down. (Enter zoom mode.)
  1088. event.type = "pointerdown";
  1089. event.pointerType = "touch";
  1090. event.button = 1;
  1091. event.pointerId = 2;
  1092. simulateEvent(this.cameraInput, event);
  1093. // Start move of 2nd pointer.
  1094. event.type = "pointermove";
  1095. event.clientX = 2000;
  1096. event.clientY = 2000;
  1097. event.button = -1;
  1098. event.pointerId = 2;
  1099. simulateEvent(this.cameraInput, event);
  1100. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1101. // Move Y coordinate. 2nd point is the one moving.
  1102. event.type = "pointermove";
  1103. event.clientX = 2000;
  1104. event.clientY = 2500;
  1105. event.button = -1;
  1106. event.pointerId = 2;
  1107. simulateEvent(this.cameraInput, event);
  1108. expect(verifyChanges(
  1109. this.camera,
  1110. this.cameraCachePos,
  1111. {inertialRadiusOffset: ValChange.Increase})
  1112. ).to.be.true;
  1113. // Move X + Y coordinate. 1st point is the one moving.
  1114. event.type = "pointermove";
  1115. event.clientX = 1700;
  1116. event.clientY = 1700;
  1117. event.button = -1;
  1118. event.pointerId = 1;
  1119. simulateEvent(this.cameraInput, event);
  1120. expect(verifyChanges(
  1121. this.camera,
  1122. this.cameraCachePos,
  1123. {inertialRadiusOffset: ValChange.Decrease})
  1124. ).to.be.true;
  1125. // One of the buttons button up. (Leave zoom mode.)
  1126. event.type = "pointerup";
  1127. event.pointerType = "touch";
  1128. event.button = 0;
  1129. event.pointerId = 1;
  1130. simulateEvent(this.cameraInput, event);
  1131. // Move X and Y coordinate of remaining pressed point.
  1132. event.type = "pointermove";
  1133. event.clientX = 2000;
  1134. event.clientY = 2700;
  1135. event.button = -1;
  1136. event.pointerId = 2;
  1137. simulateEvent(this.cameraInput, event);
  1138. expect(verifyChanges(
  1139. this.camera,
  1140. this.cameraCachePos,
  1141. {inertialBetaOffset: ValChange.Decrease})
  1142. ).to.be.true;
  1143. // Other button button up. (Now moves should have no affect.)
  1144. event.type = "pointerup";
  1145. event.pointerType = "touch";
  1146. event.button = 1;
  1147. event.pointerId = 2;
  1148. simulateEvent(this.cameraInput, event);
  1149. // Move X and Y coordinate.
  1150. event.type = "pointermove";
  1151. event.clientX = 3000;
  1152. event.clientY = 4000;
  1153. event.button = -1;
  1154. event.pointerId = 1;
  1155. simulateEvent(this.cameraInput, event);
  1156. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1157. });
  1158. it('pan on drag', function() {
  1159. // Multiple button presses interpreted as "pinch" and "swipe".
  1160. this.cameraInput.multiTouchPanAndZoom = true;
  1161. // Zoom changes are not a percentage of current value.
  1162. this.cameraInput.pinchDeltaPercentage = 0;
  1163. // Panning not enabled.
  1164. this.cameraInput.panningSensibility = 3;
  1165. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  1166. // 1st button down.
  1167. event.type = "pointerdown";
  1168. event.pointerType = "touch";
  1169. event.clientX = 1000;
  1170. event.clientY = 200;
  1171. event.button = 0;
  1172. event.pointerId = 1;
  1173. simulateEvent(this.cameraInput, event);
  1174. // Start moving before 2nd button has been pressed.
  1175. event.type = "pointermove";
  1176. event.button = -1;
  1177. event.pointerId = 1;
  1178. simulateEvent(this.cameraInput, event);
  1179. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1180. // Move X coordinate.
  1181. event.type = "pointermove";
  1182. event.clientX = 1500;
  1183. event.clientY = 200;
  1184. event.button = -1;
  1185. event.pointerId = 1;
  1186. simulateEvent(this.cameraInput, event);
  1187. expect(verifyChanges(
  1188. this.camera,
  1189. this.cameraCachePos,
  1190. {inertialAlphaOffset: ValChange.Decrease})
  1191. ).to.be.true;
  1192. // 2nd button down. (Enter zoom mode.)
  1193. event.type = "pointerdown";
  1194. event.pointerType = "touch";
  1195. event.button = 1;
  1196. event.pointerId = 2;
  1197. simulateEvent(this.cameraInput, event);
  1198. // Start move of 2nd pointer.
  1199. event.type = "pointermove";
  1200. event.clientX = 2000;
  1201. event.clientY = 2000;
  1202. event.button = -1;
  1203. event.pointerId = 2;
  1204. simulateEvent(this.cameraInput, event);
  1205. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1206. // Move Y coordinate. 2nd point is the one moving.
  1207. event.type = "pointermove";
  1208. event.clientX = 2000;
  1209. event.clientY = 2500;
  1210. event.button = -1;
  1211. event.pointerId = 2;
  1212. simulateEvent(this.cameraInput, event);
  1213. expect(verifyChanges(
  1214. this.camera,
  1215. this.cameraCachePos,
  1216. {inertialRadiusOffset: ValChange.Increase,
  1217. inertialPanningY: ValChange.Increase})
  1218. ).to.be.true;
  1219. // Move X + Y coordinate. 1st point is the one moving.
  1220. event.type = "pointermove";
  1221. event.clientX = 1700;
  1222. event.clientY = 1700;
  1223. event.button = -1;
  1224. event.pointerId = 1;
  1225. simulateEvent(this.cameraInput, event);
  1226. expect(verifyChanges(
  1227. this.camera,
  1228. this.cameraCachePos,
  1229. {inertialRadiusOffset: ValChange.Decrease,
  1230. inertialPanningX: ValChange.Decrease,
  1231. inertialPanningY: ValChange.Increase})
  1232. ).to.be.true;
  1233. // One of the buttons button up. (Leave zoom mode.)
  1234. event.type = "pointerup";
  1235. event.pointerType = "touch";
  1236. event.button = 0;
  1237. event.pointerId = 1;
  1238. simulateEvent(this.cameraInput, event);
  1239. // Move X and Y coordinate of remaining pressed point.
  1240. event.type = "pointermove";
  1241. event.clientX = 2000;
  1242. event.clientY = 2700;
  1243. event.button = -1;
  1244. event.pointerId = 2;
  1245. simulateEvent(this.cameraInput, event);
  1246. expect(verifyChanges(
  1247. this.camera,
  1248. this.cameraCachePos,
  1249. {inertialBetaOffset: ValChange.Decrease})
  1250. ).to.be.true;
  1251. // Other button button up. (Now moves should have no affect.)
  1252. event.type = "pointerup";
  1253. event.pointerType = "touch";
  1254. event.button = 1;
  1255. event.pointerId = 2;
  1256. simulateEvent(this.cameraInput, event);
  1257. // Move X and Y coordinate.
  1258. event.type = "pointermove";
  1259. event.clientX = 3000;
  1260. event.clientY = 4000;
  1261. event.button = -1;
  1262. event.pointerId = 1;
  1263. simulateEvent(this.cameraInput, event);
  1264. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1265. });
  1266. });
  1267. describe('multiTouchPanAndZoom disabled', function() {
  1268. it('pinchDeltaPercentage enabled', function() {
  1269. // Multiple button presses not interpreted as multitouch.
  1270. this.cameraInput.multiTouchPanAndZoom = false;
  1271. // Zoom changes are a percentage of current value.
  1272. this.cameraInput.pinchDeltaPercentage = 10;
  1273. // Panning not enabled.
  1274. this.cameraInput.panningSensibility = 3;
  1275. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  1276. // 1st button down.
  1277. event.type = "pointerdown";
  1278. event.pointerType = "touch";
  1279. event.clientX = 1000;
  1280. event.clientY = 200;
  1281. event.button = 0;
  1282. event.pointerId = 1;
  1283. simulateEvent(this.cameraInput, event);
  1284. // Start moving before 2nd button has been pressed.
  1285. event.type = "pointermove";
  1286. event.button = -1;
  1287. event.pointerId = 1;
  1288. simulateEvent(this.cameraInput, event);
  1289. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1290. // Move X coordinate.
  1291. event.type = "pointermove";
  1292. event.clientX = 1500;
  1293. event.clientY = 200;
  1294. event.button = -1;
  1295. event.pointerId = 1;
  1296. simulateEvent(this.cameraInput, event);
  1297. expect(verifyChanges(
  1298. this.camera,
  1299. this.cameraCachePos,
  1300. {inertialAlphaOffset: ValChange.Decrease})
  1301. ).to.be.true;
  1302. // 2nd button down. (Enter zoom mode.)
  1303. event.type = "pointerdown";
  1304. event.pointerType = "touch";
  1305. event.button = 1;
  1306. event.pointerId = 2;
  1307. simulateEvent(this.cameraInput, event);
  1308. // Start move of 2nd pointer.
  1309. event.type = "pointermove";
  1310. event.clientX = 2000;
  1311. event.clientY = 2000;
  1312. event.button = -1;
  1313. event.pointerId = 2;
  1314. simulateEvent(this.cameraInput, event);
  1315. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1316. // Move Y coordinate. 2nd point is the one moving.
  1317. event.type = "pointermove";
  1318. event.clientX = 2000;
  1319. event.clientY = 2500;
  1320. event.button = -1;
  1321. event.pointerId = 2;
  1322. simulateEvent(this.cameraInput, event);
  1323. expect(verifyChanges(
  1324. this.camera,
  1325. this.cameraCachePos,
  1326. {inertialRadiusOffset: ValChange.Increase})
  1327. ).to.be.true;
  1328. // Move X + Y coordinate. 1st point is the one moving.
  1329. event.type = "pointermove";
  1330. event.clientX = 1700;
  1331. event.clientY = 1700;
  1332. event.button = -1;
  1333. event.pointerId = 1;
  1334. simulateEvent(this.cameraInput, event);
  1335. expect(verifyChanges(
  1336. this.camera,
  1337. this.cameraCachePos,
  1338. {inertialRadiusOffset: ValChange.Decrease})
  1339. ).to.be.true;
  1340. // One of the buttons button up. (Leave zoom mode.)
  1341. event.type = "pointerup";
  1342. event.pointerType = "touch";
  1343. event.button = 0;
  1344. event.pointerId = 1;
  1345. simulateEvent(this.cameraInput, event);
  1346. // Move X and Y coordinate of remaining pressed point.
  1347. event.type = "pointermove";
  1348. event.clientX = 2000;
  1349. event.clientY = 2700;
  1350. event.button = -1;
  1351. event.pointerId = 2;
  1352. simulateEvent(this.cameraInput, event);
  1353. expect(verifyChanges(
  1354. this.camera,
  1355. this.cameraCachePos,
  1356. {inertialBetaOffset: ValChange.Decrease})
  1357. ).to.be.true;
  1358. // 1st button down again
  1359. event.type = "pointerdown";
  1360. event.pointerType = "touch";
  1361. event.button = 0;
  1362. event.pointerId = 1;
  1363. simulateEvent(this.cameraInput, event);
  1364. // Start move of 1st button.
  1365. // This time trigger more than 20 pointermove events without moving more
  1366. // than pinchToPanMaxDistance to lock into "pan" mode.
  1367. event.type = "pointermove";
  1368. event.clientX = 1000;
  1369. event.clientY = 1000;
  1370. event.button = -1;
  1371. event.pointerId = 1;
  1372. for (let i = 0; i < 21; i++) {
  1373. event.clientX++;
  1374. simulateEvent(this.cameraInput, event);
  1375. }
  1376. expect(verifyChanges(
  1377. this.camera,
  1378. this.cameraCachePos,
  1379. {inertialPanningX: ValChange.Decrease})
  1380. ).to.be.true;
  1381. // Now we are in "pan" mode, we can move 1st pointer larger distances.
  1382. event.type = "pointermove";
  1383. event.clientX = 5000;
  1384. event.clientY = 5000;
  1385. event.button = -1;
  1386. event.pointerId = 2;
  1387. simulateEvent(this.cameraInput, event);
  1388. expect(verifyChanges(
  1389. this.camera,
  1390. this.cameraCachePos,
  1391. {inertialPanningX: ValChange.Decrease,
  1392. inertialPanningY: ValChange.Increase})
  1393. ).to.be.true;
  1394. // One of the buttons button up. (Leave pan mode.)
  1395. event.type = "pointerup";
  1396. event.pointerType = "touch";
  1397. event.button = 0;
  1398. event.pointerId = 1;
  1399. simulateEvent(this.cameraInput, event);
  1400. // Other button button up. (Now moves should have no affect.)
  1401. event.type = "pointerup";
  1402. event.pointerType = "touch";
  1403. event.button = 1;
  1404. event.pointerId = 2;
  1405. simulateEvent(this.cameraInput, event);
  1406. // Move X and Y coordinate.
  1407. event.type = "pointermove";
  1408. event.clientX = 3000;
  1409. event.clientY = 4000;
  1410. event.button = -1;
  1411. event.pointerId = 1;
  1412. simulateEvent(this.cameraInput, event);
  1413. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1414. });
  1415. it('pinchDeltaPercentage disabled', function() {
  1416. // Multiple button presses not interpreted as multitouch.
  1417. this.cameraInput.multiTouchPanAndZoom = false;
  1418. // Zoom changes are not a percentage of current value.
  1419. this.cameraInput.pinchDeltaPercentage = 0;
  1420. // Panning not enabled.
  1421. this.cameraInput.panningSensibility = 3;
  1422. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  1423. // 1st button down.
  1424. event.type = "pointerdown";
  1425. event.pointerType = "touch";
  1426. event.clientX = 1000;
  1427. event.clientY = 200;
  1428. event.button = 0;
  1429. event.pointerId = 1;
  1430. simulateEvent(this.cameraInput, event);
  1431. // Start moving before 2nd button has been pressed.
  1432. event.type = "pointermove";
  1433. event.button = -1;
  1434. event.pointerId = 1;
  1435. simulateEvent(this.cameraInput, event);
  1436. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1437. // Move X coordinate.
  1438. event.type = "pointermove";
  1439. event.clientX = 1500;
  1440. event.clientY = 200;
  1441. event.button = -1;
  1442. event.pointerId = 1;
  1443. simulateEvent(this.cameraInput, event);
  1444. expect(verifyChanges(
  1445. this.camera,
  1446. this.cameraCachePos,
  1447. {inertialAlphaOffset: ValChange.Decrease})
  1448. ).to.be.true;
  1449. // 2nd button down. (Enter zoom mode.)
  1450. event.type = "pointerdown";
  1451. event.pointerType = "touch";
  1452. event.button = 1;
  1453. event.pointerId = 2;
  1454. simulateEvent(this.cameraInput, event);
  1455. // Start move of 2nd pointer.
  1456. event.type = "pointermove";
  1457. event.clientX = 2000;
  1458. event.clientY = 2000;
  1459. event.button = -1;
  1460. event.pointerId = 2;
  1461. simulateEvent(this.cameraInput, event);
  1462. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1463. // Move Y coordinate. 2nd point is the one moving.
  1464. event.type = "pointermove";
  1465. event.clientX = 2000;
  1466. event.clientY = 2500;
  1467. event.button = -1;
  1468. event.pointerId = 2;
  1469. simulateEvent(this.cameraInput, event);
  1470. expect(verifyChanges(
  1471. this.camera,
  1472. this.cameraCachePos,
  1473. {inertialRadiusOffset: ValChange.Increase})
  1474. ).to.be.true;
  1475. // Move X + Y coordinate. 1st point is the one moving.
  1476. event.type = "pointermove";
  1477. event.clientX = 1700;
  1478. event.clientY = 1700;
  1479. event.button = -1;
  1480. event.pointerId = 1;
  1481. simulateEvent(this.cameraInput, event);
  1482. expect(verifyChanges(
  1483. this.camera,
  1484. this.cameraCachePos,
  1485. {inertialRadiusOffset: ValChange.Decrease})
  1486. ).to.be.true;
  1487. // One of the buttons button up. (Leave zoom mode.)
  1488. event.type = "pointerup";
  1489. event.pointerType = "touch";
  1490. event.button = 0;
  1491. event.pointerId = 1;
  1492. simulateEvent(this.cameraInput, event);
  1493. // Move X and Y coordinate of remaining pressed point.
  1494. event.type = "pointermove";
  1495. event.clientX = 2000;
  1496. event.clientY = 2700;
  1497. event.button = -1;
  1498. event.pointerId = 2;
  1499. simulateEvent(this.cameraInput, event);
  1500. expect(verifyChanges(
  1501. this.camera,
  1502. this.cameraCachePos,
  1503. {inertialBetaOffset: ValChange.Decrease})
  1504. ).to.be.true;
  1505. // 1st button down again
  1506. event.type = "pointerdown";
  1507. event.pointerType = "touch";
  1508. event.button = 0;
  1509. event.pointerId = 1;
  1510. simulateEvent(this.cameraInput, event);
  1511. // Start move of 1st button.
  1512. // This time trigger more than 20 pointermove events without moving more
  1513. // than pinchToPanMaxDistance to lock into "pan" mode.
  1514. event.type = "pointermove";
  1515. event.clientX = 1000;
  1516. event.clientY = 1000;
  1517. event.button = -1;
  1518. event.pointerId = 1;
  1519. for (let i = 0; i < 21; i++) {
  1520. event.clientX++;
  1521. simulateEvent(this.cameraInput, event);
  1522. }
  1523. expect(verifyChanges(
  1524. this.camera,
  1525. this.cameraCachePos,
  1526. {inertialPanningX: ValChange.Decrease})
  1527. ).to.be.true;
  1528. // Now we are in "pan" mode, we can move 1st pointer larger distances.
  1529. event.type = "pointermove";
  1530. event.clientX = 5000;
  1531. event.clientY = 5000;
  1532. event.button = -1;
  1533. event.pointerId = 2;
  1534. simulateEvent(this.cameraInput, event);
  1535. expect(verifyChanges(
  1536. this.camera,
  1537. this.cameraCachePos,
  1538. {inertialPanningX: ValChange.Decrease,
  1539. inertialPanningY: ValChange.Increase})
  1540. ).to.be.true;
  1541. // One of the buttons button up. (Leave pan mode.)
  1542. event.type = "pointerup";
  1543. event.pointerType = "touch";
  1544. event.button = 0;
  1545. event.pointerId = 1;
  1546. simulateEvent(this.cameraInput, event);
  1547. // Other button button up. (Now moves should have no affect.)
  1548. event.type = "pointerup";
  1549. event.pointerType = "touch";
  1550. event.button = 1;
  1551. event.pointerId = 2;
  1552. simulateEvent(this.cameraInput, event);
  1553. // Move X and Y coordinate.
  1554. event.type = "pointermove";
  1555. event.clientX = 3000;
  1556. event.clientY = 4000;
  1557. event.button = -1;
  1558. event.pointerId = 1;
  1559. simulateEvent(this.cameraInput, event);
  1560. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1561. });
  1562. });
  1563. });
  1564. describe('loose focus', function() {
  1565. it('cancels drag', function() {
  1566. // Multiple button presses interpreted as "pinch" and "swipe".
  1567. this.cameraInput.multiTouchPanAndZoom = true;
  1568. // Zoom changes are a percentage of current value.
  1569. this.cameraInput.pinchDeltaPercentage = 10;
  1570. // Panning not enabled.
  1571. this.cameraInput.panningSensibility = 0;
  1572. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  1573. // 1st button down.
  1574. event.type = "pointerdown";
  1575. event.pointerType = "touch";
  1576. event.clientX = 1000;
  1577. event.clientY = 200;
  1578. event.button = 0;
  1579. event.pointerId = 1;
  1580. simulateEvent(this.cameraInput, event);
  1581. // Start moving before 2nd button has been pressed.
  1582. event.type = "pointermove";
  1583. event.button = -1;
  1584. event.pointerId = 1;
  1585. simulateEvent(this.cameraInput, event);
  1586. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1587. // Move X coordinate.
  1588. event.type = "pointermove";
  1589. event.clientX = 1500;
  1590. event.clientY = 200;
  1591. event.button = -1;
  1592. event.pointerId = 1;
  1593. simulateEvent(this.cameraInput, event);
  1594. expect(verifyChanges(
  1595. this.camera,
  1596. this.cameraCachePos,
  1597. {inertialAlphaOffset: ValChange.Decrease})
  1598. ).to.be.true;
  1599. // Loose focus.
  1600. (<any>this.cameraInput)._onLostFocus();
  1601. // Move X + Y coordinate. Should have no affect after loosing focus.
  1602. event.type = "pointermove";
  1603. event.clientX = 1700;
  1604. event.clientY = 1700;
  1605. event.button = -1;
  1606. event.pointerId = 1;
  1607. simulateEvent(this.cameraInput, event);
  1608. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1609. });
  1610. it('cancels double drag', function() {
  1611. // Multiple button presses interpreted as "pinch" and "swipe".
  1612. this.cameraInput.multiTouchPanAndZoom = true;
  1613. // Zoom changes are a percentage of current value.
  1614. this.cameraInput.pinchDeltaPercentage = 10;
  1615. // Panning not enabled.
  1616. this.cameraInput.panningSensibility = 0;
  1617. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  1618. // 1st button down.
  1619. event.type = "pointerdown";
  1620. event.pointerType = "touch";
  1621. event.clientX = 1000;
  1622. event.clientY = 200;
  1623. event.button = 0;
  1624. event.pointerId = 1;
  1625. simulateEvent(this.cameraInput, event);
  1626. // Start moving before 2nd button has been pressed.
  1627. event.type = "pointermove";
  1628. event.button = -1;
  1629. event.pointerId = 1;
  1630. simulateEvent(this.cameraInput, event);
  1631. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1632. // Move X coordinate.
  1633. event.type = "pointermove";
  1634. event.clientX = 1500;
  1635. event.clientY = 200;
  1636. event.button = -1;
  1637. event.pointerId = 1;
  1638. simulateEvent(this.cameraInput, event);
  1639. expect(verifyChanges(
  1640. this.camera,
  1641. this.cameraCachePos,
  1642. {inertialAlphaOffset: ValChange.Decrease})
  1643. ).to.be.true;
  1644. // 2nd button down. (Enter zoom mode.)
  1645. event.type = "pointerdown";
  1646. event.pointerType = "touch";
  1647. event.button = 1;
  1648. event.pointerId = 2;
  1649. simulateEvent(this.cameraInput, event);
  1650. // Start move of 2nd pointer.
  1651. event.type = "pointermove";
  1652. event.clientX = 2000;
  1653. event.clientY = 2000;
  1654. event.button = -1;
  1655. event.pointerId = 2;
  1656. simulateEvent(this.cameraInput, event);
  1657. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1658. // Move Y coordinate. 2nd point is the one moving.
  1659. event.type = "pointermove";
  1660. event.clientX = 2000;
  1661. event.clientY = 2500;
  1662. event.button = -1;
  1663. event.pointerId = 2;
  1664. simulateEvent(this.cameraInput, event);
  1665. expect(verifyChanges(
  1666. this.camera,
  1667. this.cameraCachePos,
  1668. {inertialRadiusOffset: ValChange.Increase})
  1669. ).to.be.true;
  1670. // Loose focus.
  1671. (<any>this.cameraInput)._onLostFocus();
  1672. // Move X + Y coordinate. Should have no affect after loosing focus.
  1673. event.type = "pointermove";
  1674. event.clientX = 1700;
  1675. event.clientY = 1700;
  1676. event.button = -1;
  1677. event.pointerId = 1;
  1678. simulateEvent(this.cameraInput, event);
  1679. expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
  1680. });
  1681. });
  1682. describe('double click', function() {
  1683. it('doesnt restore save position', function() {
  1684. // Disable restoring position.
  1685. this.camera.useInputToRestoreState = false;
  1686. this.camera.alpha = 10;
  1687. this.camera.beta = 10;
  1688. this.camera.radius = 10;
  1689. this.camera.storeState();
  1690. this.camera.alpha = 20;
  1691. this.camera.beta = 20;
  1692. this.camera.radius = 20;
  1693. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  1694. event.type = "POINTERDOUBLETAP";
  1695. simulateEvent(this.cameraInput, event);
  1696. expect(this.camera.alpha).to.be.equal(20);
  1697. expect(this.camera.beta).to.be.equal(20);
  1698. expect(this.camera.radius).to.be.equal(20);
  1699. });
  1700. it('restores save position', function() {
  1701. // Enable restoring position.
  1702. this.camera.useInputToRestoreState = true;
  1703. this.camera.alpha = 10;
  1704. this.camera.beta = 10;
  1705. this.camera.radius = 10;
  1706. this.camera.storeState();
  1707. this.camera.alpha = 20;
  1708. this.camera.beta = 20;
  1709. this.camera.radius = 20;
  1710. var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
  1711. event.type = "POINTERDOUBLETAP";
  1712. simulateEvent(this.cameraInput, event);
  1713. expect(this.camera.alpha).to.be.equal(10);
  1714. expect(this.camera.beta).to.be.equal(10);
  1715. expect(this.camera.radius).to.be.equal(10);
  1716. });
  1717. });
  1718. });