5 <title>Test for DataStore - basic operation on a readonly db
</title>
6 <script type=
"application/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
10 <div id=
"container"></div>
11 <script type=
"application/javascript;version=1.7">
13 var gWidgetManifestURL = 'http://test/tests/dom/apps/tests/file_app.sjs?apptype=widget&getmanifest=true';
14 var gInvalidWidgetManifestURL = 'http://test/tests/dom/apps/tests/file_app.sjs?apptype=invalidWidget&getmanifest=true';
18 ok(false,
"Error callback invoked");
22 function installApp(path) {
23 var request = navigator.mozApps.install(path);
24 request.onerror = onError;
25 request.onsuccess = function() {
26 gApp = request.result;
32 function uninstallApp() {
34 var request = navigator.mozApps.mgmt.uninstall(gApp);
35 request.onerror = onError;
36 request.onsuccess = function() {
44 function testApp(isValidWidget) {
45 info(
"Test widget feature. IsValidWidget: " + isValidWidget);
47 var ifr = document.createElement('iframe');
48 ifr.setAttribute('mozbrowser', 'true');
49 ifr.setAttribute('mozwidget', gApp.manifestURL);
50 ifr.setAttribute('src', gApp.origin+gApp.manifest.launch_path);
52 var domParent = document.getElementById('container');
53 domParent.appendChild(ifr);
55 var mm = SpecialPowers.getBrowserFrameMessageManager(ifr);
56 mm.addMessageListener('OK', function(msg) {
57 ok(isValidWidget,
"Message from widget: " + SpecialPowers.wrap(msg).json);
59 mm.addMessageListener('KO', function(msg) {
60 ok(!isValidWidget,
"Message from widget: " + SpecialPowers.wrap(msg).json);
62 mm.addMessageListener('DONE', function(msg) {
63 ok(true,
"Message from widget complete: "+SpecialPowers.wrap(msg).json);
64 domParent.removeChild(ifr);
68 ifr.addEventListener('mozbrowserloadend', function() {
69 ok(true,
"receive mozbrowserloadend");
71 // Test limited browser API feature only for valid widget case
73 testLimitedBrowserAPI(ifr);
75 SimpleTest.executeSoon(()=
>loadFrameScript(mm));
78 // Test limited browser API feature only for valid widget case
84 'mozbrowsertitlechange',
85 'mozbrowseropenwindow',
87 'mozbrowserasyncscroll'
88 ].forEach( function(topic) {
89 ifr.addEventListener(topic, function() {
90 ok(false, topic +
" should be hidden");
95 function testLimitedBrowserAPI(ifr) {
96 var securitySensitiveCalls = [
110 securitySensitiveCalls.forEach( function(call) {
111 is(typeof ifr[call],
"undefined", call +
" should be hidden for widget");
115 function loadFrameScript(mm) {
116 var script = 'data:,\
117 function ok(p, msg) { \
119 sendAsyncMessage(
"OK", msg); \
121 sendAsyncMessage(
"KO", msg); \
125 function is(a, b, msg) { \
127 sendAsyncMessage(
"OK", a +
" == " + b +
" - " + msg); \
129 sendAsyncMessage(
"KO", a +
" != " + b +
" - " + msg); \
133 function finish() { \
134 sendAsyncMessage(
"DONE",
""); \
137 function onError() { \
138 ok(false,
"Error callback invoked"); \
142 function checkWidget(widget) { \
143 /*For invalid widget case, ignore the following check*/\
145 var widgetName =
"Really Rapid Release (APPTYPETOKEN)"; \
146 is(widget.origin,
"http://test",
"Widget origin should be correct"); \
147 is(widget.installOrigin,
"http://mochi.test:8888",
"Install origin should be correct"); \
152 var request = content.window.navigator.mozApps.getSelf(); \
153 request.onsuccess = function() { \
154 var widget = request.result; \
155 ok(widget,
"Should be a widget"); \
156 checkWidget(widget); \
158 request.onerror = onError; \
159 content.window.open(
"about:blank"); /*test mozbrowseropenwindow*/ \
160 content.window.scrollTo(
4000,
4000); /*test mozbrowser(async)scroll*/ \
162 mm.loadFrameScript(script, /* allowDelayedLoad = */ false);
168 SpecialPowers.pushPermissions(
169 [{
"type":
"browser",
"allow":
1,
"context": document },
170 {
"type":
"embed-widgets",
"allow":
1,
"context": document },
171 {
"type":
"webapps-manage",
"allow":
1,
"context": document }], runTest);
176 SpecialPowers.pushPrefEnv({
"set": [[
"dom.mozBrowserFramesEnabled", true],
177 [
"dom.enable_widgets", true],
178 [
"dom.datastore.sysMsgOnChangeShortTimeoutSec",
1],
179 [
"dom.datastore.sysMsgOnChangeLongTimeoutSec",
3]]}, runTest);
183 if (SpecialPowers.isMainProcess()) {
184 SpecialPowers.Cu.import(
"resource://gre/modules/DataStoreChangeNotifier.jsm");
187 SpecialPowers.setAllAppsLaunchable(true);
191 // No confirmation needed when an app is installed
193 SpecialPowers.autoConfirmAppInstall(() =
> {
194 SpecialPowers.autoConfirmAppUninstall(runTest);
198 // Installing the app
199 ()=
>installApp(gWidgetManifestURL),
207 // Installing the app for invalid widget case
208 ()=
>installApp(gInvalidWidgetManifestURL),
210 // Run tests in app for invalid widget case
223 var test = tests.shift();
231 SimpleTest.waitForExplicitFinish();