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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/constructor/audiobuffer.html

Issue 2102133002: Add constructors for WebAudio nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and rebase Created 4 years, 3 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/constructor/audiobuffer.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/constructor/audiobuffer.html b/third_party/WebKit/LayoutTests/webaudio/constructor/audiobuffer.html
new file mode 100644
index 0000000000000000000000000000000000000000..0c1891a88e61209526ce19e69b705ad572fac0ac
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/constructor/audiobuffer.html
@@ -0,0 +1,189 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Test Constructor: AudioBuffer</title>
+ <script src="../../resources/testharness.js"></script>
+ <script src="../../resources/testharnessreport.js"></script>
+ <script src="../resources/audio-testing.js"></script>
+ </head>
+
+ <body>
+ <script>
+ var context;
+
+ var audit = Audit.createTaskRunner();
+
+ audit.defineTask("initialize", function (taskDone) {
+ Should("context = new OfflineAudioContext(...)", function () {
+ context = new OfflineAudioContext(1, 1, 48000);
+ }).notThrow();
+
+ taskDone();
+ });
+
+ audit.defineTask("invalid constructor", function (taskDone) {
+ var node;
+ var success = true;
+
+ success = Should("new AudioBuffer()", function () {
+ node = new AudioBuffer();
+ }).throw("TypeError");
+ success = Should("new AudioBuffer(1)", function () {
+ node = new AudioBuffer(1) && success;
+ }).throw("TypeError");
+ success = Should("new AudioBuffer(context, 42)", function () {
+ node = new AudioBuffer(context, 42) && success;
+ }).throw("TypeError");
+
+ Should("Invalid constructors", success)
+ .summarize(
+ "correctly threw errors",
+ "did not throw errors in all cases");
+
+ taskDone();
+ });
+
+ audit.defineTask("required options", function (taskDone) {
+ var success = true;
+
+ success = Should("new AudioBuffer(context, {})", function () {
+ var buffer = new AudioBuffer(context, {});
+ }).throw("NotFoundError");
+
+ success = Should("new AudioBuffer(context, {numberOfChannels: 1}",
+ function () {
+ var buffer = new AudioBuffer(context, {
+ numberOfChannels: 1
+ });
+ }).throw("NotFoundError") && success;
+
+ // The sampleRate isn't required, but numberOfChannels and length are.
+ success = Should(
+ "new AudioBuffer(context, {numberOfChannels: 1, length: 1}",
+ function () {
+ var buffer = new AudioBuffer(context, {
+ numberOfChannels: 1,
+ length: 1
+ });
+ }).notThrow() && success;
+
+ success = Should(
+ "new AudioBuffer(context, {numberOfChannels: 1, length: 1, sampleRate: 48000}",
+ function () {
+ var buffer = new AudioBuffer(context, {
+ numberOfChannels: 1,
+ length: 1,
+ sampleRate: 48000
+ });
+ }).notThrow() && success;
+
+ Should("Missing option values handled", success)
+ .summarize("correctly", "incorrectly");
+
+ taskDone();
+ });
+
+ audit.defineTask("invalid option values", function (taskDone) {
+ var success = true;
+
+ success = Should("new AudioBuffer(context, {numberOfChannels: 0})", function () {
hongchan 2016/09/13 22:13:22 We can apply the same technique of JSON.stringify
Raymond Toy 2016/09/14 18:02:22 Done.
+ var buffer = new AudioBuffer(context, {numberOfChannels: 0, length: 1});
+ }).throw("NotSupportedError");
+
+ success = Should("new AudioBuffer(context, {numberOfChannels: 99})", function () {
+ var buffer = new AudioBuffer(context, {numberOfChannels: 99, length: 0});
+ }).throw("NotSupportedError") && success;
+
+ success = Should("new AudioBuffer(context, {length: 0})", function () {
+ var buffer = new AudioBuffer(context, {numberOfChannels: 1, length: 0});
+ }).throw("NotSupportedError") && success;
+
+ success = Should("new AudioBuffer(context, {sampleRate: 100})", function () {
+ var buffer = new AudioBuffer(context, {numberOfChannels: 1, length: 1,
+ sampleRate: 100});
+ }).throw("NotSupportedError") && success;
+
+ Should("Invalid option values handled", success)
+ .summarize("correctly", "incorrectly");
+
+ taskDone();
+ });
+
+ audit.defineTask("default constructor", function (taskDone) {
+ var buffer;
+ var success = true;
+
+ success = Should(
+ "buffer = new AudioBuffer(context, {numberOfChannels: 5, length: 17})",
+ function () {
+ buffer = new AudioBuffer(context, {numberOfChannels: 5, length: 17});
+ }).notThrow();
+
+ success = Should("buffer.numberOfChannels", buffer.numberOfChannels)
+ .beEqualTo(5) && success;
+ success = Should("buffer.length", buffer.length)
+ .beEqualTo(17) && success;
+ success = Should("buffer.sampleRate", buffer.sampleRate)
+ .beEqualTo(context.sampleRate) && success;
+
+ Should("Default constructor values set", success)
+ .summarize("correctly", "incorrectly");
+
+ taskDone();
+ });
+
+ audit.defineTask("valid constructor", function (taskDone) {
+ var buffer;
+ var success = true;
+
+ var options = {
+ numberOfChannels: 3,
+ length: 42,
+ sampleRate: 54321
+ };
+
+ var message = "new AudioBuffer(context, {";
hongchan 2016/09/13 22:13:22 var message = "..." + "..." + val1 + "..." + v
+ message += "numberOfChannels: " + options.numberOfChannels;
+ message += ", length: " + options.length;
+ message += ", sampleRate: " + options.sampleRate;
+ message += "}";
+ success = Should(message, function () {
+ buffer = new AudioBuffer(context, options);
+ }).notThrow();
+
+ success = Should("buffer.numberOfChannels", buffer.numberOfChannels)
+ .beEqualTo(options.numberOfChannels) && success;
+
+ success = Should("buffer.length", buffer.length)
+ .beEqualTo(options.length) && success;
+
+ success = Should("buffer.sampleRate", buffer.sampleRate)
+ .beEqualTo(options.sampleRate) && success;
+
+ // Verify that we actually got the right number of channels
+ for (var k = 0; k < options.numberOfChannels; ++k) {
+ var data;
+ var message = "buffer.getChannelData(" + k + ")";
+ success = Should(message, function () {
+ data = buffer.getChannelData(k);
+ }).notThrow() && success;
+
+ success = Should(message + " length", data.length)
+ .beEqualTo(options.length) && success;
+ }
+
+ Should("buffer.getChannelData(" + options.numberOfChannels + ")",
+ function () {
+ buffer.getChannelData(options.numberOfChannels);
+ }).throw("IndexSizeError") && success;
+
+ Should("AudioBuffer constructed", success)
+ .summarize("correctly", "incorrectly");
+
+ taskDone();
+ });
+
+ audit.runTasks();
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698