Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Speech JavaScript API: Add test for constructing SpeechRecognitionErr…
…or events

https://bugs.webkit.org/show_bug.cgi?id=88868

Reviewed by Adam Barth.

Source/WebCore:

This adds a test for constructing SpeechRecognitionError events, and
code to make it work.

Test: fast/events/constructors/speech-recognition-error-constructor.html

* Modules/speech/SpeechRecognitionError.cpp:
(WebCore::SpeechRecognitionError::create):
(WebCore):
(WebCore::SpeechRecognitionError::SpeechRecognitionError):
(WebCore::SpeechRecognitionErrorInit::SpeechRecognitionErrorInit):
* Modules/speech/SpeechRecognitionError.h:
(SpeechRecognitionErrorInit):
(WebCore):
(SpeechRecognitionError):
(WebCore::SpeechRecognitionError::code):
* Modules/speech/SpeechRecognitionError.idl:

LayoutTests:

Add a layout test for constructing SpeechRecognitionError events.

* fast/events/constructors/speech-recognition-error-constructor-expected.txt: Added.
* fast/events/constructors/speech-recognition-error-constructor.html: Added.

Canonical link: https://commits.webkit.org/106803@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@120181 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
zmodem committed Jun 13, 2012
1 parent 30582e5 commit 5867c98
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 6 deletions.
12 changes: 12 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
2012-06-12 Hans Wennborg <hans@chromium.org>

Speech JavaScript API: Add test for constructing SpeechRecognitionError events
https://bugs.webkit.org/show_bug.cgi?id=88868

Reviewed by Adam Barth.

Add a layout test for constructing SpeechRecognitionError events.

* fast/events/constructors/speech-recognition-error-constructor-expected.txt: Added.
* fast/events/constructors/speech-recognition-error-constructor.html: Added.

2012-06-13 Ryosuke Niwa <rniwa@webkit.org>

Chromium rebaseline after r120173.
Expand Down
@@ -0,0 +1,17 @@
This tests the constructor for the SpeechRecognitionError DOM class.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS new webkitSpeechRecognitionError('eventType').bubbles is false
PASS new webkitSpeechRecognitionError('eventType').cancelable is false
PASS new webkitSpeechRecognitionError('eventType').code is 0
PASS new webkitSpeechRecognitionError('eventType').message is ""
PASS new webkitSpeechRecognitionError('eventType', { bubbles: false }).bubbles is false
PASS new webkitSpeechRecognitionError('eventType', { bubbles: true }).bubbles is true
PASS new webkitSpeechRecognitionError('eventType', { cancelable: false }).cancelable is false
PASS new webkitSpeechRecognitionError('eventType', { cancelable: true }).cancelable is true
PASS new webkitSpeechRecognitionError('eventType', { code: 1 }).code is 1
PASS new webkitSpeechRecognitionError('eventType', { code: 12345 }).code is 12345
PASS new webkitSpeechRecognitionError('eventType', { message: 'foo' }).message is "foo"

@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>

description("This tests the constructor for the SpeechRecognitionError DOM class.");

// Test constructor without initializer.
shouldBe("new webkitSpeechRecognitionError('eventType').bubbles", "false");
shouldBe("new webkitSpeechRecognitionError('eventType').cancelable", "false");
shouldBe("new webkitSpeechRecognitionError('eventType').code", "0");
shouldBeEqualToString("new webkitSpeechRecognitionError('eventType').message", "");

// Test passing bubbles in the initializer.
shouldBe("new webkitSpeechRecognitionError('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new webkitSpeechRecognitionError('eventType', { bubbles: true }).bubbles", "true");

// Test passing cancelable in the initializer.
shouldBe("new webkitSpeechRecognitionError('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new webkitSpeechRecognitionError('eventType', { cancelable: true }).cancelable", "true");

// Test passing code in the initializer.
shouldBe("new webkitSpeechRecognitionError('eventType', { code: 1 }).code", "1");
shouldBe("new webkitSpeechRecognitionError('eventType', { code: 12345 }).code", "12345");

// Test passing message in the initializer.
shouldBeEqualToString("new webkitSpeechRecognitionError('eventType', { message: 'foo' }).message", "foo");

</script>
<script src="../../js/resource/js-test-post.js"></script>
</body>
</html>


24 changes: 24 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,27 @@
2012-06-12 Hans Wennborg <hans@chromium.org>

Speech JavaScript API: Add test for constructing SpeechRecognitionError events
https://bugs.webkit.org/show_bug.cgi?id=88868

