Esempio n. 1
0
exports['should edit config.xml even when using old <plugins-plist> approach'] = function (test) {
    // setting up PGSQLitePlugin (with config.xml) 
    var dummy_plugin_dir = path.join(test_dir, 'plugins', 'ChildBrowser')
    var dummy_xml_path = path.join(dummy_plugin_dir, 'plugin.xml')
    
    // overriding some params
    var project_dir = path.join(test_dir, 'projects', 'ios-config-xml')
    var dummy_plugin_et  = new et.ElementTree(et.XML(fs.readFileSync(dummy_xml_path, 'utf-8')));

    // run the platform-specific function
    ios.handlePlugin('install', project_dir, dummy_plugin_dir, dummy_plugin_et, { APP_ID: 12345 });
    
    var configXmlPath = path.join(project_dir, 'SampleApp', 'config.xml');
    var pluginsTxt = fs.readFileSync(configXmlPath, 'utf-8'),
        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt)),
        expected = 'plugins/plugin[@name="com.phonegap.plugins.childbrowser"]' +
                    '[@value="ChildBrowserCommand"]';

    test.ok(pluginsDoc.find(expected));
    test.equal(pluginsDoc.findall("access").length, 3, "/access");
    test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "build.phonegap.com")
    test.equal(pluginsDoc.findall("access")[2].attrib["origin"], "12345.s3.amazonaws.com")

    test.done();
}
 it('should add a platform element to the platforms element', function() {
     var cfg = new config_parser(xml);
     cfg.add_platform('android');
     
     var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
     expect(doc.find('platforms').getchildren()[0].attrib.name).toEqual('android');
 });
Esempio n. 3
0
function getStartAppPath(dir, cb){
    cb = cb || function(){};
    var _configPath = path.join(dir, 'Payload/%s/config.xml');
    var _startAppDirPath = path.join(dir, 'Payload/%s/www/preinstalledApps/%2/');
    var _dirs = fs.readdirSync( dir );
    if( _dirs.length != 1 || _dirs[0] !== 'Payload'){
        event.emit('error', 'error ipa format');
        return cb(new Error('error ipa format'));

    }
    _dirs = fs.readdirSync(path.join(dir, 'Payload'));
    if( _dirs.length != 1){
        event.emit('error', 'error ipa format');
        return cb(new Error('error ipa format'));
    }
    _findingDir = _dirs[0];
    _configPath = _configPath.replace('%s',_findingDir);
    if(!fs.existsSync(_configPath)){
        event.emit('error', 'error ipa format');
        return cb(new Error('error ipa format'));
    }
    _startAppDirPath = _startAppDirPath.replace('%s', _findingDir);
    var _tree = new et.ElementTree(et.XML(fs.readFileSync(_configPath, 'utf-8')));
    var _startAppDir = _tree.getroot().findtext('pre_install_packages/app_package/');
    _startAppDirPath = _startAppDirPath.replace('%2', _startAppDir);
    if(!fs.existsSync(_startAppDirPath)){
        event.emit('error', 'error ipa format');
        return cb(new Error('error ipa format'));
    }
    if(cb) cb(null, _startAppDirPath);
}
Esempio n. 4
0
    update_csproj:function() {
        var raw = fs.readFileSync(this.csproj_path, 'utf-8');
        var cleaned = raw.replace(/^\uFEFF/i, '');
        var csproj_xml = new et.ElementTree(et.XML(cleaned));
        // remove any previous references to the www files
        var item_groups = csproj_xml.findall('ItemGroup');
        for (var i = 0, l = item_groups.length; i < l; i++) {
            var group = item_groups[i];
            var files = group.findall('Content');
            for (var j = 0, k = files.length; j < k; j++) {
                var file = files[j];
                if (file.attrib.Include.substr(0, 3) == 'www') {
                    // remove file reference
                    group.remove(0, file);
                    // remove ItemGroup if empty
                    var new_group = group.findall('Content');
                    if(new_group.length < 1) {
                        csproj_xml.getroot().remove(0, group);
                    }
                }
            }
        }

        // now add all www references back in
        var www_files = this.folder_contents('www', this.www_dir());
        for(file in www_files) {
            var item = new et.Element('ItemGroup');
            var content = new et.Element('Content');
            content.attrib.Include = www_files[file];
            item.append(content);
            csproj_xml.getroot().append(item);
        }
        // save file
        fs.writeFileSync(this.csproj_path, csproj_xml.write({indent:4}), 'utf-8');
    },
