tests.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. exports.defineManualTests = function(rootEl, addButton) {
  5. addButton('Get Network Interfaces', function() {
  6. chrome.system.network.getNetworkInterfaces(function(networkInterfaces) {
  7. console.log(JSON.stringify(networkInterfaces, null, 4));
  8. });
  9. });
  10. };
  11. exports.defineAutoTests = function() {
  12. 'use strict';
  13. require('cordova-plugin-chrome-apps-test-framework.jasmine_helpers').addJasmineHelpers();
  14. var customMatchers = {
  15. toHaveProperty : function(util, customEqualityTesters) {
  16. return {
  17. compare : function(actual, propName, propType){
  18. var result = {};
  19. result.pass = ((void 0 !== actual[propName]) && (propType ? (typeof actual[propName] === propType) : true));
  20. result.message = 'Expected ' + actual + ' to have property ' + propName + (propType ? ' of type ' + propType : '');
  21. return result;
  22. }
  23. };
  24. },
  25. toBeArray : function(util, customEqualityTesters) {
  26. return {
  27. compare : function(actual, expected){
  28. var result = {};
  29. result.pass = (actual instanceof Array);
  30. result.message = 'Expected ' + actual + ' to be an array.';
  31. return result;
  32. }
  33. };
  34. }
  35. };
  36. beforeEach(function(done) {
  37. jasmine.addMatchers(customMatchers);
  38. done();
  39. });
  40. describe('getNetworkInterfaces', function() {
  41. it('should exist', function() {
  42. expect(chrome.system.network.getNetworkInterfaces).toBeDefined();
  43. });
  44. it('should return an array of networkInterfaces', function(done) {
  45. chrome.system.network.getNetworkInterfaces(function(networkInterfaces) {
  46. expect(networkInterfaces).toBeDefined();
  47. expect(networkInterfaces).not.toBe(null);
  48. expect(networkInterfaces).toBeArray();
  49. // NOTE: If wifi is disabled, the array of interfaces will be empty,
  50. // even if the device has wifi capability
  51. done();
  52. });
  53. });
  54. it('should report details', function(done) {
  55. chrome.system.network.getNetworkInterfaces(function(networkInterfaces) {
  56. networkInterfaces.forEach(function(netInterface) {
  57. expect(netInterface).toHaveProperty('name', 'string');
  58. expect(netInterface.name.length).toBeGreaterThan(0);
  59. expect(netInterface).toHaveProperty('address', 'string');
  60. expect(netInterface.address.length).toBeGreaterThan(0);
  61. expect(netInterface).toHaveProperty('prefixLength', 'number');
  62. expect(netInterface.prefixLength).toBeGreaterThan(0);
  63. });
  64. done();
  65. });
  66. });
  67. });
  68. };