dom/bindings/parser/tests/test_nullable_equivalency.py

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 import WebIDL
michael@0 2
michael@0 3 def WebIDLTest(parser, harness):
michael@0 4 parser.parse("""
michael@0 5 interface TestNullableEquivalency1 {
michael@0 6 attribute long a;
michael@0 7 attribute long? b;
michael@0 8 };
michael@0 9
michael@0 10 interface TestNullableEquivalency2 {
michael@0 11 attribute ArrayBuffer a;
michael@0 12 attribute ArrayBuffer? b;
michael@0 13 };
michael@0 14
michael@0 15 /* Can't have dictionary-valued attributes, so can't test that here */
michael@0 16
michael@0 17 enum TestNullableEquivalency4Enum {
michael@0 18 "Foo",
michael@0 19 "Bar"
michael@0 20 };
michael@0 21
michael@0 22 interface TestNullableEquivalency4 {
michael@0 23 attribute TestNullableEquivalency4Enum a;
michael@0 24 attribute TestNullableEquivalency4Enum? b;
michael@0 25 };
michael@0 26
michael@0 27 interface TestNullableEquivalency5 {
michael@0 28 attribute TestNullableEquivalency4 a;
michael@0 29 attribute TestNullableEquivalency4? b;
michael@0 30 };
michael@0 31
michael@0 32 interface TestNullableEquivalency6 {
michael@0 33 attribute boolean a;
michael@0 34 attribute boolean? b;
michael@0 35 };
michael@0 36
michael@0 37 interface TestNullableEquivalency7 {
michael@0 38 attribute DOMString a;
michael@0 39 attribute DOMString? b;
michael@0 40 };
michael@0 41
michael@0 42 interface TestNullableEquivalency8 {
michael@0 43 attribute float a;
michael@0 44 attribute float? b;
michael@0 45 };
michael@0 46
michael@0 47 interface TestNullableEquivalency9 {
michael@0 48 attribute double a;
michael@0 49 attribute double? b;
michael@0 50 };
michael@0 51
michael@0 52 interface TestNullableEquivalency10 {
michael@0 53 attribute object a;
michael@0 54 attribute object? b;
michael@0 55 };
michael@0 56
michael@0 57 interface TestNullableEquivalency11 {
michael@0 58 attribute double[] a;
michael@0 59 attribute double[]? b;
michael@0 60 };
michael@0 61
michael@0 62 interface TestNullableEquivalency12 {
michael@0 63 attribute TestNullableEquivalency9[] a;
michael@0 64 attribute TestNullableEquivalency9[]? b;
michael@0 65 };
michael@0 66 """)
michael@0 67
michael@0 68 for decl in parser.finish():
michael@0 69 if decl.isInterface():
michael@0 70 checkEquivalent(decl, harness)
michael@0 71
michael@0 72 def checkEquivalent(iface, harness):
michael@0 73 type1 = iface.members[0].type
michael@0 74 type2 = iface.members[1].type
michael@0 75
michael@0 76 harness.check(type1.nullable(), False, 'attr1 should not be nullable')
michael@0 77 harness.check(type2.nullable(), True, 'attr2 should be nullable')
michael@0 78
michael@0 79 # We don't know about type1, but type2, the nullable type, definitely
michael@0 80 # shouldn't be builtin.
michael@0 81 harness.check(type2.builtin, False, 'attr2 should not be builtin')
michael@0 82
michael@0 83 # Ensure that all attributes of type2 match those in type1, except for:
michael@0 84 # - names on an ignore list,
michael@0 85 # - names beginning with '_',
michael@0 86 # - functions which throw when called with no args, and
michael@0 87 # - class-level non-callables ("static variables").
michael@0 88 #
michael@0 89 # Yes, this is an ugly, fragile hack. But it finds bugs...
michael@0 90 for attr in dir(type1):
michael@0 91 if attr.startswith('_') or \
michael@0 92 attr in ['nullable', 'builtin', 'filename', 'location',
michael@0 93 'inner', 'QName', 'getDeps'] or \
michael@0 94 (hasattr(type(type1), attr) and not callable(getattr(type1, attr))):
michael@0 95 continue
michael@0 96
michael@0 97 a1 = getattr(type1, attr)
michael@0 98
michael@0 99 if callable(a1):
michael@0 100 try:
michael@0 101 v1 = a1()
michael@0 102 except:
michael@0 103 # Can't call a1 with no args, so skip this attriute.
michael@0 104 continue
michael@0 105
michael@0 106 try:
michael@0 107 a2 = getattr(type2, attr)
michael@0 108 except:
michael@0 109 harness.ok(False, 'Missing %s attribute on type %s in %s' % (attr, type2, iface))
michael@0 110 continue
michael@0 111
michael@0 112 if not callable(a2):
michael@0 113 harness.ok(False, "%s attribute on type %s in %s wasn't callable" % (attr, type2, iface))
michael@0 114 continue
michael@0 115
michael@0 116 v2 = a2()
michael@0 117 harness.check(v2, v1, '%s method return value' % attr)
michael@0 118 else:
michael@0 119 try:
michael@0 120 a2 = getattr(type2, attr)
michael@0 121 except:
michael@0 122 harness.ok(False, 'Missing %s attribute on type %s in %s' % (attr, type2, iface))
michael@0 123 continue
michael@0 124
michael@0 125 harness.check(a2, a1, '%s attribute should match' % attr)

mercurial