Commit c3fa6817 authored by Ben Reich's avatar Ben Reich Committed by Commit Bot

[js-code-coverage] Check $i18n{} label replacement exists

Make sure the |key| supplied to getExpectedLabelText has a corresponding
value in |i18nLabelReplacements| to aid debugging.

	--devtools-code-coverage

Test: browser_tests --gtest_filter="*filesTooltip*"
Test: browser_tests --gtest_filter="*filesTooltip*"
Bug: 1152612
Change-Id: I20b50181aadbcfea61e0101365d2dd7f5fe51edc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2561224
Commit-Queue: Ben Reich <benreich@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#831194}
parent 37668bc6
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
/** /**
* $i18n{} labels used when template replacement is disabled. * $i18n{} labels used when template replacement is disabled.
*
* @const {!Object<string, string>}
*/ */
const i18nLabels = { const i18nLabelReplacements = {
'SEARCH_TEXT_LABEL': 'Search', 'SEARCH_TEXT_LABEL': 'Search',
'READONLY_INDICATOR_TOOLTIP': 'READONLY_INDICATOR_TOOLTIP':
'The contents of this folder are read-only. ' + 'The contents of this folder are read-only. ' +
...@@ -26,19 +28,25 @@ ...@@ -26,19 +28,25 @@
}; };
/** /**
* Returns $i18n{} label if devtools code coverage is active, otherwise the * Returns $i18n{} label if devtools code coverage is enabled, otherwise the
* replaced contents. * replaced contents.
* *
* @param {string} key $i18n{} key of replacement text * @param {string} key $i18n{} key of replacement text
* @return {!Promise<string>}
*/ */
async function getExpectedLabelText(key) { async function getExpectedLabelText(key) {
const isDevtoolsCoverageActive = const isDevtoolsCoverageActive =
await sendTestMessage({name: 'isDevtoolsCoverageActive'}); await sendTestMessage({name: 'isDevtoolsCoverageActive'});
if (isDevtoolsCoverageActive === 'true') { if (isDevtoolsCoverageActive === 'true') {
return '$i18n{' + key + '}'; return '$i18n{' + key + '}';
} }
return i18nLabels[key]; // Verify |key| has a $i18n{} replacement in |i18nLabelReplacements|.
const label = i18nLabelReplacements[key];
chrome.test.assertEq('string', typeof label, 'Missing: ' + key);
return label;
} }
/** /**
......
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