cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [3/3] cordova-lib git commit: CB-8043 CB-6462 CB-6105 Refactor orientation preference support (close #128)
Date Thu, 08 Jan 2015 19:36:58 GMT
CB-8043 CB-6462 CB-6105 Refactor orientation preference support (close #128)

- add support for ios, wp8 and firefoxos
- add support for specifying a custom value for a platform-specific orientation
- invalid global orientation preference value now defaults to value 'default'
- close #128


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/a6112c66
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/a6112c66
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/a6112c66

Branch: refs/heads/master
Commit: a6112c661efc90dff0f17f4514da566e23327dfc
Parents: 9874f39
Author: Marko Raatikka <marko.raatikka@gmail.com>
Authored: Thu Jan 8 15:40:04 2015 +0200
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Jan 8 14:36:11 2015 -0500

----------------------------------------------------------------------
 .../metadata/android_parser.spec.js             | 55 ++++++++++-----
 .../metadata/blackberry_parser.spec.js          |  7 +-
 .../metadata/browser_parser.spec.js             |  7 +-
 .../metadata/firefoxos_parser.spec.js           | 48 +++++++++++--
 .../spec-cordova/metadata/ios_parser.spec.js    | 53 +++++++++++++-
 .../metadata/windows8_parser.spec.js            |  7 +-
 .../spec-cordova/metadata/wp8_parser.spec.js    | 73 ++++++++++++++++++--
 .../cordova/metadata/amazon_fireos_parser.js    | 32 +++------
 .../src/cordova/metadata/android_parser.js      | 32 +++------
 .../src/cordova/metadata/blackberry10_parser.js |  2 +-
 .../src/cordova/metadata/browser_parser.js      |  2 +-
 .../src/cordova/metadata/firefoxos_parser.js    | 17 ++---
 cordova-lib/src/cordova/metadata/ios_parser.js  | 28 +++++++-
 .../src/cordova/metadata/ubuntu_parser.js       |  2 +-
 .../src/cordova/metadata/windows_parser.js      |  7 +-
 cordova-lib/src/cordova/metadata/wp8_parser.js  | 29 ++++++--
 16 files changed, 293 insertions(+), 108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/spec-cordova/metadata/android_parser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/metadata/android_parser.spec.js b/cordova-lib/spec-cordova/metadata/android_parser.spec.js
index def39b4..5d327a8 100644
--- a/cordova-lib/spec-cordova/metadata/android_parser.spec.js
+++ b/cordova-lib/spec-cordova/metadata/android_parser.spec.js
@@ -27,6 +27,7 @@ var platforms = require('../../src/cordova/platforms'),
     config = require('../../src/cordova/config'),
     Parser = require('../../src/cordova/metadata/parser'),
     ConfigParser = require('../../src/configparser/ConfigParser'),
+    CordovaError = require('../../src/CordovaError'),
     cordova = require('../../src/cordova/cordova');
 
 // Create a real config object before mocking out everything.
@@ -46,6 +47,7 @@ var MANIFEST_XML = '<manifest android:versionCode="1" android:versionName="0.0.1
 
 describe('android project parser', function() {
     var proj = path.join('some', 'path');
+    var android_proj = path.join(proj, 'platforms', 'android');
     var exists;
     beforeEach(function() {
         exists = spyOn(fs, 'existsSync').andReturn(true);
@@ -68,26 +70,30 @@ describe('android project parser', function() {
         it('should throw if provided directory does not contain an AndroidManifest.xml',
function() {
             exists.andReturn(false);
             expect(function() {
-                new platforms.android.parser(proj);
+                new platforms.android.parser(android_proj);
             }).toThrow();
         });
         it('should create an instance with path, strings, manifest and android_config properties',
function() {
             expect(function() {
-                var p = new platforms.android.parser(proj);
-                expect(p.path).toEqual(proj);
-                expect(p.strings).toEqual(path.join(proj, 'res', 'values', 'strings.xml'));
-                expect(p.manifest).toEqual(path.join(proj, 'AndroidManifest.xml'));
-                expect(p.android_config).toEqual(path.join(proj, 'res', 'xml', 'config.xml'));
+                var p = new platforms.android.parser(android_proj);
+                expect(p.path).toEqual(android_proj);
+                expect(p.strings).toEqual(path.join(android_proj, 'res', 'values', 'strings.xml'));
+                expect(p.manifest).toEqual(path.join(android_proj, 'AndroidManifest.xml'));
+                expect(p.android_config).toEqual(path.join(android_proj, 'res', 'xml', 'config.xml'));
             }).not.toThrow();
         });
         it('should be an instance of Parser', function() {
-            expect(new platforms.android.parser(proj) instanceof Parser).toBeTruthy();
+            expect(new platforms.android.parser(android_proj) instanceof Parser).toBe(true);
+        });
+        it('should call super with the correct arguments', function() {
+            var call = spyOn(Parser, 'call');
+            var p = new platforms.android.parser(android_proj);
+            expect(call).toHaveBeenCalledWith(p, 'android', android_proj);
         });
     });
 
     describe('instance', function() {
-        var p, cp, rm, mkdir, is_cordova, write, read;
-        var android_proj = path.join(proj, 'platforms', 'android');
+        var p, cp, rm, mkdir, is_cordova, write, read, getOrientation;
         var stringsRoot;
         var manifestRoot;
         beforeEach(function() {
@@ -96,7 +102,7 @@ describe('android project parser', function() {
             p = new platforms.android.parser(android_proj);
             cp = spyOn(shell, 'cp');
             rm = spyOn(shell, 'rm');
-            is_cordova = spyOn(util, 'isCordova').andReturn(proj);
+            is_cordova = spyOn(util, 'isCordova').andReturn(android_proj);
             write = spyOn(fs, 'writeFileSync');
             read = spyOn(fs, 'readFileSync');
             mkdir = spyOn(shell, 'mkdir');
@@ -105,38 +111,51 @@ describe('android project parser', function() {
                     return stringsRoot = new et.ElementTree(et.XML(STRINGS_XML));
                 } else if (/AndroidManifest/.exec(path)) {
                     return manifestRoot = new et.ElementTree(et.XML(MANIFEST_XML));
+                } else {
+                    throw new CordovaError('Unexpected parseElementtreeSync: ' + path);
                 }
             });
+            getOrientation = spyOn(p.helper, 'getOrientation');
         });
 
         describe('update_from_config method', function() {
             beforeEach(function() {
-                spyOn(fs, 'readdirSync').andReturn([path.join(proj, 'src', 'android_pkg',
'MyApp.java')]);
+                spyOn(fs, 'readdirSync').andReturn([ path.join(android_proj, 'src', 'android_pkg',
'MyApp.java') ]);
                 cfg.name = function() { return 'testname' };
                 cfg.packageName = function() { return 'testpkg' };
                 cfg.version = function() { return 'one point oh' };
                 read.andReturn('package org.cordova.somepackage; public class MyApp extends
CordovaActivity { }');
             });
 
+            it('should write out the orientation preference value', function() {
+                getOrientation.andCallThrough();
+                p.update_from_config(cfg);
+                expect(manifestRoot.getroot().find('./application/activity').attrib['android:screenOrientation']).toEqual('landscape');
+            });
             it('should handle no orientation', function() {
-                cfg.getPreference = function() { return null; };
+                getOrientation.andReturn('');
                 p.update_from_config(cfg);
-                expect(manifestRoot.getroot().find('./application/activity').attrib['android:screenOrientation']).toEqual('VAL');
+                expect(manifestRoot.getroot().find('./application/activity').attrib['android:screenOrientation']).toBeUndefined();
             });
             it('should handle default orientation', function() {
-                cfg.getPreference = function() { return 'default'; };
+                getOrientation.andReturn(p.helper.ORIENTATION_DEFAULT);
                 p.update_from_config(cfg);
                 expect(manifestRoot.getroot().find('./application/activity').attrib['android:screenOrientation']).toBeUndefined();
             });
             it('should handle portrait orientation', function() {
-                cfg.getPreference = function() { return 'portrait'; };
+                getOrientation.andReturn(p.helper.ORIENTATION_PORTRAIT);
                 p.update_from_config(cfg);
                 expect(manifestRoot.getroot().find('./application/activity').attrib['android:screenOrientation']).toEqual('portrait');
             });
-            it('should handle invalid orientation', function() {
-                cfg.getPreference = function() { return 'prtrait'; };
+            it('should handle landscape orientation', function() {
+                getOrientation.andReturn(p.helper.ORIENTATION_LANDSCAPE);
+                p.update_from_config(cfg);
+                expect(manifestRoot.getroot().find('./application/activity').attrib['android:screenOrientation']).toEqual('landscape');
+            });
+            it('should handle custom orientation', function() {
+                getOrientation.andReturn('some-custom-orientation');
                 p.update_from_config(cfg);
-                expect(manifestRoot.getroot().find('./application/activity').attrib['android:screenOrientation']).toEqual('VAL');
+                expect(manifestRoot.getroot().find('./application/activity').attrib['android:screenOrientation']).toEqual('some-custom-orientation');
             });
             it('should write out the app name to strings.xml', function() {
                 p.update_from_config(cfg);

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/spec-cordova/metadata/blackberry_parser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/metadata/blackberry_parser.spec.js b/cordova-lib/spec-cordova/metadata/blackberry_parser.spec.js
index 60484d0..2a38cdf 100644
--- a/cordova-lib/spec-cordova/metadata/blackberry_parser.spec.js
+++ b/cordova-lib/spec-cordova/metadata/blackberry_parser.spec.js
@@ -89,7 +89,12 @@ describe('blackberry10 project parser', function() {
             expect(project).toBeDefined();
         });
         it('should be an instance of Parser', function() {
-            expect(new platforms.blackberry10.parser(proj) instanceof Parser).toBeTruthy();
+            expect(new platforms.blackberry10.parser(proj) instanceof Parser).toBe(true);
+        });
+        it('should call super with the correct arguments', function() {
+            var call = spyOn(Parser, 'call');
+            var p = new platforms.blackberry10.parser(proj);
+            expect(call).toHaveBeenCalledWith(p, 'blackberry10', proj);
         });
     });
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/spec-cordova/metadata/browser_parser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/metadata/browser_parser.spec.js b/cordova-lib/spec-cordova/metadata/browser_parser.spec.js
index a869934..a41adec 100644
--- a/cordova-lib/spec-cordova/metadata/browser_parser.spec.js
+++ b/cordova-lib/spec-cordova/metadata/browser_parser.spec.js
@@ -40,7 +40,12 @@ describe('browser project parser', function() {
             }).not.toThrow();
         });
         it('should be an instance of Parser', function() {
-            expect(new platforms.browser.parser(proj) instanceof Parser).toBeTruthy();
+            expect(new platforms.browser.parser(proj) instanceof Parser).toBe(true);
+        });
+        it('should call super with the correct arguments', function() {
+            var call = spyOn(Parser, 'call');
+            var p = new platforms.browser.parser(proj);
+            expect(call).toHaveBeenCalledWith(p, 'browser', proj);
         });
     });
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/spec-cordova/metadata/firefoxos_parser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/metadata/firefoxos_parser.spec.js b/cordova-lib/spec-cordova/metadata/firefoxos_parser.spec.js
index 3eb09fc..4a7c01a 100644
--- a/cordova-lib/spec-cordova/metadata/firefoxos_parser.spec.js
+++ b/cordova-lib/spec-cordova/metadata/firefoxos_parser.spec.js
@@ -24,7 +24,8 @@ var platforms = require('../../src/cordova/platforms'),
     _ = require('underscore'),
     config = require('../../src/cordova/config'),
     Parser = require('../../src/cordova/metadata/parser'),
-    ConfigParser = require('../../src/configparser/ConfigParser');
+    ConfigParser = require('../../src/configparser/ConfigParser'),
+    CordovaError = require('../../src/CordovaError');
 
 var cfg = new ConfigParser(path.join(__dirname, '..', 'test-config.xml'));
 
@@ -56,13 +57,19 @@ describe('firefoxos project parser', function() {
             }).not.toThrow();
         });
         it('should be an instance of Parser', function() {
-            expect(new platforms.firefoxos.parser(proj) instanceof Parser).toBeTruthy();
+            expect(new platforms.firefoxos.parser(proj) instanceof Parser).toBe(true);
+        });
+        it('should call super with the correct arguments', function() {
+            var call = spyOn(Parser, 'call');
+            var p = new platforms.firefoxos.parser(proj);
+            expect(call).toHaveBeenCalledWith(p, 'firefoxos', proj);
         });
     });
 
     describe('instance', function() {
-        var p, cp, rm, is_cordova, write, read;
+        var p, cp, rm, is_cordova, write, read, getOrientation;
         var ff_proj = path.join(proj, 'platforms', 'firefoxos');
+        var manifestJson = null;
         beforeEach(function() {
             p = new platforms.firefoxos.parser(ff_proj);
             cp = spyOn(shell, 'cp');
@@ -73,11 +80,12 @@ describe('firefoxos project parser', function() {
 
             spyOn(JSON, 'parse').andCallFake(function (path) {
                 if (/manifest.webapp$/.exec(path)) {
-                    return _.extend({}, MANIFEST_JSON);
+                    return manifestJson = _.extend({}, MANIFEST_JSON);
                 } else {
                     throw new CordovaError('Unexpected JSON.parse(): ' + path);
                 }
             });
+            getOrientation = spyOn(p.helper, 'getOrientation');
         });
 
         describe('update_from_config method', function() {
@@ -87,11 +95,41 @@ describe('firefoxos project parser', function() {
                 cfg.version = function() { return '1.0'; };
                 read.andReturn(p.manifest_path);
             });
-
             it('should write manifest.webapp', function() {
                 p.update_from_config(cfg);
                 expect(write.mostRecentCall.args[0]).toEqual(p.manifest_path);
             });
+            it('should write out the orientation preference value', function() {
+                getOrientation.andCallThrough();
+                p.update_from_config(cfg);
+                expect(manifestJson.orientation).toEqual([ 'portrait' ]);
+            });
+            it('should handle no orientation', function () {
+                getOrientation.andReturn('');
+                p.update_from_config(cfg);
+                expect(manifestJson.orientation).toBeUndefined();
+            });
+            it('should handle default orientation', function () {
+                getOrientation.andReturn(p.helper.ORIENTATION_DEFAULT);
+                p.update_from_config(cfg);
+                expect(manifestJson.orientation).toBeUndefined();
+            });
+            it('should handle portrait orientation', function () {
+                getOrientation.andReturn(p.helper.ORIENTATION_PORTRAIT);
+                p.update_from_config(cfg);
+                expect(manifestJson.orientation).toEqual([ 'portrait' ]);
+            });
+            it('should handle landscape orientation', function () {
+                getOrientation.andReturn(p.helper.ORIENTATION_LANDSCAPE);
+                p.update_from_config(cfg);
+                expect(manifestJson.orientation).toEqual([ 'landscape' ]);
+            });
+            it('should handle custom orientation', function () {
+                getOrientation.andReturn('some-custom-orientation');
+                p.update_from_config(cfg);
+                expect(manifestJson.orientation).toEqual([ 'some-custom-orientation' ]);
+            });
+
         });
 
         describe('www_dir method', function() {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/spec-cordova/metadata/ios_parser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/metadata/ios_parser.spec.js b/cordova-lib/spec-cordova/metadata/ios_parser.spec.js
index c4dbe2c..884759a 100644
--- a/cordova-lib/spec-cordova/metadata/ios_parser.spec.js
+++ b/cordova-lib/spec-cordova/metadata/ios_parser.spec.js
@@ -69,12 +69,17 @@ describe('ios project parser', function () {
             }).not.toThrow();
         });
         it('should be an instance of Parser', function() {
-            expect(new platforms.ios.parser(proj) instanceof Parser).toBeTruthy();
+            expect(new platforms.ios.parser(proj) instanceof Parser).toBe(true);
+        });
+        it('should call super with the correct arguments', function() {
+            var call = spyOn(Parser, 'call');
+            var p = new platforms.ios.parser(proj);
+            expect(call).toHaveBeenCalledWith(p, 'ios', proj);
         });
     });
 
     describe('instance', function() {
-        var p, cp, rm, mkdir, is_cordova, write, read;
+        var p, cp, rm, mkdir, is_cordova, write, read, getOrientation;
         var ios_proj = path.join(proj, 'platforms', 'ios');
         beforeEach(function() {
             p = new platforms.ios.parser(ios_proj);
@@ -84,6 +89,7 @@ describe('ios project parser', function () {
             is_cordova = spyOn(util, 'isCordova').andReturn(proj);
             write = spyOn(fs, 'writeFileSync');
             read = spyOn(fs, 'readFileSync').andReturn('');
+            getOrientation = spyOn(p.helper, 'getOrientation');
         });
 
         describe('update_from_config method', function() {
@@ -106,7 +112,6 @@ describe('ios project parser', function () {
                 cfg.name = function() { return 'testname' };
                 cfg.packageName = function() { return 'testpkg' };
                 cfg.version = function() { return 'one point oh' };
-                p = new platforms.ios.parser(ios_proj);
             });
 
             it('should update the app name in pbxproj by calling xcode.updateProductName,
and move the ios native files to match the new name', function(done) {
@@ -137,6 +142,48 @@ describe('ios project parser', function () {
                     expect(plist_build.mostRecentCall.args[0].CFBundleShortVersionString).toEqual('one
point oh');
                 });
             });
+            it('should write out the orientation preference value', function(done) {
+                getOrientation.andCallThrough();
+                wrapper(p.update_from_config(cfg), done, function() {
+                    expect(plist_build.mostRecentCall.args[0].UISupportedInterfaceOrientations).toEqual([
'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown' ]);
+                    expect(plist_build.mostRecentCall.args[0].UIInterfaceOrientation).toEqual([
'UIInterfaceOrientationPortrait' ]);
+                });
+            });
+            it('should handle no orientation', function(done) {
+                getOrientation.andReturn('');
+                wrapper(p.update_from_config(cfg), done, function() {
+                    expect(plist_build.mostRecentCall.args[0].UISupportedInterfaceOrientations).toBeUndefined();
+                    expect(plist_build.mostRecentCall.args[0].UIInterfaceOrientation).toBeUndefined();
+                });
+            });
+            it('should handle default orientation', function(done) {
+                getOrientation.andReturn(p.helper.ORIENTATION_DEFAULT);
+                wrapper(p.update_from_config(cfg), done, function() {
+                    expect(plist_build.mostRecentCall.args[0].UISupportedInterfaceOrientations).toBeUndefined();
+                    expect(plist_build.mostRecentCall.args[0].UIInterfaceOrientation).toBeUndefined();
+                });
+            });
+            it('should handle portrait orientation', function(done) {
+                getOrientation.andReturn(p.helper.ORIENTATION_PORTRAIT);
+                wrapper(p.update_from_config(cfg), done, function() {
+                    expect(plist_build.mostRecentCall.args[0].UISupportedInterfaceOrientations).toEqual([
'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown' ]);
+                    expect(plist_build.mostRecentCall.args[0].UIInterfaceOrientation).toEqual([
'UIInterfaceOrientationPortrait' ]);
+                });
+            });
+            it('should handle landscape orientation', function(done) {
+                getOrientation.andReturn(p.helper.ORIENTATION_LANDSCAPE);
+                wrapper(p.update_from_config(cfg), done, function() {
+                    expect(plist_build.mostRecentCall.args[0].UISupportedInterfaceOrientations).toEqual([
'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]);
+                    expect(plist_build.mostRecentCall.args[0].UIInterfaceOrientation).toEqual([
'UIInterfaceOrientationLandscapeLeft' ]);
+                });
+            });
+            it('should handle custom orientation', function(done) {
+                getOrientation.andReturn('some-custom-orientation');
+                wrapper(p.update_from_config(cfg), done, function() {
+                    expect(plist_build.mostRecentCall.args[0].UISupportedInterfaceOrientations).toBeUndefined();
+                    expect(plist_build.mostRecentCall.args[0].UIInterfaceOrientation).toEqual([
'some-custom-orientation' ]);
+                });
+            });
         });
         describe('www_dir method', function() {
             it('should return /www', function() {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/spec-cordova/metadata/windows8_parser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/metadata/windows8_parser.spec.js b/cordova-lib/spec-cordova/metadata/windows8_parser.spec.js
index d733d26..ad279da 100644
--- a/cordova-lib/spec-cordova/metadata/windows8_parser.spec.js
+++ b/cordova-lib/spec-cordova/metadata/windows8_parser.spec.js
@@ -91,7 +91,12 @@ describe('windows8 project parser', function() {
             }).not.toThrow();
         });
         it('should be an instance of Parser', function() {
-            expect(new platforms.windows8.parser(proj) instanceof Parser).toBeTruthy();
+            expect(new platforms.windows8.parser(proj) instanceof Parser).toBe(true);
+        });
+        it('should call super with the correct arguments', function() {
+            var call = spyOn(Parser, 'call');
+            var p = new platforms.windows8.parser(proj);
+            expect(call).toHaveBeenCalledWith(p, 'windows8', proj);
         });
     });
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/spec-cordova/metadata/wp8_parser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/metadata/wp8_parser.spec.js b/cordova-lib/spec-cordova/metadata/wp8_parser.spec.js
index 72a0be6..25f16c1 100644
--- a/cordova-lib/spec-cordova/metadata/wp8_parser.spec.js
+++ b/cordova-lib/spec-cordova/metadata/wp8_parser.spec.js
@@ -36,10 +36,25 @@ var platforms = require('../../src/cordova/platforms'),
 // Create a real config object before mocking out everything.
 var cfg = new ConfigParser(path.join(__dirname, '..', 'test-config.xml'));
 
+var MANIFEST_XML, PROJ_XML, MAINPAGEXAML_XML, XAML_XML;
+MANIFEST_XML = PROJ_XML = XAML_XML = '<foo><App Title="s"><PrimaryToken /><RootNamespace/><SilverlightAppEntry/><XapFilename/><AssemblyName/></App></foo>';
+MAINPAGEXAML_XML = '<phone:PhoneApplicationPage x:Class="io.cordova.hellocordova.MainPage"'
+
+    'FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}"'
+
+    'Foreground="{StaticResource PhoneForegroundBrush}" Background="Black"' +
+    'SupportedOrientations="PortraitOrLandscape" Orientation="VAL"' +
+    'shell:SystemTray.IsVisible="True" d:DesignHeight="768" d:DesignWidth="480" xmlns:my="clr-namespace:WPCordovaClassLib">'
+
+    '<Grid x:Name="LayoutRoot" Background="Transparent" HorizontalAlignment="Stretch">'
+
+        '<Grid.RowDefinitions>' +
+            '<RowDefinition Height="*"/>' +
+        '</Grid.RowDefinitions>' +
+        '<my:CordovaView HorizontalAlignment="Stretch" Margin="0,0,0,0"  x:Name="CordovaView"
VerticalAlignment="Stretch" />' +
+    '</Grid>' +
+    '</phone:PhoneApplicationPage>';
+
 describe('wp8 project parser', function() {
     var proj = '/some/path';
     var exists, exec, custom, readdir, cfg_parser, config_read;
-    var manifestXml, projXml;
+    var manifestXml, projXml, mainPageXamlXml;
     beforeEach(function() {
         exists = spyOn(fs, 'existsSync').andReturn(true);
         exec = spyOn(child_process, 'exec').andCallFake(function(cmd, opts, cb) {
@@ -57,14 +72,16 @@ describe('wp8 project parser', function() {
             : ({})
         });
         readdir = spyOn(fs, 'readdirSync').andReturn(['test.csproj']);
-        projXml = manifestXml = null;
+        projXml = manifestXml = mainPageXamlXml = null;
         spyOn(xmlHelpers, 'parseElementtreeSync').andCallFake(function(path) {
             if (/WMAppManifest.xml$/.exec(path)) {
-                return manifestXml = new et.ElementTree(et.XML('<foo><App Title="s"><PrimaryToken
/><RootNamespace/><SilverlightAppEntry/><XapFilename/><AssemblyName/></App></foo>'));
+                return manifestXml = new et.ElementTree(et.XML(MANIFEST_XML));
             } else if (/csproj$/.exec(path)) {
-                return projXml = new et.ElementTree(et.XML('<foo><App Title="s"><PrimaryToken
/><RootNamespace/><SilverlightAppEntry/><XapFilename/><AssemblyName/></App></foo>'));
+                return projXml = new et.ElementTree(et.XML(PROJ_XML));
+            } else if (/MainPage.xaml$/.exec(path)) {
+                return mainPageXamlXml = new et.ElementTree(et.XML(MAINPAGEXAML_XML));
             } else if (/xaml$/.exec(path)) {
-                return new et.ElementTree(et.XML('<foo><App Title="s"><PrimaryToken
/><RootNamespace/><SilverlightAppEntry/><XapFilename/><AssemblyName/></App></foo>'));
+                return new et.ElementTree(et.XML(XAML_XML));
             } else {
                 throw new CordovaError('Unexpected parseElementtreeSync: ' + path);
             }
@@ -98,12 +115,17 @@ describe('wp8 project parser', function() {
             }).not.toThrow();
         });
         it('should be an instance of Parser', function() {
-            expect(new platforms.wp8.parser(proj) instanceof Parser).toBeTruthy();
+            expect(new platforms.wp8.parser(proj) instanceof Parser).toBe(true);
+        });
+        it('should call super with the correct arguments', function() {
+            var call = spyOn(Parser, 'call');
+            var p = new platforms.wp8.parser(proj);
+            expect(call).toHaveBeenCalledWith(p, 'wp8', proj);
         });
     });
 
     describe('instance', function() {
-        var p, cp, rm, is_cordova, write, read, mv, mkdir;
+        var p, cp, rm, is_cordova, write, read, mv, mkdir, getOrientation;
         var wp8_proj = path.join(proj, 'platforms', 'wp8');
         beforeEach(function() {
             p = new platforms.wp8.parser(wp8_proj);
@@ -114,6 +136,7 @@ describe('wp8 project parser', function() {
             is_cordova = spyOn(util, 'isCordova').andReturn(proj);
             write = spyOn(fs, 'writeFileSync');
             read = spyOn(fs, 'readFileSync').andReturn('');
+            getOrientation = spyOn(p.helper, 'getOrientation');
         });
 
         describe('update_from_config method', function() {
@@ -140,6 +163,42 @@ describe('wp8 project parser', function() {
                 var appEl = manifestXml.getroot().find('.//App');
                 expect(appEl.attrib.Version).toEqual('one point oh');
             });
+            it('should write out the orientation preference value', function() {
+                getOrientation.andCallThrough();
+                p.update_from_config(cfg);
+                expect(mainPageXamlXml.getroot().attrib['SupportedOrientations']).toEqual('portrait')
+                expect(mainPageXamlXml.getroot().attrib['Orientation']).toEqual('portrait');
+            });
+            it('should handle no orientation', function() {
+                getOrientation.andReturn('');
+                p.update_from_config(cfg);
+                expect(mainPageXamlXml.getroot().attrib['SupportedOrientations']).toBeUndefined();
+                expect(mainPageXamlXml.getroot().attrib['Orientation']).toBeUndefined();
+            });
+            it('should handle default orientation', function() {
+                getOrientation.andReturn(p.helper.ORIENTATION_DEFAULT);
+                p.update_from_config(cfg);
+                expect(mainPageXamlXml.getroot().attrib['SupportedOrientations']).toBeUndefined();
+                expect(mainPageXamlXml.getroot().attrib['Orientation']).toBeUndefined();
+            });
+            it('should handle portrait orientation', function() {
+                getOrientation.andReturn(p.helper.ORIENTATION_PORTRAIT);
+                p.update_from_config(cfg);
+                expect(mainPageXamlXml.getroot().attrib['SupportedOrientations']).toEqual('portrait')
+                expect(mainPageXamlXml.getroot().attrib['Orientation']).toEqual('portrait');
+            });
+            it('should handle landscape orientation', function() {
+                getOrientation.andReturn(p.helper.ORIENTATION_LANDSCAPE);
+                p.update_from_config(cfg);
+                expect(mainPageXamlXml.getroot().attrib['SupportedOrientations']).toEqual('landscape')
+                expect(mainPageXamlXml.getroot().attrib['Orientation']).toEqual('landscape');
+            });
+            it('should handle custom orientation', function() {
+                getOrientation.andReturn('some-custom-orientation');
+                p.update_from_config(cfg);
+                expect(mainPageXamlXml.getroot().attrib['SupportedOrientations']).toBeUndefined();
+                expect(mainPageXamlXml.getroot().attrib['Orientation']).toEqual('some-custom-orientation');
+            });
         });
         describe('www_dir method', function() {
             it('should return www', function() {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js b/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
index 933ecdf..a33a217 100644
--- a/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
+++ b/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
@@ -40,7 +40,7 @@ function amazon_fireos_parser(project) {
     }
 
     // Call the base class constructor
-    Parser.apply(this, arguments);
+    Parser.call(this, 'amazon_fireos', project);
 
     this.path = project;
     this.strings = path.join(this.path, 'res', 'values', 'strings.xml');
@@ -52,16 +52,6 @@ require('util').inherits(amazon_fireos_parser, Parser);
 
 module.exports = amazon_fireos_parser;
 
-amazon_fireos_parser.prototype.findOrientationPreference = function(config) {
-    var ret = config.getPreference('orientation');
-    if (ret && ret != 'default' && ret != 'portrait' && ret != 'landscape')
{
-        events.emit('warn', 'Unknown value for orientation preference: ' + ret);
-        ret = null;
-    }
-
-    return ret;
-};
-
 amazon_fireos_parser.prototype.findAndroidLaunchModePreference = function(config) {
     var launchMode = config.getPreference('AndroidLaunchMode');
     if (!launchMode) {
@@ -241,19 +231,13 @@ amazon_fireos_parser.prototype.update_from_config = function(config)
{
 
     var act = manifest.getroot().find('./application/activity');
 
-     // Set the orientation in the AndroidManifest
-    var orientationPref = this.findOrientationPreference(config);
-    if (orientationPref) {
-        switch (orientationPref) {
-            case 'default':
-                delete act.attrib['android:screenOrientation'];
-                break;
-            case 'portrait':
-                act.attrib['android:screenOrientation'] = 'portrait';
-                break;
-            case 'landscape':
-                act.attrib['android:screenOrientation'] = 'landscape';
-        }
+    // Set the android:screenOrientation in the AndroidManifest
+    var orientation = this.helper.getOrientation(config);
+
+    if (orientation && !this.helper.isDefaultOrientation(orientation)) {
+        act.attrib['android:screenOrientation'] = orientation;
+    } else {
+        delete act.attrib['android:screenOrientation'];
     }
 
     // Set android:launchMode in AndroidManifest

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/src/cordova/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/android_parser.js b/cordova-lib/src/cordova/metadata/android_parser.js
index c37b271..cb88fd4 100644
--- a/cordova-lib/src/cordova/metadata/android_parser.js
+++ b/cordova-lib/src/cordova/metadata/android_parser.js
@@ -40,7 +40,7 @@ function android_parser(project) {
     }
 
     // Call the base class constructor
-    Parser.apply(this, arguments);
+    Parser.call(this, 'android', project);
 
     this.path = project;
     this.strings = path.join(this.path, 'res', 'values', 'strings.xml');
@@ -52,16 +52,6 @@ require('util').inherits(android_parser, Parser);
 
 module.exports = android_parser;
 
-android_parser.prototype.findOrientationPreference = function(config) {
-    var ret = config.getPreference('orientation');
-    if (ret && ret != 'default' && ret != 'portrait' && ret != 'landscape')
{
-        events.emit('warn', 'Unknown value for orientation preference: ' + ret);
-        ret = null;
-    }
-
-    return ret;
-};
-
 android_parser.prototype.findAndroidLaunchModePreference = function(config) {
     var launchMode = config.getPreference('AndroidLaunchMode');
     if (!launchMode) {
@@ -241,19 +231,13 @@ android_parser.prototype.update_from_config = function(config) {
 
     var act = manifest.getroot().find('./application/activity');
 
-    // Set the orientation in the AndroidManifest
-    var orientationPref = this.findOrientationPreference(config);
-    if (orientationPref) {
-        switch (orientationPref) {
-            case 'default':
-                delete act.attrib["android:screenOrientation"];
-                break;
-            case 'portrait':
-                act.attrib["android:screenOrientation"] = 'portrait';
-                break;
-            case 'landscape':
-                act.attrib["android:screenOrientation"] = 'landscape';
-        }
+    // Set the android:screenOrientation in the AndroidManifest
+    var orientation = this.helper.getOrientation(config);
+
+    if (orientation && !this.helper.isDefaultOrientation(orientation)) {
+        act.attrib['android:screenOrientation'] = orientation;
+    } else {
+        delete act.attrib['android:screenOrientation'];
     }
 
     // Set android:launchMode in AndroidManifest

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/src/cordova/metadata/blackberry10_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/blackberry10_parser.js b/cordova-lib/src/cordova/metadata/blackberry10_parser.js
index ee2df6e..3deb54f 100644
--- a/cordova-lib/src/cordova/metadata/blackberry10_parser.js
+++ b/cordova-lib/src/cordova/metadata/blackberry10_parser.js
@@ -37,7 +37,7 @@ function blackberry_parser(project) {
     }
 
     // Call the base class constructor
-    Parser.apply(this, arguments);
+    Parser.call(this, 'blackberry10', project);
 
     this.path = project;
     this.config_path = path.join(this.path, 'www', 'config.xml');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/src/cordova/metadata/browser_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/browser_parser.js b/cordova-lib/src/cordova/metadata/browser_parser.js
index 394fe8a..91d8b38 100644
--- a/cordova-lib/src/cordova/metadata/browser_parser.js
+++ b/cordova-lib/src/cordova/metadata/browser_parser.js
@@ -32,7 +32,7 @@ var fs = require('fs'),
 function browser_parser(project) {
 
     // Call the base class constructor
-    Parser.apply(this, arguments);
+    Parser.call(this, 'browser', project);
 
     this.path = project;
 }

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/src/cordova/metadata/firefoxos_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/firefoxos_parser.js b/cordova-lib/src/cordova/metadata/firefoxos_parser.js
index c63a317..3423ba9 100644
--- a/cordova-lib/src/cordova/metadata/firefoxos_parser.js
+++ b/cordova-lib/src/cordova/metadata/firefoxos_parser.js
@@ -34,7 +34,7 @@ var fs = require('fs'),
 function firefoxos_parser(project) {
 
     // Call the base class constructor
-    Parser.apply(this, arguments);
+    Parser.call(this, 'firefoxos', project);
 
     this.path = project;
     this.config_path = path.join(project, 'config.xml');
@@ -85,16 +85,13 @@ firefoxos_parser.prototype.update_from_config = function(config) {
         manifest.fullscreen = fullScreen;
     }
 
-    var orientations = [];
-    var preferenceNodes = config.doc.findall('preference');
-    preferenceNodes.forEach(function (preference) {
-        if (preference.attrib.name.toLowerCase() === 'orientation') {
-            orientations.push(preference.attrib.value);
-        }
-    });
+    // Set orientation preference
+    var orientation = this.helper.getOrientation(config);
 
-    if (orientations && orientations.length) {
-        manifest.orientation = orientations;
+    if (orientation && !this.helper.isDefaultOrientation(orientation)) {
+        manifest.orientation = [ orientation ];
+    } else {
+        delete manifest.orientation;
     }
 
     var permissionNodes = config.doc.findall('permission');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/src/cordova/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/ios_parser.js b/cordova-lib/src/cordova/metadata/ios_parser.js
index 05e65ed..97daab7 100644
--- a/cordova-lib/src/cordova/metadata/ios_parser.js
+++ b/cordova-lib/src/cordova/metadata/ios_parser.js
@@ -37,12 +37,13 @@ var fs            = require('fs'),
 
 function ios_parser(project) {
 
-    // Call the base class constructor
-    Parser.apply(this, arguments);
-
     try {
         var xcodeproj_dir = fs.readdirSync(project).filter(function(e) { return e.match(/\.xcodeproj$/i);
})[0];
         if (!xcodeproj_dir) throw new CordovaError('The provided path "' + project + '" is
not a Cordova iOS project.');
+
+        // Call the base class constructor
+        Parser.call(this, 'ios', project);
+
         this.xcodeproj = path.join(project, xcodeproj_dir);
         this.originalName = this.xcodeproj.substring(this.xcodeproj.lastIndexOf(path.sep)+1,
this.xcodeproj.indexOf('.xcodeproj'));
         this.cordovaproj = path.join(project, this.originalName);
@@ -81,6 +82,27 @@ ios_parser.prototype.update_from_config = function(config) {
     var CFBundleVersion = config.ios_CFBundleVersion() || default_CFBundleVersion(version);
     infoPlist['CFBundleVersion'] = CFBundleVersion;
 
+    var orientation = this.helper.getOrientation(config);
+
+    if (orientation && !this.helper.isDefaultOrientation(orientation)) {
+        switch (orientation.toLowerCase()) {
+            case 'portrait':
+                infoPlist['UIInterfaceOrientation'] = [ 'UIInterfaceOrientationPortrait'
];
+                infoPlist['UISupportedInterfaceOrientations'] = [ 'UIInterfaceOrientationPortrait',
'UIInterfaceOrientationPortraitUpsideDown' ];
+                break;
+            case 'landscape':
+                infoPlist['UIInterfaceOrientation'] = [ 'UIInterfaceOrientationLandscapeLeft'
];
+                infoPlist['UISupportedInterfaceOrientations'] = [ 'UIInterfaceOrientationLandscapeLeft',
'UIInterfaceOrientationLandscapeRight' ];
+                break;
+            default:
+                infoPlist['UIInterfaceOrientation'] = [ orientation ];
+                delete infoPlist['UISupportedInterfaceOrientations'];
+        }
+    } else {
+        delete infoPlist['UISupportedInterfaceOrientations'];
+        delete infoPlist['UIInterfaceOrientation'];
+    }
+
     var info_contents = plist.build(infoPlist);
     info_contents = info_contents.replace(/<string>[\s\r\n]*<\/string>/g,'<string></string>');
     fs.writeFileSync(plistFile, info_contents, 'utf-8');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/src/cordova/metadata/ubuntu_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/ubuntu_parser.js b/cordova-lib/src/cordova/metadata/ubuntu_parser.js
index 29c4dd5..12383dd 100644
--- a/cordova-lib/src/cordova/metadata/ubuntu_parser.js
+++ b/cordova-lib/src/cordova/metadata/ubuntu_parser.js
@@ -34,7 +34,7 @@ var fs            = require('fs'),
 function ubuntu_parser(project) {
 
     // Call the base class constructor
-    Parser.apply(this, arguments);
+    Parser.call(this, 'ubuntu', project);
 
     this.path = project;
     this.config = new ConfigParser(this.config_xml());

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/src/cordova/metadata/windows_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/windows_parser.js b/cordova-lib/src/cordova/metadata/windows_parser.js
index e385bc1..4b56710 100644
--- a/cordova-lib/src/cordova/metadata/windows_parser.js
+++ b/cordova-lib/src/cordova/metadata/windows_parser.js
@@ -35,9 +35,6 @@ var fs            = require('fs'),
 
 function windows_parser(project) {
 
-    // Call the base class constructor
-    Parser.apply(this, arguments);
-
     try {
         this.isOldProjectTemplate = false;
         // Check that it's a universal windows store project
@@ -49,6 +46,10 @@ function windows_parser(project) {
         if (!projFile) {
             throw new CordovaError('No project file in "'+project+'"');
         }
+
+        // Call the base class constructor
+        Parser.call(this, 'windows8', project);
+
         this.projDir = project;
         this.projFilePath = path.join(this.projDir, projFile);
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/a6112c66/cordova-lib/src/cordova/metadata/wp8_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/wp8_parser.js b/cordova-lib/src/cordova/metadata/wp8_parser.js
index 1d60f4d..bfe24e4 100644
--- a/cordova-lib/src/cordova/metadata/wp8_parser.js
+++ b/cordova-lib/src/cordova/metadata/wp8_parser.js
@@ -35,13 +35,14 @@ var fs            = require('fs'),
 
 function wp8_parser(project) {
 
-    // Call the base class constructor
-    Parser.apply(this, arguments);
-
     try {
         // TODO : Check that it's not a wp8 project?
         var csproj_file   = fs.readdirSync(project).filter(function(e) { return e.match(/\.csproj$/i);
})[0];
         if (!csproj_file) throw new CordovaError('No .csproj file in "'+project+'"');
+
+        // Call the base class constructor
+        Parser.call(this, 'wp8', project);
+
         this.wp8_proj_dir = project;
         this.csproj_path  = path.join(this.wp8_proj_dir, csproj_file);
         this.sln_path     = path.join(this.wp8_proj_dir, csproj_file.replace(/\.csproj/,
'.sln'));
@@ -63,6 +64,23 @@ wp8_parser.prototype.update_from_config = function(config) {
     //Get manifest file
     var manifest = xml.parseElementtreeSync(this.manifest_path);
 
+    var mainPageXAML = xml.parseElementtreeSync(path.join(this.wp8_proj_dir, 'MainPage.xaml'));
+
+    var orientation = this.helper.getOrientation(config);
+    if (orientation && !this.helper.isDefaultOrientation(orientation)) {
+
+        mainPageXAML.getroot().attrib['Orientation'] = orientation;
+        mainPageXAML.getroot().attrib['SupportedOrientations'] = orientation;
+
+        if (!this.helper.isGlobalOrientation(orientation)) {
+            delete mainPageXAML.getroot().attrib['SupportedOrientations'];
+        }
+
+    } else {
+        delete mainPageXAML.getroot().attrib['SupportedOrientations'];
+        delete mainPageXAML.getroot().attrib['Orientation'];
+    }
+
     //Update app version
     var version = config.version();
     manifest.find('.//App').attrib.Version = version;
@@ -110,9 +128,7 @@ wp8_parser.prototype.update_from_config = function(config) {
         csproj.find('.//SilverlightAppEntry').text = pkg + '.App';
         fs.writeFileSync(this.csproj_path, csproj.write({indent: 4}), 'utf-8');
         //MainPage.xaml
-        var mainPageXAML = xml.parseElementtreeSync(path.join(this.wp8_proj_dir, 'MainPage.xaml'));
         mainPageXAML.getroot().attrib['x:Class'] = pkg + '.MainPage';
-        fs.writeFileSync(path.join(this.wp8_proj_dir, 'MainPage.xaml'), mainPageXAML.write({indent:
4}), 'utf-8');
         //MainPage.xaml.cs
         var mainPageCS = fs.readFileSync(path.join(this.wp8_proj_dir, 'MainPage.xaml.cs'),
'utf-8');
         var namespaceRegEx = new RegExp('namespace ' + prev_name);
@@ -126,6 +142,9 @@ wp8_parser.prototype.update_from_config = function(config) {
         fs.writeFileSync(path.join(this.wp8_proj_dir, 'App.xaml.cs'), appCS.replace(namespaceRegEx,
'namespace ' + pkg), 'utf-8');
     }
 
+    // Write out MainPage.xaml
+    fs.writeFileSync(path.join(this.wp8_proj_dir, 'MainPage.xaml'), mainPageXAML.write({indent:
4}), 'utf-8');
+
     //Write out manifest
     fs.writeFileSync(this.manifest_path, manifest.write({indent: 4}), 'utf-8');
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message