Commit 804a7673 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Files app: Convert some unittests to use chrome://file_manager_test/

Convert FilesMessage test by adding the files_message_unittest.html and
loading it from chrome://file_manager_test/. This test doesn't require
Polymer, however it was logging errors because of Polymer, this change
fixes Polymer in the test so no more log errors.

Restore the FilesToolTip test that was deleted on CL:1493332 because it
was incompatible with elements loading Polymer via
chrome://resources/html/polymer.html, now it's compatible again so
restoring it.

Using code from CL:1736348.

Bug: 991105
Change-Id: I908001c209f4291891b96714b3293ad5d86aca7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1738506
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685476}
parent 13e85b32
......@@ -164,7 +164,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ProvidersModel) {
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FilesMessage) {
RunGeneratedTest("/foreground/elements/files_message_unittest.html");
RunTestURL("/file_manager/foreground/elements/files_message_unittest.html");
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FilesToast) {
......@@ -214,3 +214,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileTableList) {
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileTransferController) {
RunGeneratedTest("/foreground/js/file_transfer_controller_unittest.html");
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FilesToolTip) {
RunTestURL("/file_manager/foreground/elements/files_tooltip_unittest.html");
}
......@@ -151,6 +151,10 @@ void FileManagerJsTestBase::RunGeneratedTest(const std::string& file) {
RunTestImpl(embedded_test_server()->GetURL(file));
}
void FileManagerJsTestBase::RunTestURL(const std::string& file) {
RunTestImpl(GURL("chrome://file_manager_test" + file));
}
void FileManagerJsTestBase::RunTestImpl(const GURL& url) {
ui_test_utils::NavigateToURL(browser(), url);
content::WebContents* const web_contents =
......
......@@ -23,6 +23,10 @@ class FileManagerJsTestBase : public InProcessBrowserTest {
// |file|, relative to DIR_EXE/gen/base_path.
void RunGeneratedTest(const std::string& file);
// Run the test from chrome://file_manager_test/.
// |file| is relative path to //ui/file_manager/ .
void RunTestURL(const std::string& file);
// Set up & tear down
void SetUpOnMainThread() override;
void TearDownOnMainThread() override;
......@@ -30,9 +34,9 @@ class FileManagerJsTestBase : public InProcessBrowserTest {
// chrome://file_manager_test.
static const std::string kTestResourceURL;
private:
void RunTestImpl(const GURL& url);
private:
std::unique_ptr<TestChromeWebUIControllerFactory> webui_controller_factory_;
base::FilePath base_path_;
};
......
<!DOCTYPE html>
<link rel="import" href="chrome://file_manager_test/file_manager/foreground/elements/files_message.html">
<script src="files_message_unittest.js"> </script>
<!DOCTYPE html>
<style type="text/css">
button {
display: flex;
height: 32px;
margin: 30px;
width: 32px;
}
#container {
display: flex;
justify-content: space-between;
}
files-tooltip {
background: yellow;
box-sizing: border-box;
position: absolute;
text-align: center;
width: 100px;
}
</style>
<script src="chrome://file_manager_test/base/js/test_error_reporting.js"> </script>
<link rel="import" href="chrome://file_manager_test/file_manager/foreground/elements/files_tooltip.html">
<script src="files_tooltip_unittest.js"> </script>
<body>
<!-- Targets for tooltip testing. -->
<div id="container">
<button id="chocolate" aria-label="Chocolate!"></button>
<button id="cherries" aria-label="Cherries!"></button>
</div>
<!-- Button without a tooltip. -->
<button id="other"></button>
<!-- Polymer files tooltip element. -->
<files-tooltip></files-tooltip>
</body>
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/** @type {Element} */
let chocolateButton;
/** @type {Element} */
let cherriesButton;
/** @type {Element} */
let otherButton;
/** @type {FilesTooltip|Element} */
let tooltip;
function setUp() {
chocolateButton = document.querySelector('#chocolate');
cherriesButton = document.querySelector('#cherries');
otherButton = document.querySelector('#other');
tooltip = document.querySelector('files-tooltip');
tooltip.addTargets([chocolateButton, cherriesButton]);
}
function waitForMutation(target) {
return new Promise((fulfill, reject) => {
const observer = new MutationObserver(mutations => {
observer.disconnect();
fulfill();
});
observer.observe(target, {attributes: true});
});
}
function testFocus(callback) {
chocolateButton.focus();
return reportPromise(
waitForMutation(tooltip)
.then(() => {
const label = tooltip.shadowRoot.querySelector('#label');
assertEquals('Chocolate!', label.textContent.trim());
assertTrue(!!tooltip.getAttribute('visible'));
assertEquals('4px', tooltip.style.left);
assertEquals('70px', tooltip.style.top);
cherriesButton.focus();
return waitForMutation(tooltip);
})
.then(() => {
const label = tooltip.shadowRoot.querySelector('#label');
assertEquals('Cherries!', label.textContent.trim());
assertTrue(!!tooltip.getAttribute('visible'));
const expectedLeft =
document.body.offsetWidth - tooltip.offsetWidth + 'px';
assertEquals(expectedLeft, tooltip.style.left);
assertEquals('70px', tooltip.style.top);
otherButton.focus();
return waitForMutation(tooltip);
})
.then(() => {
assertFalse(!!tooltip.getAttribute('visible'));
}),
callback);
}
function testHover(callback) {
chocolateButton.dispatchEvent(new MouseEvent('mouseover'));
return reportPromise(
waitForMutation(tooltip)
.then(() => {
const label = tooltip.shadowRoot.querySelector('#label');
assertEquals('Chocolate!', label.textContent.trim());
assertTrue(!!tooltip.getAttribute('visible'));
assertEquals('4px', tooltip.style.left);
assertEquals('70px', tooltip.style.top);
chocolateButton.dispatchEvent(new MouseEvent('mouseout'));
cherriesButton.dispatchEvent(new MouseEvent('mouseover'));
return waitForMutation(tooltip);
})
.then(() => {
const label = tooltip.shadowRoot.querySelector('#label');
assertEquals('Cherries!', label.textContent.trim());
assertTrue(!!tooltip.getAttribute('visible'));
const expectedLeft =
document.body.offsetWidth - tooltip.offsetWidth + 'px';
assertEquals(expectedLeft, tooltip.style.left);
assertEquals('70px', tooltip.style.top);
cherriesButton.dispatchEvent(new MouseEvent('mouseout'));
return waitForMutation(tooltip);
})
.then(() => {
assertFalse(!!tooltip.getAttribute('visible'));
}),
callback);
}
function testClickHides(callback) {
chocolateButton.dispatchEvent(new MouseEvent('mouseover', {bubbles: true}));
return reportPromise(
waitForMutation(tooltip)
.then(() => {
const label = tooltip.shadowRoot.querySelector('#label');
assertEquals('Chocolate!', label.textContent.trim());
assertTrue(!!tooltip.getAttribute('visible'));
// Hiding here is synchronous. Dispatch the event asynchronously, so
// the mutation observer is started before hiding.
setTimeout(() => {
document.body.dispatchEvent(new MouseEvent('mousedown'));
});
return waitForMutation(tooltip);
})
.then(() => {
assertFalse(!!tooltip.getAttribute('visible'));
}),
callback);
}
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