Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding test for privileged APIs: systemXHR and deviceStorage

  • Loading branch information...
commit 31f3e6e5793037d20752c82f6e328990b6f0461d 1 parent f850573
@robnyman authored
Showing with 86 additions and 3 deletions.
  1. +12 −0 css/base.css
  2. +9 −0 index.html
  3. +57 −2 js/webapp.js
  4. +8 −1 manifest.webapp
View
12 css/base.css
@@ -35,6 +35,18 @@ ul {
list-style: none;
}
+h2 {
+ font-size: 16px;
+}
+
+h3 {
+ font-size: 14px;
+}
+
+h4 {
+ font-size: 12px;
+}
+
#install {
display: none;
}
View
9 index.html
@@ -84,6 +84,15 @@
<button id="check-battery">Check battery</button>
<div id="battery-display"></div>
+
+
+ <h3>Privileged APIs</h3>
+
+ <button id="cross-domain-xhr">Cross-domain XHR</button>
+ <div id="cross-domain-xhr-display"></div>
+
+ <button id="device-storage-pictures">deviceStorage - pictures</button>
+ <div id="device-storage-pictures-display"></div>
</div>
<footer>
View
59 js/webapp.js
@@ -278,7 +278,7 @@
online = "<strong>Connected:</strong> " + (connection.bandwidth),
metered = "<strong>Metered:</strong> " + connection.metered;

- connectionDisplay.innerHTML = online + "<br>" + metered;
+ connectionDisplay.innerHTML = "<h4>Result from Check connection</h4>" + online + "<br>" + metered;
connectionDisplay.style.display = "block";
};
}
@@ -295,7 +295,7 @@
dischargingTime = parseInt(battery.dischargingTime / 60, 10),
batteryInfo;
- batteryInfo = "<strong>Battery level:</strong> " + batteryLevel + "<br>";
+ batteryInfo = "<h4>Result from Check battery</h4><strong>Battery level:</strong> " + batteryLevel + "<br>";
batteryInfo += "<strong>Battery charging:</strong> " + charging + "<br>";
batteryInfo += "<strong>Battery charging time:</strong> " + chargingTime + "<br>";
batteryInfo += "<strong>Battery discharging time:</strong> " + dischargingTime;
@@ -304,5 +304,60 @@
batteryDisplay.style.display = "block";
};
}
+
+ // Cross domain XHR
+ var crossDomainXHR = document.querySelector("#cross-domain-xhr"),
+ crossDomainXHRDisplay = document.querySelector("#cross-domain-xhr-display");
+ if (crossDomainXHR && crossDomainXHRDisplay) {
+ crossDomainXHR.onclick = function () {
+ var xhr = new XMLHttpRequest({mozSystem: true});
+ xhr.open("GET", "http://robnyman.github.com/Firefox-OS-Boilerplate-App/README.md", true);
+ xhr.onreadystatechange = function () {
+ if (xhr.status === 200 && xhr.readyState === 4) {
+ crossDomainXHRDisplay.innerHTML = "<h4>Result from Cross-domain XHR</h4>" + xhr.response;
+ crossDomainXHRDisplay.style.display = "block";
+ }
+ }
+
+ xhr.onerror = function () {
+ crossDomainXHRDisplay.innerHTML = "<h4>Result from Cross-domain XHR</h4><p>Cross-domain XHR failed</p>";
+ crossDomainXHRDisplay.style.display = "block";
+ };
+ xhr.send();
+ };
+ }
+
+ // deviceStorage, pictures
+ var deviceStoragePictures = document.querySelector("#device-storage-pictures"),
+ deviceStoragePicturesDisplay = document.querySelector("#device-storage-pictures-display");
+ if (deviceStoragePictures && deviceStoragePicturesDisplay) {
+ deviceStoragePictures.onclick = function () {
+ var deviceStorage = navigator.getDeviceStorage("pictures"),
+ cursor = deviceStorage.enumerate();

+
+ deviceStoragePicturesDisplay.innerHTML = "<h4>Result from deviceStorage - pictures</h4>";
+ 

+ 

cursor.onsuccess = function() {

+ if (!cursor.result)
 {
+ deviceStoragePicturesDisplay.innerHTML = "No files";
+ }
+
+ var file = cursor.result,
+ filePresentation;

+
+ filePresentation = "<strong>" + file.name + ":</strong> " + parseInt(file.size / 1024, 10) + "kb<br>";
+ filePresentation += "<p><img src='" + window.URL.createObjectURL(file) + "' alt=''></p>";
+ deviceStoragePicturesDisplay.innerHTML += filePresentation;
+
+ deviceStoragePicturesDisplay.style.display = "block";
+ 
};
+
+ 

cursor.onerror = function () {
+ console.log("Error");
+ deviceStoragePicturesDisplay.innerHTML = "<h4>Result from deviceStorage - pictures</h4><p>deviceStorage failed</p>";
+ deviceStoragePicturesDisplay.style.display = "block";
+ };
+ };
+ }
}
})();
View
9 manifest.webapp
@@ -1,6 +1,7 @@
{
"version": "1",
"name": "Firefox OS Boilerplate App",
+ "type" : "privileged",
"launch_path": "/Firefox-OS-Boilerplate-App/index.html",
"description": "Boilerplate Firefox OS app with example use cases to get started",
"icons": {
@@ -15,5 +16,11 @@
"url": "http://robertnyman.com"
},
"installs_allowed_from": ["*"],
- "default_locale": "en"
+ "default_locale": "en",
+ "permissions": {
+ "device-storage:pictures": {
+ "access": "readonly"
+ },
+ "systemXHR":{}
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.