Debian Codegraph @

closure-library/closure/goog/editor/focus_test.js

raw
1 // Copyright 2009 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.editor.focusTest');
16 goog.setTestOnly('goog.editor.focusTest');
17
18 goog.require('goog.dom.selection');
19 goog.require('goog.editor.BrowserFeature');
20 goog.require('goog.editor.focus');
21 goog.require('goog.testing.jsunit');
22
23 function setUp() {
24 // Make sure focus is not in the input to begin with.
25 var dummy = document.getElementById('dummyLink');
26 dummy.focus();
27 }
28
29
30 /**
31 * Tests that focusInputField() puts focus in the input field and sets the
32 * cursor to the end of the text cointained inside.
33 */
34 function testFocusInputField() {
35 var input = document.getElementById('myInput');
36 assertNotEquals(
37 'Input should not be focused initially', input, document.activeElement);
38
39 goog.editor.focus.focusInputField(input);
40 if (goog.editor.BrowserFeature.HAS_ACTIVE_ELEMENT) {
41 assertEquals(
42 'Input should be focused after call to focusInputField', input,
43 document.activeElement);
44 }
45 assertEquals(
46 'Selection should start at the end of the input text', input.value.length,
47 goog.dom.selection.getStart(input));
48 assertEquals(
49 'Selection should end at the end of the input text', input.value.length,
50 goog.dom.selection.getEnd(input));
51 }