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): ...@@ -488,16 +488,18 @@ def _ExtractVariantNodes(node):
""" """
variant_list = [] variant_list = []
for variant_node in IterElementsWithTag(node, 'variant', 1): for variant_node in IterElementsWithTag(node, 'variant', 1):
variant = dict(name=variant_node.getAttribute('name'), name = variant_node.getAttribute('name')
summary=variant_node.getAttribute('summary')) summary = variant_node.getAttribute('summary') if variant_node.hasAttribute(
'summary') else name
variant = dict(name=name, summary=summary)
obsolete_text = _GetObsoleteReason(variant_node) obsolete_text = _GetObsoleteReason(variant_node)
if obsolete_text: if obsolete_text:
variant['obsolete'] = 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: if variant_has_owners:
variant['owners'] = variant_owners variant['owners'] = owners
variant_list.append(variant) variant_list.append(variant)
......
...@@ -121,18 +121,18 @@ TEST_BASE_HISTOGRAM_XML_CONTENT = """ ...@@ -121,18 +121,18 @@ TEST_BASE_HISTOGRAM_XML_CONTENT = """
TEST_HISTOGRAM_WITH_TOKENS = """ TEST_HISTOGRAM_WITH_TOKENS = """
<histogram-configuration> <histogram-configuration>
<histograms> <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> <owner>me@chromium.org</owner>
<summary> <summary>
This is a histogram for button of {Color} color and {Size} size. This is a histogram for button of {Color} color and {Size} size.
</summary> </summary>
<token key="Color"> <token key="Color">
<variant name=".red" summary="red"> <variant name="red">
<obsolete> <obsolete>
Obsolete red Obsolete red
</obsolete> </obsolete>
</variant> </variant>
<variant name=".green" summary="green"> <variant name="green">
<owner>green@chromium.org</owner> <owner>green@chromium.org</owner>
</variant> </variant>
</token> </token>
...@@ -167,18 +167,18 @@ TEST_HISTOGRAM_WITH_VARIANTS = """ ...@@ -167,18 +167,18 @@ TEST_HISTOGRAM_WITH_VARIANTS = """
<variant name=".large" summary="large"/> <variant name=".large" summary="large"/>
</variants> </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> <owner>me@chromium.org</owner>
<summary> <summary>
This is a histogram for button of {Color} color and {Size} size. This is a histogram for button of {Color} color and {Size} size.
</summary> </summary>
<token key="Color"> <token key="Color">
<variant name=".red" summary="red"> <variant name="red">
<obsolete> <obsolete>
Obsolete red Obsolete red
</obsolete> </obsolete>
</variant> </variant>
<variant name=".green" summary="green"> <variant name="green">
<owner>green@chromium.org</owner> <owner>green@chromium.org</owner>
</variant> </variant>
</token> </token>
...@@ -690,6 +690,8 @@ class ExtractHistogramsTest(unittest.TestCase): ...@@ -690,6 +690,8 @@ class ExtractHistogramsTest(unittest.TestCase):
histogram_with_token, {}) histogram_with_token, {})
histograms_dict, _ = extract_histograms._UpdateHistogramsWithTokens( histograms_dict, _ = extract_histograms._UpdateHistogramsWithTokens(
histograms_dict) histograms_dict)
# Use the variant's name to format the summary when the variant's summary
# attribute is omitted.
self.assertEqual( self.assertEqual(
'This is a histogram for button of red color and small size.', 'This is a histogram for button of red color and small size.',
histograms_dict['HistogramName.red.small']['summary']) 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