blob: c8a3d02eccf931f50eb193e20c5e28798f270ca0 [file] [log] [blame] [edit]
<!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>createsessiondialog_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.CreateSessionDialog');
</script>
<script>
var dialog;
function setUp() {
dialog = new remote.ui.CreateSessionDialog([
'chrome',
'firefox',
'internet explorer'
]);
}
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 testShouldNotCloseDialogWhenEscapingFromSelect() {
dialog.setVisible(true);
dialog.browserSelect_.focus();
assertDialogIsVisible();
bot.action.type(bot.dom.getActiveElement(window), bot.Keyboard.Keys.ESC);
assertDialogIsVisible();
}
function testShouldCloseDialogWhenEscapingFromButtonSet_ok() {
dialog.setVisible(true);
assertDialogIsVisible();
bot.action.type(dialog.getButtonSet().getButton('ok'),
bot.Keyboard.Keys.ESC);
assertDialogNotVisible();
}
function testShouldCloseDialogWhenEscapingFromButtonSet_cancel() {
dialog.setVisible(true);
assertDialogIsVisible();
bot.action.type(dialog.getButtonSet().getButton('cancel'),
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);
bot.action.click(dialog.getButtonSet().getButton('cancel'));
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());
bot.action.click(dialog.getButtonSet().getButton('ok'));
assertDialogNotVisible();
assertEquals(0, onAction.getCallCount());
}
function testShouldResetSelectionEachTimeDialogIsShown() {
dialog.setVisible(true);
assertFalse(dialog.hasUserSelection());
dialog.browserSelect_.selectedIndex = 2;
assertTrue(dialog.hasUserSelection());
assertEquals('firefox', dialog.getUserSelection()['browserName']);
dialog.setVisible(false);
dialog.setVisible(true);
assertFalse(dialog.hasUserSelection());
}
function testFiresActionEventOnOkWithSelection() {
var onAction = goog.testing.recordFunction();
goog.events.listen(dialog, goog.ui.Component.EventType.ACTION, onAction);
dialog.setVisible(true);
dialog.getBrowserSelectElement().selectedIndex = 2;
bot.action.click(dialog.getButtonSet().getButton('ok'));
assertDialogNotVisible();
assertEquals('firefox', dialog.getUserSelection()['browserName']);
assertEquals(1, onAction.getCallCount());
}
</script>