Move the accessibility mode flags from content/ to ui/
In order to use the accessibility mode flags from the ui AXPlatformNode
and friends, we need to move the flags from content/common into
ui/accessibility. The majority of this change is mechincal renaming.
Bug: 703369
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_site_isolation
Change-Id: I683d1e0abcf5ce33b65ea206f07899a12a284bb5
Reviewed-on: https://chromium-review.googlesource.com/588383
Commit-Queue: Doug Turner <[email protected]>
Reviewed-by: Dominic Mazzoni <[email protected]>
Reviewed-by: John Abd-El-Malek <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#490630}
diff --git a/ui/accessibility/PRESUBMIT.py b/ui/accessibility/PRESUBMIT.py
index 9e1b829..b5ebd0f 100644
--- a/ui/accessibility/PRESUBMIT.py
+++ b/ui/accessibility/PRESUBMIT.py
@@ -9,6 +9,9 @@
AX_IDL = 'ui/accessibility/ax_enums.idl'
AUTOMATION_IDL = 'chrome/common/extensions/api/automation.idl'
+AX_JS_FILE = 'content/browser/resources/accessibility/accessibility.js'
+AX_MODE_HEADER = 'ui/accessibility/ax_modes.h'
+
def InitialLowerCamelCase(unix_name):
words = unix_name.split('_')
return words[0] + ''.join(word.capitalize() for word in words[1:])
@@ -88,12 +91,91 @@
'Restriction', errs, output_api)
return errs
+# Given a full path to c++ header, return an array of the first static
+# constexpr defined. (Note there can be more than one defined in a C++
+# header)
+def GetConstexprFromFile(fullpath):
+ values = []
+ for line in open(fullpath).readlines():
+ # Strip out comments
+ line = re.sub('//.*', '', line)
+
+ # Look for lines of the form "static constexpr <type> NAME "
+ m = re.search('static constexpr [\w]+ ([\w]+)', line)
+ if m:
+ values.append(m.group(1))
+
+ return values
+
+# Given a full path to js file, return the AXMode consts
+# defined
+def GetAccessibilityModesFromFile(fullpath):
+ values = []
+ inside = False
+ for line in open(fullpath).readlines():
+ # Strip out comments
+ line = re.sub('//.*', '', line)
+
+ # Look for the block of code that defines AXMode
+ m = re.search('const AXMode = {', line)
+ if m:
+ inside = True
+ continue
+
+ # Look for a "}" character signifying the end of an enum
+ if line.find('};') >= 0:
+ return values
+
+ if not inside:
+ continue
+
+ m = re.search('([\w]+):', line)
+ if m:
+ values.append(m.group(1))
+ continue
+
+ # getters
+ m = re.search('get ([\w]+)\(\)', line)
+ if m:
+ values.append(m.group(1))
+ return values
+
+# Make sure that the modes defined in the C++ header match those defined in
+# the js file. Note that this doesn't guarantee that the values are the same,
+# but does make sure if we add or remove we can signal to the developer that
+# they should be aware that this dependency exists.
+def CheckModesMatch(input_api, output_api):
+ errs = []
+ repo_root = input_api.change.RepositoryRoot()
+
+ ax_modes_in_header = GetConstexprFromFile(
+ os.path.join(repo_root,AX_MODE_HEADER))
+ ax_modes_in_js = GetAccessibilityModesFromFile(
+ os.path.join(repo_root, AX_JS_FILE))
+
+ for value in ax_modes_in_header:
+ if value not in ax_modes_in_js:
+ errs.append(output_api.PresubmitError(
+ 'Found %s in %s, but did not find %s in %s' % (
+ value, AX_MODE_HEADER, value, AX_JS_FILE)))
+ return errs
+
def CheckChangeOnUpload(input_api, output_api):
- if AX_IDL not in input_api.LocalPaths():
- return []
- return CheckEnumsMatch(input_api, output_api)
+ errs = []
+ if AX_IDL in input_api.LocalPaths():
+ errs.extend(CheckEnumsMatch(input_api, output_api))
+
+ if AX_MODE_HEADER in input_api.LocalPaths():
+ errs.extend(CheckModesMatch(input_api, output_api))
+
+ return errs
def CheckChangeOnCommit(input_api, output_api):
- if AX_IDL not in input_api.LocalPaths():
- return []
- return CheckEnumsMatch(input_api, output_api)
+ errs = []
+ if AX_IDL in input_api.LocalPaths():
+ errs.extend(CheckEnumsMatch(input_api, output_api))
+
+ if AX_MODE_HEADER in input_api.LocalPaths():
+ errs.extend(CheckModesMatch(input_api, output_api))
+
+ return errs