summaryrefslogtreecommitdiffstats
path: root/b2g/components/test/unit/head_logshake_gonk.js
blob: e94234f1f043e8ec7c77eb4cfd93b99a23ac63ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * Boostrap LogShake's tests that need gonk support.
 * This is creating a fake sdcard for LogShake tests and importing LogShake and
 * osfile
 */

/* jshint moz: true */
/* global Components, LogCapture, LogShake, ok, add_test, run_next_test, dump,
   do_get_profile, OS, volumeService, equal, XPCOMUtils */
/* exported setup_logshake_mocks */

/* disable use strict warning */
/* jshint -W097 */

"use strict";

var Cu = Components.utils;
var Ci = Components.interfaces;
var Cc = Components.classes;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/osfile.jsm");

XPCOMUtils.defineLazyServiceGetter(this, "volumeService",
                                   "@mozilla.org/telephony/volume-service;1",
                                   "nsIVolumeService");

var sdcard;

function setup_logshake_mocks() {
  do_get_profile();
  setup_fs();
}

function setup_fs() {
  OS.File.makeDir("/data/local/tmp/sdcard/", {from: "/data"}).then(function() {
    setup_sdcard();
  });
}

function setup_sdcard() {
  let volName = "sdcard";
  let mountPoint = "/data/local/tmp/sdcard";
  volumeService.createFakeVolume(volName, mountPoint);

  let vol = volumeService.getVolumeByName(volName);
  ok(vol, "volume shouldn't be null");
  equal(volName, vol.name, "name");
  equal(Ci.nsIVolume.STATE_MOUNTED, vol.state, "state");

  ensure_sdcard();
}

function ensure_sdcard() {
  sdcard = volumeService.getVolumeByName("sdcard").mountPoint;
  ok(sdcard, "Should have a valid sdcard mountpoint");
  run_next_test();
}