tests.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. exports.defineAutoTests = function() {
  22. describe('Device Information (window.device)', function () {
  23. it("should exist", function() {
  24. expect(window.device).toBeDefined();
  25. });
  26. it("should contain a platform specification that is a string", function() {
  27. expect(window.device.platform).toBeDefined();
  28. expect((new String(window.device.platform)).length > 0).toBe(true);
  29. });
  30. it("should contain a version specification that is a string", function() {
  31. expect(window.device.version).toBeDefined();
  32. expect((new String(window.device.version)).length > 0).toBe(true);
  33. });
  34. it("should contain a UUID specification that is a string or a number", function() {
  35. expect(window.device.uuid).toBeDefined();
  36. if (typeof window.device.uuid == 'string' || typeof window.device.uuid == 'object') {
  37. expect((new String(window.device.uuid)).length > 0).toBe(true);
  38. } else {
  39. expect(window.device.uuid > 0).toBe(true);
  40. }
  41. });
  42. it("should contain a cordova specification that is a string", function() {
  43. expect(window.device.cordova).toBeDefined();
  44. expect((new String(window.device.cordova)).length > 0).toBe(true);
  45. });
  46. it("should depend on the presence of cordova.version string", function() {
  47. expect(window.cordova.version).toBeDefined();
  48. expect((new String(window.cordova.version)).length > 0).toBe(true);
  49. });
  50. it("should contain device.cordova equal to cordova.version", function() {
  51. expect(window.device.cordova).toBe(window.cordova.version);
  52. });
  53. it("should contain a model specification that is a string", function() {
  54. expect(window.device.model).toBeDefined();
  55. expect((new String(window.device.model)).length > 0).toBe(true);
  56. });
  57. it("should contain a manufacturer property that is a string", function() {
  58. expect(window.device.manufacturer).toBeDefined();
  59. expect((new String(window.device.manufacturer)).length > 0).toBe(true);
  60. });
  61. });
  62. };
  63. exports.defineManualTests = function(contentEl, createActionButton) {
  64. var logMessage = function (message, color) {
  65. var log = document.getElementById('info');
  66. var logLine = document.createElement('div');
  67. if (color) {
  68. logLine.style.color = color;
  69. }
  70. logLine.innerHTML = message;
  71. log.appendChild(logLine);
  72. }
  73. var clearLog = function () {
  74. var log = document.getElementById('info');
  75. log.innerHTML = '';
  76. }
  77. var device_tests = '<h3>Press Dump Device button to get device information</h3>' +
  78. '<div id="dump_device"></div>' +
  79. 'Expected result: Status box will get updated with device info. (i.e. platform, version, uuid, model, etc)';
  80. contentEl.innerHTML = '<div id="info"></div>' + device_tests;
  81. createActionButton('Dump device', function() {
  82. clearLog();
  83. logMessage(JSON.stringify(window.device, null, '\t'));
  84. }, "dump_device");
  85. };