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