Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audit.js

Issue 2705483002: Print out label and description on task entry in Audit task runner (Closed)
Patch Set: Rebased after l-g-t-m Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 FINISHED: 2 963 FINISHED: 2
964 }; 964 };
965 965
966 966
967 /** 967 /**
968 * @class Task 968 * @class Task
969 * @description WebAudio testing task. Managed by TaskRunner. 969 * @description WebAudio testing task. Managed by TaskRunner.
970 */ 970 */
971 class Task { 971 class Task {
972 972
973 /**
974 * Task constructor.
975 * @param {Object} taskRunner Reference of associated task runner.
976 * @param {String||Object} taskLabel Task label if a string is given. This
977 * parameter can be a dictionary with the
978 * following fields.
979 * @param {String} taskLabel.label Task label.
980 * @param {String} taskLabel.description Description of task.
981 * @param {Function} taskFunction Task function to be performed.
982 * @return {Object} Task object.
983 */
973 constructor (taskRunner, taskLabel, taskFunction) { 984 constructor (taskRunner, taskLabel, taskFunction) {
974 this._taskRunner = taskRunner; 985 this._taskRunner = taskRunner;
975 this._taskFunction = taskFunction; 986 this._taskFunction = taskFunction;
976 this._label = taskLabel; 987
977 this._description = ''; 988 if (typeof taskLabel === 'string') {
989 this._label = taskLabel;
990 this._description = null;
991 } else if (typeof taskLabel === 'object') {
992 if (typeof taskLabel.label !== 'string') {
993 _throwException('Task.constructor:: task label must be string.');
994 }
995 this._label = taskLabel.label;
996 this._description = (typeof taskLabel.description === 'string')
997 ? taskLabel.description : null;
998 } else {
999 _throwException('Task.constructor:: task label must be a string or ' +
1000 'a dictionary.');
1001 }
1002
978 this._state = TaskState.PENDING; 1003 this._state = TaskState.PENDING;
979 this._result = true; 1004 this._result = true;
980 1005
981 this._totalAssertions = 0; 1006 this._totalAssertions = 0;
982 this._failedAssertions = 0; 1007 this._failedAssertions = 0;
983 } 1008 }
984 1009
985 // Set the description of this task. This is printed out in the test 1010 // TODO(hongchan): This does not have any effect. Remove this method and fix
986 // result. 1011 // layout test files use it.
987 describe (message) { 1012 describe (message) {}
988 this._description = message; 1013
989 _logPassed('> [' + this._label + '] ' 1014 get label () {
990 + this._description); 1015 return this._label;
991 } 1016 }
992 1017
993 get state () { 1018 get state () {
994 return this._state; 1019 return this._state;
995 } 1020 }
996 1021
997 get result () { 1022 get result () {
998 return this._result; 1023 return this._result;
999 } 1024 }
1000 1025
1001 // Start the assertion chain. 1026 // Start the assertion chain.
1002 should (actual, actualDescription) { 1027 should (actual, actualDescription) {
1003 // If no argument is given, we cannot proceed. Halt. 1028 // If no argument is given, we cannot proceed. Halt.
1004 if (arguments.length === 0) 1029 if (arguments.length === 0)
1005 _throwException('Task.should:: requires at least 1 argument.'); 1030 _throwException('Task.should:: requires at least 1 argument.');
1006 1031
1007 return new Should(this, actual, actualDescription); 1032 return new Should(this, actual, actualDescription);
1008 } 1033 }
1009 1034
1010 // Run this task. |this| task will be passed into the user-supplied test 1035 // Run this task. |this| task will be passed into the user-supplied test
1011 // task function. 1036 // task function.
1012 run () { 1037 run () {
1013 this._state = TaskState.STARTED; 1038 this._state = TaskState.STARTED;
1039
1040 // Print out the task entry with label and description.
1041 _logPassed('> [' + this._label + '] '
1042 + (this._description ? this._description : ''));
1043
1014 this._taskFunction( 1044 this._taskFunction(
1015 this, 1045 this,
1016 this.should.bind(this)); 1046 this.should.bind(this));
1017 } 1047 }
1018 1048
1019 // Update the task success based on the individual assertion/test inside. 1049 // Update the task success based on the individual assertion/test inside.
1020 update (subTask) { 1050 update (subTask) {
1021 // After one of tests fails within a task, the result is irreversible. 1051 // After one of tests fails within a task, the result is irreversible.
1022 if (subTask.result === false) { 1052 if (subTask.result === false) {
1023 this._result = false; 1053 this._result = false;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 } else { 1126 } else {
1097 _logPassed(prefix + this._taskSequence.length 1127 _logPassed(prefix + this._taskSequence.length
1098 + ' tasks ran successfully.'); 1128 + ' tasks ran successfully.');
1099 } 1129 }
1100 1130
1101 // From testharness.js, report back to the test infrastructure that 1131 // From testharness.js, report back to the test infrastructure that
1102 // the task runner completed all the tasks. 1132 // the task runner completed all the tasks.
1103 done(); 1133 done();
1104 } 1134 }
1105 1135
1136 // |taskLabel| can be either a string or a dictionary. See Task constructor
1137 // for the detail.
1106 define (taskLabel, taskFunction) { 1138 define (taskLabel, taskFunction) {
1107 if (this._tasks.hasOwnProperty(taskLabel)) { 1139 let task = new Task(this, taskLabel, taskFunction);
1140 if (this._tasks.hasOwnProperty(task.label)) {
1108 _throwException('Audit.define:: Duplicate task definition.'); 1141 _throwException('Audit.define:: Duplicate task definition.');
1109 return; 1142 return;
1110 } 1143 }
1111 1144 this._tasks[task.label] = task;
1112 this._tasks[taskLabel] = new Task(this, taskLabel, taskFunction); 1145 this._taskSequence.push(task.label);
1113 this._taskSequence.push(taskLabel);
1114 } 1146 }
1115 1147
1116 // Start running all the tasks scheduled. Multiple task names can be passed 1148 // Start running all the tasks scheduled. Multiple task names can be passed
1117 // to execute them sequentially. Zero argument will perform all defined 1149 // to execute them sequentially. Zero argument will perform all defined
1118 // tasks in the order of definition. 1150 // tasks in the order of definition.
1119 run () { 1151 run () {
1120 // Display the beginning of the test suite. 1152 // Display the beginning of the test suite.
1121 _logPassed('# AUDIT TASK RUNNER STARTED.'); 1153 _logPassed('# AUDIT TASK RUNNER STARTED.');
1122 1154
1123 // If the argument is specified, override the default task sequence with 1155 // If the argument is specified, override the default task sequence with
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 1259
1228 /** 1260 /**
1229 * Load file from a given URL and pass ArrayBuffer to the following promise. 1261 * Load file from a given URL and pass ArrayBuffer to the following promise.
1230 * See |loadFileFromUrl| method for the detail. 1262 * See |loadFileFromUrl| method for the detail.
1231 */ 1263 */
1232 loadFileFromUrl: loadFileFromUrl 1264 loadFileFromUrl: loadFileFromUrl
1233 1265
1234 }; 1266 };
1235 1267
1236 })(); 1268 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698