Commit 832058d1 authored by dmazzoni's avatar dmazzoni Committed by Commit bot

Sync up two accessibility enum files: ax_enums.idl and automation.idl

Add a PRESUBMIT rule that enforces that both ax_enums.idl and automation.idl
have matching enums so we don't accidentally let them get out of sync. Fix
one missing enum, and add a few missing enums directly to ChromeVox too.

BUG=641179
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2290763002
Cr-Commit-Position: refs/heads/master@{#415768}
parent bce5aa81
...@@ -36,6 +36,7 @@ chrome.automation.EventType = { ...@@ -36,6 +36,7 @@ chrome.automation.EventType = {
checkedStateChanged: '', checkedStateChanged: '',
childrenChanged: '', childrenChanged: '',
documentSelectionChanged: '', documentSelectionChanged: '',
expandedChanged: '',
focus: '', focus: '',
hide: '', hide: '',
hover: '', hover: '',
......
...@@ -46,14 +46,19 @@ DesktopAutomationHandler = function(node) { ...@@ -46,14 +46,19 @@ DesktopAutomationHandler = function(node) {
this.addListener_(e.activedescendantchanged, this.onActiveDescendantChanged); this.addListener_(e.activedescendantchanged, this.onActiveDescendantChanged);
this.addListener_(e.alert, this.onAlert); this.addListener_(e.alert, this.onAlert);
this.addListener_(e.ariaAttributeChanged, this.onEventIfInRange); this.addListener_(e.ariaAttributeChanged, this.onEventIfInRange);
this.addListener_(e.autocorrectionOccured, this.onEventIfInRange);
this.addListener_(e.checkedStateChanged, this.onCheckedStateChanged); this.addListener_(e.checkedStateChanged, this.onCheckedStateChanged);
this.addListener_(e.childrenChanged, this.onActiveDescendantChanged); this.addListener_(e.childrenChanged, this.onActiveDescendantChanged);
this.addListener_(e.expandedChanged, this.onEventIfInRange);
this.addListener_(e.focus, this.onFocus); this.addListener_(e.focus, this.onFocus);
this.addListener_(e.hover, this.onHover); this.addListener_(e.hover, this.onHover);
this.addListener_(e.invalidStatusChanged, this.onEventIfInRange);
this.addListener_(e.loadComplete, this.onLoadComplete); this.addListener_(e.loadComplete, this.onLoadComplete);
this.addListener_(e.menuEnd, this.onMenuEnd); this.addListener_(e.menuEnd, this.onMenuEnd);
this.addListener_(e.menuListItemSelected, this.onEventIfSelected); this.addListener_(e.menuListItemSelected, this.onEventIfSelected);
this.addListener_(e.menuStart, this.onMenuStart); this.addListener_(e.menuStart, this.onMenuStart);
this.addListener_(e.rowCollapsed, this.onEventIfInRange);
this.addListener_(e.rowExpanded, this.onEventIfInRange);
this.addListener_(e.scrollPositionChanged, this.onScrollPositionChanged); this.addListener_(e.scrollPositionChanged, this.onScrollPositionChanged);
this.addListener_(e.selection, this.onSelection); this.addListener_(e.selection, this.onSelection);
this.addListener_(e.textChanged, this.onTextChanged); this.addListener_(e.textChanged, this.onTextChanged);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
childrenChanged, childrenChanged,
clicked, clicked,
documentSelectionChanged, documentSelectionChanged,
expandedChanged,
focus, focus,
hide, hide,
hover, hover,
......
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Presubmit script for ui/accessibility."""
import os, re
AX_IDL = 'ui/accessibility/ax_enums.idl'
AUTOMATION_IDL = 'chrome/common/extensions/api/automation.idl'
def InitialLowerCamelCase(unix_name):
words = unix_name.split('_')
return words[0] + ''.join(word.capitalize() for word in words[1:])
# Given a full path to an IDL file containing enum definitions,
# parse the file for enums and return a dict mapping the enum name
# to a list of values for that enum.
def GetEnumsFromFile(fullpath):
enum_name = None
enums = {}
for line in open(fullpath).readlines():
# Strip out comments
line = re.sub('//.*', '', line)
# Look for lines of the form "enum ENUM_NAME {" and get the enum_name
m = re.search('enum ([\w]+) {', line)
if m:
enum_name = m.group(1)
continue
# Look for a "}" character signifying the end of an enum
if line.find('}') >= 0:
enum_name = None
continue
if not enum_name:
continue
# If we're inside an enum definition, add the first string consisting of
# alphanumerics plus underscore ("\w") to the list of values for that enum.
m = re.search('([\w]+)', line)
if m:
enums.setdefault(enum_name, [])
enums[enum_name].append(m.group(1))
return enums
def CheckMatchingEnum(ax_enums,
ax_enum_name,
automation_enums,
automation_enum_name,
errs,
output_api):
if ax_enum_name not in ax_enums:
errs.append(output_api.PresubmitError(
'Expected %s to have an enum named %s' % (AX_IDL, ax_enum_name)))
return
if automation_enum_name not in automation_enums:
errs.append(output_api.PresubmitError(
'Expected %s to have an enum named %s' % (
AUTOMATION_IDL, automation_enum_name)))
return
src = ax_enums[ax_enum_name]
dst = automation_enums[automation_enum_name]
for value in src:
if InitialLowerCamelCase(value) not in dst:
errs.append(output_api.PresubmitError(
'Found %s.%s in %s, but did not find %s.%s in %s' % (
ax_enum_name, value, AX_IDL,
automation_enum_name, InitialLowerCamelCase(value),
AUTOMATION_IDL)))
def CheckEnumsMatch(input_api, output_api):
repo_root = input_api.change.RepositoryRoot()
ax_enums = GetEnumsFromFile(os.path.join(repo_root, AX_IDL))
automation_enums = GetEnumsFromFile(os.path.join(repo_root, AUTOMATION_IDL))
errs = []
CheckMatchingEnum(ax_enums, 'AXRole', automation_enums, 'RoleType', errs,
output_api)
CheckMatchingEnum(ax_enums, 'AXState', automation_enums, 'StateType', errs,
output_api)
CheckMatchingEnum(ax_enums, 'AXEvent', automation_enums, 'EventType', errs,
output_api)
return errs
def CheckChangeOnUpload(input_api, output_api):
if AX_IDL not in input_api.LocalPaths():
return []
return CheckEnumsMatch(input_api, output_api)
def CheckChangeOnCommit(input_api, output_api):
if AX_IDL not in input_api.LocalPaths():
return []
return CheckEnumsMatch(input_api, output_api)
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
[camel_case_enum_to_string=true] namespace ui { [camel_case_enum_to_string=true] namespace ui {
// For new entries to the following three enums, also add to // For new entries to the following three enums, also add to
// chrome/common/extensions/api/automation.idl. // chrome/common/extensions/api/automation.idl. This is enforced
// by a PRESUBMIT check.
// //
// Explanation of the comments next to these events: // Explanation of the comments next to these events:
// //
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment