Backed out changeset 5cda44ae1ba0 (bug 921478) for perma-orange on Mochitest-1 on B2G Linux Opt on a CLOSED TREE

--HG--
rename : dom/indexedDB/test/test_globalObjects_content.html => dom/indexedDB/test/test_globalObjects.html
rename : dom/indexedDB/test/test_globalObjects_chrome.xul => dom/indexedDB/test/test_globalObjects.xul
rename : dom/indexedDB/test/unit/test_globalObjects_xpc.js => dom/indexedDB/test/unit/test_globalObjects.js
This commit is contained in:
Carsten "Tomcat" Book 2013-11-19 11:41:52 +01:00
parent c66b5e35ce
commit 4551469986
25 changed files with 231 additions and 152 deletions

View File

@ -20,7 +20,6 @@ this.EXPORTED_SYMBOLS = ["IndexedDBHelper"];
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.importGlobalProperties(["indexedDB"]);
this.IndexedDBHelper = function IndexedDBHelper() {}

View File

@ -18,7 +18,6 @@ const Ci = Components.interfaces;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
Cu.import("resource://gre/modules/PhoneNumberUtils.jsm");
Cu.importGlobalProperties(["indexedDB"]);
const DB_NAME = "contacts";
const DB_VERSION = 18;

View File

