| <!DOCTYPE html> |
| <!-- |
| Copyright 2012 Software Freedom Conservancy. All Rights Reserved. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <title>openscriptdialog_test.html</title> |
| <script src="test_bootstrap.js"></script> |
| <link href="../style.css" rel="stylesheet"> |
| <script> |
| goog.require('bot.Keyboard.Keys'); |
| goog.require('bot.action'); |
| goog.require('bot.dom'); |
| goog.require('goog.events'); |
| goog.require('goog.testing.jsunit'); |
| goog.require('goog.testing.recordFunction'); |
| goog.require('goog.ui.Component.EventType'); |
| goog.require('remote.ui.OpenScriptDialog'); |
| </script> |
| <script> |
| var dialog; |
| |
| function setUp() { |
| dialog = new remote.ui.OpenScriptDialog; |
| } |
| |
| function tearDown() { |
| dialog.dispose(); |
| } |
| |
| function assertDialogIsVisible() { |
| assertTrue('Expected dialog to be visible', dialog.isVisible()); |
| } |
| |
| function assertDialogNotVisible() { |
| assertFalse('Expected dialog not to be visible', dialog.isVisible()); |
| } |
| |
| function testShouldCloseDialogWhenEscapingFromButtonSet_ok() { |
| dialog.setVisible(true); |
| assertDialogIsVisible(); |
| |
| var button = dialog.getButtonSet().getButton('ok'); |
| bot.action.type(button, bot.Keyboard.Keys.ESC); |
| assertDialogNotVisible(); |
| } |
| |
| function testShouldCloseDialogWhenEscapingFromButtonSet_cancel() { |
| dialog.setVisible(true); |
| assertDialogIsVisible(); |
| |
| var button = dialog.getButtonSet().getButton('cancel'); |
| bot.action.type(button, bot.Keyboard.Keys.ESC); |
| assertDialogNotVisible(); |
| } |
| |
| function testShouldNotFireActionEventIfCancelled() { |
| var onAction = goog.testing.recordFunction(); |
| goog.events.listen(dialog, goog.ui.Component.EventType.ACTION, onAction); |
| |
| dialog.setVisible(true); |
| var button = dialog.getButtonSet().getButton('cancel'); |
| bot.action.click(button); |
| assertDialogNotVisible(); |
| assertEquals(0, onAction.getCallCount()); |
| } |
| |
| function testShouldNotFireActionEventIfSelectingOkWithoutSelection() { |
| var onAction = goog.testing.recordFunction(); |
| goog.events.listen(dialog, goog.ui.Component.EventType.ACTION, onAction); |
| |
| dialog.setVisible(true); |
| assertFalse(dialog.hasUserSelection()); |
| var button = dialog.getButtonSet().getButton('ok'); |
| bot.action.click(button); |
| assertDialogNotVisible(); |
| assertEquals(0, onAction.getCallCount()); |
| } |
| |
| function testShouldResetSelectionEachTimeDialogIsShown() { |
| dialog.setVisible(true); |
| assertFalse(dialog.hasUserSelection()); |
| |
| dialog.input_.setValue('foo'); |
| assertTrue(dialog.hasUserSelection()); |
| assertEquals('foo', dialog.getUserSelection()); |
| |
| dialog.setVisible(false); |
| dialog.setVisible(true); |
| assertFalse(dialog.hasUserSelection()); |
| assertEquals('', dialog.getUserSelection()); |
| } |
| |
| function testFiresActionEventOnOkWithSelection() { |
| var onAction = goog.testing.recordFunction(); |
| goog.events.listen(dialog, goog.ui.Component.EventType.ACTION, onAction); |
| |
| dialog.setVisible(true); |
| bot.action.type(dialog.getUrlElement(), 'foo bar'); |
| bot.action.click(dialog.getButtonSet().getButton('ok')); |
| assertDialogNotVisible(); |
| assertEquals('foo bar', dialog.getUserSelection()); |
| assertEquals(1, onAction.getCallCount()); |
| } |
| |
| function testFiresActionEventOnReturnKeyWithSelection() { |
| var onAction = goog.testing.recordFunction(); |
| goog.events.listen(dialog, goog.ui.Component.EventType.ACTION, onAction); |
| |
| dialog.setVisible(true); |
| bot.action.type(dialog.getUrlElement(), |
| ['foo bar', bot.Keyboard.Keys.ENTER]); |
| assertDialogNotVisible(); |
| assertEquals('foo bar', dialog.getUserSelection()); |
| assertEquals(1, onAction.getCallCount()); |
| } |
| </script> |