| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * @fileOverview WebAudio layout test utility library. Built around W3C's | 7 * @fileOverview WebAudio layout test utility library. Built around W3C's |
| 8 * testharness.js. Includes asynchronous test task manager, | 8 * testharness.js. Includes asynchronous test task manager, |
| 9 * assertion utilities. | 9 * assertion utilities. |
| 10 * @dependency testharness.js | 10 * @dependency testharness.js |
| (...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 FINISHED: 2 | 919 FINISHED: 2 |
| 920 }; | 920 }; |
| 921 | 921 |
| 922 | 922 |
| 923 /** | 923 /** |
| 924 * @class Task | 924 * @class Task |
| 925 * @description WebAudio testing task. Managed by TaskRunner. | 925 * @description WebAudio testing task. Managed by TaskRunner. |
| 926 */ | 926 */ |
| 927 class Task { | 927 class Task { |
| 928 | 928 |
| 929 /** |
| 930 * Task constructor. |
| 931 * @param {Object} taskRunner Reference of associated task runner. |
| 932 * @param {String||Object} taskLabel Task label if a string is given. This |
| 933 * parameter can be a dictionary with the |
| 934 * following fields. |
| 935 * @param {String} taskLabel.label Task label. |
| 936 * @param {String} taskLabel.description Description of task. |
| 937 * @param {Function} taskFunction Task function to be performed. |
| 938 * @return {Object} Task object. |
| 939 */ |
| 929 constructor (taskRunner, taskLabel, taskFunction) { | 940 constructor (taskRunner, taskLabel, taskFunction) { |
| 930 this._taskRunner = taskRunner; | 941 this._taskRunner = taskRunner; |
| 931 this._taskFunction = taskFunction; | 942 this._taskFunction = taskFunction; |
| 932 this._label = taskLabel; | 943 |
| 933 this._description = ''; | 944 if (typeof taskLabel === 'string') { |
| 945 this._label = taskLabel; |
| 946 this._description = null; |
| 947 } else if (typeof taskLabel === 'object') { |
| 948 if (typeof taskLabel.label !== 'string') { |
| 949 _throwException('Task.constructor:: task label must be string.'); |
| 950 } |
| 951 this._label = taskLabel.label; |
| 952 this._description = (typeof taskLabel.description === 'string') |
| 953 ? taskLabel.description : null; |
| 954 } else { |
| 955 _throwException('Task.constructor:: task label must be a string or ' + |
| 956 'a dictionary.'); |
| 957 } |
| 958 |
| 934 this._state = TaskState.PENDING; | 959 this._state = TaskState.PENDING; |
| 935 this._result = true; | 960 this._result = true; |
| 936 | 961 |
| 937 this._totalAssertions = 0; | 962 this._totalAssertions = 0; |
| 938 this._failedAssertions = 0; | 963 this._failedAssertions = 0; |
| 939 } | 964 } |
| 940 | 965 |
| 941 // Set the description of this task. This is printed out in the test | 966 // Set the description of this task. This is printed out in the test result |
| 942 // result. | 967 // right after the task starts. If the description is defined at the |
| 968 // construction, this method does not have any effect. |
| 943 describe (message) { | 969 describe (message) { |
| 944 this._description = message; | 970 // TODO(hongchan): remove this method and fix layout test files use it. |
| 945 _logPassed('> [' + this._label + '] ' | 971 } |
| 946 + this._description); | 972 |
| 973 get label () { |
| 974 return this._label; |
| 947 } | 975 } |
| 948 | 976 |
| 949 get state () { | 977 get state () { |
| 950 return this._state; | 978 return this._state; |
| 951 } | 979 } |
| 952 | 980 |
| 953 get result () { | 981 get result () { |
| 954 return this._result; | 982 return this._result; |
| 955 } | 983 } |
| 956 | 984 |
| 957 // Start the assertion chain. | 985 // Start the assertion chain. |
| 958 should (actual, actualDescription) { | 986 should (actual, actualDescription) { |
| 959 // If no argument is given, we cannot proceed. Halt. | 987 // If no argument is given, we cannot proceed. Halt. |
| 960 if (arguments.length === 0) | 988 if (arguments.length === 0) |
| 961 _throwException('Task.should:: requires at least 1 argument.'); | 989 _throwException('Task.should:: requires at least 1 argument.'); |
| 962 | 990 |
| 963 return new Should(this, actual, actualDescription); | 991 return new Should(this, actual, actualDescription); |
| 964 } | 992 } |
| 965 | 993 |
| 966 // Run this task. |this| task will be passed into the user-supplied test | 994 // Run this task. |this| task will be passed into the user-supplied test |
| 967 // task function. | 995 // task function. |
| 968 run () { | 996 run () { |
| 969 this._state = TaskState.STARTED; | 997 this._state = TaskState.STARTED; |
| 998 |
| 999 // Print out the task entry with label and description. |
| 1000 _logPassed('> [' + this._label + '] ' |
| 1001 + (this._description ? this._description : '')); |
| 1002 |
| 970 this._taskFunction( | 1003 this._taskFunction( |
| 971 this, | 1004 this, |
| 972 this.should.bind(this)); | 1005 this.should.bind(this)); |
| 973 } | 1006 } |
| 974 | 1007 |
| 975 // Update the task success based on the individual assertion/test inside. | 1008 // Update the task success based on the individual assertion/test inside. |
| 976 update (subTask) { | 1009 update (subTask) { |
| 977 // After one of tests fails within a task, the result is irreversible. | 1010 // After one of tests fails within a task, the result is irreversible. |
| 978 if (subTask.result === false) { | 1011 if (subTask.result === false) { |
| 979 this._result = false; | 1012 this._result = false; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 } else { | 1085 } else { |
| 1053 _logPassed(prefix + this._taskSequence.length | 1086 _logPassed(prefix + this._taskSequence.length |
| 1054 + ' tasks ran successfully.'); | 1087 + ' tasks ran successfully.'); |
| 1055 } | 1088 } |
| 1056 | 1089 |
| 1057 // From testharness.js, report back to the test infrastructure that | 1090 // From testharness.js, report back to the test infrastructure that |
| 1058 // the task runner completed all the tasks. | 1091 // the task runner completed all the tasks. |
| 1059 done(); | 1092 done(); |
| 1060 } | 1093 } |
| 1061 | 1094 |
| 1095 // |taskLabel| can be either a string or a dictionary. See Task constructor |
| 1096 // for the detail. |
| 1062 define (taskLabel, taskFunction) { | 1097 define (taskLabel, taskFunction) { |
| 1063 if (this._tasks.hasOwnProperty(taskLabel)) { | 1098 let task = new Task(this, taskLabel, taskFunction); |
| 1099 if (this._tasks.hasOwnProperty(task.label)) { |
| 1064 _throwException('Audit.define:: Duplicate task definition.'); | 1100 _throwException('Audit.define:: Duplicate task definition.'); |
| 1065 return; | 1101 return; |
| 1066 } | 1102 } |
| 1067 | 1103 this._tasks[task.label] = task; |
| 1068 this._tasks[taskLabel] = new Task(this, taskLabel, taskFunction); | 1104 this._taskSequence.push(task.label); |
| 1069 this._taskSequence.push(taskLabel); | |
| 1070 } | 1105 } |
| 1071 | 1106 |
| 1072 // Start running all the tasks scheduled. Multiple task names can be passed | 1107 // Start running all the tasks scheduled. Multiple task names can be passed |
| 1073 // to execute them sequentially. Zero argument will perform all defined | 1108 // to execute them sequentially. Zero argument will perform all defined |
| 1074 // tasks in the order of definition. | 1109 // tasks in the order of definition. |
| 1075 run () { | 1110 run () { |
| 1076 // Display the beginning of the test suite. | 1111 // Display the beginning of the test suite. |
| 1077 _logPassed('# AUDIT TASK RUNNER STARTED.'); | 1112 _logPassed('# AUDIT TASK RUNNER STARTED.'); |
| 1078 | 1113 |
| 1079 // If the argument is specified, override the default task sequence with | 1114 // If the argument is specified, override the default task sequence with |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 | 1218 |
| 1184 /** | 1219 /** |
| 1185 * Load file from a given URL and pass ArrayBuffer to the following promise. | 1220 * Load file from a given URL and pass ArrayBuffer to the following promise. |
| 1186 * See |loadFileFromUrl| method for the detail. | 1221 * See |loadFileFromUrl| method for the detail. |
| 1187 */ | 1222 */ |
| 1188 loadFileFromUrl: loadFileFromUrl | 1223 loadFileFromUrl: loadFileFromUrl |
| 1189 | 1224 |
| 1190 }; | 1225 }; |
| 1191 | 1226 |
| 1192 })(); | 1227 })(); |
| OLD | NEW |