mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 821630 - Fix retrieving blobs with get() in Settings API. r=gwagner
This commit is contained in:
parent
611275fe83
commit
87079a3d76
@ -88,10 +88,7 @@ SettingsLock.prototype = {
|
||||
if (DEBUG) debug("store1: " + JSON.stringify(obj));
|
||||
setReq = store.put(obj);
|
||||
} else {
|
||||
//Workaround for cloning issues
|
||||
let defaultVal = JSON.parse(JSON.stringify(defaultValue));
|
||||
let userVal = JSON.parse(JSON.stringify(userValue));
|
||||
let obj = {settingName: key, defaultValue: defaultVal, userValue: userVal};
|
||||
let obj = {settingName: key, defaultValue: defaultValue, userValue: userValue};
|
||||
if (DEBUG) debug("store2: " + JSON.stringify(obj));
|
||||
setReq = store.put(obj);
|
||||
}
|
||||
@ -114,7 +111,7 @@ SettingsLock.prototype = {
|
||||
Services.DOMRequest.fireError(request, setReq.error.name)
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
checkKeyRequest.onerror = function(event) {
|
||||
if (!request.error) {
|
||||
Services.DOMRequest.fireError(request, checkKeyRequest.error.name)
|
||||
@ -127,8 +124,8 @@ SettingsLock.prototype = {
|
||||
: store.mozGetAll(info.name);
|
||||
|
||||
getReq.onsuccess = function(event) {
|
||||
if (DEBUG) debug("Request for '" + info.name + "' successful. " +
|
||||
"Record count: " + event.target.result.length);
|
||||
if (DEBUG) debug("Request for '" + info.name + "' successful. " +
|
||||
"Record count: " + event.target.result.length);
|
||||
|
||||
if (event.target.result.length == 0) {
|
||||
if (DEBUG) debug("MOZSETTINGS-GET-WARNING: " + info.name + " is not in the database.\n");
|
||||
@ -214,8 +211,7 @@ SettingsLock.prototype = {
|
||||
if (this._settingsManager.hasWritePrivileges) {
|
||||
let req = Services.DOMRequest.createRequest(this._settingsManager._window);
|
||||
if (DEBUG) debug("send: " + JSON.stringify(aSettings));
|
||||
let settings = JSON.parse(JSON.stringify(aSettings));
|
||||
this._requests.enqueue({request: req, intent: "set", settings: settings});
|
||||
this._requests.enqueue({request: req, intent: "set", settings: aSettings});
|
||||
this.createTransactionAndProcess();
|
||||
return req;
|
||||
} else {
|
||||
@ -312,7 +308,6 @@ SettingsManager.prototype = {
|
||||
|
||||
switch (aMessage.name) {
|
||||
case "Settings:Change:Return:OK":
|
||||
if (DEBUG) debug("Settings:Change:Return:OK");
|
||||
if (this._onsettingchange || this._callbacks) {
|
||||
if (DEBUG) debug('data:' + msg.key + ':' + msg.value + '\n');
|
||||
|
||||
@ -334,7 +329,7 @@ SettingsManager.prototype = {
|
||||
if (DEBUG) debug("no observers stored!");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
if (DEBUG) debug("Wrong message: " + aMessage.name);
|
||||
}
|
||||
},
|
||||
|
@ -16,6 +16,7 @@ MOCHITEST_FILES = \
|
||||
test_settings_basics.html \
|
||||
test_settings_events.html \
|
||||
test_settings_onsettingchange.html \
|
||||
test_settings_blobs.html \
|
||||
$(NULL)
|
||||
|
||||
_CHROMEMOCHITEST_FILES = \
|
||||
|
128
dom/settings/tests/test_settings_blobs.html
Normal file
128
dom/settings/tests/test_settings_blobs.html
Normal file
@ -0,0 +1,128 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=821630
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 821630 Settings API</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=821630">Mozilla Bug 821630</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript;version=1.8">
|
||||
|
||||
"use strict";
|
||||
|
||||
var comp = SpecialPowers.wrap(SpecialPowers.Components);
|
||||
comp.utils.import("resource://gre/modules/SettingsChangeNotifier.jsm");
|
||||
SpecialPowers.setBoolPref("dom.mozSettings.enabled", true);
|
||||
SpecialPowers.addPermission("settings-read", true, document);
|
||||
SpecialPowers.addPermission("settings-write", true, document);
|
||||
|
||||
function onUnwantedSuccess() {
|
||||
ok(false, "onUnwantedSuccess: shouldn't get here");
|
||||
}
|
||||
|
||||
function onFailure() {
|
||||
return function(s) {
|
||||
if (s) {
|
||||
ok(false, "in on Failure! - " + s);
|
||||
} else {
|
||||
ok(false, "in on Failure!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mozSettings = window.navigator.mozSettings;
|
||||
let req;
|
||||
|
||||
let pageParts = ['<a id="a"><b id="b">hey!</b></a>'];
|
||||
let storedBlob = new Blob(pageParts, {"type": "text/xml"});
|
||||
|
||||
function checkBlob(blob) {
|
||||
try {
|
||||
let url = URL.createObjectURL(blob);
|
||||
ok(true, "Result is a blob");
|
||||
} catch (e) {
|
||||
ok(false, "Result is a blob");
|
||||
}
|
||||
}
|
||||
|
||||
let steps = [
|
||||
function() {
|
||||
let lock = mozSettings.createLock();
|
||||
req = lock.clear();
|
||||
req.onsuccess = next;
|
||||
req.onerror = onFailure("Deleting database");
|
||||
},
|
||||
function() {
|
||||
mozSettings.addObserver("test1", function(e) {
|
||||
checkBlob(e.settingValue);
|
||||
next();
|
||||
});
|
||||
next();
|
||||
},
|
||||
function() {
|
||||
let lock = mozSettings.createLock();
|
||||
// next is called by the observer above
|
||||
req = lock.set({"test1": storedBlob});
|
||||
req.onerror = onFailure("Saving blob");
|
||||
},
|
||||
function() {
|
||||
let lock = mozSettings.createLock();
|
||||
req = lock.get("test1");
|
||||
req.onsuccess = function(event) {
|
||||
checkBlob(event.target.result["test1"]);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure("Getting blob");
|
||||
},
|
||||
function() {
|
||||
let lock = mozSettings.createLock();
|
||||
req = lock.clear();
|
||||
req.onsuccess = function() {
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure("Deleting database");
|
||||
},
|
||||
function () {
|
||||
ok(true, "all done!\n");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
];
|
||||
|
||||
function next() {
|
||||
try {
|
||||
let step = steps.shift();
|
||||
if (step) {
|
||||
step();
|
||||
}
|
||||
} catch(ex) {
|
||||
ok(false, "Caught exception", ex);
|
||||
}
|
||||
}
|
||||
|
||||
function permissionTest() {
|
||||
if (gSettingsEnabled) {
|
||||
next();
|
||||
} else {
|
||||
is(mozSettings, null, "mozSettings is null when not enabled.");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
let gSettingsEnabled = SpecialPowers.getBoolPref("dom.mozSettings.enabled");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(permissionTest);
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user