OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 Google Inc. All rights reserved. | 2 # Copyright (c) 2011 Google Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
11 # copyright notice, this list of conditions and the following disclaimer | 11 # copyright notice, this list of conditions and the following disclaimer |
12 # in the documentation and/or other materials provided with the | 12 # in the documentation and/or other materials provided with the |
13 # distribution. | 13 # distribution. |
14 # * Neither the name of Google Inc. nor the names of its | 14 # * Neither the name of Google Inc. nor the names of its |
15 # contributors may be used to endorse or promote products derived from | 15 # contributors may be used to endorse or promote products derived from |
16 # this software without specific prior written permission. | 16 # this software without specific prior written permission. |
17 # | 17 # |
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 # | 29 # |
30 # Inspector protocol validator. | 30 # Inspector protocol validator. |
31 # | 31 # |
32 # Tests that subsequent protocol changes are not breaking backwards compatibilit
y. | 32 # Tests that subsequent protocol changes are not breaking backwards compatibilit
y. |
33 # Following violations are reported: | 33 # Following violations are reported: |
34 # | 34 # |
35 # - Domain has been removed | 35 # - Domain has been removed |
36 # - Command has been removed | 36 # - Command has been removed |
37 # - Required command parameter was added or changed from optional | 37 # - Required command parameter was added or changed from optional |
38 # - Required response parameter was removed or changed to optional | 38 # - Required response parameter was removed or changed to optional |
39 # - Event has been removed | 39 # - Event has been removed |
40 # - Required event parameter was removed or changed to optional | 40 # - Required event parameter was removed or changed to optional |
41 # - Parameter type has changed. | 41 # - Parameter type has changed. |
42 # | 42 # |
43 # For the parameters with composite types the above checks are also applied | 43 # For the parameters with composite types the above checks are also applied |
44 # recursively to every property of the type. | 44 # recursively to every property of the type. |
45 # | 45 # |
46 # Adding --show_changes to the command line prints out a list of valid public AP
I changes. | 46 # Adding --show_changes to the command line prints out a list of valid public AP
I changes. |
47 | 47 |
48 import collections | 48 import collections |
49 import copy | 49 import copy |
50 import os.path | 50 import os.path |
51 import optparse | 51 import optparse |
52 import re | 52 import re |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 result = { "id": "<transient>", "type": typed_object["type"] } | 190 result = { "id": "<transient>", "type": typed_object["type"] } |
191 if typed_object["type"] == "object": | 191 if typed_object["type"] == "object": |
192 result["properties"] = [] | 192 result["properties"] = [] |
193 elif typed_object["type"] == "array": | 193 elif typed_object["type"] == "array": |
194 result["items"] = typed_object["items"] | 194 result["items"] = typed_object["items"] |
195 return result | 195 return result |
196 elif "$ref" in typed_object: | 196 elif "$ref" in typed_object: |
197 ref = typed_object["$ref"] | 197 ref = typed_object["$ref"] |
198 if not ref in types_map: | 198 if not ref in types_map: |
199 errors.append("Can not resolve type: %s" % ref) | 199 errors.append("Can not resolve type: %s" % ref) |
200 types_map[ref] = { "id": "<transient>", "type": "object" } | 200 types_map[ref] = { "id": "<transient>", "type": "object" } |
201 return types_map[ref] | 201 return types_map[ref] |
202 | 202 |
203 | 203 |
204 def normalize_types_in_schema(domains): | 204 def normalize_types_in_schema(domains): |
205 types = {} | 205 types = {} |
206 for domain in domains: | 206 for domain in domains: |
207 domain_name = domain["domain"] | 207 domain_name = domain["domain"] |
208 normalize_types(domain, domain_name, types) | 208 normalize_types(domain, domain_name, types) |
209 return types | 209 return types |
210 | 210 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 output_file = open(output_path, "w") | 445 output_file = open(output_path, "w") |
446 | 446 |
447 domains = [] | 447 domains = [] |
448 baseline_domains = [] | 448 baseline_domains = [] |
449 version = load_domains_and_baselines(arg_values[0], domains, baseline_domain
s) | 449 version = load_domains_and_baselines(arg_values[0], domains, baseline_domain
s) |
450 if len(arg_values) > 1: | 450 if len(arg_values) > 1: |
451 load_domains_and_baselines(arg_values[1], domains, baseline_domains) | 451 load_domains_and_baselines(arg_values[1], domains, baseline_domains) |
452 | 452 |
453 expected_errors = [ | 453 expected_errors = [ |
454 "Debugger.globalObjectCleared: event has been removed", | 454 "Debugger.globalObjectCleared: event has been removed", |
455 "Runtime.executionContextCreated.context parameter->Runtime.ExecutionCon
textDescription.frameId: required property has been removed" | 455 "Runtime.executionContextCreated.context parameter->Runtime.ExecutionCon
textDescription.frameId: required property has been removed", |
| 456 "Debugger.canSetScriptSource: command has been removed" |
456 ] | 457 ] |
457 | 458 |
458 errors = compare_schemas(baseline_domains, domains, False) | 459 errors = compare_schemas(baseline_domains, domains, False) |
459 unexpected_errors = [] | 460 unexpected_errors = [] |
460 for i in range(len(errors)): | 461 for i in range(len(errors)): |
461 if errors[i] not in expected_errors: | 462 if errors[i] not in expected_errors: |
462 unexpected_errors.append(errors[i]) | 463 unexpected_errors.append(errors[i]) |
463 if len(unexpected_errors) > 0: | 464 if len(unexpected_errors) > 0: |
464 sys.stderr.write(" Compatibility checks FAILED\n") | 465 sys.stderr.write(" Compatibility checks FAILED\n") |
465 for error in unexpected_errors: | 466 for error in unexpected_errors: |
466 sys.stderr.write( " %s\n" % error) | 467 sys.stderr.write( " %s\n" % error) |
467 return 1 | 468 return 1 |
468 | 469 |
469 if arg_options.show_changes: | 470 if arg_options.show_changes: |
470 changes = compare_schemas(domains, baseline_domains, True) | 471 changes = compare_schemas(domains, baseline_domains, True) |
471 if len(changes) > 0: | 472 if len(changes) > 0: |
472 print " Public changes since %s:" % version | 473 print " Public changes since %s:" % version |
473 for change in changes: | 474 for change in changes: |
474 print " %s" % change | 475 print " %s" % change |
475 | 476 |
476 json.dump({"version": version, "domains": domains}, output_file, indent=4, s
ort_keys=False, separators=(',', ': ')) | 477 json.dump({"version": version, "domains": domains}, output_file, indent=4, s
ort_keys=False, separators=(',', ': ')) |
477 output_file.close() | 478 output_file.close() |
478 | 479 |
479 if __name__ == '__main__': | 480 if __name__ == '__main__': |
480 sys.exit(main()) | 481 sys.exit(main()) |
OLD | NEW |