Title: [124225] trunk
Revision
124225
Author
h...@chromium.org
Date
2012-07-31 11:26:45 -0700 (Tue, 31 Jul 2012)

Log Message

Speech _javascript_ API: Throw exception for start() when already started
https://bugs.webkit.org/show_bug.cgi?id=92756

Reviewed by Adam Barth.

Source/WebCore:

Make the start() function throw an exception if the SpeechRecognition
object was already started.

Test: fast/speech/scripted/start-exception.html

* Modules/speech/SpeechRecognition.cpp:
(WebCore::SpeechRecognition::start):
(WebCore::SpeechRecognition::stopFunction):
(WebCore::SpeechRecognition::abort):
(WebCore::SpeechRecognition::didReceiveError):
(WebCore::SpeechRecognition::didEnd):
(WebCore::SpeechRecognition::SpeechRecognition):
* Modules/speech/SpeechRecognition.h:
(SpeechRecognition):
* Modules/speech/SpeechRecognition.idl:

Tools:

Fix the task queue in MockWebSpeechRecognizer.
It's important that we remove the task from the queue before we run
it, as running the task could alter the queue's state.

* DumpRenderTree/chromium/MockWebSpeechRecognizer.cpp:
(MockWebSpeechRecognizer::abort):
(MockWebSpeechRecognizer::setError):
(MockWebSpeechRecognizer::clearTaskQueue):
(MockWebSpeechRecognizer::StepTask::runIfValid):
* DumpRenderTree/chromium/MockWebSpeechRecognizer.h:
(MockWebSpeechRecognizer):

LayoutTests:

Layout test for checking that calling start on an already started
SpeechRecognition object throws an exception.

* fast/speech/scripted/start-exception-expected.txt: Added.
* fast/speech/scripted/start-exception.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (124224 => 124225)


--- trunk/LayoutTests/ChangeLog	2012-07-31 18:19:42 UTC (rev 124224)
+++ trunk/LayoutTests/ChangeLog	2012-07-31 18:26:45 UTC (rev 124225)
@@ -1,3 +1,16 @@
+2012-07-31  Hans Wennborg  <h...@chromium.org>
+
+        Speech _javascript_ API: Throw exception for start() when already started
+        https://bugs.webkit.org/show_bug.cgi?id=92756
+
+        Reviewed by Adam Barth.
+
+        Layout test for checking that calling start on an already started
+        SpeechRecognition object throws an exception.
+
+        * fast/speech/scripted/start-exception-expected.txt: Added.
+        * fast/speech/scripted/start-exception.html: Added.
+
 2012-07-31  Adrienne Walker  <e...@google.com>
 
         [Chromium] transforms/3d/point-mapping/3d-point-mapping-*.html failing on Win

Added: trunk/LayoutTests/fast/speech/scripted/start-exception-expected.txt (0 => 124225)


--- trunk/LayoutTests/fast/speech/scripted/start-exception-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/speech/scripted/start-exception-expected.txt	2012-07-31 18:26:45 UTC (rev 124225)
@@ -0,0 +1,36 @@
+Test getting an exception when calling start() in the Speech _javascript_ API
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS 'webkitSpeechRecognition' in self is true
+PASS webkitSpeechRecognition == null is false
+
+doubleStart():
+window.r = new webkitSpeechRecognition()
+PASS r.start() did not throw exception.
+PASS r.start() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+onstart
+PASS r.start() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+onaudiostart
+PASS r.start() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+onsoundstart
+PASS r.start() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+onspeechstart
+PASS r.start() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+onnomatch
+PASS r.start() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+onspeechend
+PASS r.start() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+onsoundend
+PASS r.start() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+onaudioend
+PASS r.start() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+onend
+PASS r.start() did not throw exception.
+r.abort()
+onend
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/speech/scripted/start-exception.html (0 => 124225)


--- trunk/LayoutTests/fast/speech/scripted/start-exception.html	                        (rev 0)
+++ trunk/LayoutTests/fast/speech/scripted/start-exception.html	2012-07-31 18:26:45 UTC (rev 124225)
@@ -0,0 +1,53 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script type="text/_javascript_">
+description('Test getting an exception when calling start() in the Speech _javascript_ API');
+
+function run() {
+    // Check availability of constructors.
+    shouldBeTrue("'webkitSpeechRecognition' in self");
+    shouldBeFalse("webkitSpeechRecognition == null");
+
+    doubleStart();
+}
+
+function doubleStart() {
+    debug('\ndoubleStart():');
+    evalAndLog("window.r = new webkitSpeechRecognition()");
+
+    // Set default handlers.
+    for (var prop in r) {
+        if (prop.match('^on')) {
+            r[prop] = function() {
+                debug('on' + event.type);
+
+                if (event.type === 'end') {
+                    shouldNotThrow("r.start()");
+                    evalAndLog("r.abort()");
+
+                    r._onend_ = function() {
+                        debug('onend');
+                        finishJSTest();
+                    }
+                } else {
+                    shouldThrow("r.start()", '"Error: INVALID_STATE_ERR: DOM Exception 11"');
+                }
+            }
+        }
+    }
+
+    shouldNotThrow("r.start()");
+    shouldThrow("r.start()", '"Error: INVALID_STATE_ERR: DOM Exception 11"');
+}
+
+window._onload_ = run;
+window.jsTestIsAsync = true;
+</script>
+<script src=""
+</body>
+</html>
+