exports['should edit config.xml'] = function (test) {
    // setting up WebNotification (with config.xml) 
    var dummy_plugin_dir = path.join(test_dir, 'plugins', 'WebNotifications')
    var dummy_xml_path = path.join(test_dir, 'plugins', 'WebNotifications', 'plugin.xml')
    
    // overriding some params
    var project_dir = path.join(test_dir, 'projects', 'ios-config-xml')
    var dummy_plugin_et  = new et.ElementTree(et.XML(fs.readFileSync(dummy_xml_path, 'utf-8')));

    // run the platform-specific function
    ios.handlePlugin('install', project_dir, dummy_plugin_dir, dummy_plugin_et);
    
    ios.handlePlugin('uninstall', project_dir, dummy_plugin_dir, dummy_plugin_et);
    
    var configXmlPath = path.join(project_dir, 'SampleApp', 'config.xml');
    var pluginsTxt = fs.readFileSync(configXmlPath, 'utf-8'),
        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt)),
        expected = 'plugins/plugin[@name="WebNotifications"]' +
                    '[@value="WebNotifications"]';

    test.ok(!pluginsDoc.find(expected));
	test.equal(pluginsDoc.findall("access").length, 1, "/access");

    test.done();
}
Esempio n. 6
0
    add_mobile_spec_result:function(platform, sha, version, model, xmlData) {
        var xml = new et.ElementTree(et.XML(xmlData));
        var tests = 0, num_fails = 0, time = 0, failText = [];
        xml.getroot().findall('testsuites').forEach(function(set) {
            set.getchildren().forEach(function(suite) {
                tests += parseInt(suite.attrib.tests, 10);
                var failures = parseInt(suite.attrib.failures, 10);
                num_fails += failures;
                time += parseFloat(suite.attrib.time);
                if (failures > 0) {
                    suite.getchildren().forEach(function(testcase) {
                        var failTitle = testcase.attrib.classname + ' ' + testcase.attrib.name;
                        testcase.findall('failure').forEach(function(failure) {
                            failText.push(failTitle + ' :: Assertion failure: ' + failure.text);
                        });
                    });
                }
            });
        });

        // Make sure results have proper parent objects
        if (!results[platform]) results[platform] = {};
        if (!results[platform][sha]) results[platform][sha] = {};
        if (!results[platform][sha][version]) results[platform][sha][version] = {};
        if (!results[platform][sha][version][model]) results[platform][sha][version][model] = {};

        results[platform][sha][version][model] = {
            tests:tests,
            num_fails:num_fails,
            time:time,
            fails:failText
        };
        html = renderer(shas, results);
    },
 it('should ignore garbage platforms', function() {
     var cfg = new config_parser(xml);
     cfg.add_platform('bat country');
     
     var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
     expect(doc.find('platforms').getchildren().length).toEqual(0);
 });
Esempio n. 8
0
 project.update_from_config(config, function() {
     var native_config = new et.ElementTree(et.XML(fs.readFileSync(ios_config_xml, 'utf-8')));
     var ps = native_config.findall('preference');
     expect(ps.length).toEqual(16);
     expect(ps[2].attrib.name).toEqual('UIWebViewBounce');
     expect(ps[2].attrib.value).toEqual('false');
     done();
 });
    android.installPlugin(config, plugin, function (err) {
        var manifestTxt = fs.readFileSync(manifestPath, 'utf-8'),
            manifestDoc = new et.ElementTree(et.XML(manifestTxt)),
            expected = 'custom[@name="AppID"][@value="723658"]';

        test.ok(manifestDoc.find(expected));
        test.done();
    })
Esempio n. 10
0
        it('should update the application name properly', function() {
            config.name('bond. james bond.');
            project.update_from_config(config);

            var strings = new et.ElementTree(et.XML(fs.readFileSync(android_strings, 'utf-8')));
            var app_name = strings.find('string[@name="app_name"]').text;

            expect(app_name).toBe('bond. james bond.');
        });
            it('should remove a platform element from the platforms element', function() {
                var cfg = new config_parser(xml);
                cfg.add_platform('ios');

                cfg.remove_platform('ios');

                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
                expect(doc.find('platforms').getchildren().length).toEqual(0);
            });
