<!DOCTYPE html>
<html>
<!--
Copyright 2008 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.
-->
<!--
Author: attila@google.com (Attila Bodis)
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.ui.Control</title>
<script src="../base.js"></script>
<script>
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.events');
goog.require('goog.events.BrowserEvent.MouseButton');
goog.require('goog.events.KeyCodes');
goog.require('goog.object');
goog.require('goog.style');
goog.require('goog.testing.ExpectedFailures');
goog.require('goog.testing.events');
goog.require('goog.testing.jsunit');
goog.require('goog.ui.Component.EventType');
goog.require('goog.ui.Component.State');
goog.require('goog.ui.Control');
goog.require('goog.ui.ControlRenderer');
goog.require('goog.ui.registry');
goog.require('goog.userAgent');
</script>
</head>
<body>
<div id="sandbox"></div>
<script>
// Disabled due to problems on farm.
var testFocus = false;
var control;
var ALL_EVENTS = goog.object.getValues(goog.ui.Component.EventType);
var events = {};
var expectedFailures = new goog.testing.ExpectedFailures();
var sandbox = document.getElementById('sandbox');
/**
* A dummy renderer, for testing purposes.
* @constructor
* @extends {goog.ui.ControlRenderer}
*/
function TestRenderer() {
goog.ui.ControlRenderer.call(this);
}
goog.inherits(TestRenderer, goog.ui.ControlRenderer);
/**
* Initializes the testcase prior to execution.
*/
function setUp() {
control = new goog.ui.Control('Hello');
control.setDispatchTransitionEvents(goog.ui.Component.State.ALL, true);
goog.events.listen(control, ALL_EVENTS, countEvent);
}
/**
* Cleans up after executing the testcase.
*/
function tearDown() {
control.dispose();
expectedFailures.handleTearDown();
goog.dom.removeChildren(sandbox);
resetEventCount();
}
/**
* Resets the global counter for events dispatched by test objects.
*/
function resetEventCount() {
goog.object.clear(events);
}
/**
* Increments the global counter for events of this type.
* @param {goog.events.Event} e Event to count.
*/
function countEvent(e) {
var type = e.type;
var target = e.target;
if (!events[target]) {
events[target] = {};
}
if (events[target][type]) {
events[target][type]++;
} else {
events[target][type] = 1;
}
}
/**
* Returns the number of times test objects dispatched events of the given
* type since the global counter was last reset.
* @param {goog.ui.Control} target Event target.
* @param {string} type Event type.
* @return {number} Number of events of this type.
*/
function getEventCount(target, type) {
return events[target] && events[target][type] || 0;
}
/**
* Returns true if no events were dispatched since the last reset.
* @return {boolean} Whether no events have been dispatched since the last
* reset.
*/
function noEventsDispatched() {
return !events || goog.object.isEmpty(events);
}
/**
* Returns the number of event listeners created by the control.
* @param {goog.ui.Control} control Control whose event listers are to be
* counted.
* @return {number} Number of event listeners.
*/
function getListenerCount(control) {
return control.googUiComponentHandler_ ?
goog.object.getCount(control.getHandler().keys_) : 0;
}
/**
* Simulates a mousedown event on the given element, including focusing it.
* @param {Element} element Element on which to simulate mousedown.
* @param {goog.events.BrowserEvent.MouseButton=} opt_button Mouse button;
* defaults to {@code goog.events.BrowserEvent.MouseButton.LEFT}.
* @return {boolean} Whether the event was allowed to proceed.
*/
function fireMouseDownAndFocus(element, opt_button) {
var result = goog.testing.events.fireMouseDownEvent(element, opt_button);
if (result) {
// Browsers move focus for all buttons, not just the left button.
element.focus();
}
return result;
}
/**
* @return {boolean} Whether we're on Mac Safari 3.x.
*/
function isMacSafari3() {
return goog.userAgent.WEBKIT && goog.userAgent.MAC &&
!goog.userAgent.isVersionOrHigher('527');
}
/**
* Tests the {@link goog.ui.Control} constructor.
*/
function testConstructor() {
assertNotNull('Constructed control must not be null', control);
assertEquals('Content must have expected value', 'Hello',
control.getContent());
assertEquals('Renderer must default to the registered renderer',
goog.ui.registry.getDefaultRenderer(goog.ui.Control),
control.getRenderer());
var content = goog.dom.createDom('div', null, 'Hello',
goog.dom.createDom('b', null, 'World'));
var testRenderer = new TestRenderer();
var fakeDomHelper = {};
var foo = new goog.ui.Control(content, testRenderer, fakeDomHelper);
assertNotNull('Constructed object must not be null', foo);
assertEquals('Content must have expected value', content,
foo.getContent());
assertEquals('Renderer must have expected value', testRenderer,
foo.getRenderer());
assertEquals('DOM helper must have expected value', fakeDomHelper,
foo.getDomHelper());
foo.dispose();
}
/**
* Tests {@link goog.ui.Control#getHandler}.
*/
function testGetHandler() {
assertUndefined('Event handler must be undefined before getHandler() ' +
'is called', control.googUiComponentHandler_);
var handler = control.getHandler();
assertNotNull('Event handler must not be null', handler);
assertEquals('getHandler() must return the same instance if called again',
handler, control.getHandler());
}
/**
* Tests {@link goog.ui.Control#isHandleMouseEvents}.
*/
function testIsHandleMouseEvents() {
assertTrue('Controls must handle their own mouse events by default',
control.isHandleMouseEvents());
}
/**
* Tests {@link goog.ui.Control#setHandleMouseEvents}.
*/
function testSetHandleMouseEvents() {
assertTrue('Control must handle its own mouse events by default',
control.isHandleMouseEvents());
control.setHandleMouseEvents(false);
assertFalse('Control must no longer handle its own mouse events',
control.isHandleMouseEvents());
control.setHandleMouseEvents(true);
assertTrue('Control must once again handle its own mouse events',
control.isHandleMouseEvents());
control.render(sandbox);
assertTrue('Rendered control must handle its own mouse events',
control.isHandleMouseEvents());
control.setHandleMouseEvents(false);
assertFalse('Rendered control must no longer handle its own mouse events',
control.isHandleMouseEvents());
control.setHandleMouseEvents(true);
assertTrue('Rendered control must once again handle its own mouse events',
control.isHandleMouseEvents());
}
/**
* Tests {@link goog.ui.Control#getKeyEventTarget}.
*/
function testGetKeyEventTarget() {
assertNull('Key event target of control without DOM must be null',
control.getKeyEventTarget());
control.createDom();
assertEquals('Key event target of control with DOM must be its element',
control.getElement(), control.getKeyEventTarget());
}
/**
* Test
没有合适的资源?快使用搜索试试~ 我知道了~
closure-library-master
共2316个文件
js:1345个
html:748个
gif:115个
5星 · 超过95%的资源 需积分: 10 12 下载量 68 浏览量
2014-09-16
09:40:18
上传
评论 1
收藏 5.18MB ZIP 举报
温馨提示
此开源代码是在电脑上运用blockly时要用的,想使您的孩子赢在起跑线上,就赶快下载吧
资源推荐
资源详情
资源评论
收起资源包目录
closure-library-master (2316个子文件)
AUTHORS 533B
CONTRIBUTING 2KB
toolbar.css 10KB
emojisprite.css 7KB
g-ratio.css 6KB
hsvapalette.css 5KB
imagelessbutton.css 5KB
menubutton.css 4KB
custombutton.css 4KB
editortoolbar.css 4KB
roundedtab.css 4KB
menuitem.css 4KB
g-fixed.css 4KB
charpicker.css 4KB
hsvpalette.css 4KB
tree.css 3KB
datepicker.css 2KB
multitestrunner.css 2KB
css3button.css 2KB
bubble.css 2KB
g-base.css 2KB
tab.css 2KB
equationeditor.css 2KB
bubble.css 1KB
dialog.css 1KB
flatmenubutton.css 1KB
flatbutton.css 1KB
combobox.css 1KB
demo.css 1KB
colorpalette.css 1KB
common.css 1KB
dialog.css 1KB
dimensionpicker.css 1KB
menubar.css 1KB
colorpicker-simplegrid.css 998B
autocomplete.css 971B
hovercard.css 963B
performancetable.css 928B
tristatemenuitem.css 918B
checkbox.css 892B
tabbar.css 886B
dragdropdetector.css 869B
linkdialog.css 737B
submenu.css 712B
colormenubutton.css 692B
palette.css 690B
button.css 688B
imagelessmenubutton.css 664B
emojipicker.css 660B
css3menubutton.css 653B
menu.css 619B
filteredmenu.css 551B
linkbutton.css 535B
roundedpanel.css 499B
filterobservingmenuitem.css 496B
menuseparator.css 404B
popupdatepicker.css 341B
tablesorter.css 325B
tooltip.css 322B
inputdatepicker.css 303B
cssom_test_import_1.css 262B
style_test_import.css 232B
cssom_test_import_2.css 227B
cssom_test_link_1.css 225B
crossdomainrpc_test.css 191B
iframeio_different_base_test.data 86B
xhr_test_json.data 38B
xhr_test_text.data 15B
closure.el 1KB
closure_test.el 1KB
hsva-sprite.gif 36KB
hsv-sprite.gif 33KB
imageloader_testimg3.gif 13KB
hsva-sprite-sm.gif 12KB
hsv-sprite-sm.gif 12KB
2EF.gif 2KB
2CA.gif 2KB
2F1.gif 2KB
tree.gif 2KB
2E3.gif 2KB
ratingstars.gif 1KB
2C3.gif 1KB
2F2.gif 1KB
2C5.gif 1KB
2EB.gif 1KB
2FA.gif 1KB
2C1.gif 1KB
2C7.gif 1KB
2CE.gif 1KB
2BE.gif 1KB
2C4.gif 1KB
2F4.gif 1KB
toolbar_icons.gif 1KB
202.gif 1KB
2F9.gif 1KB
2C8.gif 1KB
2C2.gif 1KB
2D7.gif 1KB
2E2.gif 1KB
2ED.gif 1KB
共 2316 条
- 1
- 2
- 3
- 4
- 5
- 6
- 24
资源评论
- 福兔迎祥2016-05-05参考一下,谢谢分享
quray
- 粉丝: 3
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功