| 1 |
// Copyright 2010 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.ui.editor.ToolbarFactoryTest'); |
| 16 |
goog.setTestOnly('goog.ui.editor.ToolbarFactoryTest'); |
| 17 |
|
| 18 |
goog.require('goog.dom'); |
| 19 |
goog.require('goog.testing.ExpectedFailures'); |
| 20 |
goog.require('goog.testing.editor.TestHelper'); |
| 21 |
goog.require('goog.testing.jsunit'); |
| 22 |
goog.require('goog.ui.editor.ToolbarFactory'); |
| 23 |
goog.require('goog.userAgent'); |
| 24 |
|
| 25 |
var helper; |
| 26 |
var expectedFailures; |
| 27 |
|
| 28 |
function setUpPage() { |
| 29 |
helper = new goog.testing.editor.TestHelper(goog.dom.getElement('myField')); |
| 30 |
expectedFailures = new goog.testing.ExpectedFailures(); |
| 31 |
} |
| 32 |
|
| 33 |
function setUp() { |
| 34 |
helper.setUpEditableElement(); |
| 35 |
} |
| 36 |
|
| 37 |
function tearDown() { |
| 38 |
helper.tearDownEditableElement(); |
| 39 |
expectedFailures.handleTearDown(); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
/** |
| 44 |
* Makes sure we have the correct conversion table in |
| 45 |
* goog.ui.editor.ToolbarFactory.LEGACY_SIZE_TO_PX_MAP_. Can only be tested in |
| 46 |
* a browser that takes legacy size values as input to execCommand but returns |
| 47 |
* pixel size values from queryCommandValue. That's OK because that's the only |
| 48 |
* situation where this conversion table's precision is critical. (When it's |
| 49 |
* used to size the labels of the font size menu options it's ok if it's a few |
| 50 |
* pixels off.) |
| 51 |
*/ |
| 52 |
function testGetLegacySizeFromPx() { |
| 53 |
// We will be warned if other browsers start behaving like webkit pre-534.7. |
| 54 |
expectedFailures.expectFailureFor( |
| 55 |
!goog.userAgent.WEBKIT || |
| 56 |
(goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher('534.7'))); |
| 57 |
try { |
| 58 |
var fieldElem = goog.dom.getElement('myField'); |
| 59 |
// Start from 1 because size 0 is bogus (becomes 16px, legacy size 3). |
| 60 |
for (var i = 1; |
| 61 |
i < goog.ui.editor.ToolbarFactory.LEGACY_SIZE_TO_PX_MAP_.length; i++) { |
| 62 |
helper.select(fieldElem, 0, fieldElem, 1); |
| 63 |
document.execCommand('fontSize', false, i); |
| 64 |
helper.select('foo', 1); |
| 65 |
var value = document.queryCommandValue('fontSize'); |
| 66 |
assertEquals( |
| 67 |
'Px size ' + value + ' should convert to legacy size ' + i, i, |
| 68 |
goog.ui.editor.ToolbarFactory.getLegacySizeFromPx( |
| 69 |
parseInt(value, 10))); |
| 70 |
} |
| 71 |
} catch (e) { |
| 72 |
expectedFailures.handleException(e); |
| 73 |
} |
| 74 |
} |