Bug 788268 - Device Storage - Convert tests to use public types. r=bent

--HG--
extra : rebase_source : 208751cfe7b68e67d65686d6606766dd5caebf59
This commit is contained in:
Doug Turner 2012-09-05 14:30:36 -07:00
Родитель 34666917c5
Коммит 803e9134f5
14 изменённых файлов: 57 добавлений и 63 удалений

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

@ -155,13 +155,6 @@ DeviceStorageFile::IsType(nsAString& aType)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
// in testing, we ignore filtering for the testing types
if (mozilla::Preferences::GetBool("device.storage.testing", false) &&
(aType.Equals(NS_LITERAL_STRING("testing")) ||
aType.Equals(NS_LITERAL_STRING("testing-other")))) {
return true;
}
#ifdef DEBUG_ISTYPE
nsCOMPtr<nsIConsoleService> svc = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
char buffer[1024];
@ -572,12 +565,8 @@ nsDOMDeviceStorage::SetRootDirectoryForType(const nsAString& aType)
#endif
}
// in testing, we have access to a few more directory locations
if (mozilla::Preferences::GetBool("device.storage.testing", false)) {
// testing directory
if (aType.Equals(NS_LITERAL_STRING("testing")) ||
aType.Equals(NS_LITERAL_STRING("testing-other"))) {
// in testing, we default all device storage types to a temp directory
if (f && mozilla::Preferences::GetBool("device.storage.testing", false)) {
dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(f));
if (f) {
f->AppendRelativeNativePath(NS_LITERAL_CSTRING("device-storage-testing"));
@ -585,7 +574,6 @@ nsDOMDeviceStorage::SetRootDirectoryForType(const nsAString& aType)
f->Normalize();
}
}
}
#ifdef MOZ_WIDGET_GONK
RegisterForSDCardChanges(this);

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

