You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3485 lines
99 KiB

  1. /*!
  2. * ngCordova
  3. * v0.1.27-alpha
  4. * Copyright 2015 Drifty Co. http://drifty.com/
  5. * See LICENSE in this repository for license information
  6. */
  7. (function(){
  8. var ngCordovaMocks = angular.module('ngCordovaMocks', []);
  9. /**
  10. * @ngdoc service
  11. * @name ngCordovaMocks.cordovaActionSheet
  12. *
  13. * @description
  14. * A service for testing action sheet
  15. * in an app build with ngCordova.
  16. **/
  17. ngCordovaMocks.factory('$cordovaActionSheet', ['$q', function ($q) {
  18. var throwsError = false;
  19. return {
  20. /**
  21. * @ngdoc property
  22. * @name throwsError
  23. * @propertyOf ngCordovaMocks.cordovaActionSheet
  24. * @type Boolean
  25. *
  26. * @description
  27. * A flag that signals whether a promise should be rejected.
  28. * This property should only be used in automated tests
  29. */
  30. throwsError: throwsError,
  31. show: function () {
  32. var defer = $q.defer();
  33. if (this.throwsError) {
  34. defer.reject('There was an error on showing action sheet');
  35. } else {
  36. defer.resolve();
  37. }
  38. return defer.promise;
  39. }
  40. };
  41. }]);
  42. ngCordovaMocks.factory('$cordovaAppVersion', ['$q', function ($q) {
  43. var throwsError = false;
  44. return {
  45. throwsError: throwsError,
  46. getAppName: function () {
  47. var q = $q.defer();
  48. q.resolve('mock app name');
  49. return q.promise;
  50. },
  51. getPackageName: function () {
  52. var q = $q.defer();
  53. q.resolve('com.package.mock');
  54. return q.promise;
  55. },
  56. getVersionNumber: function () {
  57. var q = $q.defer();
  58. q.resolve('1.2.3');
  59. return q.promise;
  60. },
  61. getVersionCode: function () {
  62. var q = $q.defer();
  63. q.resolve('4.5.6');
  64. return q.promise;
  65. }
  66. };
  67. }]);
  68. /**
  69. * @ngdoc service
  70. * @name ngCordovaMocks.cordovaBarcodeScanner
  71. *
  72. * @description
  73. * A service for testing barcode scanner features
  74. * in an app build with ngCordova.
  75. **/
  76. ngCordovaMocks.factory('$cordovaBarcodeScanner', ['$q', function ($q) {
  77. var throwsError = false;
  78. var scannedText = '';
  79. var scannedFormat = '';
  80. var wasCancelled = false;
  81. return {
  82. /**
  83. * @ngdoc property
  84. * @name throwsError
  85. * @propertyOf ngCordovaMocks.cordovaBarcodeScanner
  86. *
  87. * @description
  88. * A flag that signals whether a promise should be rejected or not.
  89. * This property should only be used in automated tests.
  90. **/
  91. throwsError: throwsError,
  92. /**
  93. * @ngdoc property
  94. * @name scannedText
  95. * @propertyOf ngCordovaMocks.cordovaBarcodeScanner
  96. *
  97. * @description
  98. * Used to simulate the result.text property of a
  99. * successful scan. For more information, see the text at
  100. * https://github.com/wildabeast/BarcodeScanner/#using-the-plugin
  101. * This property should only be used in automated tests.
  102. **/
  103. scannedText: scannedText,
  104. /**
  105. * @ngdoc property
  106. * @name scannedFormat
  107. * @propertyOf ngCordovaMocks.cordovaBarcodeScanner
  108. * @description
  109. * Used to simulate the result.format property of a
  110. * successful scan. For more information, see the text at
  111. * https://github.com/wildabeast/BarcodeScanner/#using-the-plugin
  112. * This property should only be used in automated tests.
  113. **/
  114. scannedFormat: scannedFormat,
  115. /**
  116. * @ngdoc property
  117. * @name wasCancelled
  118. * @propertyOf ngCordovaMocks.cordovaBarcodeScanner
  119. *
  120. * @description
  121. * Used to simulate the result.cancelled property of a
  122. * successful scan. For more information, see the text at
  123. * https://github.com/wildabeast/BarcodeScanner/#using-the-plugin
  124. * This property should only be used in automated tests.
  125. **/
  126. wasCancelled: wasCancelled,
  127. scan: function () {
  128. var defer = $q.defer();
  129. if (this.throwsError) {
  130. defer.reject('There was an error scanning.');
  131. } else {
  132. defer.resolve({text: this.scannedText, format: this.scannedFormat, cancelled: this.wasCancelled});
  133. }
  134. return defer.promise;
  135. },
  136. encode: function (type, data) {
  137. this.scannedFormat = type;
  138. this.scannedText = data;
  139. var defer = $q.defer();
  140. if (this.throwsError) {
  141. defer.reject('There was an error encoding the data.');
  142. } else {
  143. defer.resolve();
  144. }
  145. return defer.promise;
  146. }
  147. };
  148. }]);
  149. /**
  150. * @ngdoc service
  151. * @name ngCordovaMocks.cordovaBLE
  152. *
  153. * @description
  154. * A service for ble features
  155. * in an app build with ngCordova.
  156. **/
  157. ngCordovaMocks.factory('$cordovaBLE', ['$q', '$timeout', '$interval', '$log', function ($q, $timeout, $interval, $log) {
  158. var deviceScan = {
  159. name: 'Test Device',
  160. id: 'AA:BB:CC:DD:EE:FF',
  161. advertising: [2, 1, 6, 3, 3, 15, 24, 8, 9, 66, 97, 116, 116, 101, 114, 121],
  162. rssi: -55
  163. };
  164. var deviceConnect = {
  165. name: 'Test Device',
  166. id: 'AA:BB:CC:DD:EE:FF',
  167. advertising: [2, 1, 6, 3, 3, 15, 24, 8, 9, 66, 97, 116, 116, 101, 114, 121],
  168. rssi: -55,
  169. services: [
  170. '1800',
  171. '1801',
  172. '180f'
  173. ],
  174. characteristics: [
  175. {
  176. service: '1800',
  177. characteristic: '2a00',
  178. properties: ['Read']
  179. },
  180. {
  181. service: '1800',
  182. characteristic: '2a01',
  183. properties: ['Read']
  184. },
  185. {
  186. service: '1801',
  187. characteristic: '2a05',
  188. properties: ['Read']
  189. },
  190. {
  191. service: '180f',
  192. characteristic: '2a19',
  193. properties: ['Read'],
  194. descriptors: [{'uuid': '2901'}, {'uuid': '2904'}]
  195. }
  196. ]
  197. };
  198. var readData = new ArrayBuffer(8);
  199. return {
  200. scan: function (services, seconds) {
  201. var q = $q.defer();
  202. // first notify about discovered device
  203. $timeout(function () {
  204. q.notify(deviceScan);
  205. }, Math.round(seconds * 1000 * Math.random()));
  206. // end scan
  207. $timeout(function () {
  208. q.resolve();
  209. }, seconds * 1000);
  210. return q.promise;
  211. },
  212. startScan: function (services, callback, errorCallback) {
  213. $timeout(function () {
  214. callback(deviceScan);
  215. }, Math.round(1000 * Math.random()));
  216. },
  217. stopScan: function () {
  218. var q = $q.defer();
  219. $timeout(function () {
  220. q.resolve();
  221. }, 500);
  222. return q.promise;
  223. },
  224. connect: function (deviceID) {
  225. var q = $q.defer();
  226. $timeout(function () {
  227. q.resolve(deviceConnect);
  228. }, 1500);
  229. return q.promise;
  230. },
  231. disconnect: function (deviceID) {
  232. var q = $q.defer();
  233. $timeout(function () {
  234. q.resolve(true);
  235. }, 500);
  236. return q.promise;
  237. },
  238. read: function (deviceID, serviceUUID, characteristicUUID) {
  239. var q = $q.defer();
  240. $timeout(function () {
  241. q.resolve(readData);
  242. }, 100);
  243. return q.promise;
  244. },
  245. write: function (deviceID, serviceUUID, characteristicUUID, data) {
  246. var q = $q.defer();
  247. $timeout(function () {
  248. q.resolve(true);
  249. }, 100);
  250. return q.promise;
  251. },
  252. writeWithoutResponse: function (deviceID, serviceUUID, characteristicUUID, data) {
  253. var q = $q.defer();
  254. $timeout(function () {
  255. q.resolve(true);
  256. }, 100);
  257. return q.promise;
  258. },
  259. writeCommand: function (deviceID, serviceUUID, characteristicUUID, data) {
  260. $log.warning('writeCommand is deprecated, use writeWithoutResponse');
  261. return this.writeWithoutResponse(deviceID, serviceUUID, characteristicUUID, data);
  262. },
  263. startNotification: function (deviceID, serviceUUID, characteristicUUID, callback, errorCallback) {
  264. $interval(function () {
  265. var data = new Uint8Array([Math.round(255 * Math.random())]); // one byte with random number
  266. callback(data);
  267. }, 200, 10); // repeat 10 times with 200 ms delay for each
  268. },
  269. stopNotification: function (deviceID, serviceUUID, characteristicUUID) {
  270. var q = $q.defer();
  271. $timeout(function () {
  272. q.resolve();
  273. }, 100);
  274. return q.promise;
  275. },
  276. isConnected: function (deviceID) {
  277. var q = $q.defer();
  278. q.resolve(true);
  279. return q.promise;
  280. },
  281. enable: function () {
  282. var q = $q.defer();
  283. $timeout(function () {
  284. q.resolve();
  285. }, 1500);
  286. return q.promise;
  287. },
  288. isEnabled: function () {
  289. var q = $q.defer();
  290. q.resolve(true);
  291. return q.promise;
  292. }
  293. };
  294. }]);
  295. ngCordovaMocks.factory('$cordovaBrightness', ['$q', function ($q) {
  296. var currentBrightness = 100;
  297. return {
  298. get: function () {
  299. var q = $q.defer();
  300. q.resolve(currentBrightness);
  301. return q.promise;
  302. },
  303. set: function (data) {
  304. var q = $q.defer();
  305. currentBrightness = data;
  306. q.resolve('OK');
  307. return q.promise;
  308. },
  309. setKeepScreenOn: function (bool) {
  310. var q = $q.defer();
  311. q.resolve('OK');
  312. return q.promise;
  313. }
  314. };
  315. }]);
  316. /**
  317. * @ngdoc service
  318. * @name ngCordovaMocks.cordovaCamera
  319. *
  320. * @description
  321. * A service for testing camera features
  322. * in an app build with ngCordova.
  323. **/
  324. ngCordovaMocks.factory('$cordovaCamera', ['$q', function ($q) {
  325. var throwsError = false;
  326. var imageData = '';
  327. return {
  328. /**
  329. * @ngdoc property
  330. * @name throwsError
  331. * @propertyOf ngCordovaMocks.cordovaCamera
  332. *
  333. * @description
  334. * A flag that signals whether a promise should be rejected or not.
  335. * This property should only be used in automated tests.
  336. **/
  337. throwsError: throwsError,
  338. /**
  339. * @ngdoc property
  340. * @name imageData
  341. * @propertyOf ngCordovaMocks.cordovaCamera
  342. *
  343. * @description
  344. * The imagedata (e.g. an url) which will be returned from the device.
  345. * This property should only be used in automated tests.
  346. **/
  347. imageData: imageData,
  348. getPicture: function (options) {
  349. var defer = $q.defer();
  350. if (this.throwsError) {
  351. defer.reject('There was an error getting the picture.');
  352. } else {
  353. if (options) {
  354. options = options; // This is just to get by JSHint.
  355. }
  356. defer.resolve(this.imageData);
  357. }
  358. return defer.promise;
  359. }
  360. };
  361. }]);
  362. /**
  363. * @ngdoc service
  364. * @name ngCordovaMocks.cordovaCapture
  365. *
  366. * @description
  367. * A service for testing media capture
  368. * in an app build with ngCordova.
  369. *
  370. * @example
  371. */
  372. ngCordovaMocks.factory('$cordovaCapture', ['$q', function ($q) {
  373. var throwsError = false;
  374. return {
  375. /**
  376. * @ngdoc property
  377. * @name throwsError
  378. * @propertyOf ngCordovaMocks.cordovaCapture
  379. *
  380. * @description
  381. * A flag that signals whether a promise should be rejected or not.
  382. * This property should only be used in automated tests.
  383. **/
  384. throwsError: throwsError,
  385. captureAudio: function () {
  386. var defer = $q.defer();
  387. if (this.throwsError) {
  388. defer.reject('There was an error capturing the audio.');
  389. } else {
  390. defer.resolve();
  391. }
  392. return defer.promise;
  393. },
  394. captureImage: function () {
  395. var defer = $q.defer();
  396. if (this.throwsError) {
  397. defer.reject('There was an error capturing the image.');
  398. } else {
  399. defer.resolve();
  400. }
  401. return defer.promise;
  402. },
  403. captureVideo: function () {
  404. var defer = $q.defer();
  405. if (this.throwsError) {
  406. defer.reject('There was an error capturing the video.');
  407. } else {
  408. defer.resolve();
  409. }
  410. return defer.promise;
  411. }
  412. };
  413. }]);
  414. /**
  415. * @ngdoc service
  416. * @name ngCordovaMocks.cordovaContacts
  417. *
  418. * @description
  419. * A service for testing features related with contacts
  420. * in an app build with ngCordova.
  421. **/
  422. ngCordovaMocks.factory('$cordovaContacts', ['$q', function ($q) {
  423. var throwsError = false;
  424. var contacts = [];
  425. return {
  426. /**
  427. @ngdoc property
  428. @name throwsError
  429. @propertyOf ngCordovaMocks.cordovaContacts
  430. @description
  431. A flag that signals whether a promise should be rejected or not.
  432. This property should only be used in automated tests.
  433. */
  434. throwsError: throwsError,
  435. /**
  436. @ngdoc contacts
  437. @name throwsError
  438. @propertyOf ngCordovaMocks.cordovaContacts
  439. @description
  440. An in-memory collection of contacts.
  441. This property should only be used in automated tests.
  442. */
  443. contacts: contacts,
  444. save: function (contact) {
  445. var defer = $q.defer();
  446. if (this.throwsError) {
  447. defer.reject('There was an error saving the contact.');
  448. } else {
  449. var existingIndex = null;
  450. for (var i = 0; i < this.contacts.length; i++) {
  451. // The actual implementation relies on the entire object match.
  452. // we're gong to rely on the ID.
  453. if (this.contacts[i].id === contact.id) {
  454. existingIndex = i;
  455. break;
  456. }
  457. }
  458. if (existingIndex === null) {
  459. this.contacts.push(contact);
  460. defer.resolve();
  461. } else {
  462. defer.reject('Contact already exists.');
  463. }
  464. }
  465. return defer.promise;
  466. },
  467. remove: function (contact) {
  468. var defer = $q.defer();
  469. if (this.throwsError) {
  470. defer.reject('There was an error saving the contact.');
  471. } else {
  472. var toRemove = null;
  473. for (var i = 0; i < this.contacts.length; i++) {
  474. // The actual implementation relies on the entire object match.
  475. // we're gong to rely on the ID.
  476. if (this.contacts[i].id === contact.id) {
  477. toRemove = i;
  478. break;
  479. }
  480. }
  481. if (toRemove === null) {
  482. defer.reject('Unable to find contact.');
  483. } else {
  484. this.contacts.splice(toRemove, 1);
  485. defer.resolve();
  486. }
  487. }
  488. return defer.promise;
  489. },
  490. find: function (options) {
  491. var defer = $q.defer();
  492. if (this.throwsError) {
  493. defer.reject('There was an error finding the contact.');
  494. } else {
  495. var fields = options.fields || ['id', 'displayName'];
  496. delete options.fields;
  497. if (!fields) {
  498. defer.reject('ContactError.INVALID_ARGUMENT_ERROR');
  499. } else {
  500. if (fields === '*') {
  501. defer.resolve(this.contacts);
  502. } else {
  503. // Implement a very rudimentary search approach for testing purposes.
  504. // This is NOT exhaustive.
  505. var results = [];
  506. for (var i = 0; i < this.contacts.length; i++) {
  507. for (var key in this.contacts[i]) {
  508. var propertyValue = this.contacts[i][key];
  509. }
  510. }
  511. // TODO: Search by individual fields
  512. defer.resolve(results);
  513. }
  514. }
  515. }
  516. return defer.promise;
  517. }
  518. };
  519. }]);
  520. /**
  521. * @ngdoc service
  522. * @name ngCordovaMocks.cordovaDatePicker
  523. *
  524. * @description
  525. * A service for testing datepicker features
  526. * in an app build with ngCordova.
  527. */
  528. ngCordovaMocks.factory('$cordovaDatePicker', ['$q', function ($q) {
  529. return {
  530. show: function (options) {
  531. var q = $q.defer();
  532. options = options || {date: new Date(), mode: 'date'};
  533. q.resolve(options.date);
  534. return q.promise;
  535. }
  536. };
  537. }]);
  538. /**
  539. * @ngdoc service
  540. * @name ngCordovaMocks.cordovaDevice
  541. *
  542. * @description
  543. * A service for testing device information
  544. * in an app build with ngCordova.
  545. **/
  546. ngCordovaMocks.factory('$cordovaDevice', function () {
  547. var device = '';
  548. var cordova = '';
  549. var model = '';
  550. var platform = '';
  551. var uuid = '';
  552. var version = '';
  553. return {
  554. /**
  555. @ngdoc property
  556. @name device
  557. @propertyOf ngCordovaMocks.cordovaDevice
  558. @description
  559. The name of the 'device'.
  560. This property should only be used in automated tests.
  561. */
  562. device: device,
  563. /**
  564. @ngdoc property
  565. @name cordova
  566. @propertyOf ngCordovaMocks.cordovaDevice
  567. @description
  568. The version of cordova in use.
  569. This property should only be used in automated tests.
  570. */
  571. cordova: cordova,
  572. /**
  573. @ngdoc property
  574. @name model
  575. @propertyOf ngCordovaMocks.cordovaDevice
  576. @description
  577. The model of the device using the app.
  578. This property should only be used in automated tests.
  579. */
  580. model: model,
  581. /**
  582. @ngdoc property
  583. @name platform
  584. @propertyOf ngCordovaMocks.cordovaDevice
  585. @description
  586. The name of the operating system in use.
  587. This property should only be used in automated tests.
  588. */
  589. platform: platform,
  590. /**
  591. @ngdoc property
  592. @name uuid
  593. @propertyOf ngCordovaMocks.cordovaDevice
  594. @description
  595. The unique identifier of a device.
  596. This property should only be used in automated tests.
  597. */
  598. uuid: uuid,
  599. /**
  600. @ngdoc property
  601. @name version
  602. @propertyOf ngCordovaMocks.cordovaDevice
  603. @description
  604. The version of the operating system.
  605. This property should only be used in automated tests.
  606. */
  607. version: version,
  608. /**
  609. @ngdoc property
  610. @name manufacturer
  611. @propertyOf ngCordovaMocks.cordovaDevice
  612. @description
  613. The manufacturer of the device.
  614. This property should only be used in automated tests.
  615. */
  616. version: version,
  617. getDevice: function () {
  618. return this.device;
  619. },
  620. getCordova: function () {
  621. return this.cordova;
  622. },
  623. getModel: function () {
  624. return this.model;
  625. },
  626. getPlatform: function () {
  627. return this.platform;
  628. },
  629. getUUID: function () {
  630. return this.uuid;
  631. },
  632. getVersion: function () {
  633. return this.version;
  634. },
  635. getManufacturer: function () {
  636. return this.manufacturer;
  637. }
  638. };
  639. });
  640. /**
  641. * @ngdoc service
  642. * @name ngCordovaMocks.cordovaDeviceMotion
  643. *
  644. * @description
  645. * A service for mocking the accelerometer
  646. * in an app build with ngCordova.
  647. **/
  648. ngCordovaMocks.factory('$cordovaDeviceMotion', ['$interval', '$q', function ($interval, $q) {
  649. var currentAcceleration = null;
  650. var throwsError = false;
  651. var positions = [];
  652. var watchIntervals = [];
  653. return {
  654. /**
  655. * @ngdoc property
  656. * @name currentAcceleration
  657. * @propertyOf ngCordovaMocks.cordovaDeviceMotion
  658. *
  659. * @description
  660. * The current acceleration.
  661. * This property should only be used in automated tests.
  662. **/
  663. currentAcceleration: currentAcceleration,
  664. /**
  665. @ngdoc property
  666. @name throwsError
  667. @propertyOf ngCordovaMocks.cordovaDeviceMotion
  668. @description
  669. A flag that signals whether a promise should be rejected or not.
  670. This property should only be used in automated tests.
  671. */
  672. throwsError: throwsError,
  673. /**
  674. @ngdoc property
  675. @name positions
  676. @propertyOf ngCordovaMocks.cordovaDeviceMotion
  677. @description
  678. The collection of 'positions' that have been logged.
  679. This property should only be used in automated tests.
  680. */
  681. positions: positions,
  682. /**
  683. @ngdoc property
  684. @name watchIntervals
  685. @propertyOf ngCordovaMocks.cordovaDeviceMotion
  686. @description
  687. The collection of watchers that are currently active.
  688. This property should only be used in automated tests.
  689. */
  690. watchIntervals: watchIntervals,
  691. getCurrentAcceleration: function () {
  692. var defer = $q.defer();
  693. if (this.throwsError) {
  694. defer.reject('There was an error getting the current acceleration.');
  695. } else {
  696. defer.resolve(this.currentAcceleration);
  697. }
  698. return defer.promise;
  699. },
  700. watchAcceleration: function (options) {
  701. var defer = $q.defer();
  702. var watchId = Math.floor((Math.random() * 1000000) + 1);
  703. this.positions = [];
  704. self = this;
  705. if (this.throwsError) {
  706. defer.reject('There was an error watching the current acceleration.');
  707. } else {
  708. var delay = 10000; // The default based on https://github.com/apache/cordova-plugin-device-motion
  709. if (options && options.frequency) {
  710. delay = options.frequency;
  711. }
  712. this.watchIntervals.push($interval(
  713. function () {
  714. if (self.throwsError) {
  715. defer.reject('There was an error watching the acceleration.');
  716. }
  717. // Generate a random position
  718. var randomX = Math.floor((Math.random() * 100) + 1);
  719. var randomY = Math.floor((Math.random() * 100) + 1);
  720. var randomZ = Math.floor((Math.random() * 100) + 1);
  721. var result = {x: randomX, y: randomY, z: randomZ, timestamp: Date.now()};
  722. self.positions.push(result);
  723. defer.notify(result);
  724. },
  725. delay
  726. ));
  727. }
  728. return {
  729. watchId: watchId,
  730. promise: defer.promise
  731. };
  732. },
  733. clearWatch: function (watchId) {
  734. var defer = $q.defer();
  735. if (watchId) {
  736. if (this.throwsError) {
  737. defer.reject('Unable to clear watch.');
  738. } else {
  739. var removed = -1;
  740. for (var i = 0; i < this.watchIntervals.length; i++) {
  741. if (this.watchIntervals[i].watchId === watchId) {
  742. $interval.cancel(watchIntervals[i].interval);
  743. removed = i;
  744. break;
  745. }
  746. }
  747. if (removed !== -1) {
  748. this.watchIntervals.splice(removed, 1);
  749. }
  750. }
  751. } else {
  752. defer.reject('Unable to clear watch. No watch ID provided.');
  753. }
  754. return defer.promise;
  755. }
  756. };
  757. }]);
  758. /**
  759. * @ngdoc service
  760. * @name ngCordovaMocks.cordovaDeviceOrientation
  761. *
  762. * @description
  763. * A service for testing compass fetures
  764. * in an app build with ngCordova.
  765. */
  766. ngCordovaMocks.factory('$cordovaDeviceOrientation', ['$interval', '$q', function ($interval, $q) {
  767. var currentHeading = null;
  768. var throwsError = false;
  769. var readings = [];
  770. var watchIntervals = [];
  771. return {
  772. /**
  773. * @ngdoc property
  774. * @name currentHeading
  775. * @propertyOf ngCordovaMocks.cordovaDeviceOrientation
  776. *
  777. * @description
  778. * The current heading.
  779. * This property should only be used in automated tests.
  780. **/
  781. currentHeading: currentHeading,
  782. /**
  783. @ngdoc property
  784. @name throwsError
  785. @propertyOf ngCordovaMocks.cordovaDeviceOrientation
  786. @description
  787. A flag that signals whether a promise should be rejected or not.
  788. This property should only be used in automated tests.
  789. */
  790. throwsError: throwsError,
  791. /**
  792. @ngdoc property
  793. @name positions
  794. @propertyOf ngCordovaMocks.cordovaDeviceOrientation
  795. @description
  796. The collection of compass 'readings' that have been logged.
  797. This property should only be used in automated tests.
  798. */
  799. readings: readings,
  800. /**
  801. @ngdoc property
  802. @name watchIntervals
  803. @propertyOf ngCordovaMocks.cordovaDeviceOrientation
  804. @description
  805. The collection of watchers that are currently active.
  806. This property should only be used in automated tests.
  807. */
  808. watchIntervals: watchIntervals,
  809. getCurrentHeading: function () {
  810. var defer = $q.defer();
  811. if (this.throwsError) {
  812. defer.reject('There was an error getting the current heading.');
  813. } else {
  814. defer.resolve(this.currentHeading);
  815. }
  816. return defer.promise;
  817. },
  818. watchHeading: function (options) {
  819. var defer = $q.defer();
  820. var watchID = Math.floor((Math.random() * 1000000) + 1);
  821. var self = this;
  822. self.readings = [];
  823. if (self.throwsError) {
  824. defer.reject('There was an error getting the compass heading.');
  825. } else {
  826. var delay = 100; // The default based on https://github.com/apache/cordova-plugin-device-orientation
  827. if (options && options.frequency) {
  828. delay = options.frequency;
  829. }
  830. self.watchIntervals.push({
  831. watchID: watchID,
  832. interval: $interval(
  833. function () {
  834. if (self.throwsError) {
  835. defer.reject('There was an error watching the acceleration.');
  836. }
  837. // Generate a random position
  838. var magneticHeading = (Math.random() * 359.99) + 1;
  839. var trueHeading = (Math.random() * 359.99) + 1;
  840. var headingAccuracy = Math.floor((Math.random() * 360) + 1);
  841. var result = {magneticHeading: magneticHeading, trueHeading: trueHeading, headingAccuracy: headingAccuracy, timestamp: Date.now()};
  842. self.readings.push(result);
  843. defer.notify(result);
  844. },
  845. delay
  846. )
  847. });
  848. }
  849. var cancel = function (id) {
  850. var removed = -1;
  851. for (var i = 0; i < self.watchIntervals.length; i++) {
  852. if (self.watchIntervals[i].watchID === id) {
  853. $interval.cancel(watchIntervals[i].interval);
  854. removed = i;
  855. break;
  856. }
  857. }
  858. if (removed !== -1) {
  859. self.watchIntervals.splice(removed, 1);
  860. }
  861. };
  862. defer.promise.cancel = function () {
  863. cancel(watchID);
  864. };
  865. defer.promise.clearWatch = function (id) {
  866. cancel(id || watchID);
  867. };
  868. defer.promise.watchID = watchID;
  869. return defer.promise;
  870. },
  871. clearWatch: function (watchId) {
  872. var defer = $q.defer();
  873. if (watchId) {
  874. if (this.throwsError) {
  875. defer.reject('Unable to clear watch.');
  876. } else {
  877. var removed = -1;
  878. for (var i = 0; i < this.watchIntervals.length; i++) {
  879. if (this.watchIntervals[i].watchId === watchId) {
  880. $interval.cancel(watchIntervals[i].interval);
  881. removed = i;
  882. break;
  883. }
  884. }
  885. if (removed !== -1) {
  886. this.watchIntervals.splice(removed, 1);
  887. }
  888. }
  889. } else {
  890. defer.reject('Unable to clear watch. No watch ID provided.');
  891. }
  892. return defer.promise;
  893. }
  894. };
  895. }]);
  896. /**
  897. * @ngdoc service
  898. * @name ngCordovaMocks.cordovaDialogs
  899. *
  900. * @description
  901. * A service for testing dialogs
  902. * in an app build with ngCordova.
  903. */
  904. ngCordovaMocks.factory('$cordovaDialogs', ['$q', function ($q) {
  905. var dialogText = false;
  906. var dialogTitle = '';
  907. var defaultValue = '';
  908. var promptResponse = '';
  909. var beepCount = 0;
  910. var useHostAbilities = true;
  911. return {
  912. /**
  913. @ngdoc property
  914. @name dialogText
  915. @propertyOf ngCordovaMocks.cordovaDialogs
  916. @description
  917. The main content in the dialog.
  918. This property should only be used in automated tests.
  919. */
  920. dialogText: dialogText,
  921. /**
  922. @ngdoc property
  923. @name dialogTitle
  924. @propertyOf ngCordovaMocks.cordovaDialogs
  925. @description
  926. The title of the dialog.
  927. This property should only be used in automated tests.
  928. */
  929. dialogTitle: dialogTitle,
  930. /**
  931. @ngdoc property
  932. @name defaultValue
  933. @propertyOf ngCordovaMocks.cordovaDialogs
  934. @description
  935. The default value to be used in a prompt.
  936. This property should only be used in automated tests.
  937. */
  938. defaultValue: defaultValue,
  939. /**
  940. @ngdoc property
  941. @name promptResponse
  942. @propertyOf ngCordovaMocks.cordovaDialogs
  943. @description
  944. Used to simulate a user's response to a prompt.
  945. This property should only be used in automated tests.
  946. */
  947. promptResponse: promptResponse,
  948. /**
  949. @ngdoc property
  950. @name buttonLabels
  951. @propertyOf ngCordovaMocks.cordovaDialogs
  952. @description
  953. An array of the text of each button in the dialog.
  954. This property should only be used in automated tests.
  955. */
  956. buttonLabels: [],
  957. /**
  958. @ngdoc property
  959. @name beepCount
  960. @propertyOf ngCordovaMocks.cordovaDialogs
  961. @description
  962. The number of times a beep has occurred.
  963. This property should only be used in automated tests.
  964. */
  965. beepCount: beepCount,
  966. /**
  967. @ngdoc property
  968. @name useHostAbilities
  969. @propertyOf ngCordovaMocks.cordovaDialogs
  970. @description
  971. A flag that signals whether or not to try and use the host's
  972. (browser or otherwise) prompting capabilities.
  973. This property should only be used in automated tests.
  974. */
  975. useHostAbilities: useHostAbilities,
  976. alert: function (message, title, buttonName) {
  977. var d = $q.defer();
  978. if (this.useHostAbilities) {
  979. // NOTE: The window.alert method doesn't support a title or callbacks.
  980. alert(message);
  981. d.resolve();
  982. } else {
  983. this.dialogText = message;
  984. this.dialogTitle = title;
  985. this.buttonLabels.push(buttonName);
  986. d.resolve();
  987. }
  988. return d.promise;
  989. },
  990. confirm: function (message, title, buttonName) {
  991. var d = $q.defer();
  992. if (this.useHostAbilities) {
  993. // NOTE: The window.confirm method doesn't support a title or custom button naming.
  994. var result = confirm(message);
  995. d.resolve(result ? 2 : 1);
  996. } else {
  997. this.dialogText = message;
  998. this.dialogTitle = title;
  999. this.buttonLabels.push(buttonName);
  1000. d.resolve(0);
  1001. }
  1002. return d.promise;
  1003. },
  1004. prompt: function (message, title, buttonLabels, defaultText) {
  1005. var d = $q.defer();
  1006. if (this.useHostAbilities) {
  1007. // NOTE: The window.prompt method doesn't support a title or custom button naming.
  1008. var result = prompt(message, defaultText);
  1009. d.resolve(result);
  1010. } else {
  1011. this.dialogText = message;
  1012. this.dialogTitle = title;
  1013. this.defaultValue = defaultText;
  1014. for (var i = 0; i < buttonLabels.length; i++) {
  1015. this.buttonLabels.push(buttonLabels[i]);
  1016. }
  1017. d.resolve(this.promptResponse);
  1018. }
  1019. return d.promise;
  1020. },
  1021. beep: function (times) {
  1022. this.beepCount = times;
  1023. }
  1024. };
  1025. }]);
  1026. /**
  1027. * @ngdoc service
  1028. * @name ngCordovaMocks.cordovaFacebook
  1029. *
  1030. * @description
  1031. * A service for testing Facebook features
  1032. * in an app built with ngCordova.
  1033. **/
  1034. ngCordovaMocks.factory('$cordovaFacebook', ['$q', function ($q) {
  1035. return {
  1036. /**
  1037. * These properties are here for the purpose of automated testing only.
  1038. **/
  1039. loginShouldSucceedWith: null,
  1040. showDialogShouldSucceedWith: null,
  1041. apiShouldSucceedWith: null,
  1042. getAccessTokenShouldSucceedWith: null,
  1043. getLoginStatusShouldSucceedWith: null,
  1044. logoutShouldSuceedWith: null,
  1045. login: function (permissions) {
  1046. if (this.loginShouldSucceedWith !== null) {
  1047. return $q.when(this.loginShouldSucceedWith);
  1048. } else {
  1049. return $q.reject();
  1050. }
  1051. },
  1052. showDialog: function (options) {
  1053. if (this.showDialogShouldSucceedWith !== null) {
  1054. return $q.when(this.showDialogShouldSucceedWith);
  1055. } else {
  1056. return $q.reject();
  1057. }
  1058. },
  1059. api: function (path, permissions) {
  1060. if (this.apiShouldSucceedWith !== null) {
  1061. return $q.when(this.apiShouldSucceedWith);
  1062. } else {
  1063. return $q.reject();
  1064. }
  1065. },
  1066. getAccessToken: function () {
  1067. if (this.getAccessTokenShouldSucceedWith !== null) {
  1068. return $q.when(this.getAccessTokenShouldSucceedWith);
  1069. } else {
  1070. return $q.reject();
  1071. }
  1072. },
  1073. getLoginStatus: function () {
  1074. if (this.getLoginStatusShouldSucceedWith !== null) {
  1075. return $q.when(this.getLoginStatusShouldSucceedWith);
  1076. } else {
  1077. return $q.reject();
  1078. }
  1079. },
  1080. logout: function () {
  1081. if (this.logoutShouldSuceedWith !== null) {
  1082. return $q.when(this.logoutShouldSuceedWith);
  1083. } else {
  1084. return $q.reject();
  1085. }
  1086. }
  1087. };
  1088. }]);
  1089. /**
  1090. * @ngdoc service
  1091. * @name ngCordovaMocks.cordovaFile
  1092. *
  1093. * @description
  1094. * A service for testing interaction with device directories and files
  1095. * in an app build with ngCordova.
  1096. */
  1097. ngCordovaMocks.factory('$cordovaFile', ['$q', function ($q) {
  1098. var throwsError = false;
  1099. var fileSystem = {};
  1100. var shouldMockFiles = false;
  1101. var files = {};
  1102. var mockIt = function (errorMessage) {
  1103. var defer = $q.defer();
  1104. if (this.throwsError) {
  1105. defer.reject(errorMessage);
  1106. } else {
  1107. defer.resolve();
  1108. }
  1109. return defer.promise;
  1110. };
  1111. return {
  1112. /**
  1113. * @ngdoc property
  1114. * @name throwsError
  1115. * @propertyOf ngCordovaMocks.cordovaFile
  1116. *
  1117. * @description
  1118. * A flag that signals whether a promise should be rejected or not.
  1119. * This property should only be used in automated tests.
  1120. **/
  1121. throwsError: throwsError,
  1122. /**
  1123. * @ngdoc property
  1124. * @name fileSystem
  1125. * @propertyOf ngCordovaMocks.cordovaFile
  1126. *
  1127. * @description
  1128. * A fake, in-memory file system. This is incomplete at this time.
  1129. * This property should only be used in automated tests.
  1130. **/
  1131. fileSystem: fileSystem,
  1132. /**
  1133. * @ngdoc property
  1134. * @name shouldMockFiles
  1135. * @propertyOf ngCordovaMocks.cordovaFile
  1136. *
  1137. * @description
  1138. * A flag that signals whether one wish to mock files.
  1139. * This is useful if you need mocks specific file scenarios.
  1140. * This property should only be used in automated tests.
  1141. **/
  1142. shouldMockFiles: shouldMockFiles,
  1143. /**
  1144. * @ngdoc property
  1145. * @name files
  1146. * @propertyOf ngCordovaMocks.cordovaFile
  1147. *
  1148. * @description
  1149. * An object that may be used for mocking files on the device.
  1150. * This property should only be used in automated tests.
  1151. *
  1152. * **/
  1153. files: files,
  1154. checkDir: function (directory) {
  1155. if (this.shouldMockFiles) {
  1156. var defer = $q.defer();
  1157. if (this.files[directory] && !this.files[directory].isFile) {
  1158. defer.resolve();
  1159. } else {
  1160. defer.reject();
  1161. }
  1162. return defer.promise;
  1163. }
  1164. return mockIt.call(this, 'There was an error checking the directory.');
  1165. },
  1166. createDir: function (directory, overwrite) {
  1167. if (this.shouldMockFiles) {
  1168. var defer = $q.defer();
  1169. this.files[directory] = {isFile: false};
  1170. defer.resolve();
  1171. return defer.promise;
  1172. }
  1173. return mockIt.call(this, 'There was an error creating the directory.');
  1174. },
  1175. listDir: function (filePath) {
  1176. return mockIt.call(this, 'There was an error listing the directory');
  1177. },
  1178. checkFile: function (filePath) {
  1179. if (this.shouldMockFiles) {
  1180. var defer = $q.defer();
  1181. if (this.files[filePath] && this.files[filePath].isFile) {
  1182. defer.resolve();
  1183. } else {
  1184. defer.reject();
  1185. }
  1186. return defer.promise;
  1187. }
  1188. return mockIt.call(this, 'There was an error checking for the file.');
  1189. },
  1190. createFile: function (filePath, overwrite) {
  1191. if (this.shouldMockFiles) {
  1192. var defer = $q.defer();
  1193. this.files[filePath] = {
  1194. isFile: true,
  1195. fileContent: ''
  1196. };
  1197. defer.resolve();
  1198. return defer.promise;
  1199. }
  1200. return mockIt.call(this, 'There was an error creating the file.');
  1201. },
  1202. removeFile: function (directory, file) {
  1203. return mockIt.call(this, 'There was an error removng the file.');
  1204. },
  1205. writeFile: function (filePath, data, options) {
  1206. if (this.shouldMockFiles && filePath && data) {
  1207. this.files[filePath] = {
  1208. isFile: true,
  1209. fileContent: data
  1210. };
  1211. }
  1212. return mockIt.call(this, 'There was an error writing the file.');
  1213. },
  1214. readFile: function (filePath) {
  1215. return this.readAsText(filePath);
  1216. },
  1217. readAsText: function (filePath) {
  1218. if (this.shouldMockFiles) {
  1219. var defer = $q.defer();
  1220. if (files[filePath] && files[filePath].isFile) {
  1221. defer.resolve(files[filePath].fileContent);
  1222. } else {
  1223. defer.reject();
  1224. }
  1225. return defer.promise;
  1226. }
  1227. return mockIt.call(this, 'There was an error reading the file as text.');
  1228. },
  1229. readAsDataURL: function (filePath) {
  1230. return mockIt.call(this, 'There was an error reading the file as a data url.');
  1231. },
  1232. readAsBinaryString: function (filePath) {
  1233. return mockIt.call(this, 'There was an error reading the file as a binary string.');
  1234. },
  1235. readAsArrayBuffer: function (filePath) {
  1236. return mockIt.call(this, 'There was an error reading the file as an array buffer.');
  1237. },
  1238. readFileMetadata: function (filePath) {
  1239. return mockIt.call(this, 'There was an error reading the file metadata');
  1240. },
  1241. readFileAbsolute: function (filePath) {
  1242. return mockIt.call(this, 'There was an error reading the file from the absolute path');
  1243. },
  1244. readFileMetadataAbsolute: function (filePath) {
  1245. return mockIt.call(this, 'There was an error reading the file metadta from the absolute path');
  1246. }
  1247. };
  1248. }]);
  1249. /**
  1250. * @ngdoc service
  1251. * @name ngCordovaMocks.cordovaFileOpener2
  1252. *
  1253. * @description
  1254. * A service for testing fileOpener2
  1255. * in an app build with ngCordova.
  1256. */
  1257. ngCordovaMocks.factory('$cordovaFileOpener2', ['$q', function ($q) {
  1258. var throwsError = false;
  1259. return {
  1260. /**
  1261. * @ngdoc property
  1262. * @name throwsError
  1263. * @propertyOf ngCordovaMocks.cordovaFileOpener2
  1264. *
  1265. * @description
  1266. * A flag that signals whether a promise should be rejected or not.
  1267. * This property should only be used in automated tests.
  1268. **/
  1269. throwsError: throwsError,
  1270. open: function (file, type) {
  1271. var defer = $q.defer();
  1272. if (this.throwError) {
  1273. defer.reject({
  1274. status: 0,
  1275. message: 'There was an error capturing the file.'
  1276. });
  1277. } else {
  1278. defer.resolve();
  1279. }
  1280. return defer.promise;
  1281. },
  1282. uninstall: function (pack) {
  1283. var defer = $q.defer();
  1284. if (this.throwError) {
  1285. defer.reject({
  1286. status: 0,
  1287. message: 'There was an error capturing the packageId.'
  1288. });
  1289. } else {
  1290. defer.resolve();
  1291. }
  1292. return defer.promise;
  1293. },
  1294. appIsInstalled: function (pack) {
  1295. var defer = $q.defer();
  1296. if (this.throwError) {
  1297. defer.reject({
  1298. status: 0,
  1299. message: 'There was an error capturing the packageId.'
  1300. });
  1301. } else {
  1302. defer.resolve();
  1303. }
  1304. return defer.promise;
  1305. }
  1306. };
  1307. }]);
  1308. /**
  1309. * @ngdoc service
  1310. * @name ngCordovaMocks.cordovaFileTransfer
  1311. *
  1312. * @description
  1313. * A service for testing download and upload
  1314. * in an app build with ngCordova.
  1315. */
  1316. ngCordovaMocks.factory('$cordovaFileTransfer', ['$q', function ($q) {
  1317. var throwsError = false;
  1318. var mockIt = function (errorMessage) {
  1319. var defer = $q.defer();
  1320. if (this.throwsError) {
  1321. defer.reject(errorMessage);
  1322. } else {
  1323. defer.resolve();
  1324. }
  1325. return defer.promise;
  1326. };
  1327. return {
  1328. /**
  1329. * @ngdoc property
  1330. * @name throwsError
  1331. * @propertyOf ngCordovaMocks.cordovaFileTransfer
  1332. *
  1333. * @description
  1334. * A flag that signals whether a promise should be rejected or not.
  1335. * This property should only be used in automated tests.
  1336. **/
  1337. throwsError: throwsError,
  1338. download: function (source, filePath, options, trust) {
  1339. return mockIt.call(this, 'There was an error downloading the file.');
  1340. },
  1341. upload: function (server, filePath, options) {
  1342. return mockIt.call(this, 'There was an error uploading the file.');
  1343. }
  1344. };
  1345. }]);
  1346. /**
  1347. * @ngdoc service
  1348. * @name ngCordovaMocks.cordovaGeolocation
  1349. *
  1350. * @description
  1351. * A service for testing location services
  1352. * in an app build with ngCordova.
  1353. */
  1354. ngCordovaMocks.factory('$cordovaGeolocation', ['$interval', '$q', function ($interval, $q) {
  1355. var throwsError = false;
  1356. var useHostAbilities = true;
  1357. var watchIntervals = [];
  1358. var locations = [];
  1359. var currentPosition = null;
  1360. var nextPosition = null;
  1361. return {
  1362. /**
  1363. @ngdoc property
  1364. @name throwsError
  1365. @propertyOf ngCordovaMocks.cordovaGeolocation
  1366. @description
  1367. A flag that signals whether a promise should be rejected or not.
  1368. This property should only be used in automated tests.
  1369. */
  1370. throwsError: throwsError,
  1371. /**
  1372. @ngdoc property
  1373. @name watchIntervals
  1374. @propertyOf ngCordovaMocks.cordovaGeolocation
  1375. @description
  1376. The collection of watchers that are currently active.
  1377. This property should only be used in automated tests.
  1378. */
  1379. watchIntervals: watchIntervals,
  1380. /**
  1381. @ngdoc property
  1382. @name locations
  1383. @propertyOf ngCordovaMocks.cordovaGeolocation
  1384. @description
  1385. The collection of 'locations' that have been logged.
  1386. This property should only be used in automated tests.
  1387. */
  1388. locations: locations,
  1389. /**
  1390. @ngdoc property
  1391. @name currentPosition
  1392. @propertyOf ngCordovaMocks.cordovaGeolocation
  1393. @description
  1394. The last location logged.
  1395. This property should only be used in automated tests.
  1396. */
  1397. currentPosition: currentPosition,
  1398. /**
  1399. @ngdoc property
  1400. @name nextPosition
  1401. @propertyOf ngCordovaMocks.cordovaGeolocation
  1402. @description
  1403. The position to be logged the next time that a watcher
  1404. gets the location.
  1405. This property should only be used in automated tests.
  1406. */
  1407. nextPosition: nextPosition,
  1408. /**
  1409. @ngdoc property
  1410. @name useHostAbilities
  1411. @propertyOf ngCordovaMocks.cordovaGeolocation
  1412. @description
  1413. A flag that signals whether or not to try and use the host's
  1414. (browser or otherwise) geolocation capabilities.
  1415. This property should only be used in automated tests.
  1416. */
  1417. useHostAbilities: useHostAbilities,
  1418. getCurrentPosition: function (options) {
  1419. var defer = $q.defer();
  1420. if (this.throwsError) {
  1421. defer.reject('There was an error getting the location.');
  1422. } else {
  1423. if (options) {
  1424. options = options; // This is just to get by JSHint.
  1425. }
  1426. if (this.useHostAbilities) {
  1427. if (navigator.geolocation) {
  1428. navigator.geolocation.getCurrentPosition(
  1429. function (position) {
  1430. this.currentPosition = position;
  1431. defer.resolve(this.currentPosition);
  1432. },
  1433. function (error) {
  1434. defer.reject(error);
  1435. }
  1436. );
  1437. } else {
  1438. defer.reject('Geolocation is not supported by this browser.');
  1439. }
  1440. } else {
  1441. defer.resolve(this.currentPosition);
  1442. }
  1443. }
  1444. return defer.promise;
  1445. },
  1446. watchPosition: function (options) {
  1447. var defer = $q.defer();
  1448. var watchID = Math.floor((Math.random() * 1000000) + 1);
  1449. var self = this;
  1450. self.locations = [];
  1451. if (self.throwsError) {
  1452. defer.reject('There was an error getting the geolocation.');
  1453. } else {
  1454. var delay = 1000;
  1455. if (options && options.timeout) {
  1456. delay = options.timeout;
  1457. }
  1458. self.watchIntervals.push({
  1459. watchID: watchID,
  1460. interval: $interval(
  1461. function () {
  1462. if (self.throwsError) {
  1463. defer.reject('There was an error watching the geolocation.');
  1464. }
  1465. // Attempt to use nextPosition.
  1466. var result = self.nextPosition;
  1467. if (result === null) {
  1468. // Determine whether to use the host's geolocation capabilities or not
  1469. if (self.useHostAbilities) {
  1470. if (navigator.geolocation) {
  1471. navigator.geolocation.getCurrentPosition(
  1472. function (position) {
  1473. self.currentPosition = position;
  1474. self.locations.push(position);
  1475. defer.resolve(position);
  1476. },
  1477. function (error) {
  1478. defer.reject(error);
  1479. }
  1480. );
  1481. } else {
  1482. defer.reject('Geolocation is not supported by this browser.');
  1483. }
  1484. } else {
  1485. result = {
  1486. coords: {
  1487. latitude: ((Math.random() * 180) + 1) - 90,
  1488. longitude: ((Math.random() * 360) + 1) - 180,
  1489. altitude: ((Math.random() * 100) + 1),
  1490. accuracy: ((Math.random() * 10) + 1),
  1491. altitudeAccuracy: ((Math.random() * 10) + 1),
  1492. heading: ((Math.random() * 360) + 1),
  1493. speed: ((Math.random() * 100) + 1)
  1494. },
  1495. timestamp: Date.now()
  1496. };
  1497. self.currentPosition = result;
  1498. self.locations.push(result);
  1499. defer.notify(result);
  1500. }
  1501. }
  1502. },
  1503. delay
  1504. )
  1505. });
  1506. }
  1507. var cancel = function (id) {
  1508. var removed = -1;
  1509. for (var i = 0; i < self.watchIntervals.length; i++) {
  1510. if (self.watchIntervals[i].watchID === id) {
  1511. $interval.cancel(watchIntervals[i].interval);
  1512. removed = i;
  1513. break;
  1514. }
  1515. }
  1516. if (removed !== -1) {
  1517. self.watchIntervals.splice(removed, 1);
  1518. }
  1519. };
  1520. defer.promise.cancel = function () {
  1521. cancel(watchID);
  1522. };
  1523. defer.promise.clearWatch = function (id) {
  1524. cancel(id || watchID);
  1525. };
  1526. defer.promise.watchID = watchID;
  1527. return defer.promise;
  1528. },
  1529. clearWatch: function (watchID) {
  1530. var defer = $q.defer();
  1531. if (watchID) {
  1532. if (this.throwsError) {
  1533. defer.reject('Unable to clear watch.');
  1534. } else {
  1535. var removed = -1;
  1536. for (var i = 0; i < this.watchIntervals.length; i++) {
  1537. if (this.watchIntervals[i].watchID === watchID) {
  1538. $interval.cancel(watchIntervals[i].interval);
  1539. removed = i;
  1540. break;
  1541. }
  1542. }
  1543. if (removed !== -1) {
  1544. this.watchIntervals.splice(removed, 1);
  1545. }
  1546. }
  1547. } else {
  1548. defer.reject('Unable to clear watch. No watch ID provided.');
  1549. }
  1550. return defer.promise;
  1551. }
  1552. };
  1553. }]);
  1554. /**
  1555. * @ngdoc service
  1556. * @name ngCordovaMocks.cordovaGlobalization
  1557. *
  1558. * @description
  1559. * A service for testing features related to a user's locale and timezone.
  1560. * in an app build with ngCordova.
  1561. */
  1562. ngCordovaMocks.factory('$cordovaGlobalization', ['$q', function ($q) {
  1563. var throwsError = false;
  1564. var language = (navigator.language) ? navigator.language : 'en-US';
  1565. var preferredLanguage = {value: language};
  1566. var firstDayOfWeek = 'Sunday';
  1567. var localeName = {value: language};
  1568. return {
  1569. /**
  1570. * @ngdoc property
  1571. * @name throwsError
  1572. * @propertyOf ngCordovaMocks.cordovaGlobalization
  1573. *
  1574. * @description
  1575. * A flag that signals whether a promise should be rejected or not.
  1576. * This property should only be used in automated tests.
  1577. **/
  1578. throwsError: throwsError,
  1579. /**
  1580. * @ngdoc property
  1581. * @name preferredLanguage
  1582. * @propertyOf ngCordovaMocks.cordovaGlobalization
  1583. *
  1584. * @description
  1585. * The user's preferred language.
  1586. * This property should only be used in automated tests.
  1587. **/
  1588. preferredLanguage: preferredLanguage,
  1589. /**
  1590. * @ngdoc property
  1591. * @name localeName
  1592. * @propertyOf ngCordovaMocks.cordovaGlobalization
  1593. *
  1594. * @description
  1595. * The name of the user's locale.
  1596. * This property should only be used in automated tests.
  1597. **/
  1598. localeName: localeName,
  1599. /**
  1600. * @ngdoc property
  1601. * @name firstDayOfWeek
  1602. * @propertyOf ngCordovaMocks.cordovaGlobalization
  1603. *
  1604. * @description
  1605. * The first day of the week based on the user's locale.
  1606. * This property should only be used in automated tests.
  1607. **/
  1608. firstDayOfWeek: firstDayOfWeek,
  1609. getPreferredLanguage: function () {
  1610. var defer = $q.defer();
  1611. if (this.throwsError) {
  1612. defer.reject('There was an error getting the preferred language.');
  1613. } else {
  1614. defer.resolve(this.preferredLanguage);
  1615. }
  1616. return defer.promise;
  1617. },
  1618. getLocaleName: function () {
  1619. var defer = $q.defer();
  1620. if (this.throwsError) {
  1621. defer.reject('There was an error getting the locale name.');
  1622. } else {
  1623. defer.resolve(this.localeName);
  1624. }
  1625. return defer.promise;
  1626. },
  1627. getFirstDayOfWeek: function () {
  1628. var defer = $q.defer();
  1629. if (this.throwsError) {
  1630. defer.reject('There was an error getting the first day of week.');
  1631. } else {
  1632. defer.resolve(this.firstDayOfWeek);
  1633. }
  1634. return defer.promise;
  1635. },
  1636. dateToString: function (date, options) {
  1637. var defer = $q.defer();
  1638. if (this.throwsError) {
  1639. defer.reject('There was an error getting the string from the date.');
  1640. } else {
  1641. var result = '';
  1642. // TODO: Review
  1643. date = date;
  1644. options = options;
  1645. // END TODO: Review
  1646. defer.resolve(result);
  1647. }
  1648. return defer.promise;
  1649. },
  1650. stringToDate: function (dateString, options) {
  1651. var defer = $q.defer();
  1652. if (this.throwsError) {
  1653. defer.reject('There was an error getting the date from the string.');
  1654. } else {
  1655. var result = '';
  1656. // TODO: Review
  1657. dateString = dateString;
  1658. options = options;
  1659. // END TODO: Review
  1660. defer.resolve(result);
  1661. }
  1662. return defer.promise;
  1663. },
  1664. getDatePattern: function (options) {
  1665. var defer = $q.defer();
  1666. if (this.throwsError) {
  1667. defer.reject('There was an error getting the date pattern.');
  1668. } else {
  1669. var result = '';
  1670. // TODO: Review
  1671. options = options;
  1672. // END TODO: Review
  1673. defer.resolve(result);
  1674. }
  1675. return defer.promise;
  1676. },
  1677. getDateNames: function (options) {
  1678. var defer = $q.defer();
  1679. if (this.throwsError) {
  1680. defer.reject('There was an error getting the date names.');
  1681. } else {
  1682. var result = '';
  1683. // TODO: Review
  1684. options = options;
  1685. // END TODO: Review
  1686. defer.resolve(result);
  1687. }
  1688. return defer.promise;
  1689. },
  1690. isDayLightSavingsTime: function (date) {
  1691. var defer = $q.defer();
  1692. if (this.throwsError) {
  1693. defer.reject('There was an error getting if this is in daylight savings time mode.');
  1694. } else {
  1695. var result = '';
  1696. // TODO: Review
  1697. date = date;
  1698. // END TODO: Review
  1699. defer.resolve(result);
  1700. }
  1701. return defer.promise;
  1702. },
  1703. numberToString: function (number, options) {
  1704. var defer = $q.defer();
  1705. if (this.throwsError) {
  1706. defer.reject('There was an error convertng the number to a string.');
  1707. } else {
  1708. var result = '';
  1709. // TODO: Review
  1710. number = number;
  1711. options = options;
  1712. // END TODO: Review
  1713. defer.resolve(result);
  1714. }
  1715. return defer.promise;
  1716. },
  1717. stringToNumber: function (numberString, options) {
  1718. var defer = $q.defer();
  1719. if (this.throwsError) {
  1720. defer.reject('There was an error convertng the string to a number.');
  1721. } else {
  1722. var result = '';
  1723. // TODO: Review
  1724. options = options;
  1725. // END TODO: Review
  1726. defer.resolve(result);
  1727. }
  1728. return defer.promise;
  1729. },
  1730. getNumberPattern: function (options) {
  1731. var defer = $q.defer();
  1732. if (this.throwsError) {
  1733. defer.reject('There was an error convertng the string to a number.');
  1734. } else {
  1735. var result = '';
  1736. // TODO: Review
  1737. options = options;
  1738. // END TODO: Review
  1739. defer.resolve(result);
  1740. }
  1741. return defer.promise;
  1742. },
  1743. getCurrencyPattern: function (currencyCode) {
  1744. var defer = $q.defer();
  1745. if (this.throwsError) {
  1746. defer.reject('There was an error convertng the string to a number.');
  1747. } else {
  1748. var result = '';
  1749. // TODO: Review
  1750. currencyCode = currencyCode;
  1751. // END TODO: Review
  1752. defer.resolve(result);
  1753. }
  1754. return defer.promise;
  1755. }
  1756. };
  1757. }]);
  1758. /**
  1759. * @ngdoc service
  1760. * @name ngCordovaMocks.cordovaGoogleAnalytics
  1761. *
  1762. * @description
  1763. * A service for testing google analytics services
  1764. * in an app build with ngCordova.
  1765. */
  1766. ngCordovaMocks.factory('$cordovaGoogleAnalytics', ['$q', function ($q) {
  1767. var throwsError = false;
  1768. var methods = {};
  1769. /**
  1770. * @ngdoc property
  1771. * @name throwsError
  1772. * @propertyOf ngCordovaMocks.cordovaGeolocation
  1773. *
  1774. * @description
  1775. * A flag that signals whether a promise should be rejected or not.
  1776. * This property should only be used in automated tests.
  1777. **/
  1778. methods.throwsError = throwsError;
  1779. var methodsName = [
  1780. 'startTrackerWithId',
  1781. 'setUserId',
  1782. 'debugMode',
  1783. 'trackView',
  1784. 'addCustomDimension',
  1785. 'trackEvent',
  1786. 'trackException',
  1787. 'trackTiming',
  1788. 'addTransaction',
  1789. 'addTransactionItem'
  1790. ];
  1791. methodsName.forEach(function (funcName) {
  1792. methods[funcName] = function () {
  1793. var defer = $q.defer();
  1794. (this.throwsError) ?
  1795. defer.reject() :
  1796. defer.resolve();
  1797. return defer.promise;
  1798. };
  1799. });
  1800. return methods;
  1801. }]);
  1802. 'use strict';
  1803. /**
  1804. * @ngdoc service
  1805. * @name ngCordovaMocks.googlePlayGame
  1806. *
  1807. * @description
  1808. * A service for testing Google Play Game features
  1809. * in an app build with ngCordova.
  1810. */
  1811. ngCordovaMocks.factory('$cordovaGooglePlayGame', ['$q', function ($q) {
  1812. var throwsError = false;
  1813. var isSignedIn = false;
  1814. var displayName = '';
  1815. return {
  1816. /**
  1817. * @ngdoc property
  1818. * @name _throwsError
  1819. * @propertyOf ngCordovaMocks.googlePlayGame
  1820. *
  1821. * @description
  1822. * A flag that signals whether a promise should be rejected or not.
  1823. * This property should only be used in automated tests.
  1824. **/
  1825. _throwsError: throwsError,
  1826. /**
  1827. * @ngdoc property
  1828. * @name _isSignedIn
  1829. * @propertyOf ngCordovaMocks.googlePlayGame
  1830. *
  1831. * @description
  1832. * A flag that signals whether a promise should be rejected or not.
  1833. * This property should only be used in automated tests.
  1834. **/
  1835. _isSignedIn: isSignedIn,
  1836. /**
  1837. * @ngdoc property
  1838. * @name _displayName
  1839. * @propertyOf ngCordovaMocks.googlePlayGame
  1840. *
  1841. * @description
  1842. * A flag that signals whether a promise should be rejected or not.
  1843. * This property should only be used in automated tests.
  1844. **/
  1845. _displayName: displayName,
  1846. auth: function () {
  1847. var defer = $q.defer();
  1848. if (this._throwsError) {
  1849. defer.reject('There was a auth error.');
  1850. } else {
  1851. this.isSignedIn = true;
  1852. defer.resolve('SIGN IN SUCCESS');
  1853. }
  1854. return defer.promise;
  1855. },
  1856. signout: function () {
  1857. var defer = $q.defer();
  1858. if (this.throwsError) {
  1859. defer.reject('There was a signout error.');
  1860. } else {
  1861. defer.resolve();
  1862. }
  1863. return defer.promise;
  1864. },
  1865. isSignedIn: function () {
  1866. var defer = $q.defer();
  1867. if (this._throwsError) {
  1868. defer.reject('There was a isSignedIn error.');
  1869. } else {
  1870. defer.resolve({
  1871. 'isSignedIn': this._isSignedIn
  1872. });
  1873. }
  1874. return defer.promise;
  1875. },
  1876. showPlayer: function () {
  1877. var defer = $q.defer();
  1878. if (this.throwsError) {
  1879. defer.reject('There was a showPlayer error.');
  1880. } else {
  1881. defer.resolve({
  1882. 'displayName': this._displayName
  1883. });
  1884. }
  1885. return defer.promise;
  1886. },
  1887. submitScore: function (data) {
  1888. var defer = $q.defer();
  1889. if (this._throwsError) {
  1890. defer.reject('There was a submitScore error.');
  1891. } else {
  1892. defer.resolve('OK');
  1893. }
  1894. return defer.promise;
  1895. },
  1896. showAllLeaderboards: function () {
  1897. var defer = $q.defer();
  1898. if (this.throwsError) {
  1899. defer.reject('There was a showAllLeaderboards error.');
  1900. } else {
  1901. defer.resolve('OK');
  1902. }
  1903. return defer.promise;
  1904. },
  1905. showLeaderboard: function (data) {
  1906. var defer = $q.defer();
  1907. if (this._throwsError) {
  1908. defer.reject('There was a showLeaderboard error.');
  1909. } else {
  1910. defer.resolve('OK');
  1911. }
  1912. return defer.promise;
  1913. },
  1914. unlockAchievement: function (data) {
  1915. var defer = $q.defer();
  1916. if (this.throwsError) {
  1917. defer.reject('There was a unlockAchievement error.');
  1918. } else {
  1919. defer.resolve('OK');
  1920. }
  1921. return defer.promise;
  1922. },
  1923. incrementAchievement: function (data) {
  1924. var defer = $q.defer();
  1925. if (this._throwsError) {
  1926. defer.reject('There was a incrementAchievement error.');
  1927. } else {
  1928. defer.resolve('OK');
  1929. }
  1930. return defer.promise;
  1931. },
  1932. showAchievements: function () {
  1933. var defer = $q.defer();
  1934. if (this.throwsError) {
  1935. defer.reject('There was a showAchievements error.');
  1936. } else {
  1937. defer.resolve('OK');
  1938. }
  1939. return defer.promise;
  1940. }
  1941. };
  1942. }]);
  1943. /**
  1944. * @ngdoc service
  1945. * @name ngCordovaMocks.cordovaKeyboard
  1946. *
  1947. * @description
  1948. * A service for testing device keyboard features
  1949. * in an app build with ngCordova.
  1950. **/
  1951. ngCordovaMocks.factory('$cordovaKeyboard', function () {
  1952. var isVisible = false;
  1953. return {
  1954. hideAccessoryBar: function (bool) {
  1955. },
  1956. close: function () {
  1957. isVisible = false;
  1958. },
  1959. show: function () {
  1960. isVisible = true;
  1961. },
  1962. disableScroll: function (bool) {
  1963. },
  1964. isVisible: function () {
  1965. return isVisible;
  1966. }
  1967. };
  1968. });
  1969. /**
  1970. * @ngdoc service
  1971. * @name ngCordovaMocks.cordovaKeychain
  1972. *
  1973. * @description
  1974. * A service for testing Keychain features
  1975. * in an app built with ngCordova.
  1976. **/
  1977. ngCordovaMocks.factory('$cordovaKeychain', ['$q', function ($q) {
  1978. var keychains = {};
  1979. return {
  1980. /**
  1981. * @ngdoc property
  1982. * @name keychains
  1983. * @propertyOf ngCordovaMocks.cordovaKeychain
  1984. *
  1985. * @description
  1986. * The collection of 'keychains' that have been saved.
  1987. * This property should only be used in automated tests.
  1988. **/
  1989. keychains: keychains,
  1990. getForKey: function (key, serviceName) {
  1991. var defer = $q.defer();
  1992. if (this.keychains[serviceName]) {
  1993. defer.resolve(this.keychains[serviceName][key]);
  1994. } else {
  1995. defer.reject();
  1996. }
  1997. return defer.promise;
  1998. },
  1999. setForKey: function (key, serviceName, value) {
  2000. var defer = $q.defer();
  2001. if (!this.keychains[serviceName]) {
  2002. this.keychains[serviceName] = {};
  2003. }
  2004. this.keychains[serviceName][key] = value;
  2005. defer.resolve();
  2006. return defer.promise;
  2007. },
  2008. removeForKey: function (key, serviceName) {
  2009. var defer = $q.defer();
  2010. if (this.keychains[serviceName]) {
  2011. delete this.keychains[serviceName][key];
  2012. }
  2013. defer.resolve();
  2014. return defer.promise;
  2015. }
  2016. };
  2017. }]);
  2018. /**
  2019. * @ngdoc service
  2020. * @name ngCordovaMocks.localNotification
  2021. *
  2022. * @description
  2023. * A service for testing LocalNotificatio
  2024. * in an app build with ngCordovaMocks.
  2025. */
  2026. ngCordovaMocks.factory('$cordovaLocalNotification', ['$q', function ($q) {
  2027. var storageKeyPfx = "ngCordLocNotif-";
  2028. function pfxId(id) {
  2029. return storageKeyPfx + id;
  2030. }
  2031. function getAllIds(){
  2032. var defer = $q.defer();
  2033. var locNotifIds = [];
  2034. for ( var i = 0, len = localStorage.length; i < len; ++i ) {
  2035. if (localStorage.key( i ).indexOf(storageKeyPfx) > -1)
  2036. locNotifIds.push(parseInt(localStorage.key( i ).split("-")[1]));
  2037. }
  2038. defer.resolve(locNotifIds);
  2039. return defer.promise;
  2040. }
  2041. return {
  2042. cancel: function (ids) {
  2043. var defer = $q.defer();
  2044. if (typeof(ids) == "number") ids = [ids];
  2045. ids.forEach(function (id){
  2046. localStorage.removeItem([pfxId(id)]);
  2047. });
  2048. defer.resolve();
  2049. return defer.promise;
  2050. },
  2051. cancelAll: function () {
  2052. var defer = $q.defer();
  2053. // TODO
  2054. defer.resolve();
  2055. return defer.promise;
  2056. },
  2057. clear: function (ids) {
  2058. if (typeof(ids) == "number") ids = [ids];
  2059. var defer = $q.defer();
  2060. ids.forEach(function (id){
  2061. localStorage.removeItem([pfxId(id)]);
  2062. });
  2063. defer.resolve();
  2064. return defer.promise;
  2065. },
  2066. clearAll: function () {
  2067. var defer = $q.defer();
  2068. // TODO
  2069. // defer.resolve();
  2070. return defer.promise;
  2071. },
  2072. isScheduled: function (id){
  2073. var defer = $q.defer();
  2074. if (localStorage[pfxId(id)]) {
  2075. defer.resolve(true);
  2076. } else {
  2077. defer.resolve(false);
  2078. }
  2079. return defer.promise;
  2080. },
  2081. isPresent: function (id){
  2082. var defer = $q.defer();
  2083. if (localStorage[pfxId(id)]) {
  2084. defer.resolve(true);
  2085. } else {
  2086. defer.resolve(false);
  2087. }
  2088. return defer.promise;
  2089. },
  2090. isTriggered: function (id){
  2091. var defer = $q.defer();
  2092. if (localStorage[pfxId(id)]) {
  2093. defer.resolve(false);
  2094. } else {
  2095. defer.resolve(true);
  2096. }
  2097. return defer.promise;
  2098. },
  2099. getAllIds: function () {
  2100. return getAllIds();
  2101. },
  2102. getIds: function () {
  2103. return getAllIds();
  2104. },
  2105. getScheduledIds: function () {
  2106. return getAllIds();
  2107. },
  2108. getTriggeredIds: function () {
  2109. var defer = $q.defer();
  2110. defer.resolve([]);
  2111. return defer.promise;
  2112. },
  2113. hasPermission: function (id){
  2114. var defer = $q.defer();
  2115. defer.resolve(true);
  2116. return defer.promise;
  2117. },
  2118. schedule: function (data){
  2119. var defer = $q.defer();
  2120. var id = pfxId(data.id);
  2121. localStorage[id] = JSON.stringify(data);
  2122. defer.resolve();
  2123. return defer.promise;
  2124. },
  2125. update: function (data){
  2126. var defer = $q.defer();
  2127. var id = pfxId(data.id);
  2128. localStorage[id] = JSON.stringify(data);
  2129. defer.resolve();
  2130. return defer.promise;
  2131. }
  2132. };
  2133. }]);
  2134. /**
  2135. * @ngdoc service
  2136. * @name ngCordovaMocks.cordovaNetwork
  2137. *
  2138. * @description
  2139. * A service for testing networked fetures
  2140. * in an app build with ngCordova.
  2141. */
  2142. ngCordovaMocks.factory('$cordovaNetwork', ['$rootScope',function ($rootScope) {
  2143. var connectionType = 'WiFi connection';
  2144. var isConnected = true;
  2145. return {
  2146. /**
  2147. * @ngdoc property
  2148. * @name connectionType
  2149. * @propertyOf ngCordovaMocks.cordovaNetwork
  2150. *
  2151. * @description
  2152. * They type of connection. Values should match those found at
  2153. * https://github.com/apache/cordova-plugin-network-information
  2154. * This property should only be used in automated tests.
  2155. **/
  2156. connectionType: connectionType,
  2157. /**
  2158. * @ngdoc property
  2159. * @name isConnected
  2160. * @propertyOf ngCordovaMocks.cordovaNetwork
  2161. *
  2162. * @description
  2163. * A flag that signals whether the app is connected to a network.
  2164. * This property should only be used in automated tests.
  2165. **/
  2166. isConnected: isConnected,
  2167. switchToOnline: function (){
  2168. this.isConnected = true;
  2169. $rootScope.$broadcast('$cordovaNetwork:online');
  2170. },
  2171. switchToOffline: function (){
  2172. this.isConnected = false;
  2173. $rootScope.$broadcast('$cordovaNetwork:offline');
  2174. },
  2175. getNetwork: function () {
  2176. return this.connectionType;
  2177. },
  2178. isOnline: function () {
  2179. return this.isConnected;
  2180. },
  2181. isOffline: function () {
  2182. return !this.isConnected;
  2183. }
  2184. };
  2185. }]);
  2186. /**
  2187. * @ngdoc service
  2188. * @name ngCordovaMocks.cordovaProgress
  2189. *
  2190. * @description
  2191. * A service for testing Progress Indicator
  2192. * in an app build with ngCordova.
  2193. */
  2194. ngCordovaMocks.factory('$cordovaProgress', [
  2195. '$timeout', function ($timeout) {
  2196. return {
  2197. show: function (_message) {
  2198. var message = _message || 'Please wait...';
  2199. console.info('$cordovaProgress.message', message);
  2200. },
  2201. showSimple: function (_dim) {
  2202. var dim = _dim || false;
  2203. console.info('$cordovaProgress.dim', dim);
  2204. },
  2205. showSimpleWithLabel: function (_dim, _label) {
  2206. var dim = _dim || false;
  2207. var label = _label || 'Loading...';
  2208. console.group();
  2209. console.info('$cordovaProgress.dim', dim);
  2210. console.info('$cordovaProgress.label', label);
  2211. console.groupEnd();
  2212. },
  2213. showSimpleWithLabelDetail: function (_dim, _label, _detail) {
  2214. var dim = _dim || false;
  2215. var label = _label || 'Loading...';
  2216. var detail = _detail || 'Please wait';
  2217. console.group();
  2218. console.info('$cordovaProgress.dim', dim);
  2219. console.info('$cordovaProgress.label', label);
  2220. console.info('$cordovaProgress.detail', detail);
  2221. console.groupEnd();
  2222. },
  2223. showDeterminate: function (_dim, _timeout) {
  2224. var dim = _dim || false;
  2225. var timeout = _timeout || 50000;
  2226. console.group();
  2227. console.info('$cordovaProgress.dim show', dim);
  2228. console.info('$cordovaProgress.timeout', timeout);
  2229. console.groupEnd();
  2230. $timeout(function () {
  2231. console.info('$cordovaProgress.dim timeout', dim);
  2232. }, timeout);
  2233. },
  2234. showDeterminateWithLabel: function (_dim, _timeout, _label) {
  2235. var dim = _dim || false;
  2236. var timeout = _timeout || 50000;
  2237. var label = _label || 'Loading...';
  2238. console.group();
  2239. console.info('$cordovaProgress.dim', dim);
  2240. console.info('$cordovaProgress.timeout', timeout);
  2241. console.info('$cordovaProgress.label', label);
  2242. console.groupEnd();
  2243. $timeout(function () {
  2244. console.info('$cordovaProgress[dim, label] timeout', [dim, label]);
  2245. }, timeout);
  2246. },
  2247. showAnnular: function (_dim, _timeout) {
  2248. var dim = _dim || false;
  2249. var timeout = _timeout || 50000;
  2250. console.group();
  2251. console.info('$cordovaProgress.dim', dim);
  2252. console.info('$cordovaProgress.timeout', timeout);
  2253. console.groupEnd();
  2254. $timeout(function () {
  2255. console.info('$cordovaProgress.dim timeout', dim);
  2256. }, timeout);
  2257. },
  2258. showAnnularWithLabel: function (_dim, _timeout, _label) {
  2259. var dim = _dim || false;
  2260. var timeout = _timeout || 50000;
  2261. var label = _label || 'Loading...';
  2262. console.group();
  2263. console.info('$cordovaProgress.dim', dim);
  2264. console.info('$cordovaProgress.timeout', timeout);
  2265. console.info('$cordovaProgress.label', label);
  2266. console.groupEnd();
  2267. $timeout(function () {
  2268. console.info('$cordovaProgress[dim, label] timeout', [dim, label]);
  2269. }, timeout);
  2270. },
  2271. showBar: function (_dim, _timeout) {
  2272. var dim = _dim || false;
  2273. var timeout = _timeout || 50000;
  2274. console.group();
  2275. console.info('$cordovaProgress.dim', dim);
  2276. console.info('$cordovaProgress.timeout', timeout);
  2277. console.groupEnd();
  2278. $timeout(function () {
  2279. console.info('$cordovaProgress.dim timeout', dim);
  2280. }, timeout);
  2281. },
  2282. showBarWithLabel: function (_dim, _timeout, _label) {
  2283. var dim = _dim || false;
  2284. var timeout = _timeout || 50000;
  2285. var label = _label || 'Loading...';
  2286. console.group();
  2287. console.info('$cordovaProgress.dim', dim);
  2288. console.info('$cordovaProgress.label', label);
  2289. console.info('$cordovaProgress.timeout', timeout);
  2290. console.groupEnd();
  2291. $timeout(function () {
  2292. console.info('$cordovaProgress[dim, label] timeout', [dim, label]);
  2293. }, timeout);
  2294. },
  2295. showSuccess: function (_dim, _label) {
  2296. var dim = _dim || false;
  2297. var label = _label || 'Success';
  2298. console.group();
  2299. console.info('$cordovaProgress.dim', dim);
  2300. console.info('$cordovaProgress.label', label);
  2301. console.groupEnd();
  2302. },
  2303. showText: function (_dim, _text, _position) {
  2304. var dim = _dim || false;
  2305. var text = _text || 'Warning';
  2306. var position = _position || 'center';
  2307. console.group();
  2308. console.info('$cordovaProgress.dim', dim);
  2309. console.info('$cordovaProgress.text', text);
  2310. console.info('$cordovaProgress.position', position);
  2311. console.groupEnd();
  2312. },
  2313. hide: function () {
  2314. console.info('$cordovaProgress.hide');
  2315. }
  2316. };
  2317. }
  2318. ]);
  2319. 'use strict';
  2320. /**
  2321. * @ngdoc service
  2322. * @name ngCordovaMocks.cordovaPush
  2323. *
  2324. * @description
  2325. * A service for testing push notifications features
  2326. * in an app build with ngCordova.
  2327. */
  2328. ngCordovaMocks.factory('$cordovaPush', ['$q', '$timeout', '$rootScope', function ($q, $timeout, $rootScope) {
  2329. var throwsError = false;
  2330. var deviceToken = '';
  2331. return {
  2332. /**
  2333. * @ngdoc property
  2334. * @name throwsError
  2335. * @propertyOf ngCordovaMocks.cordovaPush
  2336. *
  2337. * @description
  2338. * A flag that signals whether a promise should be rejected or not.
  2339. * This property should only be used in automated tests.
  2340. **/
  2341. throwsError: throwsError,
  2342. /**
  2343. * @ngdoc property
  2344. * @name deviceToken
  2345. * @propertyOf ngCordovaMocks.cordovaPush
  2346. *
  2347. * @description
  2348. * Token send when service register device
  2349. * This property should only be used in automated tests.
  2350. **/
  2351. deviceToken: deviceToken,
  2352. onNotification: function (notification) {
  2353. $timeout(function () {
  2354. $rootScope.$broadcast('$cordovaPush:notificationReceived', notification);
  2355. });
  2356. },
  2357. register: function (config) {
  2358. var _self = this;
  2359. var defer = $q.defer();
  2360. if (config !== undefined && config.ecb === undefined) {
  2361. config.ecb = this.onNotification;
  2362. }
  2363. if (this.throwsError) {
  2364. defer.reject('There was a register error.');
  2365. } else {
  2366. defer.resolve(this.deviceToken);
  2367. if (config && config.ecb) {
  2368. config.ecb({
  2369. event: 'registered',
  2370. regid: _self.deviceToken
  2371. });
  2372. }
  2373. }
  2374. return defer.promise;
  2375. },
  2376. unregister: function (options) {
  2377. var defer = $q.defer();
  2378. if (this.throwsError) {
  2379. defer.reject('There was a register error.');
  2380. } else {
  2381. defer.resolve();
  2382. }
  2383. return defer.promise;
  2384. },
  2385. };
  2386. }]);
  2387. /**
  2388. * @ngdoc service
  2389. * @name ngCordovaMocks.cordovaScreenshot
  2390. *
  2391. * @description
  2392. * A service for test app screenshot
  2393. * in an app build with ngCordova.
  2394. *
  2395. * @example
  2396. */
  2397. ngCordovaMocks.factory('$cordovaScreenshot', ['$q', function ($q) {
  2398. var throwsError = false;
  2399. var DATA_URI_MOCK = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAABYCAYAAADLGnoRAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAKLJJREFUeNrsfQmcXFWV/qmtqzudpLd0upN0kk46IQsJEHaFYAAVHFCjrC6jqOMCzAz+Hdf/oAjiKHFBnHHUERBxBNmUXZF9DyGEJBjSZO0knXSnO72l91rnfK/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K1h4esPXmxJxPSu0IkXjgtbHHfQRAC1r/N5QPGcTh5wEEDTv7DdvMugF06UgAMCopuDM+oauMcghyQ4dEKYQNHbu7y0sbdiT2QAF7LCFUco5llEQvAAd+ggLtAfvczlO733SugRcLvYXfjdAHs0pEEYEUwFMHQhfxMpca5u4UjW66UsFJjwzPotNB1fYPfmQEWcSQxh4HK3KHufkrECW88XDfqAtilIxHAipDs7loun6T0RGp9whWx6dZQE8XlC7eFgcrcBxeuoNcL1z+s5ALYpSMZwIpOFb30Qhu99GeU2LC7Jdf7oISLJ7bsON44t1G4O7j8iLiSuAB2aVQAXLur3S6A/XATdoC7jgYmu4PrIiKU4EwRynD9WcJZVxjHEQKJfFC/Eu4+YuQC2KWRorToH2zxGRt5d0ds44hlpysoPYMlRO3fUGJjpw/aXIfskkiT+rwBXsQBwzC2TDh5n/uaXToqAPxsbZC2A8Qjn6YNa6/YZhIxxvBH1veeOYkSnlGPC5eG1xf27MEu6rrfMnr9W6kDHbjJfb0uHVUi9MduidOM0gidMT9kOUn4vaO2jxHySSvXzALtOERpBCmaqWcfEz33xdF+oHBCWVztitAujQIHhitjfaufXngnSBt2B6g/PGrboGBtFktA2GD5Ae14ngFe7GqOnc8vHG3wYqoL8fPa2+ZzR5VLowNgxUEa23308tagVTp6vKPZv/UC0HMFoK1S4Pp4lQ3ARxy0sBlgomvt8tLmRj89sznfHVUujRj9nwADAFIAdCgbzMwPAAAAAElFTkSuQmCC";
  2400. return {
  2401. /**
  2402. * @ngdoc property
  2403. * @name throwsError
  2404. * @propertyOf ngCordovaMocks.cordovaScreenshot
  2405. *
  2406. * @description
  2407. * A flag that signals whether a promise should be rejected or not.
  2408. * This property should only be used in automated tests.
  2409. **/
  2410. throwsError: throwsError,
  2411. captureToFile: function () {
  2412. var defer = $q.defer();
  2413. if (this.throwsError) {
  2414. defer.reject('There was an error capturing the screenshot.');
  2415. } else {
  2416. defer.resolve("path");
  2417. }
  2418. return defer.promise;
  2419. },
  2420. captureToUri: function () {
  2421. var defer = $q.defer();
  2422. if (this.throwsError) {
  2423. defer.reject('There was an error capturing the screenshot.');
  2424. } else {
  2425. defer.resolve();
  2426. }
  2427. return defer.promise;
  2428. }
  2429. };
  2430. }]);
  2431. /**
  2432. * @ngdoc service
  2433. * @name ngCordovaMocks.cordovaSocialSharing
  2434. *
  2435. * @description
  2436. * A service for testing via social services
  2437. * in an app build with ngCordova.
  2438. */
  2439. ngCordovaMocks.factory('$cordovaSocialSharing', ['$q', function ($q) {
  2440. var throwsError = false;
  2441. var message = '';
  2442. var image = '';
  2443. var link = '';
  2444. var number = '';
  2445. var socialService = '';
  2446. var subject = '';
  2447. var toAddresses = [];
  2448. var bccAddresses = [];
  2449. var attachments = [];
  2450. return {
  2451. /**
  2452. * @ngdoc property
  2453. * @name throwsError
  2454. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2455. *
  2456. * @description
  2457. * A flag that signals whether a promise should be rejected or not.
  2458. * This property should only be used in automated tests.
  2459. **/
  2460. throwsError: throwsError,
  2461. /**
  2462. * @ngdoc property
  2463. * @name message
  2464. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2465. *
  2466. * @description
  2467. * The message to be shared via a social service.
  2468. * This property should only be used in automated tests.
  2469. **/
  2470. message: message,
  2471. /**
  2472. * @ngdoc property
  2473. * @name image
  2474. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2475. *
  2476. * @description
  2477. * An image to be shared via a social service.
  2478. * This property should only be used in automated tests.
  2479. **/
  2480. image: image,
  2481. /**
  2482. * @ngdoc property
  2483. * @name link
  2484. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2485. *
  2486. * @description
  2487. * A link to be shared via a social service.
  2488. * This property should only be used in automated tests.
  2489. **/
  2490. link: link,
  2491. /**
  2492. * @ngdoc property
  2493. * @name number
  2494. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2495. *
  2496. * @description
  2497. * A comma-delimited list of phone numbers to send a social message to.
  2498. * This property should only be used in automated tests.
  2499. **/
  2500. number: number,
  2501. /**
  2502. * @ngdoc property
  2503. * @name subject
  2504. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2505. *
  2506. * @description
  2507. * The subject of an email.
  2508. * This property should only be used in automated tests.
  2509. **/
  2510. subject: subject,
  2511. /**
  2512. * @ngdoc property
  2513. * @name toAddresses
  2514. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2515. *
  2516. * @description
  2517. * An array of email addresses to send an email to.
  2518. * This property should only be used in automated tests.
  2519. **/
  2520. toAddresses: toAddresses,
  2521. /**
  2522. * @ngdoc property
  2523. * @name bccAddresses
  2524. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2525. *
  2526. * @description
  2527. * An array of email addresses to blind carbon-copy an email to.
  2528. * This property should only be used in automated tests.
  2529. **/
  2530. bccAddresses: bccAddresses,
  2531. /**
  2532. * @ngdoc property
  2533. * @name socialService
  2534. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2535. *
  2536. * @description
  2537. * The name of a social service to share content through.
  2538. * This property should only be used in automated tests.
  2539. **/
  2540. socialService: socialService,
  2541. /**
  2542. * @ngdoc property
  2543. * @name attachments
  2544. * @propertyOf ngCordovaMocks.cordovaSocialSharing
  2545. *
  2546. * @description
  2547. * An array of attachments to include with an email to be sent.
  2548. * This property should only be used in automated tests.
  2549. **/
  2550. attachments: attachments,
  2551. shareViaTwitter: function (message, image, link) {
  2552. var defer = $q.defer();
  2553. if (this.throwsError) {
  2554. defer.reject('There was an error sharing via Twitter.');
  2555. } else {
  2556. this.message = message;
  2557. this.image = image;
  2558. this.link = link;
  2559. defer.resolve();
  2560. }
  2561. return defer.promise;
  2562. },
  2563. shareViaWhatsApp: function (message, image, link) {
  2564. var defer = $q.defer();
  2565. if (this.throwsError) {
  2566. defer.reject('There was an error sharing via WhatsApp.');
  2567. } else {
  2568. this.message = message;
  2569. this.image = image;
  2570. this.link = link;
  2571. defer.resolve();
  2572. }
  2573. return defer.promise;
  2574. },
  2575. shareViaFacebook: function (message, image, link) {
  2576. var defer = $q.defer();
  2577. if (this.throwsError) {
  2578. defer.reject('There was an error sharing via Facebook.');
  2579. } else {
  2580. this.message = message;
  2581. this.image = image;
  2582. this.link = link;
  2583. defer.resolve();
  2584. }
  2585. return defer.promise;
  2586. },
  2587. shareViaSMS: function (message, number) {
  2588. var defer = $q.defer();
  2589. if (this.throwsError) {
  2590. defer.reject('There was an error sharing via SMS.');
  2591. } else {
  2592. this.message = message;
  2593. this.number = number;
  2594. defer.resolve();
  2595. }
  2596. return defer.promise;
  2597. },
  2598. shareViaEmail: function (message, subject, toArr, bccArr, file) {
  2599. var defer = $q.defer();
  2600. if (this.throwsError) {
  2601. defer.reject('There was an error sharing via SMS.');
  2602. } else {
  2603. // These are added to get by JSHINT for now
  2604. this.message = message;
  2605. this.subject = subject;
  2606. this.toAddresses = toArr;
  2607. this.bccAddressesc = bccArr;
  2608. this.attachments = file;
  2609. defer.resolve();
  2610. }
  2611. return defer.promise;
  2612. },
  2613. canShareViaEmail: function () {
  2614. var defer = $q.defer();
  2615. if (this.throwsError) {
  2616. defer.reject(false);
  2617. } else {
  2618. defer.resolve(true);
  2619. }
  2620. return defer.promise;
  2621. },
  2622. canShareVia: function (via, message, subject, file, link) {
  2623. var defer = $q.defer();
  2624. if (this.throwsError) {
  2625. defer.reject('There was an error sharing via SMS.');
  2626. } else {
  2627. // These are added to get by JSHINT for now
  2628. this.message = message;
  2629. this.socialService = via;
  2630. this.subject = subject;
  2631. this.attachments = file;
  2632. this.link = link;
  2633. defer.resolve();
  2634. }
  2635. return defer.promise;
  2636. },
  2637. shareVia: function (via, message, subject, file, link) {
  2638. var defer = $q.defer();
  2639. if (this.throwsError) {
  2640. defer.reject('There was an error sharing via SMS.');
  2641. } else {
  2642. this.socialService = via;
  2643. this.message = message;
  2644. this.subject = subject;
  2645. this.attachments = file;
  2646. this.link = link;
  2647. defer.resolve();
  2648. }
  2649. return defer.promise;
  2650. },
  2651. share: function (message, subject, file, link) {
  2652. var defer = $q.defer();
  2653. if (this.throwsError) {
  2654. defer.reject('There was an error sharing via SMS.');
  2655. } else {
  2656. this.message = message;
  2657. this.subject = subject;
  2658. this.attachments = file;
  2659. this.link = link;
  2660. defer.resolve();
  2661. }
  2662. return defer.promise;
  2663. },
  2664. shareWithOptions: function (options) {
  2665. var defer = $q.defer();
  2666. if (this.throwsError) {
  2667. defer.reject('There was an error sharing via SMS.');
  2668. } else {
  2669. this.message = options.message;
  2670. this.subject = options.subject;
  2671. this.attachments = options.files;
  2672. this.link = options.url;
  2673. defer.resolve();
  2674. }
  2675. return defer.promise;
  2676. }
  2677. };
  2678. }]);
  2679. /**
  2680. * @ngdoc service
  2681. * @name ngCordovaMocks.cordovaSplashscreen
  2682. *
  2683. * @description
  2684. * A service for testing the splash screen
  2685. * in an app build with ngCordova.
  2686. */
  2687. ngCordovaMocks.factory('$cordovaSplashscreen', function () {
  2688. var isVisible = false;
  2689. return {
  2690. /**
  2691. * @ngdoc property
  2692. * @name isVisible
  2693. * @propertyOf ngCordovaMocks.cordovaSplashscreen
  2694. *
  2695. * @description
  2696. * A flag that signals whether the splash screen is visible or not.
  2697. * This property should only be used in automated tests.
  2698. **/
  2699. isVisible: isVisible,
  2700. hide: function () {
  2701. // do nothing. everything happens behind the scenes in this case.
  2702. // its a stub that is present for completeness.
  2703. this.isVisible = false;
  2704. return true;
  2705. },
  2706. show: function () {
  2707. // do nothing. everything happens behind the scenes in this case.
  2708. // its a stub that is present for completeness.
  2709. this.isVisible = true;
  2710. return true;
  2711. }
  2712. };
  2713. });
  2714. /**
  2715. * @ngdoc service
  2716. * @name ngCordovaMocks.cordovaSQLite
  2717. *
  2718. * @description
  2719. * A service for testing SQLite
  2720. * in an app build with ngCordova.
  2721. */
  2722. ngCordovaMocks.factory('$cordovaSQLite', ['$q', function ($q) {
  2723. return {
  2724. /**
  2725. * These properties are here for the purpose of automated testing only.
  2726. **/
  2727. openDBShouldSucceedWith: null,
  2728. executeShouldSucceedWith: null,
  2729. insertCollectionShouldSucceedWith: null,
  2730. nestedExecuteShouldSucceedWith: null,
  2731. deleteDBShouldSucceedWith : null,
  2732. openDB: function (options, background) {
  2733. if (this.openDBShouldSucceedWith !== null) {
  2734. $q.when(this.openDBShouldSucceedWith)
  2735. } else {
  2736. $q.reject()
  2737. }
  2738. },
  2739. execute: function (db, query, binding) {
  2740. if (this.executeShouldSucceedWith !== null) {
  2741. $q.when(this.executeShouldSucceedWith)
  2742. } else {
  2743. $q.reject()
  2744. }
  2745. },
  2746. insertCollection: function (db, query, bindings) {
  2747. if (this.insertCollectionShouldSucceedWith !== null) {
  2748. $q.when(this.insertCollectionShouldSucceedWith)
  2749. } else {
  2750. $q.reject()
  2751. }
  2752. },
  2753. nestedExecute: function (db, query1, query2, binding1, binding2) {
  2754. if (this.nestedExecuteShouldSucceedWith !== null) {
  2755. $q.when(this.nestedExecuteShouldSucceedWith)
  2756. } else {
  2757. $q.reject()
  2758. }
  2759. },
  2760. deleteDB: function (dbName) {
  2761. if (this.deleteDBShouldSucceedWith !== null) {
  2762. $q.when(this.deleteDBShouldSucceedWith)
  2763. } else {
  2764. $q.reject()
  2765. }
  2766. }
  2767. }
  2768. }]);
  2769. /**
  2770. * @ngdoc service
  2771. * @name ngCordovaMocks.cordovaStatusbar
  2772. *
  2773. * @description
  2774. * A service for testing the status bar
  2775. * in an app build with ngCordova.
  2776. */
  2777. ngCordovaMocks.factory('$cordovaStatusbar', function () {
  2778. var isStatusBarVisible = true;
  2779. var canOverlayWebView = true;
  2780. return {
  2781. /**
  2782. * @ngdoc property
  2783. * @name isStatusBarVisible
  2784. * @propertyOf ngCordovaMocks.cordovaStatusbar
  2785. *
  2786. * @description
  2787. * A flag that signals whether the status bar is visible or not.
  2788. * This property should only be used in automated tests.
  2789. **/
  2790. isStatusBarVisible: isStatusBarVisible,
  2791. /**
  2792. * @ngdoc property
  2793. * @name canOverlayWebView
  2794. * @propertyOf ngCordovaMocks.cordovaStatusbar
  2795. *
  2796. * @description
  2797. * A flag that signals whether the status bar can overlay the web view.
  2798. * This property should only be used in automated tests.
  2799. **/
  2800. canOverlayWebView: canOverlayWebView,
  2801. overlaysWebView: function (bool) {
  2802. this.canOverlayWebView = bool;
  2803. },
  2804. style: function (style) {
  2805. // TODO: Review
  2806. return style;
  2807. },
  2808. styleHex: function (colorHex) {
  2809. // TODO: review
  2810. return colorHex;
  2811. },
  2812. styleColor: function (color) {
  2813. // TODO: review
  2814. return color;
  2815. },
  2816. hide: function () {
  2817. this.isStatusBarVisible = false;
  2818. },
  2819. show: function () {
  2820. this.isStatusBarVisible = true;
  2821. },
  2822. isVisible: function () {
  2823. return this.isStatusBarVisible;
  2824. }
  2825. };
  2826. });
  2827. /**
  2828. * @ngdoc service
  2829. * @name ngCordovaMocks.cordovaToast
  2830. *
  2831. * @description
  2832. * A service for testing toasts
  2833. * in an app build with ngCordova.
  2834. *
  2835. * @example
  2836. */
  2837. ngCordovaMocks.factory('$cordovaToast', ['$q', function ($q) {
  2838. var throwsError = false;
  2839. return {
  2840. /**
  2841. * @ngdoc property
  2842. * @name throwsError
  2843. * @propertyOf ngCordovaMocks.cordovaToast
  2844. *
  2845. * @description
  2846. * A flag that signals whether a promise should be rejected or not.
  2847. * This property should only be used in automated tests.
  2848. **/
  2849. throwsError: throwsError,
  2850. showShortTop: function (message) {
  2851. var defer = $q.defer();
  2852. if (this.throwsError) {
  2853. defer.reject('There was an error showing the toast.');
  2854. } else {
  2855. defer.resolve();
  2856. }
  2857. return defer.promise;
  2858. },
  2859. showShortCenter: function (message) {
  2860. var defer = $q.defer();
  2861. if (this.throwsError) {
  2862. defer.reject('There was an error showing the toast.');
  2863. } else {
  2864. defer.resolve();
  2865. }
  2866. return defer.promise;
  2867. },
  2868. showShortBottom: function (message) {
  2869. var defer = $q.defer();
  2870. if (this.throwsError) {
  2871. defer.reject('There was an error showing the toast.');
  2872. } else {
  2873. defer.resolve();
  2874. }
  2875. return defer.promise;
  2876. },
  2877. showLongTop: function (message) {
  2878. var defer = $q.defer();
  2879. if (this.throwsError) {
  2880. defer.reject('There was an error showing the toast.');
  2881. } else {
  2882. defer.resolve();
  2883. }
  2884. return defer.promise;
  2885. },
  2886. showLongCenter: function (message) {
  2887. var defer = $q.defer();
  2888. if (this.throwsError) {
  2889. defer.reject('There was an error showing the toast.');
  2890. } else {
  2891. defer.resolve();
  2892. }
  2893. return defer.promise;
  2894. },
  2895. showLongBottom: function (message) {
  2896. var defer = $q.defer();
  2897. if (this.throwsError) {
  2898. defer.reject('There was an error showing the toast.');
  2899. } else {
  2900. defer.resolve();
  2901. }
  2902. return defer.promise;
  2903. },
  2904. showWithOptions: function (options) {
  2905. var defer = $q.defer();
  2906. if (this.throwsError) {
  2907. defer.reject('There was an error showing the toast.');
  2908. } else {
  2909. defer.resolve();
  2910. }
  2911. return defer.promise;
  2912. },
  2913. show: function (message, duration, position) {
  2914. var defer = $q.defer();
  2915. if (this.throwsError) {
  2916. defer.reject('There was an error showing the toast.');
  2917. } else {
  2918. defer.resolve();
  2919. }
  2920. return defer.promise;
  2921. },
  2922. hide: function () {
  2923. var defer = $q.defer();
  2924. if (this.throwsError) {
  2925. defer.reject('There was an error hiding the toast.');
  2926. } else {
  2927. defer.resolve();
  2928. }
  2929. return defer.promise;
  2930. }
  2931. };
  2932. }]);
  2933. /**
  2934. * @ngdoc service
  2935. * @name ngCordovaMocks.cordovaVibration
  2936. *
  2937. * @description
  2938. * A service for testing vibration
  2939. * in an app build with ngCordova.
  2940. */
  2941. ngCordovaMocks.factory('$cordovaVibration', ['$timeout', function ($timeout) {
  2942. var isVibrating = false;
  2943. var vibrateTimer = null;
  2944. return {
  2945. /**
  2946. * @ngdoc property
  2947. * @name vibrateTimer
  2948. * @propertyOf ngCordovaMocks.cordovaVibration
  2949. *
  2950. * @description
  2951. * Access to the timer associated with vibration.
  2952. * This property should only be used in automated tests.
  2953. **/
  2954. vibrateTimer: vibrateTimer,
  2955. /**
  2956. * @ngdoc property
  2957. * @name isVibrating
  2958. * @propertyOf ngCordovaMocks.cordovaVibration
  2959. *
  2960. * @description
  2961. * A flag that signals whether vibration is active.
  2962. * This property should only be used in automated tests.
  2963. **/
  2964. isVibrating: isVibrating,
  2965. vibrate: function (time) {
  2966. if (time > 0) {
  2967. this.isVibrating = true;
  2968. self = this;
  2969. if (time instanceof Array) {
  2970. // TODO: Implement pattern here.
  2971. // The following is a temporary timer that just looks at the first value
  2972. this.vibrateTimer = $timeout(
  2973. function () {
  2974. self.isVibrating = false;
  2975. self.vibrateTimer = null;
  2976. },
  2977. time[0]
  2978. );
  2979. } else {
  2980. this.vibrateTimer = $timeout(
  2981. function () {
  2982. self.isVibrating = false;
  2983. self.vibrateTimer = null;
  2984. },
  2985. time
  2986. );
  2987. }
  2988. }
  2989. },
  2990. /* jshint ignore:start */
  2991. vibrateWithPattern: function (pattern, repeat) {
  2992. // Based on the documentation (https://github.com/apache/cordova-plugin-vibration)
  2993. // This method is deprecated. For that reason, this isn't implemented at this time.
  2994. },
  2995. /* jshint ignore:end */
  2996. cancelVibration: function () {
  2997. if (this.vibrateTimer !== null) {
  2998. if (this.isVibrating === true) {
  2999. $timeout.cancel(this.vibrateTimer);
  3000. this.isVibrating = false;
  3001. }
  3002. }
  3003. }
  3004. };
  3005. }]);
  3006. })();