test_protocol_index.js (1529B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 const { lazyLoadFront } = require("resource://devtools/shared/specs/index.js"); 6 const Types = 7 require("resource://devtools/shared/specs/index.js").__TypesForTests; 8 const { getType } = require("resource://devtools/shared/protocol.js").types; 9 10 function run_test() { 11 test_index_is_alphabetically_sorted(); 12 test_specs(); 13 test_fronts(); 14 } 15 16 // Check alphabetic order of specs defined in devtools/shared/specs/index.js, 17 // in order to ease its maintenance and readability. 18 function test_index_is_alphabetically_sorted() { 19 let lastSpec = ""; 20 for (const type of Types) { 21 const spec = type.spec; 22 if (lastSpec && spec < lastSpec) { 23 ok(false, `Spec definition for "${spec}" should be before "${lastSpec}"`); 24 } 25 lastSpec = spec; 26 } 27 ok(true, "Specs index is alphabetically sorted"); 28 } 29 30 function test_specs() { 31 for (const type of Types) { 32 for (const typeName of type.types) { 33 ok(!!getType(typeName), `${typeName} spec is defined`); 34 } 35 } 36 ok(true, "Specs are all accessible"); 37 } 38 39 function test_fronts() { 40 for (const item of Types) { 41 if (!item.front) { 42 continue; 43 } 44 for (const typeName of item.types) { 45 lazyLoadFront(typeName); 46 const type = getType(typeName); 47 ok(!!type, `Front for ${typeName} has a spec`); 48 ok(type.frontClass, `${typeName} has a front correctly defined`); 49 } 50 } 51 ok(true, "Front are all accessible"); 52 }