tests.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /* jshint jasmine: true */
  22. exports.defineAutoTests = function() {
  23. describe('Device Information (window.device)', function () {
  24. it("should exist", function() {
  25. expect(window.device).toBeDefined();
  26. });
  27. it("should contain a platform specification that is a string", function() {
  28. expect(window.device.platform).toBeDefined();
  29. expect((String(window.device.platform)).length > 0).toBe(true);
  30. });
  31. it("should contain a version specification that is a string", function() {
  32. expect(window.device.version).toBeDefined();
  33. expect((String(window.device.version)).length > 0).toBe(true);
  34. });
  35. it("should contain a UUID specification that is a string or a number", function() {
  36. expect(window.device.uuid).toBeDefined();
  37. if (typeof window.device.uuid == 'string' || typeof window.device.uuid == 'object') {
  38. expect((String(window.device.uuid)).length > 0).toBe(true);
  39. } else {
  40. expect(window.device.uuid > 0).toBe(true);
  41. }
  42. });
  43. it("should contain a cordova specification that is a string", function() {
  44. expect(window.device.cordova).toBeDefined();
  45. expect((String(window.device.cordova)).length > 0).toBe(true);
  46. });
  47. it("should depend on the presence of cordova.version string", function() {
  48. expect(window.cordova.version).toBeDefined();
  49. expect((String(window.cordova.version)).length > 0).toBe(true);
  50. });
  51. it("should contain device.cordova equal to cordova.version", function() {
  52. expect(window.device.cordova).toBe(window.cordova.version);
  53. });
  54. it("should contain a model specification that is a string", function() {
  55. expect(window.device.model).toBeDefined();
  56. expect((String(window.device.model)).length > 0).toBe(true);
  57. });
  58. it("should contain a manufacturer property that is a string", function() {
  59. expect(window.device.manufacturer).toBeDefined();
  60. expect((String(window.device.manufacturer)).length > 0).toBe(true);
  61. });
  62. it("should contain an isVirtual property that is a boolean", function() {
  63. expect(window.device.isVirtual).toBeDefined();
  64. expect(typeof window.device.isVirtual).toBe("boolean");
  65. });
  66. it("should contain a serial number specification that is a string", function() {
  67. expect(window.device.serial).toBeDefined();
  68. expect((String(window.device.serial)).length > 0).toBe(true);
  69. });
  70. });
  71. };
  72. exports.defineManualTests = function(contentEl, createActionButton) {
  73. var logMessage = function (message, color) {
  74. var log = document.getElementById('info');
  75. var logLine = document.createElement('div');
  76. if (color) {
  77. logLine.style.color = color;
  78. }
  79. logLine.innerHTML = message;
  80. log.appendChild(logLine);
  81. };
  82. var clearLog = function () {
  83. var log = document.getElementById('info');
  84. log.innerHTML = '';
  85. };
  86. var device_tests = '<h3>Press Dump Device button to get device information</h3>' +
  87. '<div id="dump_device"></div>' +
  88. 'Expected result: Status box will get updated with device info. (i.e. platform, version, uuid, model, etc)';
  89. contentEl.innerHTML = '<div id="info"></div>' + device_tests;
  90. createActionButton('Dump device', function() {
  91. clearLog();
  92. logMessage(JSON.stringify(window.device, null, '\t'));
  93. }, "dump_device");
  94. };