Esempio n. 12
0
    android.installPlugin(config, plugin, function (err) {
        var pluginsTxt = fs.readFileSync('test/project/res/xml/plugins.xml', 'utf-8'),
            pluginsDoc = new et.ElementTree(et.XML(pluginsTxt)),
            expected = 'plugin[@name="ChildBrowser"]' +
                        '[@value="com.phonegap.plugins.childBrowser.ChildBrowser"]';

        test.ok(pluginsDoc.find(expected));
        test.done();
    })
Esempio n. 13
0
module.exports.updateBuildConfig = function (buildConfig) {
    var projectRoot = path.join(__dirname, '../..');
    var config = new ConfigParser(path.join(projectRoot, 'config.xml'));

    // if no buildConfig is provided dont do anything
    buildConfig = buildConfig || {};

    // Merge buildConfig with config
    for (var attr in buildConfig) {
        config[attr] = buildConfig[attr];
    }

    var root = new et.Element('Project');
    root.set('xmlns', 'http://schemas.microsoft.com/developer/msbuild/2003');
    var buildConfigXML = new et.ElementTree(root);
    var propertyGroup = new et.Element('PropertyGroup');
    var itemGroup = new et.Element('ItemGroup');

    // Append PropertyGroup and ItemGroup
    buildConfigXML.getroot().append(propertyGroup);
    buildConfigXML.getroot().append(itemGroup);

    // packageCertificateKeyFile - defaults to 'CordovaApp_TemporaryKey.pfx'
    var packageCertificateKeyFile = config.packageCertificateKeyFile || 'CordovaApp_TemporaryKey.pfx';

    if (config.packageCertificateKeyFile) {
        // Convert packageCertificateKeyFile from absolute to relative path
        packageCertificateKeyFile = path.relative(projectRoot, packageCertificateKeyFile);
    }

    var certificatePropertyElement = new et.Element('PackageCertificateKeyFile');
    certificatePropertyElement.text = packageCertificateKeyFile;
    propertyGroup.append(certificatePropertyElement);

    var certificateItemElement = new et.Element('None', { 'Include': packageCertificateKeyFile });
    itemGroup.append(certificateItemElement);

    // packageThumbprint
    if (config.packageThumbprint) {
        var thumbprintElement = new et.Element('PackageCertificateThumbprint');
        thumbprintElement.text = config.packageThumbprint;
        propertyGroup.append(thumbprintElement);
    }

    // DefaultLanguage - defaults to 'en-US'
    var defaultLocale = config.defaultLocale() || 'en-US';
    var defaultLocaleElement = new et.Element('DefaultLanguage');
    defaultLocaleElement.text = defaultLocale;
    propertyGroup.append(defaultLocaleElement);

    var buildConfigFileName = buildConfig.buildType === 'release' ?
        path.join(projectRoot, 'CordovaAppRelease.projitems') :
        path.join(projectRoot, 'CordovaAppDebug.projitems');

    fs.writeFileSync(buildConfigFileName, TEMPLATE + buildConfigXML.write({indent: 2, xml_declaration: false}), 'utf-8');
};
Esempio n. 14
0
 project.update_from_config(config, function() {
     var native_config = new et.ElementTree(et.XML(fs.readFileSync(ios_config_xml, 'utf-8')));
     var ps = native_config.findall('preference');
     expect(ps.length).toEqual(17);
     expect(ps[0].attrib.name).toEqual('KeyboardDisplayRequiresUserAction');
     expect(ps[0].attrib.value).toEqual('true');
     expect(ps[16].attrib.name).toEqual('henrik');
     expect(ps[16].attrib.value).toEqual('sedin');
     done();
 });
            it('should update the whitelist when using access elements with uri attributes', function() {
                fs.writeFileSync(www_config, fs.readFileSync(www_config, 'utf-8').replace(/origin="\*/,'uri="http://rim.com'), 'utf-8');
                config = new config_parser(www_config);
                project.update_from_config(config);

                var bb_cfg = new et.ElementTree(et.XML(fs.readFileSync(blackberry_config, 'utf-8')));
                var as = bb_cfg.getroot().findall('access');
                expect(as.length).toEqual(1);
                expect(as[0].attrib.uri).toEqual('http://rim.com');
            });
Esempio n. 16
0
            it('should override a default project preference if applicable', function() {
                config.preference.add({name:'useBrowserHistory',value:'false'});
                project.update_from_config(config);

                var native_config = new et.ElementTree(et.XML(fs.readFileSync(android_config, 'utf-8')));
                var ps = native_config.findall('preference');
                expect(ps.length).toEqual(6);
                expect(ps[0].attrib.name).toEqual('useBrowserHistory');
                expect(ps[0].attrib.value).toEqual('false');
            });
Esempio n. 17
0
exports['should search/replace manifest.xml files'] = function (test) {
	android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 });

    var manifestXmlPath = path.join(test_dir, 'projects', 'android_one', 'AndroidManifest.xml');
    var manifestTxt = fs.readFileSync(manifestXmlPath, 'utf-8'),
        manifestDoc = new et.ElementTree(et.XML(manifestTxt));

	test.equal(manifestDoc.findall("appid")[0].attrib["value"], "12345")
    test.done();
}
function buildMetadata(metadata) {
  var didl = et.Element('DIDL-Lite');
  didl.set('xmlns', 'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/');
  didl.set('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
  didl.set('xmlns:upnp', 'urn:schemas-upnp-org:metadata-1-0/upnp/');
  didl.set('xmlns:sec', 'http://www.sec.co.kr/');

  var item = et.SubElement(didl, 'item');
  item.set('id', 0);
  item.set('parentID', -1);
  item.set('restricted', false);

  var OBJECT_CLASSES = {
    'audio': 'object.item.audioItem.musicTrack',
    'video': 'object.item.videoItem.movie',
    'image': 'object.item.imageItem.photo'
  }

  if(metadata.type) {
    var klass = et.SubElement(item, 'upnp:class');
    klass.text = OBJECT_CLASSES[metadata.type];
  }

  if(metadata.title) {
    var title = et.SubElement(item, 'dc:title');
    title.text = metadata.title;
  }

  if(metadata.creator) {
    var creator = et.SubElement(item, 'dc:creator');
    creator.text = metadata.creator;
  }

  if(metadata.subtitlesUrl) {
    var captionInfo = et.SubElement(item, 'sec:CaptionInfo');
    captionInfo.set('sec:type', 'srt');
    captionInfo.text = metadata.subtitlesUrl;

    var captionInfoEx = et.SubElement(item, 'sec:CaptionInfoEx');
    captionInfoEx.set('sec:type', 'srt');
    captionInfoEx.text = metadata.subtitlesUrl;

    // Commented-out for now as it makes some TVs which don't have it
    // in their supported protocols choke.
    //var res = et.SubElement(item, 'res');
    //res.set('protocolInfo', 'http-get:*:text/srt:*');
    //res.text = metadata.subtitlesUrl;

  }

  var doc = new et.ElementTree(didl);
  var xml = doc.write({ xml_declaration: false });

  return xml;
}
            it('should return a populated array if there are platforms specified in the document', function() {
                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
                var p = new et.Element('platform');
                p.attrib.name = 'android';
                doc.find('platforms').append(p);
                fs.writeFileSync(xml, doc.write(), 'utf-8');

                var cfg = new config_parser(xml);
                expect(cfg.ls_platforms().length).toBe(1);
                expect(cfg.ls_platforms()[0]).toEqual('android');
            });
exports['should remove whitelist hosts'] = function (test) {
	android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
	android.handlePlugin('uninstall', test_project_dir, test_plugin_dir, plugin_et);
    
	var pluginsXmlPath = path.join(test_dir, 'projects', 'android_one', 'res', 'xml', 'plugins.xml');
    var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'),
        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt));

    test.equal(pluginsDoc.findall("access").length, 0, "/access");
    test.done();
}
Esempio n. 21
0
exports['should edit config.xml'] = function (test) {
    bb10.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
    
    var configXmlPath = path.join(test_project_dir, 'config.xml');
    var pluginsTxt = fs.readFileSync(configXmlPath, 'utf-8'),
        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt)),
        expected = 'feature[@id="cordova.echo"]';
    test.ok(pluginsDoc.find(expected));

    test.done();
}
exports['should add whitelist hosts'] = function (test) {
	android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);

    var pluginsXmlPath = path.join(test_dir, 'projects', 'android_two', 'res', 'xml', 'config.xml');
    var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'),
        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt));

    test.equal(pluginsDoc.findall("access").length, 3, "/access");
	test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "build.phonegap.com")
    test.equal(pluginsDoc.findall("access")[2].attrib["origin"], "s3.amazonaws.com")
    test.done();
}
Esempio n. 23
0
            it('should not change default project preferences and copy over additional project preferences to platform-level config.xml', function() {
                config.preference.add({name:'henrik',value:'sedin'});
                project.update_from_config(config);

                var native_config = new et.ElementTree(et.XML(fs.readFileSync(android_config, 'utf-8')));
                var ps = native_config.findall('preference');
                expect(ps.length).toEqual(7);
                expect(ps[0].attrib.name).toEqual('useBrowserHistory');
                expect(ps[0].attrib.value).toEqual('true');
                expect(ps[6].attrib.name).toEqual('henrik');
                expect(ps[6].attrib.value).toEqual('sedin');
            });
