aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/ui/editor/toolbarfactory_test.html
blob: 6141fc4325d0f33331ba95082f0153c71647ddcd (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
71
72
73
<!DOCTYPE html>
<!--
  All Rights Reserved.

  @author jparent@google.com (Julie Parent)
--><html>
<!--
Copyright 2010 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>Closure Unit Tests - goog.ui.editor.ToolbarFactory</title>
<script src="../../base.js"></script>
<script>
  goog.require('goog.testing.ExpectedFailures');
  goog.require('goog.testing.editor.TestHelper');
  goog.require('goog.testing.jsunit');
  goog.require('goog.ui.editor.ToolbarFactory');
</script>
</head>
<body>
<div id="myField">foo</div>
<script>
var helper = new goog.testing.editor.TestHelper(goog.dom.getElement('myField'));
var expectedFailures = new goog.testing.ExpectedFailures();

function setUp() {
  helper.setUpEditableElement();
}

function tearDown() {
  helper.tearDownEditableElement();
  expectedFailures.handleTearDown();
}

/**
 * Makes sure we have the correct conversion table in
 * goog.ui.editor.ToolbarFactory.LEGACY_SIZE_TO_PX_MAP_. Can only be tested in
 * a browser that takes legacy size values as input to execCommand but returns
 * pixel size values from queryCommandValue. That's OK because that's the only
 * situation where this conversion table's precision is critical. (When it's
 * used to size the labels of the font size menu options it's ok if it's a few
 * pixels off.)
 */
function testGetLegacySizeFromPx() {
  // We will be warned if other browsers start behaving like webkit pre-534.7.
  expectedFailures.expectFailureFor(
      !goog.userAgent.WEBKIT ||
      (goog.userAgent.WEBKIT && goog.userAgent.isVersion('534.7')));
  try {
    var fieldElem = goog.dom.getElement('myField');
    // Start from 1 because size 0 is bogus (becomes 16px, legacy size 3).
    for (var i = 1; i <
        goog.ui.editor.ToolbarFactory.LEGACY_SIZE_TO_PX_MAP_.length; i++) {
      helper.select(fieldElem, 0, fieldElem, 1);
      document.execCommand('fontSize', false, i);
      helper.select('foo', 1);
      var value = document.queryCommandValue('fontSize');
      assertEquals('Px size ' + value + ' should convert to legacy size ' + i,
          i, goog.ui.editor.ToolbarFactory.getLegacySizeFromPx(
              parseInt(value, 10)));
    }
  } catch (e) {
    expectedFailures.handleException(e);
  }
}
</script>
</body>
</html>