aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <me@emiliocobos.me>2016-05-12 18:09:56 +0200
committerEmilio Cobos Álvarez <me@emiliocobos.me>2016-05-12 20:39:31 +0200
commitf893a2eaacee70b1044cea88dd184cd05dda31fa (patch)
tree368ba2c1c7f6d3187edda940b3ba4f7b3b8a6c0f
parent203898c941e4ac2c3a3a2f247ea3924c60858633 (diff)
downloadservo-f893a2eaacee70b1044cea88dd184cd05dda31fa.tar.gz
servo-f893a2eaacee70b1044cea88dd184cd05dda31fa.zip
bindings: Add test for keywords in dictionaries
-rw-r--r--components/script/dom/testbinding.rs69
-rw-r--r--components/script/dom/webidls/TestBinding.webidl4
-rw-r--r--tests/wpt/mozilla/meta/MANIFEST.json6
-rw-r--r--tests/wpt/mozilla/meta/mozilla/binding_keyword.html.ini3
-rw-r--r--tests/wpt/mozilla/tests/mozilla/binding_keyword.html16
5 files changed, 97 insertions, 1 deletions
diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs
index f8b45599b18..e7d4d1a9cff 100644
--- a/components/script/dom/testbinding.rs
+++ b/components/script/dom/testbinding.rs
@@ -6,7 +6,9 @@
use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
-use dom::bindings::codegen::Bindings::TestBindingBinding::{self, TestBindingMethods, TestEnum};
+use dom::bindings::codegen::Bindings::TestBindingBinding;
+use dom::bindings::codegen::Bindings::TestBindingBinding::{TestBindingMethods, TestDictionary};
+use dom::bindings::codegen::Bindings::TestBindingBinding::{TestDictionaryDefaults, TestEnum};
use dom::bindings::codegen::UnionTypes::{BlobOrBoolean, BlobOrBlobSequence};
use dom::bindings::codegen::UnionTypes::{BlobOrString, BlobOrUnsignedLong, EventOrString};
use dom::bindings::codegen::UnionTypes::{EventOrUSVString, HTMLElementOrLong};
@@ -286,6 +288,71 @@ impl TestBindingMethods for TestBinding {
Some(UnsignedLongOrBoolean::UnsignedLong(0u32))
}
fn ReceiveNullableSequence(&self) -> Option<Vec<i32>> { Some(vec![1]) }
+ fn ReceiveTestDictionaryWithSuccessOnKeyword(&self) -> TestDictionary {
+ TestDictionary {
+ anyValue: NullValue(),
+ booleanValue: None,
+ byteValue: None,
+ dict: TestDictionaryDefaults {
+ UnrestrictedDoubleValue: 0.0,
+ anyValue: NullValue(),
+ booleanValue: false,
+ byteValue: 0,
+ doubleValue: Finite::new(1.0).unwrap(),
+ enumValue: TestEnum::Foo,
+ floatValue: Finite::new(1.0).unwrap(),
+ longLongValue: 54,
+ longValue: 12,
+ nullableBooleanValue: None,
+ nullableByteValue: None,
+ nullableDoubleValue: None,
+ nullableFloatValue: None,
+ nullableLongLongValue: None,
+ nullableLongValue: None,
+ nullableObjectValue: ptr::null_mut(),
+ nullableOctetValue: None,
+ nullableShortValue: None,
+ nullableStringValue: None,
+ nullableUnrestrictedDoubleValue: None,
+ nullableUnrestrictedFloatValue: None,
+ nullableUnsignedLongLongValue: None,
+ nullableUnsignedLongValue: None,
+ nullableUnsignedShortValue: None,
+ nullableUsvstringValue: None,
+ octetValue: 0,
+ shortValue: 0,
+ stringValue: DOMString::new(),
+ unrestrictedFloatValue: 0.0,
+ unsignedLongLongValue: 0,
+ unsignedLongValue: 0,
+ unsignedShortValue: 0,
+ usvstringValue: USVString("".to_owned()),
+ },
+ doubleValue: None,
+ enumValue: None,
+ floatValue: None,
+ interfaceValue: None,
+ longLongValue: None,
+ longValue: None,
+ objectValue: None,
+ octetValue: None,
+ requiredValue: true,
+ seqDict: None,
+ shortValue: None,
+ stringValue: None,
+ type_: Some(DOMString::from("success")),
+ unrestrictedDoubleValue: None,
+ unrestrictedFloatValue: None,
+ unsignedLongLongValue: None,
+ unsignedLongValue: None,
+ unsignedShortValue: None,
+ usvstringValue: None,
+ }
+ }
+
+ fn TypeKeywordIsSuccess(&self, arg: &TestDictionary) -> bool {
+ arg.type_.as_ref().map(|s| s == "success").unwrap_or(false)
+ }
fn PassBoolean(&self, _: bool) {}
fn PassByte(&self, _: i8) {}
diff --git a/components/script/dom/webidls/TestBinding.webidl b/components/script/dom/webidls/TestBinding.webidl
index d0bfbbfef2a..e9d94509473 100644
--- a/components/script/dom/webidls/TestBinding.webidl
+++ b/components/script/dom/webidls/TestBinding.webidl
@@ -30,6 +30,8 @@ dictionary TestDictionary {
object objectValue;
TestDictionaryDefaults dict;
sequence<TestDictionaryDefaults> seqDict;
+ // Reserved rust keyword
+ DOMString type;
};
dictionary TestDictionaryDefaults {
@@ -196,6 +198,8 @@ interface TestBinding {
(sequence<long> or boolean)? receiveNullableUnion4();
(unsigned long or boolean)? receiveNullableUnion5();
sequence<long>? receiveNullableSequence();
+ TestDictionary receiveTestDictionaryWithSuccessOnKeyword();
+ boolean typeKeywordIsSuccess(TestDictionary arg);
void passBoolean(boolean arg);
void passByte(byte arg);
diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json
index d81335ad928..1b3f5967e4b 100644
--- a/tests/wpt/mozilla/meta/MANIFEST.json
+++ b/tests/wpt/mozilla/meta/MANIFEST.json
@@ -6064,6 +6064,12 @@
"url": "/_mozilla/mozilla/bad_cert_detected.html"
}
],
+ "mozilla/binding_keyword.html": [
+ {
+ "path": "mozilla/binding_keyword.html",
+ "url": "/_mozilla/mozilla/binding_keyword.html"
+ }
+ ],
"mozilla/blob.html": [
{
"path": "mozilla/blob.html",
diff --git a/tests/wpt/mozilla/meta/mozilla/binding_keyword.html.ini b/tests/wpt/mozilla/meta/mozilla/binding_keyword.html.ini
new file mode 100644
index 00000000000..4b7bda760f0
--- /dev/null
+++ b/tests/wpt/mozilla/meta/mozilla/binding_keyword.html.ini
@@ -0,0 +1,3 @@
+[binding_keyword.html]
+ type: testharness
+ prefs: [dom.testbinding.enabled:true]
diff --git a/tests/wpt/mozilla/tests/mozilla/binding_keyword.html b/tests/wpt/mozilla/tests/mozilla/binding_keyword.html
new file mode 100644
index 00000000000..2faa1ccc8f3
--- /dev/null
+++ b/tests/wpt/mozilla/tests/mozilla/binding_keyword.html
@@ -0,0 +1,16 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>Test for conversions from and to dictionary properties with keywords</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+test(function() {
+ var t = new TestBinding();
+
+ var dict = t.receiveTestDictionaryWithSuccessOnKeyword();
+ assert_equals(dict.type, "success");
+
+ var is_success = t.typeKeywordIsSuccess(dict);
+ assert_true(is_success);
+}, "Conversion of dictionary elements with rust keywords works")
+</script>