aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/editor/plugins/linkshortcutplugin_test.html
blob: 9de327fcf110d7ca338f658325a383d07d610db7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<!--
Copyright 2011 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>goog.editor.plugins.LinkShortcutPlugin Tests</title>
<script src="../../base.js"></script>
<script>
  goog.require('goog.dom.Range');
  goog.require('goog.editor.plugins.BasicTextFormatter');
  goog.require('goog.editor.plugins.LinkShortcutPlugin');
  goog.require('goog.editor.plugins.LinkBubble');
  goog.require('goog.editor.Field');
  goog.require('goog.events.KeyCodes');
  goog.require('goog.testing.PropertyReplacer');
  goog.require('goog.testing.dom');
  goog.require('goog.testing.events');
  goog.require('goog.testing.jsunit');
</script>
</head>
<body>
  <div id="cleanup">
    <div id="field">http://www.google.com/</div>
  </div>
  <script>
    var propertyReplacer;

    function setUp() {
      propertyReplacer = new goog.testing.PropertyReplacer();
    }

    function tearDown() {
      propertyReplacer.reset();
      var field = document.getElementById('cleanup');
      goog.dom.removeChildren(field);
      field.innerHTML = '<div id="field">http://www.google.com/</div>';
    }

    function testShortcutCreatesALink() {
      propertyReplacer.set(window, 'prompt', function() {
        return 'http://www.google.com/'; });
      var linkBubble = new goog.editor.plugins.LinkBubble();
      var formatter = new goog.editor.plugins.BasicTextFormatter();
      var plugin = new goog.editor.plugins.LinkShortcutPlugin();
      var fieldEl = document.getElementById('field');
      var field = new goog.editor.Field('field');
      field.registerPlugin(formatter);
      field.registerPlugin(linkBubble);
      field.registerPlugin(plugin);
      field.makeEditable();
      field.focusAndPlaceCursorAtStart();
      var textNode = goog.testing.dom.findTextNode('http://www.google.com/',
          fieldEl);
      goog.testing.events.fireKeySequence(
          field.getElement(), goog.events.KeyCodes.K, { ctrlKey: true });

      var href = field.getElement().getElementsByTagName('A')[0];
      assertEquals('http://www.google.com/', href.href);
      var bubbleLink =
          document.getElementById(goog.editor.plugins.LinkBubble.TEST_LINK_ID_);
      assertEquals('http://www.google.com/', bubbleLink.innerHTML);
    }
  </script>
</body>
</html>