123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959 |
- /**
- * Mock event interface used in place of real events when testing BaseCameraPointersInput
- * and derived classes.
- * Many PointerEvent properties are read-only so using real "new PointerEvent()"
- * is unpractical.
- */
- interface MockPointerEvent {
- target?: HTMLElement;
- type?: string;
- button?: number;
- pointerId?: number;
- pointerType?: string;
- clientX?: number;
- clientY?: number;
- movementX?: number;
- movementY?: number;
- altKey?: boolean;
- ctrlKey?: boolean;
- metaKey?: boolean;
- shiftKey?: boolean;
- buttons?: number[];
- [propName: string]: any;
- }
- /**
- * Make a mock PointerEvent.
- * Many PointerEvent properties are read-only so using real "new PointerEvent()"
- * is unpractical.
- */
- function eventTemplate(target: HTMLElement): MockPointerEvent {
- let returnVal = {
- target,
- button: 0,
- preventDefault: () => {},
- };
- return returnVal;
- }
- /**
- * Simulate PointerEvent in CameraPointersInput instance.
- */
- function simulateEvent(cameraInput: BABYLON.ICameraInput<BABYLON.Camera>,
- event: MockPointerEvent) {
- let pointerInfo = {};
- switch (event.type) {
- case "pointerdown":
- pointerInfo = {type: BABYLON.PointerEventTypes.POINTERDOWN, event};
- // Cast "camera" to <any> to relax "private" classification.
- (<any>cameraInput)._pointerInput(pointerInfo, undefined);
- break;
- case "pointerup":
- pointerInfo = {type: BABYLON.PointerEventTypes.POINTERUP, event};
- // Cast "camera" to <any> to relax "private" classification.
- (<any>cameraInput)._pointerInput(pointerInfo, undefined);
- break;
- case "pointermove":
- pointerInfo = {type: BABYLON.PointerEventTypes.POINTERMOVE, event};
- // Cast "camera" to <any> to relax "private" classification.
- (<any>cameraInput)._pointerInput(pointerInfo, undefined);
- break;
- case "blur":
- // Cast "camera" to <any> to relax "private" classification.
- (<any>cameraInput)._onLostFocus();
- break;
- case "POINTERDOUBLETAP":
- // Not a real DOM event. Just a shortcut to trigger
- // PointerEventTypes.POINTERMOVE on the Input class.
- pointerInfo = {type: BABYLON.PointerEventTypes.POINTERDOUBLETAP, event};
- // Cast "camera" to <any> to relax "private" classification.
- (<any>cameraInput)._pointerInput(pointerInfo, undefined);
- break;
- default:
- console.error("Invalid pointer event: " + event.type);
- }
- }
- /**
- * Override the methods of an existing camera to create a stub for testing
- * BaseCameraPointersInput.
- * @returns An instance of ArcRotateCameraPointersInput with the interesting
- * methods stubbed out.
- */
- function StubCameraInput() {
- // Force our CameraPointersInput instance to type "any" so we can access
- // protected methods from within this function.
- let cameraInput: any = (<any>new BABYLON.ArcRotateCameraPointersInput());
- /**
- * Reset all counters.
- */
- cameraInput.reset = ((): void => {
- cameraInput.countOnDoubleTap = 0;
- cameraInput.countOnTouch = 0;
- cameraInput.countOnMultiTouch = 0;
- cameraInput.countOnContextMenu = 0;
- cameraInput.countOnButtonDown = 0;
- cameraInput.countOnButtonUp = 0;
- cameraInput.countOnLostFocus = 0;
- cameraInput.lastOnDoubleTap = undefined;
- cameraInput.lastOnTouch = undefined;
- cameraInput.lastOnMultiTouch = undefined;
- cameraInput.lastOnContextMenu = undefined;
- cameraInput.lastOnButtonDown = undefined;
- cameraInput.lastOnButtonUp = undefined;
- });
- cameraInput.reset();
- /**
- * Stub out all mothods we want to test as part of the BaseCameraPointersInput testing.
- * These stubs keep track of how many times they were called and
- */
- cameraInput.onTouch =
- ((point: BABYLON.Nullable<BABYLON.PointerTouch>, offsetX: number, offsetY: number) => {
- cameraInput.countOnTouch++;
- cameraInput.lastOnTouch = {point, offsetX, offsetY};
- });
- cameraInput.onDoubleTap = ((type: string) => {
- cameraInput.countOnDoubleTap++;
- cameraInput.lastOnDoubleTap = type;
- });
- cameraInput.onMultiTouch = (
- (pointA: BABYLON.Nullable<BABYLON.PointerTouch>,
- pointB: BABYLON.Nullable<BABYLON.PointerTouch>,
- previousPinchSquaredDistance: number,
- pinchSquaredDistance: number,
- previousMultiTouchPanPosition: BABYLON.Nullable<BABYLON.PointerTouch>,
- multiTouchPanPosition: BABYLON.Nullable<BABYLON.PointerTouch>) =>
- {
- cameraInput.countOnMultiTouch++;
- cameraInput.lastOnMultiTouch = {
- pointA,
- pointB,
- previousPinchSquaredDistance,
- pinchSquaredDistance,
- previousMultiTouchPanPosition,
- multiTouchPanPosition,
- };
- });
- cameraInput.onButtonDown = ((evt: PointerEvent) => {
- cameraInput.countOnButtonDown++;
- let buttonCount = cameraInput.pointB !== null ? 2 : 1;
- cameraInput.lastOnButtonDown = {evt, buttonCount};
- });
- cameraInput.onButtonUp = ((evt: PointerEvent) => {
- cameraInput.countOnButtonUp++;
- let buttonCount = cameraInput.pointA !== null ? 1 : 0;
- cameraInput.lastOnButtonUp = {evt, buttonCount};
- });
- cameraInput.onContextMenu = ((evt: PointerEvent) => {
- cameraInput.countOnContextMenu++;
- cameraInput.lastOnContextMenu = evt;
- });
- cameraInput.onLostFocus = (() => {
- cameraInput.countOnLostFocus++;
- });
- return cameraInput;
- }
- /**
- * Test the things.
- * The BaseCameraPointersInput class first.
- */
- describe('BaseCameraPointersInput', function() {
- /**
- * Sets the timeout of all the tests to 10 seconds.
- */
- this.timeout(10000);
- before(function(done) {
- // runs before all tests in this block
- this.timeout(180000);
- (BABYLONDEVTOOLS).Loader
- .useDist()
- .testMode()
- .load(function() {
- // Force apply promise polyfill for consistent behavior between
- // PhantomJS, IE11, and other browsers.
- BABYLON.PromisePolyfill.Apply(true);
- done();
- });
- this._canvas = document.createElement("canvas");
- this._engine = new BABYLON.NullEngine();
- this._scene = new BABYLON.Scene(this._engine);
-
- // Set up an instance of a Camera with the ArcRotateCameraPointersInput.
- this.camera = new BABYLON.ArcRotateCamera(
- "StubCamera", 0, 0, 0, new BABYLON.Vector3(0, 0, 0), this._scene);
- this.cameraInput = StubCameraInput();
- this.cameraInput.camera = this.camera;
- this.cameraInput.attachControl(this._canvas);
- });
- beforeEach(function() {
- // runs before each test in this block
- this.cameraInput.reset();
- });
- describe('one button drag', function() {
- it('calls "onTouch" method', function() {
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // Button down.
- event.type = "pointerdown";
- event.clientX = 100;
- event.clientY = 200;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- // Button down but no movement events have fired yet.
- expect(this.cameraInput.countOnTouch).to.equal(0);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
-
- // Start moving.
- event.type = "pointermove";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnTouch).to.equal(1);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- // Move just started; No value yet.
- expect(this.cameraInput.lastOnTouch.offsetX).to.equal(0);
- expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
- // Drag.
- event.type = "pointermove";
- event.clientX = 1000;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- // Pointer dragged in X direction.
- expect(this.cameraInput.lastOnTouch.offsetX).to.above(0);
- expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
- // Button up.
- event.type = "pointerup";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(1);
-
- // These callbacks were never called.
- expect(this.cameraInput.countOnDoubleTap).to.equal(0);
- expect(this.cameraInput.countOnMultiTouch).to.equal(0);
- expect(this.cameraInput.countOnContextMenu).to.equal(0);
- expect(this.cameraInput.countOnLostFocus).to.equal(0);
- });
- it('leaves a clean state allowing repeat calls', function() {
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // Button down.
- event.type = "pointerdown";
- event.clientX = 100;
- event.clientY = 200;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- // Button down but no movement events have fired yet.
- expect(this.cameraInput.countOnTouch).to.equal(0);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
-
- // Start moving.
- event.type = "pointermove";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnTouch).to.equal(1);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- // Move just started; No value yet.
- expect(this.cameraInput.lastOnTouch.offsetX).to.equal(0);
- expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
- // Drag.
- event.type = "pointermove";
- event.clientX = 1000;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- // Pointer dragged in X direction.
- expect(this.cameraInput.lastOnTouch.offsetX).to.above(0);
- expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
- // Button up.
- event.type = "pointerup";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(1);
-
- // Button down for 2nd time.
- event.type = "pointerdown";
- event.clientX = 100;
- event.clientY = 200;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- // Button down but no movement events have fired yet.
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(1);
-
- // Start moving.
- event.type = "pointermove";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnTouch).to.equal(3);
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(1);
- // Move just started; No value yet.
- expect(this.cameraInput.lastOnTouch.offsetX).to.equal(0);
- expect(this.cameraInput.lastOnTouch.offsetY).to.equal(0);
- // Drag again.
- event.type = "pointermove";
- event.clientY = 2000;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnTouch).to.equal(4);
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(1);
- // Pointer dragged in Y direction.
- expect(this.cameraInput.lastOnTouch.offsetX).to.equal(0);
- expect(this.cameraInput.lastOnTouch.offsetY).to.above(0);
- // Button up.
- event.type = "pointerup";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnTouch).to.equal(4);
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(2);
-
- // These callbacks were never called.
- expect(this.cameraInput.countOnDoubleTap).to.equal(0);
- expect(this.cameraInput.countOnMultiTouch).to.equal(0);
- expect(this.cameraInput.countOnContextMenu).to.equal(0);
- expect(this.cameraInput.countOnLostFocus).to.equal(0);
- });
- });
-
- describe('two button drag', function() {
- it('calls "onMultiTouch" method', function() {
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.clientX = 1000;
- event.clientY = 200;
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Button down but no movement events have fired yet.
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.countOnTouch).to.equal(0);
- expect(this.cameraInput.countOnMultiTouch).to.equal(0);
- // Start moving before 2nd button has been pressed.
- event.type = "pointermove";
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Moving with one button down will start a drag.
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.countOnTouch).to.equal(1);
- expect(this.cameraInput.countOnMultiTouch).to.equal(0);
- // Move X coordinate.
- event.type = "pointermove";
- event.clientX = 1500;
- event.clientY = 200;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // One button drag.
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnMultiTouch).to.equal(0);
- // 2nd button down. (Enter zoom mode.)
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // 2nd button down but hasn't moved yet.
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnMultiTouch).to.equal(0);
- // Start move of 2nd pointer.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2000;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Start of drag with 2 buttons down.
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnMultiTouch).to.equal(1);
- // First time onMultiTouch() is called for a new drag.
- expect(this.cameraInput.lastOnMultiTouch.pinchSquaredDistance).to.be.above(0);
- expect(this.cameraInput.lastOnMultiTouch.multiTouchPanPosition).to.not.be.null;
- // previousPinchSquaredDistance will be null.
- expect(this.cameraInput.lastOnMultiTouch.previousPinchSquaredDistance).to.be.equal(0);
- expect(this.cameraInput.lastOnMultiTouch.previousMultiTouchPanPosition).to.be.null;
- // Move Y coordinate. 2nd point is the one moving.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2500;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Moving two button drag.
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnMultiTouch).to.equal(2);
- // Neither first nor last event in a drag so everything populated.
- expect(this.cameraInput.lastOnMultiTouch.pinchSquaredDistance).to.be.above(0);
- expect(this.cameraInput.lastOnMultiTouch.multiTouchPanPosition).to.not.be.null;
- expect(this.cameraInput.lastOnMultiTouch.previousPinchSquaredDistance).to.be.above(0);
- expect(this.cameraInput.lastOnMultiTouch.previousMultiTouchPanPosition).to.not.be.null;
- // Move X and Y coordinate. 1st point is the one moving.
- event.type = "pointermove";
- event.clientX = 1700;
- event.clientY = 1700;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Moving two button drag.
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnMultiTouch).to.equal(3);
- // One of the buttons button up.
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Button up.
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(1);
- expect(this.cameraInput.countOnTouch).to.equal(2);
- expect(this.cameraInput.countOnMultiTouch).to.equal(4);
- // onMultiTouch() is called one last time when drag ends with null value for
- // multiTouchPanPosition.
- expect(this.cameraInput.lastOnMultiTouch.pinchSquaredDistance).to.equal(0);
- expect(this.cameraInput.lastOnMultiTouch.multiTouchPanPosition).to.be.null;
- // previousPinchSquaredDistance and previousMultiTouchPanPosition are
- // populated though.
- expect(this.cameraInput.lastOnMultiTouch.previousPinchSquaredDistance).to.be.above(0);
- expect(this.cameraInput.lastOnMultiTouch.previousMultiTouchPanPosition).to.not.be.null;
- // Move X and Y coordinate of remaining pressed point.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2700;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Back to one button drag.
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(1);
- expect(this.cameraInput.countOnTouch).to.equal(3);
- expect(this.cameraInput.countOnMultiTouch).to.equal(4);
- // Other button button up. (Now moves should have no affect.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Button up.
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(2);
- expect(this.cameraInput.countOnTouch).to.equal(3);
- expect(this.cameraInput.countOnMultiTouch).to.equal(4);
- // Move X and Y coordinate.
- event.type = "pointermove";
- event.clientX = 3000;
- event.clientY = 4000;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Not dragging anymore so no change in callbacks.
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(2);
- expect(this.cameraInput.countOnTouch).to.equal(3);
- expect(this.cameraInput.countOnMultiTouch).to.equal(4);
- // These callbacks were never called.
- expect(this.cameraInput.countOnDoubleTap).to.equal(0);
- expect(this.cameraInput.countOnContextMenu).to.equal(0);
- expect(this.cameraInput.countOnLostFocus).to.equal(0);
- });
- });
- describe('button down then up', function() {
- it('calls "onButtonDown" and "onButtonUp"', function() {
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(1);
- // 2nd button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(2);
- // One button up.
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(1);
- expect(this.cameraInput.lastOnButtonUp.buttonCount).to.be.equal(1);
-
- // Other button up.
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(2);
- expect(this.cameraInput.lastOnButtonUp.buttonCount).to.be.equal(0);
-
- // These callbacks were never called.
- expect(this.cameraInput.countOnTouch).to.equal(0);
- expect(this.cameraInput.countOnMultiTouch).to.equal(0);
- expect(this.cameraInput.countOnDoubleTap).to.equal(0);
- expect(this.cameraInput.countOnContextMenu).to.equal(0);
- expect(this.cameraInput.countOnLostFocus).to.equal(0);
- });
- it('pointerId of pointerup doesnt match', function() {
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnButtonDown).to.equal(1);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(1);
- // 2nd button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnButtonDown).to.equal(2);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(2);
- // 3rd button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 2;
- event.pointerId = 3;
- simulateEvent(this.cameraInput, event);
- // Only 2 buttons are tracked.
- // onButtonDown() gets called but nothing else changes.
- expect(this.cameraInput.countOnButtonDown).to.equal(3);
- expect(this.cameraInput.countOnButtonUp).to.equal(0);
- expect(this.cameraInput.lastOnButtonDown.buttonCount).to.be.equal(2);
- // One button up.
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 99;
- simulateEvent(this.cameraInput, event);
- expect(this.cameraInput.countOnButtonDown).to.equal(3);
- expect(this.cameraInput.countOnButtonUp).to.equal(1);
- // Button state gets cleared. No buttons registered as being down.
- expect(this.cameraInput.lastOnButtonUp.buttonCount).to.be.equal(0);
-
- // These callbacks were never called.
- expect(this.cameraInput.countOnTouch).to.equal(0);
- expect(this.cameraInput.countOnMultiTouch).to.equal(0);
- expect(this.cameraInput.countOnDoubleTap).to.equal(0);
- expect(this.cameraInput.countOnContextMenu).to.equal(0);
- expect(this.cameraInput.countOnLostFocus).to.equal(0);
- });
- });
- });
- /**
- * Test the things.
- * The ArcRotateCameraInput class.
- */
- describe('ArcRotateCameraInput', function() {
- /**
- * Sets the timeout of all the tests to 10 seconds.
- */
- this.timeout(10000);
- enum ValChange {
- Increase,
- Same,
- Decrease,
- DontCare,
- }
- const interestingValues = [
- "inertialPanningX",
- "inertialPanningY",
- "inertialAlphaOffset",
- "inertialBetaOffset",
- "inertialRadiusOffset",
- ];
- function resetCameraPos(camera: BABYLON.ArcRotateCamera, cameraCachePos: {}) {
- camera.alpha = 10;
- camera.beta = 20;
- camera.radius = 30;
- camera.inertialPanningX = 0;
- camera.inertialPanningY = 0;
- camera.inertialAlphaOffset = 0;
- camera.inertialBetaOffset = 0;
- camera.inertialRadiusOffset = 0;
- camera._panningMouseButton = 2;
- camera.useInputToRestoreState = true;
- camera._useCtrlForPanning = true;
-
- interestingValues.forEach((key) => {
- cameraCachePos[key] = camera[key];
- });
- }
- function verifyChanges(
- camera: BABYLON.ArcRotateCamera,
- cameraCachePos: {},
- toCheck: {[key: string]: ValChange}): boolean {
- let result = true;
- interestingValues.forEach((key) => {
- if (toCheck[key] === undefined) {
- toCheck[key] = ValChange.Same;
- }
- let r = (
- toCheck[key] === ValChange.DontCare ||
- (toCheck[key] === ValChange.Decrease && camera[key] < cameraCachePos[key]) ||
- (toCheck[key] === ValChange.Same && camera[key] === cameraCachePos[key]) ||
- (toCheck[key] === ValChange.Increase && camera[key] > cameraCachePos[key])
- );
- if (!r) {
- console.log(
- `Incorrect value for ${key}, previous: ${cameraCachePos[key]}, current: ${camera[key]}`
- );
- }
- result = result && r;
- cameraCachePos[key] = camera[key];
- });
- if (!result) {
- displayCamera(camera);
- }
- return result;
- }
- function displayCamera(camera: BABYLON.ArcRotateCamera): void {
- let info = {
- inertialPanningX: camera.inertialPanningX,
- inertialPanningY: camera.inertialPanningY,
- inertialAlphaOffset: camera.inertialAlphaOffset,
- inertialBetaOffset: camera.inertialBetaOffset,
- inertialRadiusOffset: camera.inertialRadiusOffset
- };
- console.log(info);
- };
- before(function(done) {
- // runs before all tests in this block
- this.timeout(180000);
- (BABYLONDEVTOOLS).Loader
- .useDist()
- .testMode()
- .load(function() {
- // Force apply promise polyfill for consistent behavior between
- // PhantomJS, IE11, and other browsers.
- BABYLON.PromisePolyfill.Apply(true);
- done();
- });
- this._canvas = document.createElement("canvas");
- this._scene = new BABYLON.Scene(new BABYLON.NullEngine());
-
- // Set up an instance of a Camera with the ArcRotateCameraPointersInput.
- this.camera = new BABYLON.ArcRotateCamera(
- "Camera", 0, 0, 0, new BABYLON.Vector3(0, 0, 0), this._scene);
- this.cameraInput = new BABYLON.ArcRotateCameraPointersInput();
- this.cameraInput.camera = this.camera;
- this.cameraInput.attachControl(this._canvas);
- this.cameraCachePos = {};
- });
- beforeEach(function() {
- // runs before each test in this block
- resetCameraPos(this.camera, this.cameraCachePos);
- });
- describe('Test infrastructure', function() {
- it('verifyChanges checks Decrease', function() {
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 10.001;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
-
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 9.999;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.false;
- });
-
- it('verifyChanges checks Same', function() {
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 10;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Same})
- ).to.be.true;
-
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 10.001;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Same})
- ).to.be.false;
- });
-
- it('verifyChanges checks undefined', function() {
- // If the 'toCheck' field is undefined, treat is as ValChange.Same.
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 10;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {})
- ).to.be.true;
-
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 10.001;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {})
- ).to.be.false;
- });
-
- it('verifyChanges checks DontCare', function() {
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 10;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.DontCare})
- ).to.be.true;
-
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 1001;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.DontCare})
- ).to.be.true;
- });
-
- it('verifyChanges checks Increase', function() {
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 9.999;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Increase})
- ).to.be.true;
-
- this.camera.inertialAlphaOffset = 10;
- this.cameraCachePos.inertialAlphaOffset = 10.001;
- expect(
- verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Increase})
- ).to.be.false;
- });
- });
- describe('one button drag', function() {
- it('changes inertialAlphaOffset', function() {
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // Button down.
- event.type = "pointerdown";
- event.clientX = 100;
- event.clientY = 200;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
-
- // Start moving.
- event.type = "pointermove";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move X coordinate. Drag camera.
- event.type = "pointermove";
- event.clientX = 1000;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
- // Button up. Primary button.
- event.type = "pointerup";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
- it('followed by another one button drag', function() {
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // Button down.
- event.type = "pointerdown";
- event.clientX = 100;
- event.clientY = 200;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
-
- // Start moving.
- event.type = "pointermove";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move X coordinate. Drag camera.
- event.type = "pointermove";
- event.clientX = 1000;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
- // Button up. Primary button.
- event.type = "pointerup";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // 2nd drag.
- // Button down.
- event.type = "pointerdown";
- event.clientX = 100;
- event.clientY = 200;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
-
- // Start moving.
- event.type = "pointermove";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move Y coordinate. Drag camera.
- event.type = "pointermove";
- event.clientY = 1000;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
- // Button up. Primary button.
- event.type = "pointerup";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
- it('with Ctrl key changes inertialPanningY', function() {
- this.cameraInput.panningSensibility = 3;
- this.cameraInput._useCtrlForPanning = true;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // Button down.
- event.type = "pointerdown";
- event.clientX = 100;
- event.clientY = 200;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
-
- // Start moving.
- event.type = "pointermove";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move Y coordinate. Drag camera. (Not panning yet.)
- event.type = "pointermove";
- event.clientY = 1000;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
- // Move X coordinate with Ctrl key depressed. Panning now.
- event.type = "pointermove";
- event.clientY = 2000;
- event.button = 0;
- event.ctrlKey = true; // Will cause pan motion.
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialPanningY: ValChange.Increase})
- ).to.be.true;
-
- // Move X coordinate having released Ctrl.
- event.type = "pointermove";
- event.clientY = 3000;
- event.button = 0;
- event.ctrlKey = false; // Will cancel pan motion.
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
-
- // Button up. Primary button.
- event.type = "pointerup";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
- it('with panningSensibility disabled', function() {
- this.cameraInput.panningSensibility = 0;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // Button down.
- event.type = "pointerdown";
- event.clientX = 100;
- event.clientY = 200;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
-
- // Start moving.
- event.type = "pointermove";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move Y coordinate. Drag camera.
- event.type = "pointermove";
- event.clientY = 1000;
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
- // Move X coordinate with Ctrl key depressed.
- // Panning disabled so continue regular drag..
- event.type = "pointermove";
- event.clientY = 1500;
- event.button = 0;
- event.ctrlKey = true; // Will cause pan motion.
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
-
- // Move X coordinate having released Ctrl.
- event.type = "pointermove";
- event.clientY = 3000;
- event.button = 0;
- event.ctrlKey = false;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
-
- // Button up. Primary button.
- event.type = "pointerup";
- event.button = 0;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
- });
- describe('two button drag', function() {
- describe('multiTouchPanAndZoom enabled', function() {
- it('pinchDeltaPercentage enabled', function() {
- // Multiple button presses interpreted as "pinch" and "swipe".
- this.cameraInput.multiTouchPanAndZoom = true;
- // Zoom changes are a percentage of current value.
- this.cameraInput.pinchDeltaPercentage = 10;
- // Panning not enabled.
- this.cameraInput.panningSensibility = 0;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.clientX = 1000;
- event.clientY = 200;
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Start moving before 2nd button has been pressed.
- event.type = "pointermove";
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move X coordinate.
- event.type = "pointermove";
- event.clientX = 1500;
- event.clientY = 200;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
- // 2nd button down. (Enter zoom mode.)
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Start move of 2nd pointer.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2000;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move Y coordinate. 2nd point is the one moving.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2500;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Increase})
- ).to.be.true;
- // Move X + Y coordinate. 1st point is the one moving.
- event.type = "pointermove";
- event.clientX = 1700;
- event.clientY = 1700;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Decrease})
- ).to.be.true;
- // One of the buttons button up. (Leave zoom mode.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate of remaining pressed point.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2700;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
- // Other button button up. (Now moves should have no affect.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate.
- event.type = "pointermove";
- event.clientX = 3000;
- event.clientY = 4000;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
-
- it('pinchDeltaPercentage disabled', function() {
- // Multiple button presses interpreted as "pinch" and "swipe".
- this.cameraInput.multiTouchPanAndZoom = true;
- // Zoom changes are not a percentage of current value.
- this.cameraInput.pinchDeltaPercentage = 0;
- // Panning not enabled.
- this.cameraInput.panningSensibility = 0;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.clientX = 1000;
- event.clientY = 200;
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Start moving before 2nd button has been pressed.
- event.type = "pointermove";
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move X coordinate.
- event.type = "pointermove";
- event.clientX = 1500;
- event.clientY = 200;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
- // 2nd button down. (Enter zoom mode.)
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Start move of 2nd pointer.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2000;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move Y coordinate. 2nd point is the one moving.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2500;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Increase})
- ).to.be.true;
- // Move X + Y coordinate. 1st point is the one moving.
- event.type = "pointermove";
- event.clientX = 1700;
- event.clientY = 1700;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Decrease})
- ).to.be.true;
- // One of the buttons button up. (Leave zoom mode.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate of remaining pressed point.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2700;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
- // Other button button up. (Now moves should have no affect.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate.
- event.type = "pointermove";
- event.clientX = 3000;
- event.clientY = 4000;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
-
- it('pan on drag', function() {
- // Multiple button presses interpreted as "pinch" and "swipe".
- this.cameraInput.multiTouchPanAndZoom = true;
- // Zoom changes are not a percentage of current value.
- this.cameraInput.pinchDeltaPercentage = 0;
- // Panning not enabled.
- this.cameraInput.panningSensibility = 3;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.clientX = 1000;
- event.clientY = 200;
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Start moving before 2nd button has been pressed.
- event.type = "pointermove";
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move X coordinate.
- event.type = "pointermove";
- event.clientX = 1500;
- event.clientY = 200;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
- // 2nd button down. (Enter zoom mode.)
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Start move of 2nd pointer.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2000;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move Y coordinate. 2nd point is the one moving.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2500;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Increase,
- inertialPanningY: ValChange.Increase})
- ).to.be.true;
- // Move X + Y coordinate. 1st point is the one moving.
- event.type = "pointermove";
- event.clientX = 1700;
- event.clientY = 1700;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Decrease,
- inertialPanningX: ValChange.Decrease,
- inertialPanningY: ValChange.Increase})
- ).to.be.true;
- // One of the buttons button up. (Leave zoom mode.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate of remaining pressed point.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2700;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
- // Other button button up. (Now moves should have no affect.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate.
- event.type = "pointermove";
- event.clientX = 3000;
- event.clientY = 4000;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
- });
- describe('multiTouchPanAndZoom disabled', function() {
- it('pinchDeltaPercentage enabled', function() {
- // Multiple button presses not interpreted as multitouch.
- this.cameraInput.multiTouchPanAndZoom = false;
- // Zoom changes are a percentage of current value.
- this.cameraInput.pinchDeltaPercentage = 10;
- // Panning not enabled.
- this.cameraInput.panningSensibility = 3;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.clientX = 1000;
- event.clientY = 200;
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Start moving before 2nd button has been pressed.
- event.type = "pointermove";
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move X coordinate.
- event.type = "pointermove";
- event.clientX = 1500;
- event.clientY = 200;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
- // 2nd button down. (Enter zoom mode.)
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Start move of 2nd pointer.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2000;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move Y coordinate. 2nd point is the one moving.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2500;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Increase})
- ).to.be.true;
- // Move X + Y coordinate. 1st point is the one moving.
- event.type = "pointermove";
- event.clientX = 1700;
- event.clientY = 1700;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Decrease})
- ).to.be.true;
- // One of the buttons button up. (Leave zoom mode.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate of remaining pressed point.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2700;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
- // 1st button down again
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Start move of 1st button.
- // This time trigger more than 20 pointermove events without moving more
- // than pinchToPanMaxDistance to lock into "pan" mode.
- event.type = "pointermove";
- event.clientX = 1000;
- event.clientY = 1000;
- event.button = -1;
- event.pointerId = 1;
- for (let i = 0; i < 21; i++) {
- event.clientX++;
- simulateEvent(this.cameraInput, event);
- }
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialPanningX: ValChange.Decrease})
- ).to.be.true;
- // Now we are in "pan" mode, we can move 1st pointer larger distances.
- event.type = "pointermove";
- event.clientX = 5000;
- event.clientY = 5000;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialPanningX: ValChange.Decrease,
- inertialPanningY: ValChange.Increase})
- ).to.be.true;
- // One of the buttons button up. (Leave pan mode.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Other button button up. (Now moves should have no affect.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate.
- event.type = "pointermove";
- event.clientX = 3000;
- event.clientY = 4000;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
-
- it('pinchDeltaPercentage disabled', function() {
- // Multiple button presses not interpreted as multitouch.
- this.cameraInput.multiTouchPanAndZoom = false;
- // Zoom changes are not a percentage of current value.
- this.cameraInput.pinchDeltaPercentage = 0;
- // Panning not enabled.
- this.cameraInput.panningSensibility = 3;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.clientX = 1000;
- event.clientY = 200;
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Start moving before 2nd button has been pressed.
- event.type = "pointermove";
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move X coordinate.
- event.type = "pointermove";
- event.clientX = 1500;
- event.clientY = 200;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
- // 2nd button down. (Enter zoom mode.)
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Start move of 2nd pointer.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2000;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move Y coordinate. 2nd point is the one moving.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2500;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Increase})
- ).to.be.true;
- // Move X + Y coordinate. 1st point is the one moving.
- event.type = "pointermove";
- event.clientX = 1700;
- event.clientY = 1700;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Decrease})
- ).to.be.true;
- // One of the buttons button up. (Leave zoom mode.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate of remaining pressed point.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2700;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialBetaOffset: ValChange.Decrease})
- ).to.be.true;
- // 1st button down again
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Start move of 1st button.
- // This time trigger more than 20 pointermove events without moving more
- // than pinchToPanMaxDistance to lock into "pan" mode.
- event.type = "pointermove";
- event.clientX = 1000;
- event.clientY = 1000;
- event.button = -1;
- event.pointerId = 1;
- for (let i = 0; i < 21; i++) {
- event.clientX++;
- simulateEvent(this.cameraInput, event);
- }
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialPanningX: ValChange.Decrease})
- ).to.be.true;
- // Now we are in "pan" mode, we can move 1st pointer larger distances.
- event.type = "pointermove";
- event.clientX = 5000;
- event.clientY = 5000;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialPanningX: ValChange.Decrease,
- inertialPanningY: ValChange.Increase})
- ).to.be.true;
- // One of the buttons button up. (Leave pan mode.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Other button button up. (Now moves should have no affect.)
- event.type = "pointerup";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Move X and Y coordinate.
- event.type = "pointermove";
- event.clientX = 3000;
- event.clientY = 4000;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
- });
- });
- describe('loose focus', function() {
- it('cancels drag', function() {
- // Multiple button presses interpreted as "pinch" and "swipe".
- this.cameraInput.multiTouchPanAndZoom = true;
- // Zoom changes are a percentage of current value.
- this.cameraInput.pinchDeltaPercentage = 10;
- // Panning not enabled.
- this.cameraInput.panningSensibility = 0;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.clientX = 1000;
- event.clientY = 200;
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Start moving before 2nd button has been pressed.
- event.type = "pointermove";
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move X coordinate.
- event.type = "pointermove";
- event.clientX = 1500;
- event.clientY = 200;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
- // Lost focus
- (<any>this.cameraInput)._onLostFocus();
- // Move X + Y coordinate. Should have no affect after loosing focus.
- event.type = "pointermove";
- event.clientX = 1700;
- event.clientY = 1700;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
- it('cancels double drag', function() {
- // Multiple button presses interpreted as "pinch" and "swipe".
- this.cameraInput.multiTouchPanAndZoom = true;
- // Zoom changes are a percentage of current value.
- this.cameraInput.pinchDeltaPercentage = 10;
- // Panning not enabled.
- this.cameraInput.panningSensibility = 0;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- // 1st button down.
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.clientX = 1000;
- event.clientY = 200;
- event.button = 0;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- // Start moving before 2nd button has been pressed.
- event.type = "pointermove";
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move X coordinate.
- event.type = "pointermove";
- event.clientX = 1500;
- event.clientY = 200;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialAlphaOffset: ValChange.Decrease})
- ).to.be.true;
- // 2nd button down. (Enter zoom mode.)
- event.type = "pointerdown";
- event.pointerType = "touch";
- event.button = 1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- // Start move of 2nd pointer.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2000;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- // Move Y coordinate. 2nd point is the one moving.
- event.type = "pointermove";
- event.clientX = 2000;
- event.clientY = 2500;
- event.button = -1;
- event.pointerId = 2;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(
- this.camera,
- this.cameraCachePos,
- {inertialRadiusOffset: ValChange.Increase})
- ).to.be.true;
- // Lost focus
- (<any>this.cameraInput)._onLostFocus();
- // Move X + Y coordinate. Should have no affect after loosing focus.
- event.type = "pointermove";
- event.clientX = 1700;
- event.clientY = 1700;
- event.button = -1;
- event.pointerId = 1;
- simulateEvent(this.cameraInput, event);
- expect(verifyChanges(this.camera, this.cameraCachePos, {})).to.be.true;
- });
- });
- describe('double click', function() {
- it('doesnt restore save position', function() {
- // Disable restoring position.
- this.camera.useInputToRestoreState = false;
- this.camera.alpha = 10;
- this.camera.beta = 10;
- this.camera.radius = 10;
- this.camera.storeState();
- this.camera.alpha = 20;
- this.camera.beta = 20;
- this.camera.radius = 20;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- event.type = "POINTERDOUBLETAP";
- simulateEvent(this.cameraInput, event);
-
- expect(this.camera.alpha).to.be.equal(20);
- expect(this.camera.beta).to.be.equal(20);
- expect(this.camera.radius).to.be.equal(20);
- });
- it('restores save position', function() {
- // Enable restoring position.
- this.camera.useInputToRestoreState = true;
- this.camera.alpha = 10;
- this.camera.beta = 10;
- this.camera.radius = 10;
- this.camera.storeState();
- this.camera.alpha = 20;
- this.camera.beta = 20;
- this.camera.radius = 20;
- var event: MockPointerEvent = eventTemplate(<HTMLElement>this._canvas);
- event.type = "POINTERDOUBLETAP";
- simulateEvent(this.cameraInput, event);
-
- expect(this.camera.alpha).to.be.equal(10);
- expect(this.camera.beta).to.be.equal(10);
- expect(this.camera.radius).to.be.equal(10);
- });
- });
- });
|