dom/bindings/parser/tests/test_dictionary.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.

     1 def WebIDLTest(parser, harness):
     2     parser.parse("""
     3       dictionary Dict2 : Dict1 {
     4         long child = 5;
     5         Dict1 aaandAnother;
     6       };
     7       dictionary Dict1 {
     8         long parent;
     9         double otherParent;
    10       };
    11     """)
    12     results = parser.finish()
    14     dict1 = results[1];
    15     dict2 = results[0];
    17     harness.check(len(dict1.members), 2, "Dict1 has two members")
    18     harness.check(len(dict2.members), 2, "Dict2 has four members")
    20     harness.check(dict1.members[0].identifier.name, "otherParent",
    21                   "'o' comes before 'p'")
    22     harness.check(dict1.members[1].identifier.name, "parent",
    23                   "'o' really comes before 'p'")
    24     harness.check(dict2.members[0].identifier.name, "aaandAnother",
    25                   "'a' comes before 'c'")
    26     harness.check(dict2.members[1].identifier.name, "child",
    27                   "'a' really comes before 'c'")
    29     # Now reset our parser
    30     parser = parser.reset()
    31     threw = False
    32     try:
    33         parser.parse("""
    34           dictionary Dict {
    35             long prop = 5;
    36             long prop;
    37           };
    38         """)
    39         results = parser.finish()
    40     except:
    41         threw = True
    43     harness.ok(threw, "Should not allow name duplication in a dictionary")
    45     # Now reset our parser again
    46     parser = parser.reset()
    47     threw = False
    48     try:
    49         parser.parse("""
    50           dictionary Dict1 : Dict2 {
    51             long prop = 5;
    52           };
    53           dictionary Dict2 : Dict3 {
    54             long prop2;
    55           };
    56           dictionary Dict3 {
    57             double prop;
    58           };
    59         """)
    60         results = parser.finish()
    61     except:
    62         threw = True
    64     harness.ok(threw, "Should not allow name duplication in a dictionary and "
    65                "its ancestor")
    67     # More reset
    68     parser = parser.reset()
    69     threw = False
    70     try:
    71         parser.parse("""
    72           interface Iface {};
    73           dictionary Dict : Iface {
    74             long prop;
    75           };
    76         """)
    77         results = parser.finish()
    78     except:
    79         threw = True
    81     harness.ok(threw, "Should not allow non-dictionary parents for dictionaries")
    83     # Even more reset
    84     parser = parser.reset()
    85     threw = False
    86     try:
    87         parser.parse("""
    88             dictionary A : B {};
    89             dictionary B : A {};
    90         """)
    91         results = parser.finish()
    92     except:
    93         threw = True
    95     harness.ok(threw, "Should not allow cycles in dictionary inheritance chains")
    97     parser = parser.reset()
    98     threw = False
    99     try:
   100         parser.parse("""
   101             dictionary A {
   102               [TreatNullAs=EmptyString] DOMString foo;
   103             };
   104         """)
   105         results = parser.finish()
   106     except:
   107         threw = True
   109     harness.ok(threw, "Should not allow [TreatNullAs] on dictionary members");
   111     parser = parser.reset()
   112     threw = False
   113     try:
   114         parser.parse("""
   115             dictionary A {
   116             };
   117             interface X {
   118               void doFoo(A arg);
   119             };
   120         """)
   121         results = parser.finish()
   122     except:
   123         threw = True
   125     harness.ok(threw, "Trailing dictionary arg must be optional")
   127     parser = parser.reset()
   128     threw = False
   129     try:
   130         parser.parse("""
   131             dictionary A {
   132             };
   133             interface X {
   134               void doFoo((A or DOMString) arg);
   135             };
   136         """)
   137         results = parser.finish()
   138     except:
   139         threw = True
   141     harness.ok(threw,
   142                "Trailing union arg containing a dictionary must be optional")
   144     parser = parser.reset()
   145     threw = False
   146     try:
   147         parser.parse("""
   148             dictionary A {
   149             };
   150             interface X {
   151               void doFoo(A arg1, optional long arg2);
   152             };
   153         """)
   154         results = parser.finish()
   155     except:
   156         threw = True
   158     harness.ok(threw, "Dictionary arg followed by optional arg must be optional")
   160     parser = parser.reset()
   161     threw = False
   162     try:
   163         parser.parse("""
   164             dictionary A {
   165             };
   166             interface X {
   167               void doFoo(A arg1, optional long arg2, long arg3);
   168             };
   169         """)
   170         results = parser.finish()
   171     except:
   172         threw = True
   174     harness.ok(not threw,
   175                "Dictionary arg followed by non-optional arg doesn't have to be optional")
   177     parser = parser.reset()
   178     threw = False
   179     try:
   180         parser.parse("""
   181             dictionary A {
   182             };
   183             interface X {
   184               void doFoo((A or DOMString) arg1, optional long arg2);
   185             };
   186         """)
   187         results = parser.finish()
   188     except:
   189         threw = True
   191     harness.ok(threw,
   192                "Union arg containing dictionary followed by optional arg must "
   193                "be optional")
   195     parser = parser.reset()
   196     parser.parse("""
   197             dictionary A {
   198             };
   199             interface X {
   200               void doFoo(A arg1, long arg2);
   201             };
   202         """)
   203     results = parser.finish()
   204     harness.ok(True, "Dictionary arg followed by required arg can be required")
   206     parser = parser.reset()
   207     threw = False
   208     try:
   209         parser.parse("""
   210             dictionary A {
   211             };
   212             interface X {
   213               void doFoo(optional A? arg1);
   214             };
   215         """)
   216         results = parser.finish()
   217     except:
   218         threw = True
   220     harness.ok(threw, "Dictionary arg must not be nullable")
   222     parser = parser.reset()
   223     threw = False
   224     try:
   225         parser.parse("""
   226             dictionary A {
   227             };
   228             interface X {
   229               void doFoo(optional (A or long)? arg1);
   230             };
   231         """)
   232         results = parser.finish()
   233     except:
   234         threw = True
   236     harness.ok(threw, "Dictionary arg must not be in a nullable union")
   238     parser = parser.reset()
   239     threw = False
   240     try:
   241         parser.parse("""
   242             dictionary A {
   243             };
   244             interface X {
   245               void doFoo(optional (A or long?) arg1);
   246             };
   247         """)
   248         results = parser.finish()
   249     except:
   250         threw = True
   251     harness.ok(threw,
   252                "Dictionary must not be in a union with a nullable type")
   254     parser = parser.reset()
   255     threw = False
   256     try:
   257         parser.parse("""
   258             dictionary A {
   259             };
   260             interface X {
   261               void doFoo(optional (long? or A) arg1);
   262             };
   263         """)
   264         results = parser.finish()
   265     except:
   266         threw = True
   267     harness.ok(threw,
   268                "A nullable type must not be in a union with a dictionary")
   270     parser = parser.reset()
   271     parser.parse("""
   272         dictionary A {
   273         };
   274         interface X {
   275           A? doFoo();
   276         };
   277     """)
   278     results = parser.finish()
   279     harness.ok(True, "Dictionary return value can be nullable")
   281     parser = parser.reset()
   282     parser.parse("""
   283         dictionary A {
   284         };
   285         interface X {
   286           void doFoo(optional A arg);
   287         };
   288     """)
   289     results = parser.finish()
   290     harness.ok(True, "Dictionary arg should actually parse")
   292     parser = parser.reset()
   293     parser.parse("""
   294         dictionary A {
   295         };
   296         interface X {
   297           void doFoo(optional (A or DOMString) arg);
   298         };
   299     """)
   300     results = parser.finish()
   301     harness.ok(True, "Union arg containing a dictionary should actually parse")
   303     parser = parser.reset()
   304     threw = False
   305     try:
   306         parser.parse("""
   307             dictionary Foo {
   308               Foo foo;
   309             };
   310         """)
   311         results = parser.finish()
   312     except:
   313         threw = True
   315     harness.ok(threw, "Member type must not be its Dictionary.")
   317     parser = parser.reset()
   318     threw = False
   319     try:
   320         parser.parse("""
   321             dictionary Foo3 : Foo {
   322               short d;
   323             };
   325             dictionary Foo2 : Foo3 {
   326               boolean c;
   327             };
   329             dictionary Foo1 : Foo2 {
   330               long a;
   331             };
   333             dictionary Foo {
   334               Foo1 b;
   335             };
   336         """)
   337         results = parser.finish()
   338     except:
   339         threw = True
   341     harness.ok(threw, "Member type must not be a Dictionary that "
   342                       "inherits from its Dictionary.")
   344     parser = parser.reset()
   345     threw = False
   346     try:
   347         parser.parse("""
   348             dictionary Foo {
   349               (Foo or DOMString)[]? b;
   350             };
   351         """)
   352         results = parser.finish()
   353     except:
   354         threw = True
   356     harness.ok(threw, "Member type must not be a Nullable type "
   357                       "whose inner type includes its Dictionary.")
   359     parser = parser.reset()
   360     threw = False
   361     try:
   362         parser.parse("""
   363             dictionary Foo {
   364               (DOMString or Foo) b;
   365             };
   366         """)
   367         results = parser.finish()
   368     except:
   369         threw = True
   371     harness.ok(threw, "Member type must not be a Union type, one of "
   372                       "whose member types includes its Dictionary.")
   374     parser = parser.reset()
   375     threw = False
   376     try:
   377         parser.parse("""
   378             dictionary Foo {
   379               sequence<sequence<sequence<Foo>>> c;
   380             };
   381         """)
   382         results = parser.finish()
   383     except:
   384         threw = True
   386     harness.ok(threw, "Member type must not be a Sequence type "
   387                       "whose element type includes its Dictionary.")
   389     parser = parser.reset()
   390     threw = False
   391     try:
   392         parser.parse("""
   393             dictionary Foo {
   394               (DOMString or Foo)[] d;
   395             };
   396         """)
   397         results = parser.finish()
   398     except:
   399         threw = True
   401     harness.ok(threw, "Member type must not be an Array type "
   402                       "whose element type includes its Dictionary.")
   404     parser = parser.reset()
   405     threw = False
   406     try:
   407         parser.parse("""
   408             dictionary Foo {
   409               Foo1 b;
   410             };
   412             dictionary Foo3 {
   413               Foo d;
   414             };
   416             dictionary Foo2 : Foo3 {
   417               short c;
   418             };
   420             dictionary Foo1 : Foo2 {
   421               long a;
   422             };
   423         """)
   424         results = parser.finish()
   425     except:
   426         threw = True
   428     harness.ok(threw, "Member type must not be a Dictionary, one of whose "
   429                       "members or inherited members has a type that includes "
   430                       "its Dictionary.")
   432     parser = parser.reset();
   433     threw = False
   434     try:
   435         parser.parse("""
   436             dictionary Foo {
   437             };
   439             dictionary Bar {
   440               Foo? d;
   441             };
   442         """)
   443         results = parser.finish()
   444     except:
   445         threw = True
   447     harness.ok(threw, "Member type must not be a nullable dictionary")
   449     parser = parser.reset();
   450     parser.parse("""
   451         dictionary Foo {
   452           unrestricted float  urFloat = 0;
   453           unrestricted float  urFloat2 = 1.1;
   454           unrestricted float  urFloat3 = -1.1;
   455           unrestricted float? urFloat4 = null;
   456           unrestricted float  infUrFloat = Infinity;
   457           unrestricted float  negativeInfUrFloat = -Infinity;
   458           unrestricted float  nanUrFloat = NaN;
   460           unrestricted double  urDouble = 0;
   461           unrestricted double  urDouble2 = 1.1;
   462           unrestricted double  urDouble3 = -1.1;
   463           unrestricted double? urDouble4 = null;
   464           unrestricted double  infUrDouble = Infinity;
   465           unrestricted double  negativeInfUrDouble = -Infinity;
   466           unrestricted double  nanUrDouble = NaN;
   467         };
   468     """)
   469     results = parser.finish()
   470     harness.ok(True, "Parsing default values for unrestricted types succeeded.")
   472     parser = parser.reset();
   473     threw = False
   474     try:
   475         parser.parse("""
   476             dictionary Foo {
   477               double f = Infinity;
   478             };
   479         """)
   480         results = parser.finish()
   481     except:
   482         threw = True
   484     harness.ok(threw, "Only unrestricted values can be initialized to Infinity")
   486     parser = parser.reset();
   487     threw = False
   488     try:
   489         parser.parse("""
   490             dictionary Foo {
   491               double f = -Infinity;
   492             };
   493         """)
   494         results = parser.finish()
   495     except:
   496         threw = True
   498     harness.ok(threw, "Only unrestricted values can be initialized to -Infinity")
   500     parser = parser.reset();
   501     threw = False
   502     try:
   503         parser.parse("""
   504             dictionary Foo {
   505               double f = NaN;
   506             };
   507         """)
   508         results = parser.finish()
   509     except:
   510         threw = True
   512     harness.ok(threw, "Only unrestricted values can be initialized to NaN")
   514     parser = parser.reset();
   515     threw = False
   516     try:
   517         parser.parse("""
   518             dictionary Foo {
   519               float f = Infinity;
   520             };
   521         """)
   522         results = parser.finish()
   523     except:
   524         threw = True
   526     harness.ok(threw, "Only unrestricted values can be initialized to Infinity")
   529     parser = parser.reset();
   530     threw = False
   531     try:
   532         parser.parse("""
   533             dictionary Foo {
   534               float f = -Infinity;
   535             };
   536         """)
   537         results = parser.finish()
   538     except:
   539         threw = True
   541     harness.ok(threw, "Only unrestricted values can be initialized to -Infinity")
   543     parser = parser.reset();
   544     threw = False
   545     try:
   546         parser.parse("""
   547             dictionary Foo {
   548               float f = NaN;
   549             };
   550         """)
   551         results = parser.finish()
   552     except:
   553         threw = True
   555     harness.ok(threw, "Only unrestricted values can be initialized to NaN")

mercurial