Modified: trunk/Source/WebCore/ChangeLog (124224 => 124225)


--- trunk/Source/WebCore/ChangeLog	2012-07-31 18:19:42 UTC (rev 124224)
+++ trunk/Source/WebCore/ChangeLog	2012-07-31 18:26:45 UTC (rev 124225)
@@ -1,3 +1,26 @@
+2012-07-31  Hans Wennborg  <h...@chromium.org>
+
+        Speech _javascript_ API: Throw exception for start() when already started
+        https://bugs.webkit.org/show_bug.cgi?id=92756
+
+        Reviewed by Adam Barth.
+
+        Make the start() function throw an exception if the SpeechRecognition
+        object was already started.
+
+        Test: fast/speech/scripted/start-exception.html
+
+        * Modules/speech/SpeechRecognition.cpp:
+        (WebCore::SpeechRecognition::start):
+        (WebCore::SpeechRecognition::stopFunction):
+        (WebCore::SpeechRecognition::abort):
+        (WebCore::SpeechRecognition::didReceiveError):
+        (WebCore::SpeechRecognition::didEnd):
+        (WebCore::SpeechRecognition::SpeechRecognition):
+        * Modules/speech/SpeechRecognition.h:
+        (SpeechRecognition):
+        * Modules/speech/SpeechRecognition.idl:
+
 2012-07-31  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r124207.

Modified: trunk/Source/WebCore/Modules/speech/SpeechRecognition.cpp (124224 => 124225)


--- trunk/Source/WebCore/Modules/speech/SpeechRecognition.cpp	2012-07-31 18:19:42 UTC (rev 124224)
+++ trunk/Source/WebCore/Modules/speech/SpeechRecognition.cpp	2012-07-31 18:26:45 UTC (rev 124225)
@@ -30,6 +30,7 @@
 #include "SpeechRecognition.h"
 
 #include "Document.h"
+#include "ExceptionCode.h"
 #include "Page.h"
 #include "SpeechRecognitionController.h"
 #include "SpeechRecognitionError.h"
@@ -44,25 +45,29 @@
     return speechRecognition.release();
 }
 
-void SpeechRecognition::start()
+void SpeechRecognition::start(ExceptionCode& ec)
 {
     ASSERT(m_controller);
-    // FIXME: Spec should say what to do if we are already started.
+    if (m_started) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
 
     setPendingActivity(this);
     m_controller->start(this, m_grammars.get(), m_lang, m_continuous, m_maxAlternatives);
+    m_started = true;
 }
 
 void SpeechRecognition::stopFunction()
 {
     ASSERT(m_controller);
-    m_controller->stop(this); // FIXME: Spec should say what to do if we are not started.
+    m_controller->stop(this);
 }
 
 void SpeechRecognition::abort()
 {
     ASSERT(m_controller);
-    m_controller->abort(this); // FIXME: Spec should say what to do if we are not started.
+    m_controller->abort(this);
 }
 
 void SpeechRecognition::didStartAudio()
@@ -113,6 +118,7 @@
 void SpeechRecognition::didReceiveError(PassRefPtr<SpeechRecognitionError> error)
 {
     dispatchEvent(error);
+    m_started = false;
 }
 
 void SpeechRecognition::didStart()
