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

Inline variants should be able to combine with out-of-line ones

Users should be able to extend the out-of-line variants by specifying
some inline variants under the <token> node.

Bug: 758782
Change-Id: I44a91a4b694dee148435f588552c6c91d89ecdd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473442
Commit-Queue: Weilun Shi <sweilun@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Auto-Submit: Weilun Shi <sweilun@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817754}
parent 702f7460
...@@ -476,6 +476,7 @@ def _ExtractTokens(histogram, variants_dict): ...@@ -476,6 +476,7 @@ def _ExtractTokens(histogram, variants_dict):
continue continue
token = dict(key=token_key) token = dict(key=token_key)
token['variants'] = []
# If 'variants' attribute is set for the <token>, get the list of Variant # If 'variants' attribute is set for the <token>, get the list of Variant
# objects from from the |variants_dict|. Else, extract the <variant> # objects from from the |variants_dict|. Else, extract the <variant>
...@@ -484,7 +485,7 @@ def _ExtractTokens(histogram, variants_dict): ...@@ -484,7 +485,7 @@ def _ExtractTokens(histogram, variants_dict):
variants_name = token_node.getAttribute('variants') variants_name = token_node.getAttribute('variants')
variant_list = variants_dict.get(variants_name) variant_list = variants_dict.get(variants_name)
if variant_list: if variant_list:
token['variants'] = variant_list token['variants'] = variant_list[:]
else: else:
logging.error( logging.error(
"The variants attribute %s of token key %s of histogram %s does " "The variants attribute %s of token key %s of histogram %s does "
...@@ -492,8 +493,8 @@ def _ExtractTokens(histogram, variants_dict): ...@@ -492,8 +493,8 @@ def _ExtractTokens(histogram, variants_dict):
(variants_name, token_key, histogram_name)) (variants_name, token_key, histogram_name))
token['variants'] = [] token['variants'] = []
have_error = True have_error = True
else: # Inline and out-of-line variants can be combined.
token['variants'] = _ExtractVariantNodes(token_node) token['variants'].extend(_ExtractVariantNodes(token_node))
tokens.append(token) tokens.append(token)
......
...@@ -243,6 +243,43 @@ TEST_HISTOGRAM_VARIANTS_DUPLICATE = """ ...@@ -243,6 +243,43 @@ TEST_HISTOGRAM_VARIANTS_DUPLICATE = """
""" """
TEST_HISTOGRAM_WITH_MIXED_VARIANTS = """
<histogram-configuration>
<histograms>
<variants name="HistogramNameSize">
<variant name=".medium" summary="medium"/>
<variant name=".large" summary="large"/>
</variants>
<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">
<obsolete>
Obsolete red
</obsolete>
</variant>
<variant name="green">
<owner>green@chromium.org</owner>
</variant>
</token>
<token key="Size" variants="HistogramNameSize">
<variant name="" summary="all"/>
<variant name=".small" summary="small">
<owner>small@chromium.org</owner>
<obsolete>
Obsolete small
</obsolete>
</variant>
</token>
</histogram>
</histograms>
</histogram-configuration>
"""
class ExtractHistogramsTest(unittest.TestCase): class ExtractHistogramsTest(unittest.TestCase):
def testSuffixObsoletion(self): def testSuffixObsoletion(self):
...@@ -701,6 +738,7 @@ class ExtractHistogramsTest(unittest.TestCase): ...@@ -701,6 +738,7 @@ class ExtractHistogramsTest(unittest.TestCase):
@parameterized.expand([ @parameterized.expand([
('InlineTokens', TEST_HISTOGRAM_WITH_TOKENS), ('InlineTokens', TEST_HISTOGRAM_WITH_TOKENS),
('InlineTokenAndOutOfLineVariants', TEST_HISTOGRAM_WITH_VARIANTS), ('InlineTokenAndOutOfLineVariants', TEST_HISTOGRAM_WITH_VARIANTS),
('MixedVariants', TEST_HISTOGRAM_WITH_MIXED_VARIANTS),
]) ])
def testUpdateNameWithTokens(self, _, input_xml): def testUpdateNameWithTokens(self, _, input_xml):
histogram_with_token = xml.dom.minidom.parseString(input_xml) histogram_with_token = xml.dom.minidom.parseString(input_xml)
...@@ -725,6 +763,7 @@ class ExtractHistogramsTest(unittest.TestCase): ...@@ -725,6 +763,7 @@ class ExtractHistogramsTest(unittest.TestCase):
@parameterized.expand([ @parameterized.expand([
('InlineTokens', TEST_HISTOGRAM_WITH_TOKENS), ('InlineTokens', TEST_HISTOGRAM_WITH_TOKENS),
('InlineTokenAndOutOfLineVariants', TEST_HISTOGRAM_WITH_VARIANTS), ('InlineTokenAndOutOfLineVariants', TEST_HISTOGRAM_WITH_VARIANTS),
('MixedVariants', TEST_HISTOGRAM_WITH_MIXED_VARIANTS),
]) ])
def testUpdateSummaryWithTokens(self, _, input_xml): def testUpdateSummaryWithTokens(self, _, input_xml):
histogram_with_token = xml.dom.minidom.parseString(input_xml) histogram_with_token = xml.dom.minidom.parseString(input_xml)
...@@ -762,6 +801,7 @@ class ExtractHistogramsTest(unittest.TestCase): ...@@ -762,6 +801,7 @@ class ExtractHistogramsTest(unittest.TestCase):
@parameterized.expand([ @parameterized.expand([
('InlineTokens', TEST_HISTOGRAM_WITH_TOKENS), ('InlineTokens', TEST_HISTOGRAM_WITH_TOKENS),
('InlineTokenAndOutOfLineVariants', TEST_HISTOGRAM_WITH_VARIANTS), ('InlineTokenAndOutOfLineVariants', TEST_HISTOGRAM_WITH_VARIANTS),
('MixedVariants', TEST_HISTOGRAM_WITH_MIXED_VARIANTS),
]) ])
def testUpdateWithTokenOwner(self, _, input_xml): def testUpdateWithTokenOwner(self, _, input_xml):
histogram_with_token = xml.dom.minidom.parseString(input_xml) histogram_with_token = xml.dom.minidom.parseString(input_xml)
...@@ -790,6 +830,7 @@ class ExtractHistogramsTest(unittest.TestCase): ...@@ -790,6 +830,7 @@ class ExtractHistogramsTest(unittest.TestCase):
@parameterized.expand([ @parameterized.expand([
('InlineTokens', TEST_HISTOGRAM_WITH_TOKENS), ('InlineTokens', TEST_HISTOGRAM_WITH_TOKENS),
('InlineTokenAndOutOfLineVariants', TEST_HISTOGRAM_WITH_VARIANTS), ('InlineTokenAndOutOfLineVariants', TEST_HISTOGRAM_WITH_VARIANTS),
('MixedVariants', TEST_HISTOGRAM_WITH_MIXED_VARIANTS),
]) ])
def testUpdateWithTokenObsolete(self, _, input_xml): def testUpdateWithTokenObsolete(self, _, input_xml):
histogram_with_token = xml.dom.minidom.parseString(input_xml) histogram_with_token = xml.dom.minidom.parseString(input_xml)
......
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