Esempio n. 24
0
        it('should update the whitelist properly', function() {
            config.access.remove('*');
            config.access.add('http://apache.org');
            config.access.add('http://github.com');
            project.update_from_config(config);

            var native_config = new et.ElementTree(et.XML(fs.readFileSync(android_config, 'utf-8')));
            var as = native_config.findall('access');
            expect(as.length).toEqual(2);
            expect(as[0].attrib.origin).toEqual('http://apache.org');
            expect(as[1].attrib.origin).toEqual('http://github.com');
        });
Esempio n. 25
0
exports['should search/replace plugin.xml'] = function (test) {
	android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 });

    var pluginsXmlPath = path.join(test_dir, 'projects', 'android_one', 'res', 'xml', 'plugins.xml');
    var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'),
        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt));

    test.equal(pluginsDoc.findall("access").length, 2, "/access");
	test.equal(pluginsDoc.findall("access")[0].attrib["origin"], "build.phonegap.com")
    test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "s3.amazonaws.com")
    test.done();
}
Esempio n. 26
0
exports['should add ChildBrowser to plugins.xml'] = function (test) {
    android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID: 12345 });

    var pluginsXmlPath = path.join(test_dir, 'projects', 'android_one', 'res', 'xml', 'plugins.xml');
    var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'),
        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt)),
        expected = 'plugin[@name="ChildBrowser"]' +
                    '[@value="com.phonegap.plugins.childBrowser.ChildBrowser"]';

    test.ok(pluginsDoc.find(expected));
    test.done();
}
            it('should update the whitelist when using access elements with origin attribute', function() {
                config.access.remove('*');
                config.access.add('http://blackberry.com');
                config.access.add('http://rim.com');
                project.update_from_config(config);

                var bb_cfg = new et.ElementTree(et.XML(fs.readFileSync(blackberry_config, 'utf-8')));
                var as = bb_cfg.getroot().findall('access');
                expect(as.length).toEqual(2);
                expect(as[0].attrib.uri).toEqual('http://blackberry.com');
                expect(as[1].attrib.uri).toEqual('http://rim.com');
            });
