1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/datastore/tests/test_bug976311.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,135 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <meta charset="utf-8"> 1.8 + <title>Test for DataStore - bug 976311</title> 1.9 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.11 +</head> 1.12 +<body> 1.13 +<div id="container"></div> 1.14 + <script type="application/javascript;version=1.7"> 1.15 + 1.16 + var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_bug976311.html&template=file_bug976311.template.webapp'; 1.17 + var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_bug976311.html&template=file_bug976311.template.webapp'; 1.18 + var gApps = []; 1.19 + 1.20 + function cbError() { 1.21 + ok(false, "Error callback invoked"); 1.22 + finish(); 1.23 + } 1.24 + 1.25 + function installApp(aApp) { 1.26 + var request = navigator.mozApps.install(aApp); 1.27 + request.onerror = cbError; 1.28 + request.onsuccess = function() { 1.29 + gApps.push(request.result); 1.30 + runTest(); 1.31 + } 1.32 + } 1.33 + 1.34 + function uninstallApps() { 1.35 + if (!gApps.length) { 1.36 + ok(true, "All done!"); 1.37 + runTest(); 1.38 + return; 1.39 + } 1.40 + 1.41 + var app = gApps.pop(); 1.42 + var request = navigator.mozApps.mgmt.uninstall(app); 1.43 + request.onerror = cbError; 1.44 + request.onsuccess = uninstallApps; 1.45 + } 1.46 + 1.47 + 1.48 + function testApp() { 1.49 + var ifr = document.createElement('iframe'); 1.50 + ifr.setAttribute('mozbrowser', 'true'); 1.51 + ifr.setAttribute('mozapp', gApps[0].manifestURL); 1.52 + ifr.setAttribute('src', gApps[0].manifest.launch_path); 1.53 + var domParent = document.getElementById('container'); 1.54 + 1.55 + // Set us up to listen for messages from the app. 1.56 + var listener = function(e) { 1.57 + var message = e.detail.message; 1.58 + if (/^OK/.exec(message)) { 1.59 + ok(true, "Message from app: " + message); 1.60 + } else if (/KO/.exec(message)) { 1.61 + ok(false, "Message from app: " + message); 1.62 + } else if (/DONE/.exec(message)) { 1.63 + ok(true, "Messaging from app complete"); 1.64 + ifr.removeEventListener('mozbrowsershowmodalprompt', listener); 1.65 + domParent.removeChild(ifr); 1.66 + runTest(); 1.67 + } 1.68 + } 1.69 + 1.70 + // This event is triggered when the app calls "alert". 1.71 + ifr.addEventListener('mozbrowsershowmodalprompt', listener, false); 1.72 + domParent.appendChild(ifr); 1.73 + 1.74 + } 1.75 + 1.76 + var tests = [ 1.77 + // Permissions 1.78 + function() { 1.79 + SpecialPowers.pushPermissions( 1.80 + [{ "type": "browser", "allow": 1, "context": document }, 1.81 + { "type": "embed-apps", "allow": 1, "context": document }, 1.82 + { "type": "webapps-manage", "allow": 1, "context": document }], runTest); 1.83 + }, 1.84 + 1.85 + // Preferences 1.86 + function() { 1.87 + SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true], 1.88 + ["dom.testing.ignore_ipc_principal", true], 1.89 + ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest); 1.90 + }, 1.91 + 1.92 + function() { 1.93 + SpecialPowers.setAllAppsLaunchable(true); 1.94 + SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true); 1.95 + runTest(); 1.96 + }, 1.97 + 1.98 + // No confirmation needed when an app is installed 1.99 + function() { 1.100 + SpecialPowers.autoConfirmAppInstall(runTest); 1.101 + }, 1.102 + 1.103 + // Installing the app1 1.104 + function() { installApp(gHostedManifestURL); }, 1.105 + 1.106 + // Installing the app2 1.107 + function() { installApp(gHostedManifestURL2); }, 1.108 + 1.109 + // Run tests in app 1.110 + testApp, 1.111 + 1.112 + // Uninstall the apps 1.113 + uninstallApps 1.114 + ]; 1.115 + 1.116 + function runTest() { 1.117 + if (!tests.length) { 1.118 + finish(); 1.119 + return; 1.120 + } 1.121 + 1.122 + var test = tests.shift(); 1.123 + test(); 1.124 + } 1.125 + 1.126 + function finish() { 1.127 + SimpleTest.finish(); 1.128 + } 1.129 + 1.130 + if (SpecialPowers.isMainProcess()) { 1.131 + SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm"); 1.132 + } 1.133 + 1.134 + SimpleTest.waitForExplicitFinish(); 1.135 + runTest(); 1.136 + </script> 1.137 +</body> 1.138 +</html>