Commit afeffa1e authored by Weilun Shi's avatar Weilun Shi Committed by Commit Bot

Support a shorthand to set<variant>'s summary attribute

Support a shorthand to use the variant's name to format the generated
histogram's summary when the variant's summary attribute is omitted.

Bug: 758782
Change-Id: I38d8659be97cdc26d3f0e0eb692bf423aded82b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387205
Commit-Queue: Weilun Shi <sweilun@chromium.org>
Commit-Queue: Steven Holte <holte@chromium.org>
Auto-Submit: Weilun Shi <sweilun@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803627}
parent a380d683
......@@ -488,16 +488,18 @@ def _ExtractVariantNodes(node):
"""
variant_list = []
for variant_node in IterElementsWithTag(node, 'variant', 1):
variant = dict(name=variant_node.getAttribute('name'),
summary=variant_node.getAttribute('summary'))
name = variant_node.getAttribute('name')
summary = variant_node.getAttribute('summary') if variant_node.hasAttribute(
'summary') else name
variant = dict(name=name, summary=summary)
obsolete_text = _GetObsoleteReason(variant_node)
if obsolete_text:
variant['obsolete'] = obsolete_text
variant_owners, variant_has_owners = _ExtractOwners(variant_node)
owners, variant_has_owners = _ExtractOwners(variant_node)
if variant_has_owners:
variant['owners'] = variant_owners
variant['owners'] = owners
variant_list.append(variant)
......
......@@ -121,18 +121,18 @@ TEST_BASE_HISTOGRAM_XML_CONTENT = """
TEST_HISTOGRAM_WITH_TOKENS = """
<histogram-configuration>
<histograms>
<histogram name="HistogramName{Color}{Size}" expires_after="2017-10-16">
<histogram name="HistogramName.{Color}{Size}" expires_after="2017-10-16">
<owner>me@chromium.org</owner>
<summary>
This is a histogram for button of {Color} color and {Size} size.
</summary>
<token key="Color">
<variant name=".red" summary="red">
<variant name="red">
<obsolete>
Obsolete red
</obsolete>
</variant>
<variant name=".green" summary="green">
<variant name="green">
<owner>green@chromium.org</owner>
</variant>
</token>
......@@ -167,18 +167,18 @@ TEST_HISTOGRAM_WITH_VARIANTS = """
<variant name=".large" summary="large"/>
</variants>
<histogram name="HistogramName{Color}{Size}" expires_after="2017-10-16">
<histogram name="HistogramName.{Color}{Size}" expires_after="2017-10-16">
<owner>me@chromium.org</owner>
<summary>
This is a histogram for button of {Color} color and {Size} size.
</summary>
<token key="Color">
<variant name=".red" summary="red">
<variant name="red">
<obsolete>
Obsolete red
</obsolete>
</variant>
<variant name=".green" summary="green">
<variant name="green">
<owner>green@chromium.org</owner>
</variant>
</token>
......@@ -690,6 +690,8 @@ class ExtractHistogramsTest(unittest.TestCase):
histogram_with_token, {})
histograms_dict, _ = extract_histograms._UpdateHistogramsWithTokens(
histograms_dict)
# Use the variant's name to format the summary when the variant's summary
# attribute is omitted.
self.assertEqual(
'This is a histogram for button of red color and small size.',
histograms_dict['HistogramName.red.small']['summary'])
......
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