| 1 |
// Copyright 2011 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.plugins.LinkShortcutPluginTest'); |
| 16 |
goog.setTestOnly('goog.editor.plugins.LinkShortcutPluginTest'); |
| 17 |
|
| 18 |
goog.require('goog.dom'); |
| 19 |
goog.require('goog.dom.TagName'); |
| 20 |
goog.require('goog.editor.Field'); |
| 21 |
goog.require('goog.editor.plugins.BasicTextFormatter'); |
| 22 |
goog.require('goog.editor.plugins.LinkBubble'); |
| 23 |
goog.require('goog.editor.plugins.LinkShortcutPlugin'); |
| 24 |
goog.require('goog.events.KeyCodes'); |
| 25 |
goog.require('goog.testing.PropertyReplacer'); |
| 26 |
goog.require('goog.testing.dom'); |
| 27 |
goog.require('goog.testing.events'); |
| 28 |
goog.require('goog.testing.jsunit'); |
| 29 |
goog.require('goog.userAgent.product'); |
| 30 |
|
| 31 |
var propertyReplacer; |
| 32 |
|
| 33 |
function setUp() { |
| 34 |
propertyReplacer = new goog.testing.PropertyReplacer(); |
| 35 |
} |
| 36 |
|
| 37 |
function tearDown() { |
| 38 |
propertyReplacer.reset(); |
| 39 |
var field = document.getElementById('cleanup'); |
| 40 |
goog.dom.removeChildren(field); |
| 41 |
field.innerHTML = '<div id="field">http://www.google.com/</div>'; |
| 42 |
} |
| 43 |
|
| 44 |
function testShortcutCreatesALink() { |
| 45 |
if (goog.userAgent.product.SAFARI) { |
| 46 |
// TODO(b/20733468): Disabled so we can get the rest of the Closure test |
| 47 |
// suite running in a continuous build. Will investigate later. |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
propertyReplacer.set( |
| 52 |
window, 'prompt', function() { return 'http://www.google.com/'; }); |
| 53 |
var linkBubble = new goog.editor.plugins.LinkBubble(); |
| 54 |
var formatter = new goog.editor.plugins.BasicTextFormatter(); |
| 55 |
var plugin = new goog.editor.plugins.LinkShortcutPlugin(); |
| 56 |
var fieldEl = document.getElementById('field'); |
| 57 |
var field = new goog.editor.Field('field'); |
| 58 |
field.registerPlugin(formatter); |
| 59 |
field.registerPlugin(linkBubble); |
| 60 |
field.registerPlugin(plugin); |
| 61 |
field.makeEditable(); |
| 62 |
field.focusAndPlaceCursorAtStart(); |
| 63 |
var textNode = |
| 64 |
goog.testing.dom.findTextNode('http://www.google.com/', fieldEl); |
| 65 |
goog.testing.events.fireKeySequence( |
| 66 |
field.getElement(), goog.events.KeyCodes.K, {ctrlKey: true}); |
| 67 |
|
| 68 |
var href = |
| 69 |
goog.dom.getElementsByTagName(goog.dom.TagName.A, field.getElement())[0]; |
| 70 |
assertEquals('http://www.google.com/', href.href); |
| 71 |
var bubbleLink = |
| 72 |
document.getElementById(goog.editor.plugins.LinkBubble.TEST_LINK_ID_); |
| 73 |
assertEquals('http://www.google.com/', bubbleLink.innerHTML); |
| 74 |
} |