@ -54,8 +54,8 @@ function getRandomBuffer() {
return buffer;
}
function createRandomBlob() {
return blob = new Blob([getRandomBuffer()], {type: 'binary/random'});
function createRandomBlob(mime) {
return blob = new Blob([getRandomBuffer()], {type: mime});
}
function randomFilename(l) {

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

@ -33,9 +33,9 @@ function unload() {
devicestorage_setup();
var gFileName = "devicestorage/hi";
var gFileName = "devicestorage/hi.png";
var gData = "My name is Doug Turner. My IRC nick is DougT. I like Maple cookies."
var gDataBlob = new Blob([gData], {type: 'text/plain'});
var gDataBlob = new Blob([gData], {type: 'image/png'});
var gFileReader = new FileReader();
function getAfterDeleteSuccess(e) {
@ -53,7 +53,7 @@ function deleteSuccess(e) {
ok(e.target.result == gFileName, "File name should match");
dump(e.target.result + "\n")
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
request = storage.get(e.target.result);
request.onsuccess = getAfterDeleteSuccess;
request.onerror = getAfterDeleteError;
@ -66,7 +66,7 @@ function deleteError(e) {
}
function getSuccess(e) {
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
ok(e.target.result.name == gFileName, "File name should match");
@ -101,7 +101,7 @@ function addSuccess(e) {
ok(e.target.result == gFileName, "File name should match");
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
request = storage.get(gFileName);
request.onsuccess = getSuccess;
request.onerror = getError;
@ -116,10 +116,10 @@ function addError(e) {
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(storage, "Should have gotten a storage");
request = storage.addNamed(gDataBlob, "devicestorage/hi");
request = storage.addNamed(gDataBlob, "devicestorage/hi.png");
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;

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

@ -25,17 +25,17 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
devicestorage_setup();
function testingStorage() {
return navigator.getDeviceStorage("testing");
return navigator.getDeviceStorage("pictures");
}
var tests = [
function () { return testingStorage().addNamed(createRandomBlob(), gFileName); },
function () { return testingStorage().addNamed(createRandomBlob('image/png'), gFileName); },
function () { return testingStorage().delete(gFileName); },
function () { return testingStorage().get(gFileName); },
function () { var r = testingStorage().enumerate("../"); return r; }
];
var gFileName = "../owned";
var gFileName = "../owned.png";
function fail(e) {
ok(false, "addSuccess was called");

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

@ -67,17 +67,17 @@ function addError(e) {
devicestorage_cleanup();
}
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var prefix = "devicestorage/" + randomFilename(12)
var prefix = "devicestorage/" + randomFilename(12) + ".png"
var files = [ "a", "b", "c", "d/a", "d/b", "d/c", "d/d", "The/quick/brown/fox/jumps/over/the/lazy/dog"]
var files = [ "a.png", "b.png", "c.png", "d/a.png", "d/b.png", "d/c.png", "d/d.png", "The/quick/brown/fox/jumps/over/the/lazy/dog.png"]
var addedSoFar = 0;
for (var i=0; i<files.length; i++) {
request = storage.addNamed(createRandomBlob(), prefix + '/' + files[i]);
request = storage.addNamed(createRandomBlob('image/png'), prefix + '/' + files[i]);
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;

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

@ -30,7 +30,7 @@ function enumerateSuccess(e) {
function enumerateFailure(e) {
}
var cursor = navigator.getDeviceStorage("testing").enumerate();
var cursor = navigator.getDeviceStorage("pictures").enumerate();
cursor.onsuccess = enumerateSuccess;
cursor.onerror = enumerateFailure;

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

@ -71,17 +71,17 @@ function addError(e) {
devicestorage_cleanup();
}
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
var prefix = "devicestorage/" + randomFilename(12)
var files = [ "a", "b", "c" ]
var files = [ "a.png", "b.png", "c.png" ]
var addedSoFar = 0;
for (var i=0; i<files.length; i++) {
request = storage.addNamed(createRandomBlob(), prefix + '/' + files[i]);
request = storage.addNamed(createRandomBlob('image/png'), prefix + '/' + files[i]);
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;

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

@ -25,7 +25,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
devicestorage_setup()
storage = navigator.getDeviceStorage("testing");
storage = navigator.getDeviceStorage("pictures");
throws = false;

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

@ -44,7 +44,7 @@ function verifyAndDelete(prefix, files, e) {
files.remove(index);
// clean up
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
var cleanup = storage.delete(prefix + "/" + filename);
cleanup.onsuccess = function(e) {}
}
@ -76,15 +76,15 @@ devicestorage_setup();
var prefix = "devicestorage/" + randomFilename(12)
var oldFiles = ["a", "b", "c"];
var newFiles = ["d", "e", "f"];
var oldFiles = ["a.png", "b.png", "c.png"];
var newFiles = ["d.png", "e.png", "f.png"];
// 157795200 is a long long time ago.
addFiles(prefix, oldFiles, 157795200, addNewFiles);
function enumerateNew() {
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
// 836031600 is a long time ago

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

@ -23,7 +23,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
<pre id="test">
<script class="testbody" type="text/javascript">
var filename = "devicestorage/aaaa"
var filename = "devicestorage/aaaa.png"
devicestorage_setup();
@ -45,7 +45,7 @@ function addOverwritingSuccess(e) {
function addOverwritingError(e) {
ok(true, "Adding to the same location should fail");
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
request = storage.delete(filename)
request.onsuccess = deleteSuccess;
request.onerror = deleteError;
@ -54,10 +54,10 @@ function addOverwritingError(e) {
function addSuccess(e) {
ok(true, "addSuccess was called");
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
request = storage.addNamed(createRandomBlob(), filename);
request = storage.addNamed(createRandomBlob('image/png'), filename);
ok(request, "Should have a non-null request");
request.onsuccess = addOverwritingSuccess;
@ -66,16 +66,16 @@ function addSuccess(e) {
function addError(e) {
// test file is already exists. clean it up and try again..
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
request = storage.delete(filename)
request.onsuccess = runtest;
}
function runtest() {
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
request = storage.addNamed(createRandomBlob(), filename);
request = storage.addNamed(createRandomBlob('image/png'), filename);
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;

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

@ -38,8 +38,14 @@ ok(throws, "getDeviceStorage takes one arg");
storage = navigator.getDeviceStorage("kilimanjaro");
ok(!storage, "kilimanjaro - Should not have this type of storage");
storage = navigator.getDeviceStorage("testing");
ok(storage, "testing - Should have getDeviceStorage");
storage = navigator.getDeviceStorage("pictures");
ok(storage, "pictures - Should have getDeviceStorage");
storage = navigator.getDeviceStorage("music");
ok(storage, "music - Should have getDeviceStorage");
storage = navigator.getDeviceStorage("videos");
ok(storage, "videos - Should have getDeviceStorage");
var cursor = storage.enumerate();
ok(cursor, "Should have a non-null cursor");

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

@ -35,7 +35,7 @@ function statError(e) {
devicestorage_cleanup();
}
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
function addError(e) {
@ -51,7 +51,7 @@ function addSuccess(e) {
request.onerror = statError;
}
request = storage.addNamed(createRandomBlob(), "a/b");
request = storage.addNamed(createRandomBlob('image/png'), "a/b.png");
request.onsuccess = addSuccess;
request.onerror = addError;

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

@ -24,7 +24,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
devicestorage_setup();
var gFileName = randomFilename(20);
var gFileName = randomFilename(20) + ".png"
function addSuccess(e) {
}
@ -49,11 +49,11 @@ function onChange(e) {
}
}
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(storage, "Should have storage");
storage.addEventListener("change", onChange);
request = storage.addNamed(createRandomBlob(), gFileName);
request = storage.addNamed(createRandomBlob('image/png'), gFileName);
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;

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

@ -24,7 +24,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
devicestorage_setup();
var gFileName = randomFilename(20);
var gFileName = randomFilename(20) + ".png"
function addSuccess(e) {
}
@ -54,15 +54,15 @@ function onChangeFail(e) {
ok(false, "We should never see any changes");
}
var storage = navigator.getDeviceStorage("testing");
var storage = navigator.getDeviceStorage("pictures");
ok(storage, "Should have storage");
storage.addEventListener("change", onChange);
var storageOther = navigator.getDeviceStorage("testing-other");
var storageOther = navigator.getDeviceStorage("music");
ok(storageOther, "Should have storage");
storageOther.addEventListener("change", onChangeFail);
request = storage.addNamed(createRandomBlob(), gFileName);
request = storage.addNamed(createRandomBlob('image/png'), gFileName);
ok(request, "Should have a non-null request");
request.onsuccess = addSuccess;