|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 const Cc = Components.classes; |
|
5 const Ci = Components.interfaces; |
|
6 const Cu = Components.utils; |
|
7 const Cr = Components.results; |
|
8 const CC = Components.Constructor; |
|
9 |
|
10 Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); |
|
11 Cu.import("resource://gre/modules/devtools/dbg-client.jsm"); |
|
12 |
|
13 Cu.import("resource://gre/modules/Services.jsm"); |
|
14 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
15 Cu.import("resource://gre/modules/FileUtils.jsm"); |
|
16 |
|
17 let gClient, gActor; |
|
18 |
|
19 function connect(onDone) { |
|
20 // Initialize a loopback remote protocol connection |
|
21 DebuggerServer.init(function () { return true; }); |
|
22 // We need to register browser actors to have `listTabs` working |
|
23 // and also have a root actor |
|
24 DebuggerServer.addBrowserActors(); |
|
25 |
|
26 // Setup client and actor used in all tests |
|
27 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
28 gClient.connect(function onConnect() { |
|
29 gClient.listTabs(function onListTabs(aResponse) { |
|
30 gActor = aResponse.webappsActor; |
|
31 onDone(); |
|
32 }); |
|
33 }); |
|
34 } |
|
35 |
|
36 function webappActorRequest(request, onResponse) { |
|
37 if (!gActor) { |
|
38 connect(webappActorRequest.bind(null, request, onResponse)); |
|
39 return; |
|
40 } |
|
41 |
|
42 request.to = gActor; |
|
43 gClient.request(request, onResponse); |
|
44 } |
|
45 |
|
46 // Install a test packaged webapp from data folder |
|
47 function installTestApp(zipName, appId, onDone) { |
|
48 // Copy our package to tmp folder, where the actor retrieves it |
|
49 let zip = do_get_file("data/" + zipName); |
|
50 let appDir = FileUtils.getDir("TmpD", ["b2g", appId], true, true); |
|
51 zip.copyTo(appDir, "application.zip"); |
|
52 |
|
53 let request = {type: "install", appId: appId}; |
|
54 webappActorRequest(request, function (aResponse) { |
|
55 do_check_eq(aResponse.appId, appId); |
|
56 if ("error" in aResponse) { |
|
57 do_throw("Error: " + aResponse.error); |
|
58 } |
|
59 if ("message" in aResponse) { |
|
60 do_throw("Error message: " + aResponse.message); |
|
61 } |
|
62 do_check_false("error" in aResponse); |
|
63 |
|
64 onDone(); |
|
65 }); |
|
66 }; |
|
67 |
|
68 function setup() { |
|
69 // We have to setup a profile, otherwise indexed db used by webapps |
|
70 // will throw random exception when trying to get profile folder |
|
71 do_get_profile(); |
|
72 |
|
73 // The webapps dir isn't registered on b2g xpcshell tests, |
|
74 // we have to manually set it to the directory service. |
|
75 do_get_webappsdir(); |
|
76 |
|
77 // We also need a valid nsIXulAppInfo service as Webapps.jsm is querying it |
|
78 Components.utils.import("resource://testing-common/AppInfo.jsm"); |
|
79 updateAppInfo(); |
|
80 |
|
81 // We have to toggle this flag in order to have apps being listed in getAll |
|
82 // as only launchable apps are returned |
|
83 Components.utils.import('resource://gre/modules/Webapps.jsm'); |
|
84 DOMApplicationRegistry.allAppsLaunchable = true; |
|
85 } |
|
86 |
|
87 function do_get_webappsdir() { |
|
88 var webappsDir = Services.dirsvc.get("ProfD", Ci.nsILocalFile); |
|
89 webappsDir.append("test_webapps"); |
|
90 if (!webappsDir.exists()) |
|
91 webappsDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("755", 8)); |
|
92 |
|
93 var coreAppsDir = Services.dirsvc.get("ProfD", Ci.nsILocalFile); |
|
94 coreAppsDir.append("test_coreapps"); |
|
95 if (!coreAppsDir.exists()) |
|
96 coreAppsDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("755", 8)); |
|
97 |
|
98 // Register our own provider for the profile directory. |
|
99 // It will return our special docshell profile directory. |
|
100 var provider = { |
|
101 getFile: function(prop, persistent) { |
|
102 persistent.value = true; |
|
103 if (prop == "webappsDir") { |
|
104 return webappsDir.clone(); |
|
105 } |
|
106 else if (prop == "coreAppsDir") { |
|
107 return coreAppsDir.clone(); |
|
108 } |
|
109 throw Cr.NS_ERROR_FAILURE; |
|
110 }, |
|
111 QueryInterface: function(iid) { |
|
112 if (iid.equals(Ci.nsIDirectoryServiceProvider) || |
|
113 iid.equals(Ci.nsISupports)) { |
|
114 return this; |
|
115 } |
|
116 throw Cr.NS_ERROR_NO_INTERFACE; |
|
117 } |
|
118 }; |
|
119 Services.dirsvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider); |
|
120 } |
|
121 |
|
122 |