Reviewed by Adam Barth.

This adds a test for constructing SpeechRecognitionError events, and
code to make it work.

Test: fast/events/constructors/speech-recognition-error-constructor.html

* Modules/speech/SpeechRecognitionError.cpp:
(WebCore::SpeechRecognitionError::create):
(WebCore):
(WebCore::SpeechRecognitionError::SpeechRecognitionError):
(WebCore::SpeechRecognitionErrorInit::SpeechRecognitionErrorInit):
* Modules/speech/SpeechRecognitionError.h:
(SpeechRecognitionErrorInit):
(WebCore):
(SpeechRecognitionError):
(WebCore::SpeechRecognitionError::code):
* Modules/speech/SpeechRecognitionError.idl:

2012-06-13 Taiju Tsuiki <tzik@chromium.org>

Implement InspectorFileSystemAgent::readDirectory for FileSystem support.
Expand Down
19 changes: 18 additions & 1 deletion Source/WebCore/Modules/speech/SpeechRecognitionError.cpp
Expand Up @@ -36,18 +36,35 @@ PassRefPtr<SpeechRecognitionError> SpeechRecognitionError::create(Code code, con
return adoptRef(new SpeechRecognitionError(code, message));
}

PassRefPtr<SpeechRecognitionError> SpeechRecognitionError::create(const AtomicString& eventName, const SpeechRecognitionErrorInit& initializer)
{
return adoptRef(new SpeechRecognitionError(eventName, initializer));
}

SpeechRecognitionError::SpeechRecognitionError(Code code, const String& message)
: Event(eventNames().errorEvent, /*canBubble=*/false, /*cancelable=*/false) // FIXME: Spec should say whether it bubbles and is cancelable.
, m_code(code)
, m_code(static_cast<unsigned short>(code))
, m_message(message)
{
}

SpeechRecognitionError::SpeechRecognitionError(const AtomicString& eventName, const SpeechRecognitionErrorInit& initializer)
: Event(eventName, initializer)
, m_code(initializer.code)
, m_message(initializer.message)
{
}

const AtomicString& SpeechRecognitionError::interfaceName() const
{
return eventNames().interfaceForSpeechRecognitionError;
}

SpeechRecognitionErrorInit::SpeechRecognitionErrorInit()
: code(0)
{
}

} // namespace WebCore

#endif // ENABLE(SCRIPTED_SPEECH)
13 changes: 11 additions & 2 deletions Source/WebCore/Modules/speech/SpeechRecognitionError.h
Expand Up @@ -34,6 +34,13 @@

namespace WebCore {

struct SpeechRecognitionErrorInit : public EventInit {
SpeechRecognitionErrorInit();

unsigned short code;
String message;
};

class SpeechRecognitionError : public Event {
public:
enum Code {
Expand All @@ -50,16 +57,18 @@ class SpeechRecognitionError : public Event {

static PassRefPtr<SpeechRecognitionError> create(Code, const String&);
static PassRefPtr<SpeechRecognitionError> create() { return create(OTHER, emptyString()); }
static PassRefPtr<SpeechRecognitionError> create(const AtomicString&, const SpeechRecognitionErrorInit&);

Code code() { return m_code; }
unsigned short code() { return m_code; }
const String& message() { return m_message; }

virtual const AtomicString& interfaceName() const OVERRIDE;

private:
SpeechRecognitionError(Code, const String&);
SpeechRecognitionError(const AtomicString&, const SpeechRecognitionErrorInit&);

Code m_code;
unsigned short m_code;
String m_message;
};

Expand Down
7 changes: 4 additions & 3 deletions Source/WebCore/Modules/speech/SpeechRecognitionError.idl
Expand Up @@ -25,7 +25,8 @@

module core {
interface [
Conditional=SCRIPTED_SPEECH
Conditional=SCRIPTED_SPEECH,
ConstructorTemplate=Event
] SpeechRecognitionError : Event {
const unsigned short OTHER = 0;
const unsigned short NO_SPEECH = 1;
Expand All @@ -37,7 +38,7 @@ module core {
const unsigned short BAD_GRAMMAR = 7;
const unsigned short LANGUAGE_NOT_SUPPORTED = 8;

readonly attribute unsigned short code;
readonly attribute DOMString message;
readonly attribute [InitializedByEventConstructor] unsigned short code;
readonly attribute [InitializedByEventConstructor] DOMString message;
};
}

0 comments on commit 5867c98

Please sign in to comment.