Esempio n. 28
0
exports['should remove ChildBrowser from config.xml'] = function (test) {
    android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
    android.handlePlugin('uninstall', test_project_dir, test_plugin_dir, plugin_et);
    
    var pluginsXmlPath = path.join(test_dir, 'projects', 'android_two', 'res', 'xml', 'config.xml');
    var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'),
        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt)),
        expected = 'plugins/plugin[@name="ChildBrowser"]' +
                    '[@value="com.phonegap.plugins.childBrowser.ChildBrowser"]';
    test.ok(!pluginsDoc.find(expected));
    test.done();
}
Esempio n. 29
0
function updatejsprojFile(config, jsProjFilePath) {
    var defaultLocale = config.defaultLocale() || 'en-US';

    var contents = fs.readFileSync(jsProjFilePath, 'utf-8');
    // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
    if (contents.charCodeAt(0) === 0xFEFF) {
        contents = contents.slice(1);
    }
    var jsProjXML =  new et.ElementTree(et.XML(contents));
    var jsProjDefaultLocale = jsProjXML.find('./PropertyGroup/DefaultLanguage');
    jsProjDefaultLocale.text = defaultLocale;
    fs.writeFileSync(jsProjFilePath, jsProjXML.write({indent: 2}), 'utf-8');
}
Esempio n. 30
0
function parsePlugin (pluginPath) {
    var pluginXML = fs.readFileSync(path.join(pluginPath, "plugin.xml"), "utf-8"),
        pluginEt = new et.ElementTree(et.XML(pluginXML)),
        platformTag = pluginEt.find('./platform[@name="blackberry10"]');

    return {
        path: pluginPath,
        id: pluginEt._root.attrib.id,
        assets: pluginEt.findall('./asset'),
        srcFiles: platformTag.findall('./source-file'),
        configChanges: platformTag.findall('./config-file'),
        libFiles: platformTag.findall('./lib-file')
    };
}