| 1 |
// Copyright 2015 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.graphics.CanvasGraphicsTest'); |
| 16 |
goog.setTestOnly('goog.graphics.CanvasGraphicsTest'); |
| 17 |
|
| 18 |
goog.require('goog.dom'); |
| 19 |
goog.require('goog.graphics.CanvasGraphics'); |
| 20 |
goog.require('goog.graphics.SolidFill'); |
| 21 |
goog.require('goog.graphics.Stroke'); |
| 22 |
goog.require('goog.testing.jsunit'); |
| 23 |
|
| 24 |
|
| 25 |
var graphics; |
| 26 |
|
| 27 |
function shouldRunTests() { |
| 28 |
graphics = new goog.graphics.CanvasGraphics(100, 100); |
| 29 |
graphics.createDom(); |
| 30 |
return graphics.canvas_.getContext; |
| 31 |
} |
| 32 |
|
| 33 |
function setUp() { |
| 34 |
graphics = new goog.graphics.CanvasGraphics(100, 100); |
| 35 |
graphics.createDom(); |
| 36 |
goog.dom.getElement('root').appendChild(graphics.getElement()); |
| 37 |
graphics.enterDocument(); |
| 38 |
} |
| 39 |
|
| 40 |
function tearDown() { |
| 41 |
graphics.dispose(); |
| 42 |
goog.dom.removeNode(graphics.getElement()); |
| 43 |
} |
| 44 |
|
| 45 |
function testDrawRemoveRect() { |
| 46 |
var fill = new goog.graphics.SolidFill('red'); |
| 47 |
var stroke = new goog.graphics.Stroke('blue'); |
| 48 |
var element = graphics.drawRect(10, 10, 80, 80, stroke, fill); |
| 49 |
assertEquals(1, graphics.canvasElement.children_.length); |
| 50 |
graphics.removeElement(element); |
| 51 |
assertEquals(0, graphics.canvasElement.children_.length); |
| 52 |
} |
| 53 |
|
| 54 |
function testDrawRemoveNestedRect() { |
| 55 |
var fill = new goog.graphics.SolidFill('red'); |
| 56 |
var stroke = new goog.graphics.Stroke('blue'); |
| 57 |
var group = graphics.createGroup(); |
| 58 |
assertEquals(1, graphics.canvasElement.children_.length); |
| 59 |
assertEquals(0, graphics.canvasElement.children_[0].children_.length); |
| 60 |
var element = graphics.drawRect(10, 10, 80, 80, stroke, fill, group); |
| 61 |
assertEquals(1, graphics.canvasElement.children_.length); |
| 62 |
assertEquals(1, graphics.canvasElement.children_[0].children_.length); |
| 63 |
graphics.removeElement(element); |
| 64 |
assertEquals(1, graphics.canvasElement.children_.length); |
| 65 |
assertEquals(0, graphics.canvasElement.children_[0].children_.length); |
| 66 |
} |