1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/datastore/tests/test_oop_events.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,158 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <meta charset="utf-8"> 1.8 + <title>Test for DataStore - basic operation on a readonly db</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 gHostedManifestURL1 = 'http://test/tests/dom/datastore/tests/file_app.sjs?template=file_app2.template.webapp&testToken=file_event_receiver.html'; 1.17 + var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_event_maker.html'; 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(manifest) { 1.26 + var request = navigator.mozApps.install(manifest); 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 uninstallApp(app) { 1.35 + // Uninstall the app 1.36 + var request = navigator.mozApps.mgmt.uninstall(app); 1.37 + request.onerror = cbError; 1.38 + request.onsuccess = function() { 1.39 + runTest(); 1.40 + } 1.41 + } 1.42 + 1.43 + function testApp() { 1.44 + var ifr = document.createElement('iframe'); 1.45 + ifr.setAttribute('mozbrowser', 'true'); 1.46 + ifr.setAttribute('mozapp', gApps[0].manifestURL); 1.47 + ifr.setAttribute('src', gApps[0].manifest.launch_path); 1.48 + var domParent = document.getElementById('container'); 1.49 + 1.50 + // Set us up to listen for messages from the app. 1.51 + var listener = function(e) { 1.52 + var message = e.detail.message; 1.53 + if (/^OK/.exec(message)) { 1.54 + ok(true, "Message from app: " + message); 1.55 + } else if (/KO/.exec(message)) { 1.56 + ok(false, "Message from app: " + message); 1.57 + } else if (/READY/.exec(message)) { 1.58 + ok(true, "App ready"); 1.59 + testApp2(); 1.60 + } else if (/DONE/.exec(message)) { 1.61 + ok(true, "Messaging from app complete"); 1.62 + ifr.removeEventListener('mozbrowsershowmodalprompt', listener); 1.63 + domParent.removeChild(ifr); 1.64 + runTest(); 1.65 + } 1.66 + } 1.67 + 1.68 + // This event is triggered when the app calls "alert". 1.69 + ifr.addEventListener('mozbrowsershowmodalprompt', listener, false); 1.70 + domParent.appendChild(ifr); 1.71 + } 1.72 + 1.73 + function testApp2() { 1.74 + var ifr = document.createElement('iframe'); 1.75 + ifr.setAttribute('mozbrowser', 'true'); 1.76 + ifr.setAttribute('mozapp', gApps[1].manifestURL); 1.77 + ifr.setAttribute('src', gApps[1].manifest.launch_path); 1.78 + var domParent = document.getElementById('container'); 1.79 + 1.80 + // Set us up to listen for messages from the app. 1.81 + var listener = function(e) { 1.82 + var message = e.detail.message; 1.83 + if (/^OK/.exec(message)) { 1.84 + ok(true, "Message from app: " + message); 1.85 + } else if (/KO/.exec(message)) { 1.86 + ok(false, "Message from app: " + message); 1.87 + } else if (/DONE/.exec(message)) { 1.88 + ok(true, "Messaging from app complete"); 1.89 + ifr.removeEventListener('mozbrowsershowmodalprompt', listener); 1.90 + domParent.removeChild(ifr); 1.91 + } 1.92 + } 1.93 + 1.94 + // This event is triggered when the app calls "alert". 1.95 + ifr.addEventListener('mozbrowsershowmodalprompt', listener, false); 1.96 + domParent.appendChild(ifr); 1.97 + } 1.98 + 1.99 + var tests = [ 1.100 + // Permissions 1.101 + function() { 1.102 + SpecialPowers.pushPermissions( 1.103 + [{ "type": "browser", "allow": 1, "context": document }, 1.104 + { "type": "embed-apps", "allow": 1, "context": document }, 1.105 + { "type": "webapps-manage", "allow": 1, "context": document }], runTest); 1.106 + }, 1.107 + 1.108 + // Preferences 1.109 + function() { 1.110 + SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true], 1.111 + ["dom.ipc.browser_frames.oop_by_default", true], 1.112 + ["dom.testing.ignore_ipc_principal", true], 1.113 + ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest); 1.114 + }, 1.115 + 1.116 + function() { 1.117 + SpecialPowers.setAllAppsLaunchable(true); 1.118 + SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true); 1.119 + runTest(); 1.120 + }, 1.121 + 1.122 + // No confirmation needed when an app is installed 1.123 + function() { 1.124 + SpecialPowers.autoConfirmAppInstall(runTest); 1.125 + }, 1.126 + 1.127 + // Installing the apps 1.128 + function() { installApp(gHostedManifestURL1); }, 1.129 + function() { installApp(gHostedManifestURL2); }, 1.130 + 1.131 + // Run tests in apps 1.132 + testApp, 1.133 + 1.134 + // Uninstall the apps 1.135 + function() { uninstallApp(gApps[0]); }, 1.136 + function() { uninstallApp(gApps[1]); }, 1.137 + ]; 1.138 + 1.139 + function runTest() { 1.140 + if (!tests.length) { 1.141 + finish(); 1.142 + return; 1.143 + } 1.144 + 1.145 + var test = tests.shift(); 1.146 + test(); 1.147 + } 1.148 + 1.149 + function finish() { 1.150 + SimpleTest.finish(); 1.151 + } 1.152 + 1.153 + if (SpecialPowers.isMainProcess()) { 1.154 + SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm"); 1.155 + } 1.156 + 1.157 + SimpleTest.waitForExplicitFinish(); 1.158 + runTest(); 1.159 + </script> 1.160 +</body> 1.161 +</html>