Bug 906432 - Use getOwnPropertyNames() in test_interfaces.html. r=smaug

This commit is contained in:
Masatoshi Kimura 2013-08-22 22:44:19 +09:00
Родитель 37640717b2
Коммит 5188bb1a3e
3 изменённых файлов: 217 добавлений и 88 удалений

Просмотреть файл

@ -23,6 +23,9 @@ SpecialPowers.addCategoryEntry("JavaScript-global-property", "testSNSM", "@mozil
SimpleTest.executeSoon(function () {
ok(window.testSNSM, "testSNSM should return an object");
// The category entry must be removed before finishing the test,
// otherwise it will affect all following tests in the test suite.
SpecialPowers.deleteCategoryEntry("JavaScript-global-property", "testSNSM", false);
SimpleTest.finish();
});

Просмотреть файл

@ -7,11 +7,12 @@
var win = XPCNativeWrapper.unwrap(window);
var SpecialPowers = win.SpecialPowers;
var is = win.is;
var todo_is = win.todo_is;
var ok = win.ok;
var interfaceNamesInGlobalScope = win.interfaceNamesInGlobalScope;
var interfaceNamesInXBLScope = win.interfaceNamesInXBLScope;
var excludedNames = win.excludedNames;
var createInterfaceMap = win.createInterfaceMap;
eval(win.runTest.toString());
runTest(window, true);
runTest(true);
win.SimpleTest.finish();
</constructor>
</implementation>

Просмотреть файл

@ -23,26 +23,88 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=766694
// This is a list of all interfaces that are exposed to every webpage. Please only
// add things to this list with great care.
// IMPORTANT: Do not change this list without review from a JavaScript Engine peer!
var ecmaGlobals =
[
"Array",
"ArrayBuffer",
"Boolean",
"DataView",
"Date",
"Error",
"EvalError",
"Float32Array",
"Float64Array",
"Function",
"Infinity",
"Int16Array",
"Int32Array",
"Int8Array",
"InternalError",
"Iterator",
"JSON",
"Map",
"Math",
"NaN",
"Number",
"Object",
{name: "ParallelArray", nightly: true},
"Proxy",
"RangeError",
"ReferenceError",
"RegExp",
"Set",
"StopIteration",
"String",
"SyntaxError",
"TypeError",
"Uint16Array",
"Uint32Array",
"Uint8Array",
"Uint8ClampedArray",
"URIError",
"WeakMap",
];
// IMPORTANT: Do not change this list without review from a JavaScript Engine peer!
// IMPORTANT: Do not change this list without review from a DOM peer!
var interfaceNamesInGlobalScope =
[
"AnalyserNode",
"AnimationEvent",
"Array",
"ArchiveRequest",
"AsyncScrollEventDetail",
"Attr",
"Audio",
"AudioBuffer",
"AudioContext",
"AudioBufferSourceNode",
"AudioDestinationNode",
"AudioListener",
"AudioNode",
"AudioParam",
"AudioProcessingEvent",
"AudioStreamTrack",
"BarProp",
"BatteryManager",
"BeforeUnloadEvent",
"BiquadFilterNode",
"Blob",
"BlobEvent",
{name: "BoxObject", xbl: true},
{name: "BrowserFeedWriter", android: false},
"CameraCapabilities",
"CameraControl",
"CameraManager",
"CanvasGradient",
"CanvasPattern",
"CanvasRenderingContext2D",
"CaretPosition",
"CDATASection",
"ChannelMergerNode",
"ChannelSplitterNode",
"CharacterData",
{name: "ChromeWindow", xbl: true},
"ClientRect",
"ClientRectList",
"ClipboardEvent",
@ -51,17 +113,21 @@ var interfaceNamesInGlobalScope =
"Comment",
"CompositionEvent",
"Controllers",
"CRMFObject",
"ConvolverNode",
{name: "CRMFObject", android: false},
"Crypto",
"CSS",
"CSS2Properties",
"CSSCharsetRule",
"CSSConditionRule",
"CSSFontFaceRule",
"CSSFontFeatureValuesRule",
{name: "CSSFontFeatureValuesRule", release: false},
"CSSGroupingRule",
"CSSGroupRuleRuleList",
"CSSImportRule",
"CSSMediaRule",
"CSSMozDocumentRule",
"CSSNameSpaceRule",
"CSSPageRule",
"CSSPrimitiveValue",
"CSSRule",
@ -76,6 +142,7 @@ var interfaceNamesInGlobalScope =
"DataChannel",
"DataContainerEvent",
"DataTransfer",
"DelayNode",
"DesktopNotification",
"DesktopNotificationCenter",
"DeviceAcceleration",
@ -86,14 +153,16 @@ var interfaceNamesInGlobalScope =
"DeviceRotationRate",
"DeviceStorage",
"DeviceStorageChangeEvent",
"DeviceStorageCursor",
"Document",
"DocumentFragment",
"DocumentType",
{name: "DOMConstructor", xbl: true},
"DOMCursor",
"DOMError",
"DOMException",
"DOMImplementation",
"DOMMMIError",
"DOMParser",
"DOMRequest",
"DOMSettableTokenList",
"DOMStringList",
@ -101,9 +170,9 @@ var interfaceNamesInGlobalScope =
"DOMTokenList",
"DOMTransactionEvent",
"DragEvent",
"DynamicsCompressorNode",
"Element",
"ElementReplaceEvent",
"ElementTimeControl",
"Event",
"EventListenerInfo",
"EventSource",
@ -115,10 +184,11 @@ var interfaceNamesInGlobalScope =
"FileRequest",
"FocusEvent",
"FormData",
"Gamepad",
"GamepadAxisMoveEvent",
"GamepadButtonEvent",
"GamepadEvent",
"GainNode",
{name: "Gamepad", android: false},
{name: "GamepadAxisMoveEvent", android: false},
{name: "GamepadButtonEvent", android: false},
{name: "GamepadEvent", android: false},
"HashChangeEvent",
"History",
"HTMLAnchorElement",
@ -131,7 +201,7 @@ var interfaceNamesInGlobalScope =
"HTMLButtonElement",
"HTMLCanvasElement",
"HTMLCollection",
"HTMLCommandElement",
"HTMLDataElement",
"HTMLDataListElement",
"HTMLDirectoryElement",
"HTMLDivElement",
@ -177,6 +247,7 @@ var interfaceNamesInGlobalScope =
"HTMLScriptElement",
"HTMLSelectElement",
"HTMLSourceElement",
"HTMLSpanElement",
"HTMLStyleElement",
"HTMLTableCaptionElement",
"HTMLTableCellElement",
@ -184,7 +255,9 @@ var interfaceNamesInGlobalScope =
"HTMLTableElement",
"HTMLTableRowElement",
"HTMLTableSectionElement",
"HTMLTemplateElement",
"HTMLTextAreaElement",
"HTMLTimeElement",
"HTMLTitleElement",
"HTMLUListElement",
"HTMLUnknownElement",
@ -193,6 +266,7 @@ var interfaceNamesInGlobalScope =
"IDBCursorWithValue",
"IDBDatabase",
"IDBFactory",
"IDBFileHandle",
"IDBIndex",
"IDBKeyRange",
"IDBObjectStore",
@ -200,18 +274,25 @@ var interfaceNamesInGlobalScope =
"IDBRequest",
"IDBTransaction",
"IDBVersionChangeEvent",
"Image",
"ImageData",
"JSON",
{name: "InstallTrigger", xbl: false},
"KeyEvent",
"KeyboardEvent",
"LoadStatus",
"LocalMediaStream",
"Location",
"LockedFile",
"LSProgressEvent",
"MediaElementAudioSourceNode",
"MediaError",
"MediaList",
"MediaQueryList",
"MediaRecorder",
"MediaStream",
"MediaStreamAudioDestinationNode",
"MediaStreamAudioSourceNode",
"MediaStreamEvent",
"MediaStreamTrack",
"MessageEvent",
"MimeType",
"MimeTypeArray",
@ -219,31 +300,26 @@ var interfaceNamesInGlobalScope =
"MouseEvent",
"MouseScrollEvent",
"MozApplicationEvent",
"MozBlobBuilder",
"MozCanvasPrintState",
"MozConnection",
"mozContact",
"MozContactChangeEvent",
"MozCSSKeyframeRule",
"MozCSSKeyframesRule",
"MozMmsEvent",
"MozMmsMessage",
"MozMobileCellInfo",
"MozMobileConnectionInfo",
"MozMobileMessageManager",
"MozMobileMessageThread",
"MozMobileNetworkInfo",
"MozNamedAttrMap",
"MozNetworkStats",
"MozNetworkStatsData",
"MozNetworkStatsManager",
"MozPowerManager",
"mozRTCIceCandidate",
"mozRTCPeerConnection",
"mozRTCSessionDescription",
"MozSettingsEvent",
"MozSmsEvent",
"MozSmsFilter",
"MozSmsMessage",
"MozSmsSegmentInfo",
"MozTimeManager",
"MozTouchEvent",
"MozWakeLock",
"MutationEvent",
"MutationObserver",
@ -253,47 +329,54 @@ var interfaceNamesInGlobalScope =
"NodeFilter",
"NodeIterator",
"NodeList",
"NodeSelector",
"NotifyAudioAvailableEvent",
"Notification",
"NotifyPaintEvent",
"NSRGBAColor",
"OfflineAudioCompletionEvent",
"OfflineAudioContext",
"OfflineResourceList",
"OpenWindowEventDetail",
"Option",
"OscillatorNode",
"PageTransitionEvent",
"PaintRequest",
"PaintRequestList",
"PaymentRequestInfo",
"PannerNode",
"Performance",
"PerformanceNavigation",
"PerformanceTiming",
"PeriodicWave",
"PhoneNumberService",
"Plugin",
"PluginArray",
"PopStateEvent",
"PopupBlockedEvent",
"ProcessingInstruction",
"ProgressEvent",
{name: "Promise", release: false},
{name: "PromiseResolver", release: false},
"PropertyNodeList",
"Range",
"RecordErrorEvent",
"Rect",
"RGBColor",
"RTCIceCandidate",
"RTCPeerConnection",
"RTCSessionDescription",
"RTCDataChannelEvent",
"RTCPeerConnectionIceEvent",
"Screen",
"ScriptProcessorNode",
"ScrollAreaEvent",
"Selection",
"SettingsLock",
"SettingsManager",
"SimpleGestureEvent",
{name: "SimpleTest", xbl: false},
"SmartCardEvent",
"SpeechRecognitionError",
"SpeechRecognitionEvent",
"SpeechSynthesisEvent",
{name: "SpecialPowers", xbl: false},
"Storage",
"StorageEvent",
"StorageItem",
"StorageObsolete",
"StyleRuleChangeEvent",
"StyleSheet",
"StyleSheetApplicableStateChangeEvent",
@ -310,8 +393,6 @@ var interfaceNamesInGlobalScope =
"SVGAnimatedLengthList",
"SVGAnimatedNumber",
"SVGAnimatedNumberList",
"SVGAnimatedPathData",
"SVGAnimatedPoints",
"SVGAnimatedPreserveAspectRatio",
"SVGAnimatedRect",
"SVGAnimatedString",
@ -328,7 +409,6 @@ var interfaceNamesInGlobalScope =
"SVGDocument",
"SVGElement",
"SVGEllipseElement",
"SVGEvent",
"SVGFEBlendElement",
"SVGFEColorMatrixElement",
"SVGFEComponentTransferElement",
@ -354,22 +434,20 @@ var interfaceNamesInGlobalScope =
"SVGFETileElement",
"SVGFETurbulenceElement",
"SVGFilterElement",
"SVGFilterPrimitiveStandardAttributes",
"SVGFitToViewBox",
"SVGForeignObjectElement",
"SVGGElement",
"SVGGradientElement",
"SVGGraphicsElement",
"SVGImageElement",
"SVGLength",
"SVGLengthList",
"SVGLinearGradientElement",
"SVGLineElement",
"SVGLocatable",
"SVGMarkerElement",
"SVGMaskElement",
"SVGMatrix",
"SVGMetadataElement",
"SVGMpathElement",
"SVGMPathElement",
"SVGNumber",
"SVGNumberList",
"SVGPathElement",
@ -407,31 +485,26 @@ var interfaceNamesInGlobalScope =
"SVGSetElement",
"SVGStopElement",
"SVGStringList",
"SVGStylable",
"SVGStyleElement",
"SVGSVGElement",
"SVGSwitchElement",
"SVGSymbolElement",
"SVGTests",
"SVGTextContentElement",
"SVGTextElement",
"SVGTextPathElement",
"SVGTextPositioningElement",
"SVGTitleElement",
"SVGTransform",
"SVGTransformable",
"SVGTransformList",
"SVGTSpanElement",
"SVGUnitTypes",
"SVGURIReference",
"SVGUseElement",
"SVGViewElement",
"SVGViewSpec",
"SVGZoomAndPan",
"SVGZoomEvent",
"TCPSocket",
"TCPServerSocket",
"Text",
"TextDecoder",
"TextEncoder",
"TextMetrics",
"TimeEvent",
"TimeRanges",
@ -439,79 +512,131 @@ var interfaceNamesInGlobalScope =
"TouchEvent",
"TouchList",
"TransitionEvent",
{name: "TreeColumn", xbl: true},
{name: "TreeColumns", xbl: true},
{name: "TreeContentView", xbl: true},
{name: "TreeSelection", xbl: true},
"TreeWalker",
"UIEvent",
"UndoManager",
"URL",
"UserDataHandler",
"UserProximityEvent",
"USSDReceivedEvent",
"ValidityState",
"VideoStreamTrack",
"WaveShaperNode",
"WebGLActiveInfo",
"WebGLBuffer",
"WebGLFramebuffer",
"WebGLProgram",
"WebGLRenderbuffer",
"WebGLRenderingContext",
"WebGLShader",
"WebGLShaderPrecisionFormat",
"WebGLTexture",
"WebGLUniformLocation",
"WebGLVertexArray",
"WebSocket",
"WheelEvent",
"Window",
"WindowUtils",
"XMLDocument",
"XMLHttpRequest",
"XMLHttpRequestEventTarget",
"XMLHttpRequestUpload",
"XMLSerializer",
"XMLStylesheetProcessingInstruction",
"XPathEvaluator",
"XPathExpression",
"XPathNamespace",
"XPathNSResolver",
"XPathResult",
"XSLTProcessor",
"XULElement",
{name: "XULButtonElement", xbl: true},
{name: "XULCheckboxElement", xbl: true},
{name: "XULCommandDispatcher", xbl: true},
{name: "XULCommandEvent", xbl: true},
{name: "XULControlElement", xbl: true},
{name: "XULControllers", xbl: true},
{name: "XULDocument", xbl: true},
{name: "XULElement", win: true, xbl: true},
{name: "XULLabeledControlElement", xbl: true},
{name: "XULPopupElement", xbl: true},
{name: "XULTemplateBuilder", xbl: true},
{name: "XULTreeBuilder", xbl: true},
]
// IMPORTANT: Do not change this list without review from a DOM peer!
// If your interface is named nsIDOMSomeInterface and you don't mean to expose
// it to every webpage, simply change its name to nsISomeInterface to fix this problem.
var interfaceNamesInXBLScope = [
"BoxObject",
"ChromeWindow",
"DOMConstructor",
"TreeColumn",
"TreeColumns",
"TreeContentView",
"TreeSelection",
"XULButtonElement",
"XULCheckboxElement",
"XULCommandDispatcher",
"XULCommandEvent",
"XULControlElement",
"XULControllers",
"XULDocument",
"XULLabeledControlElement",
"XULPopupElement",
"XULTemplateBuilder",
"XULTreeBuilder",
var excludedNames = [
"TraceMallocDisable", // debug builds only
"TraceMallocEnable", // debug builds only
"TraceMallocOpenLogFile", // debug builds only
"TraceMallocChangeLogFD", // debug builds only
"TraceMallocCloseLogFD", // debug builds only
"TraceMallocLogTimestamp", // debug builds only
"TraceMallocDumpAllocations", // debug builds only
];
function runTest(win, isXBLScope) {
for (var i in SpecialPowers.Components.interfaces) {
var s = i.toString();
var name = null;
if (s.indexOf("nsIDOM") == 0) {
name = s.substring("nsIDOM".length);
} else if (s.indexOf("nsI") == 0) {
name = s.substring("nsI".length);
}
if (name && (name in win)) {
ok(interfaceNamesInGlobalScope.indexOf(name) >= 0 ||
(isXBLScope && interfaceNamesInXBLScope.indexOf(name) >= 0),
"If this is failing: DANGER, are you sure you want to expose the new interface " + name + " to all webpages as a property on the window?");
function createInterfaceMap(isXBLScope) {
var version = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
var isNightly = version.endsWith("a1");
var isRelease = !version.contains("a");
var isAndroid = navigator.userAgent.indexOf("Android") >= 0;
var isWin = navigator.userAgent.indexOf("Windows") >= 0;
var interfaceMap = {};
for (var entry of ecmaGlobals) {
if (typeof(entry) === "string") {
// Standard ECMAScript global objects are not defined on the XBL scope.
interfaceMap[entry] = !isXBLScope;
} else if (entry.nightly === isNightly) {
interfaceMap[entry.name] = !isXBLScope;
} else {
interfaceMap[entry.name] = false;
}
}
for (var name of interfaceNamesInXBLScope) {
is(name in win, isXBLScope,
name + " should" + (isXBLScope ? "" : " NOT") + " be present in the global scope");
for (var entry of interfaceNamesInGlobalScope) {
if (typeof(entry) === "string") {
interfaceMap[entry] = true;
} else if (entry.xbl === isXBLScope ||
entry.win === isWin ||
entry.android === isAndroid ||
entry.release === isRelease) {
interfaceMap[entry.name] = true;
} else {
interfaceMap[entry.name] = false;
}
}
return interfaceMap;
}
function runTest(isXBLScope) {
var interfaceMap = createInterfaceMap(isXBLScope);
for (var name of Object.getOwnPropertyNames(window)) {
// An interfae name should start with an upper case character.
if (!/^(moz)?[A-Z]/.test(name) ||
excludedNames.indexOf(name) >= 0) {
continue;
}
ok(interfaceMap[name],
"If this is failing: DANGER, are you sure you want to expose the new interface " + name + " to all webpages as a property on the window?");
delete interfaceMap[name];
}
for (var name of Object.keys(interfaceMap)) {
ok(name in window === interfaceMap[name],
name + " should " + (interfaceMap[name] ? "" : " NOT") + " be defined on the " + (isXBLScope ? "XBL" : "global") +" scope");
if (!interfaceMap[name]) {
delete interfaceMap[name];
}
}
if (isXBLScope) {
todo_is(Object.keys(interfaceMap).length, 0,
"The following interface(s) are not enumerated: " + Object.keys(interfaceMap).join(", "));
} else {
is(Object.keys(interfaceMap).length, 0,
"The following interface(s) are not enumerated: " + Object.keys(interfaceMap).join(", "));
}
}
runTest(window, false);
runTest(false);
SimpleTest.waitForExplicitFinish();
</script>