@@ -122,6 +128,7 @@
 
 void SpeechRecognition::didEnd()
 {
+    m_started = false;
     if (!m_stoppedByActiveDOMObject)
         dispatchEvent(Event::create(eventNames().endEvent, /*canBubble=*/false, /*cancelable=*/false));
     unsetPendingActivity(this);
@@ -151,6 +158,7 @@
     , m_maxAlternatives(1)
     , m_controller(0)
     , m_stoppedByActiveDOMObject(false)
+    , m_started(false)
 {
     ASSERT(scriptExecutionContext()->isDocument());
     Document* document = static_cast<Document*>(scriptExecutionContext());

Modified: trunk/Source/WebCore/Modules/speech/SpeechRecognition.h (124224 => 124225)


--- trunk/Source/WebCore/Modules/speech/SpeechRecognition.h	2012-07-31 18:19:42 UTC (rev 124224)
+++ trunk/Source/WebCore/Modules/speech/SpeechRecognition.h	2012-07-31 18:26:45 UTC (rev 124225)
@@ -60,7 +60,7 @@
     void setMaxAlternatives(unsigned long maxAlternatives) { m_maxAlternatives = maxAlternatives; }
 
     // Callable by the user.
-    void start();
+    void start(ExceptionCode&);
     void stopFunction();
     void abort();
 
@@ -122,6 +122,7 @@
 
     SpeechRecognitionController* m_controller;
     bool m_stoppedByActiveDOMObject;
+    bool m_started;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/speech/SpeechRecognition.idl (124224 => 124225)


--- trunk/Source/WebCore/Modules/speech/SpeechRecognition.idl	2012-07-31 18:19:42 UTC (rev 124224)
+++ trunk/Source/WebCore/Modules/speech/SpeechRecognition.idl	2012-07-31 18:26:45 UTC (rev 124225)
@@ -36,7 +36,7 @@
         attribute boolean continuous;
         attribute unsigned long maxAlternatives;
 
-        void start();
+        void start() raises (DOMException);
         [ImplementedAs=stopFunction] void stop();
         void abort();
 

Modified: trunk/Tools/ChangeLog (124224 => 124225)


--- trunk/Tools/ChangeLog	2012-07-31 18:19:42 UTC (rev 124224)
+++ trunk/Tools/ChangeLog	2012-07-31 18:26:45 UTC (rev 124225)
@@ -1,3 +1,22 @@
+2012-07-31  Hans Wennborg  <h...@chromium.org>
+
+        Speech _javascript_ API: Throw exception for start() when already started
+        https://bugs.webkit.org/show_bug.cgi?id=92756
+
+        Reviewed by Adam Barth.
+
+        Fix the task queue in MockWebSpeechRecognizer.
+        It's important that we remove the task from the queue before we run
+        it, as running the task could alter the queue's state.
+
+        * DumpRenderTree/chromium/MockWebSpeechRecognizer.cpp:
+        (MockWebSpeechRecognizer::abort):
+        (MockWebSpeechRecognizer::setError):
+        (MockWebSpeechRecognizer::clearTaskQueue):
+        (MockWebSpeechRecognizer::StepTask::runIfValid):
+        * DumpRenderTree/chromium/MockWebSpeechRecognizer.h:
+        (MockWebSpeechRecognizer):
+
 2012-07-31  Dirk Pranke  <dpra...@chromium.org>
 
         nrwt: move handling the initial list of tests to skip to finder

Modified: trunk/Tools/DumpRenderTree/chromium/MockWebSpeechRecognizer.cpp (124224 => 124225)


--- trunk/Tools/DumpRenderTree/chromium/MockWebSpeechRecognizer.cpp	2012-07-31 18:19:42 UTC (rev 124224)
+++ trunk/Tools/DumpRenderTree/chromium/MockWebSpeechRecognizer.cpp	2012-07-31 18:26:45 UTC (rev 124225)
@@ -153,7 +153,7 @@
     m_handle = handle;
     m_client = client;
 
-    m_taskQueue.clear();
+    clearTaskQueue();
     m_wasAborted = true;
     m_taskQueue.append(adoptPtr(new ClientCallTask(this, &WebSpeechRecognizerClient::didEnd)));
     startTaskQueue();
@@ -167,7 +167,7 @@
 
 void MockWebSpeechRecognizer::setError(int code, const WebString& message)
 {
-    m_taskQueue.clear();
+    clearTaskQueue();
     m_taskQueue.append(adoptPtr(new ErrorTask(this, code, message)));
     m_taskQueue.append(adoptPtr(new ClientCallTask(this, &WebSpeechRecognizerClient::didEnd)));
     startTaskQueue();
@@ -191,17 +191,22 @@
     m_taskQueueRunning = true;
 }
 
+void MockWebSpeechRecognizer::clearTaskQueue()
+{
+    m_taskQueue.clear();
+    m_taskQueueRunning = false;
+}
+
 void MockWebSpeechRecognizer::StepTask::runIfValid()
 {
-    ASSERT(m_object->m_taskQueueRunning);
-
     if (m_object->m_taskQueue.isEmpty()) {
         m_object->m_taskQueueRunning = false;
         return;
     }
 
-    m_object->m_taskQueue[0]->run();
+    OwnPtr<Task> task = m_object->m_taskQueue[0].release();
     m_object->m_taskQueue.remove(0);
+    task->run();
 
     if (m_object->m_taskQueue.isEmpty()) {
         m_object->m_taskQueueRunning = false;

Modified: trunk/Tools/DumpRenderTree/chromium/MockWebSpeechRecognizer.h (124224 => 124225)


--- trunk/Tools/DumpRenderTree/chromium/MockWebSpeechRecognizer.h	2012-07-31 18:19:42 UTC (rev 124224)
+++ trunk/Tools/DumpRenderTree/chromium/MockWebSpeechRecognizer.h	2012-07-31 18:26:45 UTC (rev 124225)
@@ -72,6 +72,7 @@
 private:
     MockWebSpeechRecognizer();
     void startTaskQueue();
+    void clearTaskQueue();
 
     TaskList m_taskList;
     WebKit::WebSpeechRecognitionHandle m_handle;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to