2016-02-29 23:49:17 +08:00
/ * *
Licensed to the Apache Software Foundation ( ASF ) under one
or more contributor license agreements . See the NOTICE file
distributed with this work for additional information
regarding copyright ownership . The ASF licenses this file
to you under the Apache License , Version 2.0 ( the
"License" ) ; you may not use this file except in compliance
with the License . You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing ,
software distributed under the License is distributed on an
"AS IS" BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND , either express or implied . See the License for the
specific language governing permissions and limitations
under the License .
* /
var rewire = require ( 'rewire' ) ;
2017-06-14 02:42:20 +08:00
var common = rewire ( '../../../bin/templates/cordova/lib/pluginHandlers' ) ;
2016-02-29 23:49:17 +08:00
var android = common . _ _get _ _ ( 'handlers' ) ;
2017-06-14 02:42:20 +08:00
var path = require ( 'path' ) ;
var fs = require ( 'fs' ) ;
var shell = require ( 'shelljs' ) ;
var os = require ( 'os' ) ;
var temp = path . join ( os . tmpdir ( ) , 'plugman' ) ;
2016-02-29 23:49:17 +08:00
var plugins _dir = path . join ( temp , 'cordova/plugins' ) ;
var dummyplugin = path . join ( _ _dirname , '../../fixtures/org.test.plugins.dummyplugin' ) ;
var faultyplugin = path . join ( _ _dirname , '../../fixtures/org.test.plugins.faultyplugin' ) ;
2018-04-18 19:16:54 +08:00
var android _studio _project = path . join ( _ _dirname , '../../fixtures/android_studio_project/*' ) ;
2016-02-29 23:49:17 +08:00
var PluginInfo = require ( 'cordova-common' ) . PluginInfo ;
var AndroidProject = require ( '../../../bin/templates/cordova/lib/AndroidProject' ) ;
var dummyPluginInfo = new PluginInfo ( dummyplugin ) ;
2017-06-14 02:42:20 +08:00
var valid _source = dummyPluginInfo . getSourceFiles ( 'android' ) ;
var valid _resources = dummyPluginInfo . getResourceFiles ( 'android' ) ;
var valid _libs = dummyPluginInfo . getLibFiles ( 'android' ) ;
2016-02-29 23:49:17 +08:00
var faultyPluginInfo = new PluginInfo ( faultyplugin ) ;
var invalid _source = faultyPluginInfo . getSourceFiles ( 'android' ) ;
2017-06-14 02:42:20 +08:00
describe ( 'android project handler' , function ( ) {
describe ( 'installation' , function ( ) {
2016-02-29 23:49:17 +08:00
var copyFileOrig = common . _ _get _ _ ( 'copyFile' ) ;
var copyFileSpy = jasmine . createSpy ( 'copyFile' ) ;
var dummyProject ;
2017-06-14 02:42:20 +08:00
beforeEach ( function ( ) {
2016-02-29 23:49:17 +08:00
shell . mkdir ( '-p' , temp ) ;
dummyProject = AndroidProject . getProjectFile ( temp ) ;
2017-01-04 03:02:48 +08:00
copyFileSpy . calls . reset ( ) ;
2016-02-29 23:49:17 +08:00
common . _ _set _ _ ( 'copyFile' , copyFileSpy ) ;
} ) ;
2017-06-14 02:42:20 +08:00
afterEach ( function ( ) {
2016-02-29 23:49:17 +08:00
shell . rm ( '-rf' , temp ) ;
common . _ _set _ _ ( 'copyFile' , copyFileOrig ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <lib-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#001 : should copy files for Android Studio projects' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'lib-file' ] . install ( valid _libs [ 0 ] , dummyPluginInfo , dummyProject ) ;
2016-09-17 06:41:20 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin , 'src/android/TestLib.jar' , temp , path . join ( 'app' , 'libs' , 'TestLib.jar' ) , false ) ;
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <resource-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#002 : should copy files to the correct location on an Android Studio project' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'resource-file' ] . install ( valid _resources [ 0 ] , dummyPluginInfo , dummyProject ) ;
2018-04-18 19:16:54 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin , 'android-resource.xml' , temp , path . join ( 'app' , 'src' , 'main' , 'res' , 'xml' , 'dummy.xml' ) , false ) ;
2016-02-29 23:49:17 +08:00
} ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <source-file> elements' , function ( ) {
beforeEach ( function ( ) {
2018-04-18 19:16:54 +08:00
shell . cp ( '-rf' , android _studio _project , temp ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#003 : should copy stuff from one location to another by calling common.copyFile' , function ( ) {
2016-02-29 23:49:17 +08:00
android [ 'source-file' ] . install ( valid _source [ 0 ] , dummyPluginInfo , dummyProject ) ;
expect ( copyFileSpy )
2018-09-06 10:06:18 +08:00
. toHaveBeenCalledWith ( dummyplugin , 'src/android/DummyPlugin.java' , temp , path . join ( 'app' , 'src' , 'main' , 'java' , 'com' , 'phonegap' , 'plugins' , 'dummyplugin' , 'DummyPlugin.java' ) , false ) ;
2016-09-17 06:41:20 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#005 : should throw if source file cannot be found' , function ( ) {
2016-02-29 23:49:17 +08:00
common . _ _set _ _ ( 'copyFile' , copyFileOrig ) ;
2017-06-14 02:42:20 +08:00
expect ( function ( ) {
2016-02-29 23:49:17 +08:00
android [ 'source-file' ] . install ( invalid _source [ 0 ] , faultyPluginInfo , dummyProject ) ;
2017-01-04 03:02:48 +08:00
} ) . toThrow ( new Error ( '"' + path . resolve ( faultyplugin , 'src/android/NotHere.java' ) + '" not found!' ) ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#006 : should throw if target file already exists' , function ( ) {
2016-02-29 23:49:17 +08:00
// write out a file
2018-09-06 10:06:18 +08:00
let target = path . resolve ( temp , 'app' , 'src' , 'main' , 'java' , 'com' , 'phonegap' , 'plugins' , 'dummyplugin' ) ;
2016-02-29 23:49:17 +08:00
shell . mkdir ( '-p' , target ) ;
target = path . join ( target , 'DummyPlugin.java' ) ;
fs . writeFileSync ( target , 'some bs' , 'utf-8' ) ;
2017-06-14 02:42:20 +08:00
expect ( function ( ) {
2016-02-29 23:49:17 +08:00
android [ 'source-file' ] . install ( valid _source [ 0 ] , dummyPluginInfo , dummyProject ) ;
2017-06-14 02:42:20 +08:00
} ) . toThrow ( new Error ( '"' + target + '" already exists!' ) ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-11-09 02:23:29 +08:00
2018-11-13 10:42:31 +08:00
// TODO: renumber these tests and other tests below
it ( 'Test#00a6 : should allow installing sources with new app target-dir scheme' , function ( ) {
2018-11-09 02:23:29 +08:00
android [ 'source-file' ] . install ( valid _source [ 1 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( copyFileSpy )
. toHaveBeenCalledWith ( dummyplugin , 'src/android/DummyPlugin2.java' , temp , path . join ( 'app/src/main/src/com/phonegap/plugins/dummyplugin/DummyPlugin2.java' ) , false ) ;
} ) ;
2018-11-10 03:43:47 +08:00
2018-11-13 10:42:31 +08:00
it ( 'Test#006b : should allow installing jar lib file from sources with new app target-dir scheme' , function ( ) {
2018-11-10 03:43:47 +08:00
android [ 'source-file' ] . install ( valid _source [ 2 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( copyFileSpy )
. toHaveBeenCalledWith ( dummyplugin , 'src/android/TestLib.jar' , temp , path . join ( 'app/libs/TestLib.jar' ) , false ) ;
} ) ;
2018-11-13 10:42:31 +08:00
it ( 'Test#006c : should allow installing aar lib file from sources with new app target-dir scheme' , function ( ) {
2018-11-10 03:43:47 +08:00
android [ 'source-file' ] . install ( valid _source [ 3 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( copyFileSpy )
. toHaveBeenCalledWith ( dummyplugin , 'src/android/TestAar.aar' , temp , path . join ( 'app/libs/TestAar.aar' ) , false ) ;
} ) ;
2018-11-13 10:50:20 +08:00
it ( 'Test#006d : should allow installing xml file from sources with old target-dir scheme' , function ( ) {
android [ 'source-file' ] . install ( valid _source [ 4 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/mysettings.xml' , temp ,
path . join ( 'app/src/main/res/xml/mysettings.xml' ) , false ) ;
} ) ;
2018-11-13 11:01:13 +08:00
it ( 'Test#006e : should allow installing file with other extension from sources with old target-dir scheme' , function ( ) {
android [ 'source-file' ] . install ( valid _source [ 5 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/other.extension' , temp ,
path . join ( 'app/src/main/res/values/other.extension' ) , false ) ;
} ) ;
2018-11-14 02:06:48 +08:00
2018-11-15 02:19:58 +08:00
it ( 'Test#006f : should allow installing aidl file from sources with old target-dir scheme (GH-547)' , function ( ) {
2018-11-14 02:06:48 +08:00
android [ 'source-file' ] . install ( valid _source [ 6 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/myapi.aidl' , temp ,
2018-11-15 02:19:58 +08:00
path . join ( 'app/src/main/aidl/com/mytest/myapi.aidl' ) , false ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#006g : should allow installing aar lib file from sources with old target-dir scheme (GH-547)' , function ( ) {
2018-11-14 02:06:48 +08:00
android [ 'source-file' ] . install ( valid _source [ 7 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/testaar2.aar' , temp ,
2018-11-15 02:19:58 +08:00
path . join ( 'app/libs/testaar2.aar' ) , false ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#006h : should allow installing jar lib file from sources with old target-dir scheme (GH-547)' , function ( ) {
2018-11-14 02:06:48 +08:00
android [ 'source-file' ] . install ( valid _source [ 8 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/testjar2.jar' , temp ,
2018-11-15 02:19:58 +08:00
path . join ( 'app/libs/testjar2.jar' ) , false ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#006i : should allow installing .so lib file from sources with old target-dir scheme (GH-547)' , function ( ) {
2018-11-14 02:06:48 +08:00
android [ 'source-file' ] . install ( valid _source [ 9 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/jniLibs/x86/libnative.so' , temp ,
2018-11-15 02:19:58 +08:00
path . join ( 'app/src/main/jniLibs/x86/libnative.so' ) , false ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <framework> elements' , function ( ) {
2016-02-29 23:49:17 +08:00
var someString = jasmine . any ( String ) ;
var copyNewFileOrig = common . _ _get _ _ ( 'copyNewFile' ) ;
var copyNewFileSpy = jasmine . createSpy ( 'copyNewFile' ) ;
2017-06-14 02:42:20 +08:00
beforeEach ( function ( ) {
2018-04-18 19:16:54 +08:00
shell . cp ( '-rf' , android _studio _project , temp ) ;
2016-02-29 23:49:17 +08:00
spyOn ( dummyProject , 'addSystemLibrary' ) ;
spyOn ( dummyProject , 'addSubProject' ) ;
spyOn ( dummyProject , 'addGradleReference' ) ;
common . _ _set _ _ ( 'copyNewFile' , copyNewFileSpy ) ;
} ) ;
2017-06-14 02:42:20 +08:00
afterEach ( function ( ) {
2016-02-29 23:49:17 +08:00
common . _ _set _ _ ( 'copyNewFile' , copyNewFileOrig ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#007 : should throw if framework doesn\'t have "src" attribute' , function ( ) {
2017-06-14 02:42:20 +08:00
expect ( function ( ) { android . framework . install ( { } , dummyPluginInfo , dummyProject ) ; } ) . toThrow ( ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#008 : should install framework without "parent" attribute into project root' , function ( ) {
2016-02-29 23:49:17 +08:00
var framework = { src : 'plugin-lib' } ;
android . framework . install ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . addSystemLibrary ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#009 : should install framework with "parent" attribute into parent framework dir' , function ( ) {
2016-02-29 23:49:17 +08:00
var childFramework = { src : 'plugin-lib2' , parent : 'plugin-lib' } ;
android . framework . install ( childFramework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . addSystemLibrary ) . toHaveBeenCalledWith ( path . resolve ( dummyProject . projectDir , childFramework . parent ) , someString ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#010 : should not copy anything if "custom" attribute is not set' , function ( ) {
2016-02-29 23:49:17 +08:00
var framework = { src : 'plugin-lib' } ;
var cpSpy = spyOn ( shell , 'cp' ) ;
android . framework . install ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . addSystemLibrary ) . toHaveBeenCalledWith ( someString , framework . src ) ;
expect ( cpSpy ) . not . toHaveBeenCalled ( ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#011 : should copy framework sources if "custom" attribute is set' , function ( ) {
2016-02-29 23:49:17 +08:00
var framework = { src : 'plugin-lib' , custom : true } ;
android . framework . install ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . addSubProject ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
expect ( copyNewFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , framework . src , dummyProject . projectDir , someString , false ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#012 : should install gradleReference using project.addGradleReference' , function ( ) {
2016-02-29 23:49:17 +08:00
var framework = { src : 'plugin-lib' , custom : true , type : 'gradleReference' } ;
android . framework . install ( framework , dummyPluginInfo , dummyProject ) ;
expect ( copyNewFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , framework . src , dummyProject . projectDir , someString , false ) ;
expect ( dummyProject . addGradleReference ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
} ) ;
} ) ;
2016-04-07 18:24:41 +08:00
2017-06-14 02:42:20 +08:00
describe ( 'of <js-module> elements' , function ( ) {
2016-04-18 16:55:31 +08:00
var jsModule = { src : 'www/dummyplugin.js' } ;
2016-04-07 18:24:41 +08:00
var wwwDest , platformWwwDest ;
beforeEach ( function ( ) {
spyOn ( fs , 'writeFileSync' ) ;
wwwDest = path . resolve ( dummyProject . www , 'plugins' , dummyPluginInfo . id , jsModule . src ) ;
platformWwwDest = path . resolve ( dummyProject . platformWww , 'plugins' , dummyPluginInfo . id , jsModule . src ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#013 : should put module to both www and platform_www when options.usePlatformWww flag is specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android [ 'js-module' ] . install ( jsModule , dummyPluginInfo , dummyProject , { usePlatformWww : true } ) ;
expect ( fs . writeFileSync ) . toHaveBeenCalledWith ( wwwDest , jasmine . any ( String ) , 'utf-8' ) ;
expect ( fs . writeFileSync ) . toHaveBeenCalledWith ( platformWwwDest , jasmine . any ( String ) , 'utf-8' ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#014 : should put module to www only when options.usePlatformWww flag is not specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android [ 'js-module' ] . install ( jsModule , dummyPluginInfo , dummyProject ) ;
expect ( fs . writeFileSync ) . toHaveBeenCalledWith ( wwwDest , jasmine . any ( String ) , 'utf-8' ) ;
expect ( fs . writeFileSync ) . not . toHaveBeenCalledWith ( platformWwwDest , jasmine . any ( String ) , 'utf-8' ) ;
} ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <asset> elements' , function ( ) {
2016-04-07 18:24:41 +08:00
var asset = { src : 'www/dummyPlugin.js' , target : 'foo/dummy.js' } ;
2017-06-14 02:42:20 +08:00
var wwwDest ; /* eslint no-unused-vars: "off" */
var platformWwwDest ; /* eslint no-unused-vars: "off" */
2016-04-07 18:24:41 +08:00
beforeEach ( function ( ) {
wwwDest = path . resolve ( dummyProject . www , asset . target ) ;
platformWwwDest = path . resolve ( dummyProject . platformWww , asset . target ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#015 : should put asset to both www and platform_www when options.usePlatformWww flag is specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android . asset . install ( asset , dummyPluginInfo , dummyProject , { usePlatformWww : true } ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , asset . src , dummyProject . www , asset . target ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , asset . src , dummyProject . platformWww , asset . target ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#016 : should put asset to www only when options.usePlatformWww flag is not specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android . asset . install ( asset , dummyPluginInfo , dummyProject ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , asset . src , dummyProject . www , asset . target ) ;
expect ( copyFileSpy ) . not . toHaveBeenCalledWith ( dummyPluginInfo . dir , asset . src , dummyProject . platformWww , asset . target ) ;
} ) ;
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'uninstallation' , function ( ) {
2016-02-29 23:49:17 +08:00
var removeFileOrig = common . _ _get _ _ ( 'removeFile' ) ;
var deleteJavaOrig = common . _ _get _ _ ( 'deleteJava' ) ;
var removeFileSpy = jasmine . createSpy ( 'removeFile' ) ;
var deleteJavaSpy = jasmine . createSpy ( 'deleteJava' ) ;
var dummyProject ;
2017-06-14 02:42:20 +08:00
beforeEach ( function ( ) {
2016-02-29 23:49:17 +08:00
shell . mkdir ( '-p' , temp ) ;
shell . mkdir ( '-p' , plugins _dir ) ;
2018-04-18 19:16:54 +08:00
shell . cp ( '-rf' , android _studio _project , temp ) ;
2016-02-29 23:49:17 +08:00
AndroidProject . purgeCache ( ) ;
dummyProject = AndroidProject . getProjectFile ( temp ) ;
common . _ _set _ _ ( 'removeFile' , removeFileSpy ) ;
common . _ _set _ _ ( 'deleteJava' , deleteJavaSpy ) ;
} ) ;
2017-06-14 02:42:20 +08:00
afterEach ( function ( ) {
2016-02-29 23:49:17 +08:00
shell . rm ( '-rf' , temp ) ;
common . _ _set _ _ ( 'removeFile' , removeFileOrig ) ;
common . _ _set _ _ ( 'deleteJava' , deleteJavaOrig ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <lib-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#017 : should remove jar files for Android Studio projects' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'lib-file' ] . install ( valid _libs [ 0 ] , dummyPluginInfo , dummyProject ) ;
android [ 'lib-file' ] . uninstall ( valid _libs [ 0 ] , dummyPluginInfo , dummyProject ) ;
2016-09-17 06:41:20 +08:00
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/libs/TestLib.jar' ) ) ;
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <resource-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#018 : should remove files for Android Studio projects' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'resource-file' ] . install ( valid _resources [ 0 ] , dummyPluginInfo , dummyProject ) ;
android [ 'resource-file' ] . uninstall ( valid _resources [ 0 ] , dummyPluginInfo , dummyProject ) ;
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app' , 'src' , 'main' , 'res' , 'xml' , 'dummy.xml' ) ) ;
2017-10-04 05:16:27 +08:00
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <source-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#019 : should remove stuff by calling common.deleteJava for Android Studio projects' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'source-file' ] . install ( valid _source [ 0 ] , dummyPluginInfo , dummyProject ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 0 ] , dummyPluginInfo , dummyProject ) ;
2016-09-17 06:41:20 +08:00
expect ( deleteJavaSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/src/main/java/com/phonegap/plugins/dummyplugin/DummyPlugin.java' ) ) ;
} ) ;
2016-02-29 23:49:17 +08:00
2018-11-12 02:36:31 +08:00
it ( 'Test#019a : should remove stuff by calling common.deleteJava for Android Studio projects, with specific app target-dir' , function ( ) {
android [ 'source-file' ] . install ( valid _source [ 1 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 1 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( deleteJavaSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/src/main/src/com/phonegap/plugins/dummyplugin/DummyPlugin2.java' ) ) ;
} ) ;
2018-11-13 10:42:31 +08:00
it ( 'Test#019b : should remove stuff by calling common.removeFile for Android Studio projects, of jar with new app target-dir scheme' , function ( ) {
2018-11-12 02:36:31 +08:00
android [ 'source-file' ] . install ( valid _source [ 2 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 2 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/libs/TestLib.jar' ) ) ;
} ) ;
2018-11-13 10:42:31 +08:00
it ( 'Test#019c : should remove stuff by calling common.removeFile for Android Studio projects, of aar with new app target-dir scheme' , function ( ) {
2018-11-12 02:36:31 +08:00
android [ 'source-file' ] . install ( valid _source [ 3 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 3 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/libs/TestAar.aar' ) ) ;
} ) ;
2018-11-13 10:50:20 +08:00
it ( 'Test#019d : should remove stuff by calling common.removeFile for Android Studio projects, of xml with old target-dir scheme' , function ( ) {
android [ 'source-file' ] . install ( valid _source [ 4 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 4 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/src/main/res/xml/mysettings.xml' ) ) ;
} ) ;
2018-11-13 11:01:13 +08:00
it ( 'Test#019e : should remove stuff by calling common.removeFile for Android Studio projects, of file with other extension with old target-dir scheme' , function ( ) {
android [ 'source-file' ] . install ( valid _source [ 5 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 5 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/src/main/res/values/other.extension' ) ) ;
} ) ;
2018-11-14 02:06:48 +08:00
2018-11-15 02:19:58 +08:00
it ( 'Test#019f : should remove stuff by calling common.removeFile for Android Studio projects, of aidl with old target-dir scheme (GH-547)' , function ( ) {
2018-11-14 02:06:48 +08:00
android [ 'source-file' ] . install ( valid _source [ 6 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 6 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-15 02:19:58 +08:00
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/src/main/aidl/com/mytest/myapi.aidl' ) ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#019g : should remove stuff by calling common.removeFile for Android Studio projects, of aar with old target-dir scheme (GH-547)' , function ( ) {
2018-11-14 02:06:48 +08:00
android [ 'source-file' ] . install ( valid _source [ 7 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 7 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-15 02:19:58 +08:00
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/libs/testaar2.aar' ) ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#019h : should remove stuff by calling common.removeFile for Android Studio projects, of jar with old target-dir scheme (GH-547)' , function ( ) {
2018-11-14 02:06:48 +08:00
android [ 'source-file' ] . install ( valid _source [ 8 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 8 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-15 02:19:58 +08:00
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/libs/testjar2.jar' ) ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#019i : should remove stuff by calling common.removeFile for Android Studio projects, of .so lib file with old target-dir scheme (GH-547)' , function ( ) {
2018-11-14 02:06:48 +08:00
android [ 'source-file' ] . install ( valid _source [ 9 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 9 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-15 02:19:58 +08:00
expect ( removeFileSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/src/main/jniLibs/x86/libnative.so' ) ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-12 02:36:31 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <framework> elements' , function ( ) {
2016-02-29 23:49:17 +08:00
var someString = jasmine . any ( String ) ;
2017-06-14 02:42:20 +08:00
beforeEach ( function ( ) {
2016-02-29 23:49:17 +08:00
shell . mkdir ( path . join ( dummyProject . projectDir , dummyPluginInfo . id ) ) ;
spyOn ( dummyProject , 'removeSystemLibrary' ) ;
spyOn ( dummyProject , 'removeSubProject' ) ;
spyOn ( dummyProject , 'removeGradleReference' ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#020 : should throw if framework doesn\'t have "src" attribute' , function ( ) {
2017-06-14 02:42:20 +08:00
expect ( function ( ) { android . framework . uninstall ( { } , dummyPluginInfo , dummyProject ) ; } ) . toThrow ( ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#021 : should uninstall framework without "parent" attribute into project root' , function ( ) {
2016-02-29 23:49:17 +08:00
var framework = { src : 'plugin-lib' } ;
android . framework . uninstall ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . removeSystemLibrary ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#022 : should uninstall framework with "parent" attribute into parent framework dir' , function ( ) {
2016-02-29 23:49:17 +08:00
var childFramework = { src : 'plugin-lib2' , parent : 'plugin-lib' } ;
android . framework . uninstall ( childFramework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . removeSystemLibrary ) . toHaveBeenCalledWith ( path . resolve ( dummyProject . projectDir , childFramework . parent ) , someString ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#023 : should remove framework sources if "custom" attribute is set' , function ( ) {
2016-02-29 23:49:17 +08:00
var framework = { src : 'plugin-lib' , custom : true } ;
android . framework . uninstall ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . removeSubProject ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
expect ( removeFileSpy ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#24 : should install gradleReference using project.removeGradleReference' , function ( ) {
2016-02-29 23:49:17 +08:00
var framework = { src : 'plugin-lib' , custom : true , type : 'gradleReference' } ;
android . framework . uninstall ( framework , dummyPluginInfo , dummyProject ) ;
expect ( removeFileSpy ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
expect ( dummyProject . removeGradleReference ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
} ) ;
} ) ;
2016-04-07 18:24:41 +08:00
2017-06-14 02:42:20 +08:00
describe ( 'of <js-module> elements' , function ( ) {
2016-04-07 18:24:41 +08:00
var jsModule = { src : 'www/dummyPlugin.js' } ;
2017-06-14 02:42:20 +08:00
var wwwDest ;
var platformWwwDest ;
2016-04-07 18:24:41 +08:00
beforeEach ( function ( ) {
wwwDest = path . resolve ( dummyProject . www , 'plugins' , dummyPluginInfo . id , jsModule . src ) ;
platformWwwDest = path . resolve ( dummyProject . platformWww , 'plugins' , dummyPluginInfo . id , jsModule . src ) ;
spyOn ( shell , 'rm' ) ;
var existsSyncOrig = fs . existsSync ;
2017-01-04 03:02:48 +08:00
spyOn ( fs , 'existsSync' ) . and . callFake ( function ( file ) {
2017-06-14 02:42:20 +08:00
if ( [ wwwDest , platformWwwDest ] . indexOf ( file ) >= 0 ) return true ;
2016-04-07 18:24:41 +08:00
return existsSyncOrig . call ( fs , file ) ;
} ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#025 : should put module to both www and platform_www when options.usePlatformWww flag is specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android [ 'js-module' ] . uninstall ( jsModule , dummyPluginInfo , dummyProject , { usePlatformWww : true } ) ;
expect ( shell . rm ) . toHaveBeenCalledWith ( '-Rf' , wwwDest ) ;
expect ( shell . rm ) . toHaveBeenCalledWith ( '-Rf' , platformWwwDest ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#026 : should put module to www only when options.usePlatformWww flag is not specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android [ 'js-module' ] . uninstall ( jsModule , dummyPluginInfo , dummyProject ) ;
expect ( shell . rm ) . toHaveBeenCalledWith ( '-Rf' , wwwDest ) ;
expect ( shell . rm ) . not . toHaveBeenCalledWith ( '-Rf' , platformWwwDest ) ;
} ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <asset> elements' , function ( ) {
2016-04-07 18:24:41 +08:00
var asset = { src : 'www/dummyPlugin.js' , target : 'foo/dummy.js' } ;
var wwwDest , platformWwwDest ;
beforeEach ( function ( ) {
wwwDest = path . resolve ( dummyProject . www , asset . target ) ;
platformWwwDest = path . resolve ( dummyProject . platformWww , asset . target ) ;
spyOn ( shell , 'rm' ) ;
var existsSyncOrig = fs . existsSync ;
2017-01-04 03:02:48 +08:00
spyOn ( fs , 'existsSync' ) . and . callFake ( function ( file ) {
2017-06-14 02:42:20 +08:00
if ( [ wwwDest , platformWwwDest ] . indexOf ( file ) >= 0 ) return true ;
2016-04-07 18:24:41 +08:00
return existsSyncOrig . call ( fs , file ) ;
} ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#027 : should put module to both www and platform_www when options.usePlatformWww flag is specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android . asset . uninstall ( asset , dummyPluginInfo , dummyProject , { usePlatformWww : true } ) ;
expect ( shell . rm ) . toHaveBeenCalledWith ( jasmine . any ( String ) , wwwDest ) ;
expect ( shell . rm ) . toHaveBeenCalledWith ( jasmine . any ( String ) , platformWwwDest ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#028 : should put module to www only when options.usePlatformWww flag is not specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android . asset . uninstall ( asset , dummyPluginInfo , dummyProject ) ;
expect ( shell . rm ) . toHaveBeenCalledWith ( jasmine . any ( String ) , wwwDest ) ;
expect ( shell . rm ) . not . toHaveBeenCalledWith ( jasmine . any ( String ) , platformWwwDest ) ;
} ) ;
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
} ) ;