summaryrefslogtreecommitdiff
path: root/utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py')
-rwxr-xr-xutils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py87
1 files changed, 83 insertions, 4 deletions
diff --git a/utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py b/utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py
index 9f51ea77..06769c95 100755
--- a/utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py
+++ b/utils/ipc/mojo/public/tools/mojom/check_stable_mojom_compatibility_unittest.py
@@ -1,5 +1,5 @@
-#!/usr/bin/env python
-# Copyright 2020 The Chromium Authors. All rights reserved.
+#!/usr/bin/env python3
+# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -15,7 +15,7 @@ import check_stable_mojom_compatibility
from mojom.generate import module
-class Change(object):
+class Change:
"""Helper to clearly define a mojom file delta to be analyzed."""
def __init__(self, filename, old=None, new=None):
@@ -28,7 +28,7 @@ class Change(object):
class UnchangedFile(Change):
def __init__(self, filename, contents):
- super(UnchangedFile, self).__init__(filename, old=contents, new=contents)
+ super().__init__(filename, old=contents, new=contents)
class CheckStableMojomCompatibilityTest(unittest.TestCase):
@@ -258,3 +258,82 @@ class CheckStableMojomCompatibilityTest(unittest.TestCase):
[Stable] struct T { foo.S s; int32 x; };
""")
])
+
+ def testWithPartialImport(self):
+ """The compatibility checking tool correctly parses imports with partial
+ paths."""
+ self.assertBackwardCompatible([
+ UnchangedFile('foo/foo.mojom', 'module foo; [Stable] struct S {};'),
+ Change('foo/bar.mojom',
+ old="""\
+ module bar;
+ import "foo/foo.mojom";
+ [Stable] struct T { foo.S s; };
+ """,
+ new="""\
+ module bar;
+ import "foo.mojom";
+ [Stable] struct T { foo.S s; };
+ """)
+ ])
+
+ self.assertBackwardCompatible([
+ UnchangedFile('foo/foo.mojom', 'module foo; [Stable] struct S {};'),
+ Change('foo/bar.mojom',
+ old="""\
+ module bar;
+ import "foo.mojom";
+ [Stable] struct T { foo.S s; };
+ """,
+ new="""\
+ module bar;
+ import "foo/foo.mojom";
+ [Stable] struct T { foo.S s; };
+ """)
+ ])
+
+ self.assertNotBackwardCompatible([
+ UnchangedFile('foo/foo.mojom', 'module foo; [Stable] struct S {};'),
+ Change('bar/bar.mojom',
+ old="""\
+ module bar;
+ import "foo/foo.mojom";
+ [Stable] struct T { foo.S s; };
+ """,
+ new="""\
+ module bar;
+ import "foo.mojom";
+ [Stable] struct T { foo.S s; };
+ """)
+ ])
+
+ self.assertNotBackwardCompatible([
+ UnchangedFile('foo/foo.mojom', 'module foo; [Stable] struct S {};'),
+ Change('bar/bar.mojom',
+ old="""\
+ module bar;
+ import "foo.mojom";
+ [Stable] struct T { foo.S s; };
+ """,
+ new="""\
+ module bar;
+ import "foo/foo.mojom";
+ [Stable] struct T { foo.S s; };
+ """)
+ ])
+
+ def testNewEnumDefault(self):
+ # Should be backwards compatible since it does not affect the wire format.
+ # This specific case also checks that the backwards compatibility checker
+ # does not throw an error due to the older version of the enum not
+ # specifying [Default].
+ self.assertBackwardCompatible([
+ Change('foo/foo.mojom',
+ old='[Extensible] enum E { One };',
+ new='[Extensible] enum E { [Default] One };')
+ ])
+ self.assertBackwardCompatible([
+ Change('foo/foo.mojom',
+ old='[Extensible] enum E { [Default] One, Two, };',
+ new='[Extensible] enum E { One, [Default] Two, };')
+ ])