<!doctype html>
<html>
  <head>
    <title>
      Test AudioWorklet AudioParam Warning Messages
    </title>
    <script src="../../imported/w3c/web-platform-tests/resources/testharness.js"></script>
    <script src="../../resources/testharnessreport.js"></script>
    <script src="../resources/audit-util.js"></script>
    <script src="../resources/audit.js"></script>
    <script src="../resources/worklet-test.js"></script>
  </head>
  <body>
    <script id="layout-test-code">
      let audit = Audit.createTaskRunner();

      audit.define(
          {
            label: 'AudioWorklet AudioParam',
            description: 'Generate warnings if outside nominal range'
          },
          (task, should) => {
            // Any reasonable sample rate will work
            let sampleRate = 16000;
            let renderTime = 1;
            let renderLength = renderTime * sampleRate;
            let context =
                new OfflineAudioContext(1, renderLength, sampleRate);
            context.audioWorklet.addModule(NoiseGenWorkletUrl).then(() => {
              let noiseGenerator =
                  new AudioWorkletNode(context, 'noise-generator');
              noiseGenerator.connect(context.destination);
              let param = noiseGenerator.parameters.get('amplitude');
              // Set the value inside the nominal range; no warning should be
              // generated.
              param.value = .1;
              // Set the value outside the nominal range to generate a
              // warning.
              param.value = 99;

              // Set up automation outside the nominal range to generate a
              // warning.
              param.setValueAtTime(-1, renderTime / 4);
              param.linearRampToValueAtTime(5, renderTime);

              // Render; we don't care what the generated result is.
              context.startRendering()
                  .then(() => {
                    should(true, 'Rendering succeeded').beTrue();
                  })
                  .then(() => task.done());
            });
          });

      audit.run();
    </script>
  </body>
</html>
