| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. All Rights Reserved. | |
| 3 * | |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 * you may not use this file except in compliance with the License. | |
| 6 * You may obtain a copy of the License at | |
| 7 * | |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 * | |
| 10 * Unless required by applicable law or agreed to in writing, software | |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 * See the License for the specific language governing permissions and | |
| 14 * limitations under the License. | |
| 15 */ | |
| 16 "use strict"; | |
| 17 | |
| 18 (function() { | |
| 19 var pass; | |
| 20 var completedTests; | |
| 21 var allDone; | |
| 22 var numTests; | |
| 23 | |
| 24 // Call to initialize the testing environment. | |
| 25 function setupTutorialTests() { | |
| 26 setState("Manual"); | |
| 27 var timeOfAnimation = document.createElement('div'); | |
| 28 timeOfAnimation.id = "animViewerText"; | |
| 29 timeOfAnimation.innerHTML = "Current animation time: 0.00"; | |
| 30 document.body.appendChild(timeOfAnimation); | |
| 31 numTests = 0; | |
| 32 completedTests = 0; | |
| 33 allDone = false; | |
| 34 pass = true; | |
| 35 } | |
| 36 | |
| 37 // This function mimics the async_test function in testharness.js so that | |
| 38 // extra-asserts.js will run as intended for a tutorial. | |
| 39 function async_test(func, name, properties) { | |
| 40 numTests++; | |
| 41 step = function(func) { | |
| 42 func(); | |
| 43 if (!pass) { | |
| 44 parent.TryItDisplay.fail(); | |
| 45 allDone = true; | |
| 46 }; | |
| 47 }; | |
| 48 | |
| 49 done = function() { | |
| 50 completedTests++; | |
| 51 if (completedTests == numTests && !allDone) { | |
| 52 allDone = true; | |
| 53 parent.TryItDisplay.pass(); | |
| 54 }; | |
| 55 }; | |
| 56 return this; | |
| 57 } | |
| 58 | |
| 59 function assert_equals(actual, expected, description) { | |
| 60 pass = (actual == expected); | |
| 61 } | |
| 62 | |
| 63 function assert_approx_equals(actual, expected, epsilon, description) { | |
| 64 var lowerBound = expected - (epsilon / 2) < actual; | |
| 65 var upperBound = expected + (epsilon / 2) > actual; | |
| 66 pass = (lowerBound && upperBound); | |
| 67 } | |
| 68 | |
| 69 // This function is required to do nothing for tutorial testing, | |
| 70 // but extra-asserts calls it and thus without this function, | |
| 71 // extra-asserts.js will cause the page to crash. | |
| 72 function add_completion_callback(anything) { | |
| 73 } | |
| 74 | |
| 75 /////////////////////////////////////////////////////////////////////////////// | |
| 76 // Exposing functions to be accessed externally // | |
| 77 /////////////////////////////////////////////////////////////////////////////// | |
| 78 | |
| 79 window.setupTutorialTests = setupTutorialTests; | |
| 80 window.async_test = async_test; | |
| 81 window.assert_approx_equals = assert_approx_equals; | |
| 82 window.assert_equals = assert_equals; | |
| 83 window.add_completion_callback = add_completion_callback; | |
| 84 })(); | |
| OLD | NEW |