• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
B2G OS
  1. MDN
  2. Archive of obsolete content
  3. B2G OS
  4. Debugging on Firefox OS
  5. Testing in a privileged context: Shipping your own Gaia apps

Testing in a privileged context: Shipping your own Gaia apps

In This Article
  1. Downloading and building Gaia
    1. Preparing a custom app
  2. Load B2G desktop using the new profile
    1. Linux
    2. Mac OS X
    3. Windows
    4. What to expect
  3. Done

« Previous

As you may have noticed, executing JavaScript does not give you full access to all the shiny WebAPIs. For an app to use a specific API, it has to request access to that API in its manifest. This article takes you through how to test privileged apps before they are submitted to a Marketplace.

To obtain the currently running app's metadata and manifest into a variable, you can use code like this:

navigator.mozApps.getSelf().onsuccess = function(e) {
  appself = e.result;
}

This fetches the app's metadata into the variable appself.

On a similar note, if you want to see the permissions for a different app, take a look at the test app "Permissions", which comes with your b2g-desktop testing build: it enumerates the permissions given to all of the currently-installed apps.

Some of the existing WebAPIs are just not available to any kind of app. To use these APIs, you need to install an app with the highest privileges (that is, a certified app). To do that yourself, you have to build a custom version of the top b2g layer, Gaia. Doing this requires git and a working make environment. See Firefox OS build prerequisites for details on setting up a Firefox OS build environment.

In this case, you don't need to build all of Firefox OS, just Gaia. Let's see how you do that.

Downloading and building Gaia

First, you need to download Gaia then build it. This creates a profile you can load with b2g desktop. This can be done using the following commands:

$ git clone https://github.com/mozilla-b2g/gaia
$ cd gaia
$ make

Warning: Building Gaia for the first time requires downloading XULRunner, which is about 500 MB, so it takes some time and a lot of space.

This will build the standard Gaia for you, so that it's ready for action.

Preparing a custom app

While XULRunner is being downloaded, I recommend reading the Gaia source code. You can be getting your custom app ready while this download progresses.

All the apps that come with Gaia (Settings, Contacts, Browser, etc.) are stored in the apps/ directory. That means that your high-privileged app will also have to go there. For the purposes of this article, an example app called allperms has been made available on Github.

Change into the apps/ directory in your Gaia code tree and clone the example app into it:

cd apps
git clone https://github.com/freddyb/allperms.git

Once your first Gaia build is done and xulrunner-sdk has been downloaded, you can rebuild Gaia with allperms in the apps/ directory. But don't worry, this time the build will be much faster, since most things have already been compiled. Just do:

make

Load B2G desktop using the new profile

B2G Desktop comes with two main executables: b2g and b2g-bin: we want the latter, as this allows us to specify command line arguments.

Note: See Using the B2G desktop client for additional information about the B2G Desktop application.

Load the b2g executable, supplying the -profile option with the path to the Gaia profile you've just built.

Linux

$ b2g-bin -profile /path/to/gaia/profile 

Mac OS X

On Mac OS X, the command to launch from the gaia directory (assuming you've installed B2G in the standard applications folder) is as follows:

$ /Applications/B2G.app/Contents/MacOS/b2g-bin -profile /path/to/gaia/profile 

Windows

TBD

What to expect

Assuming it all works, you should see the lock screen:

There are some useful command-line options available when using B2G Desktop.

Note: This profile starts with default settings again. Any customizations you have to your testing setup will have to be done again; this includes configuration of Marionette, proxies, and certificates.

Done

Your allperms app should now be installed and should be equipped with all possible permissions.

Now you will only have to re-iterate on the Marionette steps from Debugging and security testing with Firefox OS to have a testing environment that can access all WebAPIs.

« Previous

Document Tags and Contributors

Tags: 
  • Apps
  • Firefox OS
  • Security
  • Testing
 Contributors to this page: chrisdavidmills, kechol, jswisher, Sheppy, freddyb
 Last updated by: chrisdavidmills, Feb 27, 2017, 2:59:44 AM
See also
  1. Build and install
    1. Build and install overview
    2. B2G OS build process summary
    3. Build prerequisites
    4. Preparing for your first build
    5. Building B2G OS
    6. B2G installer add-on
    7. Building B2G OS for Flame on Mac OS X
    8. Choosing how to run Gaia or B2G OS
    9. Compatible Devices
    10. Installing B2G OS on a mobile device
    11. Creating and applying B2G OS update packages
    12. Building and installing FOTA community builds
    13. B2G build variables reference sheet
  2. Porting B2G OS
    1. Porting overview
    2. Porting basics
    3. Porting on CyanogenMod
  3. Developing Gaia
    1. Developing Gaia overview
    2. Running the Gaia codebase
    3. Run Gaia on desktop using Mulet
    4. Understanding the Gaia codebase
    5. Making Gaia code changes
    6. Testing Gaia code changes
    7. Submitting a Gaia patch
    8. Gaia build system primer
    9. Different ways to run Gaia
    10. Make options reference
    11. Gaia tools reference
  4. B2G OS APIs