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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js

Issue 2212023002: Modifying audio-testing.js to support testharness.js. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initial patch Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js b/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js
index c2487625a83482b9942ec2bbc95e069dc9fce537..aad86cf1ba2192436bf0ef589b5310aec27cad96 100644
--- a/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/audio-testing.js
@@ -1,3 +1,20 @@
+/* global self */
+
+// Check if testharness is properly included and set up a flag for it.
+var TESTHARNESS = true;
+var testharnessFunctions = [
+ 'test', 'async_test', 'promise_test', 'promise_rejects', 'generate_tests',
+ 'setup', 'done', 'assert_true', 'assert_false'
+];
+
+for (var func in testharnessFunctions) {
+ if (!self.hasOwnProperty(testharnessFunctions[func])) {
+ TESTHARNESS = false;
+ break;
+ }
+}
+
+
function writeString(s, a, offset) {
for (var i = 0; i < s.length; ++i) {
a[offset + i] = s.charCodeAt(i);
@@ -301,6 +318,35 @@ function isValidNumber(x) {
this.currentTask = 0;
}
+ // This is to prime the task runner for the testharness.js async operation.
+ Tasks.prototype._initialize = function () {
+ if (TESTHARNESS) {
+ setup(new Function(), {
+ explicit_done: true
+ });
+ } else {
+ // For js-test.js
+ window.jsTestIsAsync = true;
Raymond Toy 2016/08/04 18:07:08 Are you sure we always want to set this? Thus far
hongchan 2016/08/04 18:31:37 If the value is already set, this doesn't do anyth
+ }
+
+ return;
+ };
+
+ // Finalize the task runner by notifying testharness and testRunner that
+ // all the task is completed.
+ Tasks.prototype._finalize = function () {
+ if (TESTHARNESS) {
+ // From testharness.js
+ done();
+
+ } else {
+ // For js-test.js
+ finishJSTest();
Raymond Toy 2016/08/04 18:07:08 Won't this break existing tests? I've always been
hongchan 2016/08/04 18:31:37 I've tested this against our existing test suites.
+ }
+
+ return;
+ };
+
Tasks.prototype.defineTask = function (taskName, taskFunc) {
// Check if there is a task defined with the same name. If found, do
// not add the task to the roster.
@@ -320,6 +366,8 @@ function isValidNumber(x) {
// is no argument, run all the defined tasks.
Tasks.prototype.runTasks = function () {
+ this._initialize();
+
if (arguments.length > 0) {
// Reset task queue and refill it with the with the given arguments,
@@ -341,21 +389,23 @@ function isValidNumber(x) {
return;
}
- // done() callback from each task. Increase the task index and call the
- // next task. Note that explicit signaling by done() in each task
- // is needed because some of tests run asynchronously.
- var done = function () {
+ // taskDone() callback from each task. Increase the task index and call
+ // the next task. Note that explicit signaling by taskDone() in each
+ // task is needed because some of tests run asynchronously.
+ var taskDone = function () {
if (this.currentTask !== this.queue.length - 1) {
++this.currentTask;
// debug('>> Audit.runTasks: ' + this.queue[this.currentTask]);
- this.tasks[this.queue[this.currentTask]](done);
+ this.tasks[this.queue[this.currentTask]](taskDone);
+ } else {
+ this._finalize();
}
return;
}.bind(this);
// Start the first task.
// debug('>> Audit.runTasks: ' + this.queue[this.currentTask]);
- this.tasks[this.queue[this.currentTask]](done);
+ this.tasks[this.queue[this.currentTask]](taskDone);
};
return {
@@ -399,12 +449,6 @@ var Should = (function () {
// Check if the target contains any NaN value.
this._checkNaN(this.target, 'ACTUAL');
- // if (resultNaNCheck.length > 0) {
- // var failureMessage = 'NaN found while testing the target (' + label + ')';
- // testFailed(failureMessage + ': "' + this.desc + '" \n' +
- // resultNaNCheck);
- // throw failureMessage;
- // }
// |_testPassed| and |_testFailed| set this appropriately.
this._success = false;
@@ -428,13 +472,28 @@ var Should = (function () {
// Internal methods starting with a underscore.
ShouldModel.prototype._testPassed = function (msg) {
- testPassed(this.desc + ' ' + msg + '.');
this._success = true;
+ if (TESTHARNESS) {
+ // Using testharness.js
+ test(function () {
+ assert_true(true);
Raymond Toy 2016/08/04 18:07:08 This is different from what you showed me this mor
hongchan 2016/08/04 18:31:37 When the assert passes, we should print out the me
+ }, this.desc + ' ' + msg + '.');
+ } else {
+ // Using js-test.js
+ testPassed(this.desc + ' ' + msg + '.');
+ }
};
ShouldModel.prototype._testFailed = function (msg) {
- testFailed(this.desc + ' ' + msg + '.');
this._success = false;
+ var that = this;
+ if (TESTHARNESS) {
+ test(function () {
+ assert_true(false, that.desc + ' ' + msg + '.');
Raymond Toy 2016/08/04 18:07:08 Why is this different from line 479?
hongchan 2016/08/04 18:31:37 On the other hand, this description message gets p
+ }, this.desc);
+ } else {
+ testFailed(this.desc + ' ' + msg + '.');
+ }
};
ShouldModel.prototype._isArray = function (arg) {
@@ -451,7 +510,15 @@ var Should = (function () {
var failureMessage = 'Assertion failed: ' + reason + ' ' + this.desc +'.';
if (arguments.length >= 3)
failureMessage += ": " + value;
- testFailed(failureMessage);
+
+ if (TESTHARNESS) {
+ test(function () {
+ assert_true(false, reason + ' (' + value + ')');
Raymond Toy 2016/08/04 18:07:08 Hard to tell, but why is this different from just
hongchan 2016/08/04 18:31:37 When assert_true fails it prints out the message s
+ }, this.desc)
+ } else {
+ testFailed(failureMessage);
+ }
+
throw failureMessage;
};
@@ -464,7 +531,14 @@ var Should = (function () {
// Checking a single variable first.
if (Number.isNaN(value)) {
- testFailed(failureMessage);
+ if (TESTHARNESS) {
+ test(function () {
+ assert_true(false, failureMessage);
+ }, this.desc)
+ } else {
+ testFailed(failureMessage);
+ }
+
throw failureMessage;
}
@@ -492,7 +566,14 @@ var Should = (function () {
}
}
- testFailed(failureMessage + failureDetail);
+ if (TESTHARNESS) {
+ test(function () {
+ assert_true(false, failureMessage + failureDetail);
+ }, this.desc)
+ } else {
+ testFailed(failureMessage + failureDetail);
+ }
+
throw failureMessage;
};

Powered by Google App Engine
This is Rietveld 408576698