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

Unified Diff: remoting/webapp/unittests/menu_button_unittest.js

Issue 401623004: Add unit-tests for MenuButton and simplify implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 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
« no previous file with comments | « remoting/webapp/menu_button.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/unittests/menu_button_unittest.js
diff --git a/remoting/webapp/unittests/menu_button_unittest.js b/remoting/webapp/unittests/menu_button_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..9e687a4504656bd047d10a99bd1ecb8ae209de06
--- /dev/null
+++ b/remoting/webapp/unittests/menu_button_unittest.js
@@ -0,0 +1,78 @@
+// Copyright 2014 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.
+
+(function() {
+
+'use strict';
+
+var menuButton = null;
+var menuShown = false;
+
+module('MenuButton', {
+ setup: function() {
+ var fixture = document.getElementById('qunit-fixture');
+ fixture.innerHTML =
+ '<span class="menu-button" id="menu-button-container">' +
+ '<button class="menu-button-activator">Click me</button>' +
+ '<ul>' +
+ '<li id="menu-option-1">Option 1</li>' +
+ '</ul>' +
+ '</span>';
+ menuButton = new remoting.MenuButton(
+ document.getElementById('menu-button-container'),
+ function() { menuShown = true; });
+ menuShown = false;
+ },
+ teardown: function() {
+ }
+});
+
+test('should display on click', function() {
+ var menu = menuButton.menu();
+ ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
+ menuButton.button().click();
+ ok(menu.offsetWidth != 0 && menu.offsetHeight != 0);
+});
+
+test('should dismiss when <body> is clicked', function() {
+ var menu = menuButton.menu();
+ menuButton.button().click();
+ document.body.click();
+ ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
+});
+
+test('should dismiss when button is clicked', function() {
+ var menu = menuButton.menu();
+ menuButton.button().click();
+ menuButton.button().click();
+ ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
+});
+
+test('should dismiss when menu item is clicked', function() {
+ var menu = menuButton.menu();
+ menuButton.button().click();
+ var element = document.getElementById('menu-option-1');
+ element.click();
+ ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
+});
+
+test('should invoke callback', function() {
+ ok(!menuShown);
+ menuButton.button().click();
+ ok(menuShown);
+});
+
+test('select method should set/unset background image', function() {
+ var element = document.getElementById('menu-option-1');
+ var style = window.getComputedStyle(element);
+ ok(style.backgroundImage == 'none');
+ remoting.MenuButton.select(element, true);
+ style = window.getComputedStyle(element);
+ ok(style.backgroundImage != 'none');
+ remoting.MenuButton.select(element, false);
+ style = window.getComputedStyle(element);
+ ok(style.backgroundImage == 'none');
+});
+
+}());
« no previous file with comments | « remoting/webapp/menu_button.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698