Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: ui/file_manager/file_manager/foreground/js/tooltip_controller_unittest.js

Issue 1223693002: Add tooltips to the header buttons in Files app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/file_manager/foreground/js/tooltip_controller_unittest.js
diff --git a/ui/file_manager/file_manager/foreground/js/tooltip_controller_unittest.js b/ui/file_manager/file_manager/foreground/js/tooltip_controller_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..573a58de15d9ad326ab6789a8fb8eed7724d515f
--- /dev/null
+++ b/ui/file_manager/file_manager/foreground/js/tooltip_controller_unittest.js
@@ -0,0 +1,100 @@
+// 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.
+
+var chocolateButton;
+var cherriesButton;
+var otherButton;
+var tooltip;
+var controller;
+
+function waitForMutation(target) {
+ return new Promise(function(fulfill, reject) {
+ var observer = new MutationObserver(function(mutations) {
+ observer.disconnect();
+ fulfill();
+ });
+ observer.observe(target, {attributes: true});
+ });
+}
+
+function setUp() {
+ chocolateButton = document.querySelector('#chocolate');
+ cherriesButton = document.querySelector('#cherries');
+ otherButton = document.querySelector('#other');
+ tooltip = document.querySelector('#tooltip');
+ controller = new TooltipController(
+ tooltip, [chocolateButton, cherriesButton]);
+}
+
+function testFocus(callback) {
+ chocolateButton.focus();
+
+ return reportPromise(
+ waitForMutation(tooltip).then(function() {
+ assertEquals('Chocolate!', tooltip.textContent.trim());
+ assertTrue(!!tooltip.getAttribute('visible'));
+ assertEquals('4px', tooltip.style.left);
+ assertEquals('70px', tooltip.style.top);
+
+ cherriesButton.focus();
+ return waitForMutation(tooltip);
+ }).then(function() {
+ assertEquals('Cherries!', tooltip.textContent.trim());
+ assertTrue(!!tooltip.getAttribute('visible'));
+ var expectedLeft = document.body.offsetWidth - tooltip.offsetWidth + 'px';
+ assertEquals(expectedLeft, tooltip.style.left);
+ assertEquals('70px', tooltip.style.top);
+
+ otherButton.focus();
+ return waitForMutation(tooltip);
+ }).then(function() {
+ assertFalse(!!tooltip.getAttribute('visible'));
+ }), callback);
+}
+
+function testHover(callback) {
+ chocolateButton.dispatchEvent(new MouseEvent('mouseover'));
+
+ return reportPromise(
+ waitForMutation(tooltip).then(function() {
+ assertEquals('Chocolate!', tooltip.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(function() {
+ assertEquals('Cherries!', tooltip.textContent.trim());
+ assertTrue(!!tooltip.getAttribute('visible'));
+ var 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(function() {
+ assertFalse(!!tooltip.getAttribute('visible'));
+ }), callback);
+}
+
+function testClickHides(callback) {
+ chocolateButton.dispatchEvent(new MouseEvent('mouseover', {bubbles: true}));
+
+ return reportPromise(
+ waitForMutation(tooltip).then(function() {
+ assertEquals('Chocolate!', tooltip.textContent.trim());
+ assertTrue(!!tooltip.getAttribute('visible'));
+
+ // Hiding here is synchronous. Dispatch the event asynchronously, so the
+ // mutation observer is started before hiding.
+ setTimeout(function() {
+ document.body.dispatchEvent(new MouseEvent('mousedown'));
+ });
+ return waitForMutation(tooltip);
+ }).then(function() {
+ assertFalse(!!tooltip.getAttribute('visible'));
+ }), callback);
+}
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/tooltip_controller_unittest.html ('k') | ui/file_manager/file_manager/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698