@ -148,7 +148,6 @@ function makeFailure(reason) {
const {Cc, Ci, Cu} = SpecialPowers;
Cu.import("resource://gre/modules/ContactDB.jsm", window);
Cu.importGlobalProperties(["indexedDB"]);
let cdb = new ContactDB();
cdb.init();

View File

@ -111,6 +111,35 @@ mozilla::StaticRefPtr<IndexedDatabaseManager> gInstance;
mozilla::Atomic<int32_t> gInitialized(0);
mozilla::Atomic<int32_t> gClosed(0);
// See ResolveConstructors below.
struct ConstructorInfo {
const char* const name;
JS::Handle<JSObject*> (* const resolve)(JSContext*, JS::Handle<JSObject*>,
bool);
jsid id;
};
ConstructorInfo gConstructorInfo[] = {
#define BINDING_ENTRY(_name) \
{ #_name, _name##Binding::GetConstructorObject, JSID_VOID },
BINDING_ENTRY(IDBCursor)
BINDING_ENTRY(IDBCursorWithValue)
BINDING_ENTRY(IDBDatabase)
BINDING_ENTRY(IDBFactory)
BINDING_ENTRY(IDBFileHandle)
BINDING_ENTRY(IDBIndex)
BINDING_ENTRY(IDBKeyRange)
BINDING_ENTRY(IDBObjectStore)
BINDING_ENTRY(IDBOpenDBRequest)
BINDING_ENTRY(IDBRequest)
BINDING_ENTRY(IDBTransaction)
BINDING_ENTRY(IDBVersionChangeEvent)
#undef BINDING_ENTRY
};
class AsyncDeleteFileRunnable MOZ_FINAL : public nsIRunnable
{
public:
@ -178,6 +207,53 @@ struct MOZ_STACK_CLASS InvalidateInfo
const nsACString& pattern;
};
bool
GetIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
JS::MutableHandle<JS::Value> aResult)
{
MOZ_ASSERT(nsContentUtils::IsCallerChrome(), "Only for chrome!");
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
"Not a global object!");
nsRefPtr<IDBFactory> factory;
if (NS_FAILED(IDBFactory::Create(aCx, aGlobal, nullptr,
getter_AddRefs(factory)))) {
return false;
}
MOZ_ASSERT(factory, "This should never fail for chrome!");
return !!WrapNewBindingObject(aCx, aGlobal, factory, aResult);
}
bool
IndexedDBLazyGetter(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
JS::Handle<jsid> aId, JS::MutableHandle<JS::Value> aVp)
{
MOZ_ASSERT(nsContentUtils::IsCallerChrome(), "Only for chrome!");
MOZ_ASSERT(JSID_IS_STRING(aId), "Bad id!");
MOZ_ASSERT(JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(aId), IDB_STR),
"Bad id!");
JS::Rooted<JSObject*> global(aCx, CheckedUnwrap(aGlobal,
/* stopAtOuter = */ false));
NS_ENSURE_TRUE(global, false);
NS_ENSURE_TRUE(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL, false);
JS::Rooted<JS::Value> indexedDB(aCx);
if (!GetIndexedDB(aCx, global, &indexedDB)) {
return false;
}
if (!JS_DefinePropertyById(aCx, global, aId, indexedDB, nullptr, nullptr,
JSPROP_ENUMERATE)) {
return false;
}
aVp.set(indexedDB);
return true;
}
} // anonymous namespace
IndexedDatabaseManager::IndexedDatabaseManager()
@ -406,39 +482,32 @@ IndexedDatabaseManager::TabContextMayAccessOrigin(const TabContext& aContext,
// static
bool
IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
IndexedDatabaseManager::DefineConstructors(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
{
MOZ_ASSERT(NS_IsMainThread());
for (uint32_t i = 0; i < mozilla::ArrayLength(gConstructorInfo); i++) {
if (!gConstructorInfo[i].resolve(aCx, aGlobal, true)) {
return false;
}
}
return true;
}
// static
bool
IndexedDatabaseManager::DefineIndexedDBGetter(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(nsContentUtils::IsCallerChrome(), "Only for chrome!");
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
"Passed object is not a global object!");
if (!IDBCursorBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBCursorWithValueBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBDatabaseBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBFactoryBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBFileHandleBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBIndexBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBKeyRangeBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBObjectStoreBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBOpenDBRequestBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBRequestBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBTransactionBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBVersionChangeEventBinding::GetConstructorObject(aCx, aGlobal)) {
return false;
}
nsRefPtr<IDBFactory> factory;
if (NS_FAILED(IDBFactory::Create(aCx, aGlobal, nullptr,
getter_AddRefs(factory)))) {
return false;
}
MOZ_ASSERT(factory, "This should never fail for chrome!");
JS::Rooted<JS::Value> indexedDB(aCx);
if (!WrapNewBindingObject(aCx, aGlobal, factory, &indexedDB)) {
if (!GetIndexedDB(aCx, aGlobal, &indexedDB)) {
return false;
}
@ -446,6 +515,20 @@ IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
JSPROP_ENUMERATE);
}
// static
bool
IndexedDatabaseManager::DefineIndexedDBLazyGetter(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(nsContentUtils::IsCallerChrome(), "Only for chrome!");
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
"Passed object is not a global object!");
return JS_DefineProperty(aCx, aGlobal, IDB_STR, JSVAL_VOID,
IndexedDBLazyGetter, nullptr, 0);
}
// static
bool
IndexedDatabaseManager::IsClosed()
@ -666,7 +749,7 @@ IndexedDatabaseManager::InitWindowless(const jsval& aGlobal, JSContext* aCx)
return NS_ERROR_FAILURE;
}
if (!DefineIndexedDB(aCx, global)) {
if (!DefineConstructors(aCx, global) || !DefineIndexedDBGetter(aCx, global)) {
return NS_ERROR_FAILURE;
}
@ -918,3 +1001,49 @@ GetFileReferencesHelper::Run()
return NS_OK;
}
BEGIN_INDEXEDDB_NAMESPACE
bool
ResolveConstructors(JSContext* aCx, JS::Handle<JSObject*> aObj,
JS::Handle<jsid> aId, JS::MutableHandle<JSObject*> aObjp)
{
MOZ_ASSERT(NS_IsMainThread());
// The first time this function is called we need to intern all the strings we
// care about.
if (JSID_IS_VOID(gConstructorInfo[0].id)) {
for (uint32_t i = 0; i < mozilla::ArrayLength(gConstructorInfo); i++) {
JS::Rooted<JSString*> str(aCx,
JS_InternString(aCx, gConstructorInfo[i].name));
if (!str) {
NS_WARNING("Failed to intern string!");
while (i) {
gConstructorInfo[--i].id = JSID_VOID;
}
return false;
}
gConstructorInfo[i].id = INTERNED_STRING_TO_JSID(aCx, str);
}
}
// Now resolve.
for (uint32_t i = 0; i < mozilla::ArrayLength(gConstructorInfo); i++) {
if (gConstructorInfo[i].id == aId) {
JS::Rooted<JSObject*> constructor(aCx,
gConstructorInfo[i].resolve(aCx, aObj, true));
if (!constructor) {
return false;
}
aObjp.set(aObj);
return true;
}
}
// Not resolved.
aObjp.set(nullptr);
return true;
}
END_INDEXEDDB_NAMESPACE

View File

