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

[js-code-coverage] Make filesTooltip tests optionally use $i18n{} labels

CL:2559234 introduced changes to disable $i18n{} template replacement
when the --devtools-code-coverage flag is passed and only for the Files
app extension. Introduce a helper to identify when a filesTooltip test
is in code coverage mode and use the $i18n{} label instead of the
replaced string.

--devtools-code-coverage

Bug: 1152612
Test: browser_tests --gtest_filter="*filesTooltip*"
Test: browser_tests --gtest_filter="*filesTooltip*"
Change-Id: Ia43f1b17ecdf8eea0a42dc5b23a2efd9787791c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2558814Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Noel Gordon <noel@chromium.org>
Commit-Queue: Ben Reich <benreich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830913}
parent 247af791
...@@ -14,6 +14,33 @@ ...@@ -14,6 +14,33 @@
const fileList = '#file-list'; const fileList = '#file-list';
const cancelButton = '#cancel-selection-button[has-tooltip]'; const cancelButton = '#cancel-selection-button[has-tooltip]';
/**
* $i18n{} labels used when template replacement is disabled.
*/
const i18nLabels = {
'SEARCH_TEXT_LABEL': 'Search',
'READONLY_INDICATOR_TOOLTIP':
'The contents of this folder are read-only. ' +
'Some activities are not supported.',
'CANCEL_SELECTION_BUTTON_LABEL': 'Cancel selection',
};
/**
* Returns $i18n{} label if devtools code coverage is active, otherwise the
* replaced contents.
*
* @param {string} key $i18n{} key of replacement text
*/
async function getExpectedLabelText(key) {
const isDevtoolsCoverageActive =
await sendTestMessage({name: 'isDevtoolsCoverageActive'});
if (isDevtoolsCoverageActive === 'true') {
return '$i18n{' + key + '}';
}
return i18nLabels[key];
}
/** /**
* Tests that tooltip is displayed when focusing an element with tooltip. * Tests that tooltip is displayed when focusing an element with tooltip.
*/ */
...@@ -27,10 +54,11 @@ ...@@ -27,10 +54,11 @@
await remoteCall.callRemoteTestUtil('focus', appId, [searchButton])); await remoteCall.callRemoteTestUtil('focus', appId, [searchButton]));
// The tooltip should be visible. // The tooltip should be visible.
let expectedLabelText = await getExpectedLabelText('SEARCH_TEXT_LABEL');
tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible); tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible);
let label = let label =
await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']); await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']);
chrome.test.assertEq('Search', label.text); chrome.test.assertEq(expectedLabelText, label.text);
// Focus another button with tooltip. // Focus another button with tooltip.
chrome.test.assertTrue( chrome.test.assertTrue(
...@@ -58,10 +86,12 @@ ...@@ -58,10 +86,12 @@
await remoteCall.callRemoteTestUtil('focus', appId, [cancelButton])); await remoteCall.callRemoteTestUtil('focus', appId, [cancelButton]));
// The tooltip should be visible. // The tooltip should be visible.
expectedLabelText =
await getExpectedLabelText('CANCEL_SELECTION_BUTTON_LABEL');
tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible); tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible);
label = label =
await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']); await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']);
chrome.test.assertEq('Cancel selection', label.text); chrome.test.assertEq(expectedLabelText, label.text);
}; };
/** /**
...@@ -77,10 +107,11 @@ ...@@ -77,10 +107,11 @@
'fakeMouseOver', appId, [searchButton])); 'fakeMouseOver', appId, [searchButton]));
// The tooltip should be visible. // The tooltip should be visible.
let expectedLabelText = await getExpectedLabelText('SEARCH_TEXT_LABEL');
tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible); tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible);
let label = let label =
await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']); await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']);
chrome.test.assertEq('Search', label.text); chrome.test.assertEq(expectedLabelText, label.text);
// Hover another button with tooltip. // Hover another button with tooltip.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
...@@ -101,13 +132,12 @@ ...@@ -101,13 +132,12 @@
'fakeMouseOver', appId, [readonlyIndicator])); 'fakeMouseOver', appId, [readonlyIndicator]));
// The tooltip should be visible. // The tooltip should be visible.
expectedLabelText =
await getExpectedLabelText('READONLY_INDICATOR_TOOLTIP');
tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible); tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible);
label = label =
await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']); await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']);
chrome.test.assertEq( chrome.test.assertEq(expectedLabelText, label.text);
'The contents of this folder are read-only.' +
' Some activities are not supported.',
label.text);
chrome.test.assertEq('card-tooltip', tooltip.attributes['class']); chrome.test.assertEq('card-tooltip', tooltip.attributes['class']);
chrome.test.assertEq('card-label', label.attributes['class']); chrome.test.assertEq('card-label', label.attributes['class']);
...@@ -124,10 +154,11 @@ ...@@ -124,10 +154,11 @@
'fakeMouseOver', appId, [searchButton])); 'fakeMouseOver', appId, [searchButton]));
// The tooltip should be visible. // The tooltip should be visible.
expectedLabelText = await getExpectedLabelText('SEARCH_TEXT_LABEL');
tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible); tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible);
label = label =
await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']); await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']);
chrome.test.assertEq('Search', label.text); chrome.test.assertEq(expectedLabelText, label.text);
// Tooltip class should be cleared as ordinary tooltip shown. // Tooltip class should be cleared as ordinary tooltip shown.
chrome.test.assertEq('', label.attributes['class']); chrome.test.assertEq('', label.attributes['class']);
...@@ -147,10 +178,11 @@ ...@@ -147,10 +178,11 @@
'fakeMouseOver', appId, [searchButton])); 'fakeMouseOver', appId, [searchButton]));
// The tooltip should be visible. // The tooltip should be visible.
const expectedLabelText = await getExpectedLabelText('SEARCH_TEXT_LABEL');
tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible); tooltip = await remoteCall.waitForElement(appId, tooltipQueryVisible);
const label = const label =
await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']); await remoteCall.waitForElement(appId, [tooltipQueryVisible, '#label']);
chrome.test.assertEq('Search', label.text); chrome.test.assertEq(expectedLabelText, label.text);
// Hover an element with tooltip. // Hover an element with tooltip.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
......
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