vk_support.js (2572B)
1 // Ends a manual test. Must be called before any async tests are started. 2 function skipManualTest() { 3 test(function() { assert_true(false); }, "Manual Test Skipped"); 4 done(); 5 } 6 7 var stepInstructions = []; 8 var testNames = []; 9 var stepFunctions = []; 10 var steps; 11 var curStep = 0; 12 13 // Adds a manual test step to the test. A test will add a series of steps, 14 // along with instructions. Once all the tests steps are added, the test can 15 // be run by continually running the nextStep() function. All manual test steps 16 // must be added before calling nextStep. 17 // 18 // |func| A function to be executed at the given step. This function can include 19 // testharness assertions if |testName| is provided. If this is the last 20 // step, the |done()| function (used for manual testharness.js tests) 21 // will be called after |func| is executed. 22 // |testName| If provided, the |func| will be wrapped in a testharness.js 23 // async_test with this name. If null, |func| will be executed as a 24 // free function. 25 // |instructions| The text to display to the user. Note, these are shown after 26 // step is executed so these should be instructions to setup the 27 // checks in the next step. 28 function addManualTestStep(func, testName, instructions) { 29 stepFunctions.push(func); 30 testNames.push(testName); 31 stepInstructions.push(instructions); 32 } 33 34 // Runs the next step of the test. This must be called only after all test steps 35 // have been added using |addManualTestStep|. 36 // 37 // |callbackFunc| If provided, will be called with a single argument being the 38 // instruction string for the current step. Use this to update 39 // any necessary UI. 40 function nextStep(callbackFunc) { 41 if (curStep == 0) 42 _startManualTest(); 43 44 if (typeof(callbackFunc) === 'function') 45 callbackFunc(stepInstructions[curStep]); 46 47 steps[curStep](); 48 curStep++; 49 } 50 51 function _startManualTest() { 52 steps = []; 53 for (let i = 0; i < stepFunctions.length; ++i) { 54 var stepFunc = stepFunctions[i]; 55 var testName = testNames[i]; 56 if (testName) { 57 steps.push(async_test(testName).step_func(function() { 58 stepFunctions[i](); 59 this.done(); 60 if (i == stepFunctions.length - 1) 61 done(); 62 })); 63 } else { 64 steps.push(function() { 65 stepFunctions[i](); 66 if (i == stepFunctions.length - 1) 67 done(); 68 }); 69 } 70 } 71 }