@ -140,7 +140,13 @@ public:
const nsACString& aOrigin);
static bool
DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
DefineConstructors(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
static bool
DefineIndexedDBGetter(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
static bool
DefineIndexedDBLazyGetter(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
private:
IndexedDatabaseManager();
@ -170,6 +176,10 @@ private:
static mozilla::Atomic<int32_t> sLowDiskSpaceMode;
};
bool
ResolveConstructors(JSContext* aCx, JS::Handle<JSObject*> aObj,
JS::Handle<jsid> aId, JS::MutableHandle<JSObject*> aObjp);
END_INDEXEDDB_NAMESPACE
#endif /* mozilla_dom_indexeddb_indexeddatabasemanager_h__ */

View File

@ -1,5 +1,4 @@
[DEFAULT]
support-files = chromeHelpers.js
[test_globalObjects_chrome.xul]
[test_globalObjects_other.xul]
[test_globalObjects.xul]

View File

@ -7,15 +7,11 @@ const { 'classes': Cc, 'interfaces': Ci, 'utils': Cu } = Components;
let testGenerator = testSteps();
if (!window.runTest) {
window.runTest = function()
{
Cu.importGlobalProperties(["indexedDB"]);
function runTest()
{
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForExplicitFinish();
testGenerator.next();
}
testGenerator.next();
}
function finishTest()

View File

@ -58,7 +58,7 @@ support-files =
[test_filehandle_store_snapshot.html]
[test_getAll.html]
[test_get_filehandle.html]
[test_globalObjects_content.html]
[test_globalObjects.html]
[test_global_data.html]
[test_index_empty_keyPath.html]
[test_index_getAll.html]

View File

@ -14,6 +14,20 @@
<script type="application/javascript;version=1.7">
<![CDATA[
function testSteps() {
const name = window.location.pathname;
// Test for IDBKeyRange and indexedDB availability in chrome windows.
var keyRange = IDBKeyRange.only(42);
ok(keyRange, "Got keyRange");
var request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
ok(db, "Got database");
// Test for IDBKeyRange and indexedDB availability in bootstrap files.
let test = Cc["@mozilla.org/dom/indexeddb/GlobalObjectsComponent;1"].
createInstance(Ci.nsISupports).wrappedJSObject;
@ -46,12 +60,6 @@
finishTest();
yield undefined;
}
window.runTest = function() {
SimpleTest.waitForExplicitFinish();
testGenerator.next();
}
]]>
</script>

View File

@ -1,43 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<window title="Mozilla Bug 832883"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="runTest();">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript;version=1.7">
<![CDATA[
function testSteps() {
const name = window.location.pathname;
// Test for IDBKeyRange and indexedDB availability in chrome windows.
var keyRange = IDBKeyRange.only(42);
ok(keyRange, "Got keyRange");
var request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
ok(db, "Got database");
finishTest();
yield undefined;
}
]]>
</script>
<script type="text/javascript;version=1.7" src="chromeHelpers.js"></script>
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=832883"
target="_blank">Mozilla Bug 832883</a>
</body>
</window>

View File

@ -18,8 +18,6 @@ function finishTest()
function run_test() {
const name = "Splendid Test";
Cu.importGlobalProperties(["indexedDB"]);
do_test_pending();
let keyRange = IDBKeyRange.only(42);

View File

@ -3,10 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.importGlobalProperties(["indexedDB"]);
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function GlobalObjectsComponent() {
this.wrappedJSObject = this;

View File

@ -3,8 +3,6 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
Components.utils.importGlobalProperties(["indexedDB"]);
this.EXPORTED_SYMBOLS = [
"GlobalObjectsModule"
];

View File

@ -38,19 +38,15 @@ function run_test() {
runTest();
};
if (!this.runTest) {
this.runTest = function()
{
// XPCShell does not get a profile by default.
do_get_profile();
function runTest()
{
// XPCShell does not get a profile by default.
do_get_profile();
enableExperimental();
enableExperimental();
Cu.importGlobalProperties(["indexedDB"]);
do_test_pending();
testGenerator.next();
}
do_test_pending();
testGenerator.next();
}
function finishTest()

View File

@ -18,9 +18,8 @@
[test_deleteDatabase_interactions.js]
[test_event_source.js]
[test_getAll.js]
[test_globalObjects.js]
[test_globalObjects_ipc.js]
[test_globalObjects_other.js]
[test_globalObjects_xpc.js]
[test_global_data.js]
[test_index_empty_keyPath.js]
[test_index_getAll.js]

View File

@ -7,6 +7,8 @@ var testGenerator = testSteps();
function testSteps()
{
const name = "Splendid Test";
let ioService =
Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
@ -16,6 +18,18 @@ function testSteps()
return uri.spec;
}
// Test for IDBKeyRange and indexedDB availability in xpcshell.
let keyRange = IDBKeyRange.only(42);
ok(keyRange, "Got keyRange");
let request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
ok(db, "Got database");
// Test for IDBKeyRange and indexedDB availability in JS modules.
Cu.import(getSpec("GlobalObjectsModule.jsm"));
let test = new GlobalObjectsModule();
@ -51,10 +65,3 @@ function testSteps()
finishTest();
yield undefined;
}
this.runTest = function() {
do_get_profile();
do_test_pending();
testGenerator.next();
}

View File

@ -1,26 +0,0 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var testGenerator = testSteps();
function testSteps()
{
const name = "Splendid Test";
// Test for IDBKeyRange and indexedDB availability in xpcshell.
let keyRange = IDBKeyRange.only(42);
ok(keyRange, "Got keyRange");
let request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
ok(db, "Got database");
finishTest();
yield undefined;
}

View File

@ -28,11 +28,10 @@ support-files =
[test_deleteDatabase_interactions.js]
[test_event_source.js]
[test_getAll.js]
[test_globalObjects.js]
[test_globalObjects_ipc.js]
# FIXME/bug 575918: out-of-process xpcshell is broken on OS X
#skip-if = os == "mac" || os == "android"
[test_globalObjects_other.js]
[test_globalObjects_xpc.js]
skip-if = os == "mac" || os == "android"
[test_global_data.js]
[test_index_empty_keyPath.js]
[test_index_getAll.js]

View File

@ -9,7 +9,6 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/PhoneNumberUtils.jsm");
Cu.importGlobalProperties(["indexedDB"]);
const RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID =
"@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1";

View File

@ -13,7 +13,6 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
Cu.importGlobalProperties(["indexedDB"]);
const DB_NAME = "net_stats";
const DB_VERSION = 3;

View File

@ -23,7 +23,6 @@ Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
Cu.import("resource://gre/modules/Timer.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
Cu.importGlobalProperties(["indexedDB"]);
XPCOMUtils.defineLazyModuleGetter(this, "AlarmService",
"resource://gre/modules/AlarmService.jsm");

View File

@ -948,7 +948,8 @@ bool
xpc::GlobalProperties::Define(JSContext *cx, JS::HandleObject obj)
{
if (indexedDB && AccessCheck::isChrome(obj) &&
!IndexedDatabaseManager::DefineIndexedDB(cx, obj))
(!IndexedDatabaseManager::DefineConstructors(cx, obj) ||
!IndexedDatabaseManager::DefineIndexedDBGetter(cx, obj)))
return false;
if (XMLHttpRequest &&

View File

@ -10,9 +10,11 @@
#include "nsDOMClassInfo.h"
#include "nsIPrincipal.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "mozilla/dom/workers/Workers.h"
using mozilla::dom::workers::ResolveWorkerClasses;
namespace indexedDB = mozilla::dom::indexedDB;
NS_INTERFACE_MAP_BEGIN(BackstagePass)
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
@ -73,6 +75,14 @@ BackstagePass::NewResolve(nsIXPConnectWrappedNative *wrapper,
return NS_OK;
}
*_retval = indexedDB::ResolveConstructors(cx, obj, id, &objp);
NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE);
if (objp) {
*objpArg = objp;
return NS_OK;
}
return NS_OK;
}

View File

@ -515,6 +515,7 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
MOZ_ASSERT(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL);
// Init WebIDL binding constructors wanted on all XPConnect globals.
// Additional bindings may be created lazily, see BackstagePass::NewResolve.
//
// XXX Please do not add any additional classes here without the approval of
// the XPConnect module owner.
@ -524,6 +525,12 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
return UnexpectedFailure(NS_ERROR_FAILURE);
}
if (nsContentUtils::IsSystemPrincipal(aPrincipal) &&
!IndexedDatabaseManager::DefineIndexedDBLazyGetter(aJSContext,
global)) {
return UnexpectedFailure(NS_ERROR_FAILURE);
}
wrappedGlobal.forget(_retval);
return NS_OK;
}