From 2a3e4d480719f6e950ad81bcca26b9574024fbaf Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Tue, 20 Aug 2019 13:40:03 +0100 Subject: [PATCH 1/8] [path_provider] Activate getApplicationSupportDirectory integration test --- packages/path_provider/CHANGELOG.md | 4 ++++ .../example/test_driver/path_provider.dart | 19 +++++++------------ packages/path_provider/pubspec.yaml | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/path_provider/CHANGELOG.md b/packages/path_provider/CHANGELOG.md index 2e7f5ad33464..ccd0bd866585 100644 --- a/packages/path_provider/CHANGELOG.md +++ b/packages/path_provider/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.2.1 + +* Correct the integration test for Androids `getApplicationSupportDirectory` call. + ## 1.2.0 * On Android, `getApplicationSupportDirectory` is now supported using `getFilesDir`. diff --git a/packages/path_provider/example/test_driver/path_provider.dart b/packages/path_provider/example/test_driver/path_provider.dart index 219d6660df7e..ca9ae8cf642a 100644 --- a/packages/path_provider/example/test_driver/path_provider.dart +++ b/packages/path_provider/example/test_driver/path_provider.dart @@ -36,18 +36,13 @@ void main() { }); test('getApplicationSupportDirectory', () async { - if (Platform.isIOS) { - final Directory result = await getApplicationSupportDirectory(); - final String uuid = Uuid().v1(); - final File file = File('${result.path}/$uuid.txt'); - file.writeAsStringSync('Hello world!'); - expect(file.readAsStringSync(), 'Hello world!'); - expect(result.listSync(), isNotEmpty); - file.deleteSync(); - } else if (Platform.isAndroid) { - final Future result = getApplicationSupportDirectory(); - expect(result, throwsA(isInstanceOf())); - } + final Directory result = await getApplicationSupportDirectory(); + final String uuid = Uuid().v1(); + final File file = File('${result.path}/$uuid.txt'); + file.writeAsStringSync('Hello world!'); + expect(file.readAsStringSync(), 'Hello world!'); + expect(result.listSync(), isNotEmpty); + file.deleteSync(); }); test('getExternalStorageDirectory', () async { diff --git a/packages/path_provider/pubspec.yaml b/packages/path_provider/pubspec.yaml index 2eed0ae7bd9d..634ba1ce834b 100644 --- a/packages/path_provider/pubspec.yaml +++ b/packages/path_provider/pubspec.yaml @@ -3,7 +3,7 @@ description: Flutter plugin for getting commonly used locations on the Android & iOS file systems, such as the temp and app data directories. author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider -version: 1.2.0 +version: 1.2.1 flutter: plugin: From 72a943bb9338bd69733411ace4c82ec32799235c Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Tue, 20 Aug 2019 14:08:04 +0100 Subject: [PATCH 2/8] Add missing unit tests --- .../test/path_provider_test.dart | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/path_provider/test/path_provider_test.dart b/packages/path_provider/test/path_provider_test.dart index 9da5a2568a9a..134f258a00d7 100644 --- a/packages/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/test/path_provider_test.dart @@ -33,18 +33,38 @@ void main() { expect(directory, isNull); }); - test('getApplicationDocumentsDirectory test', () async { + test('getApplicationSupportDirectory test', () async { response = null; - final Directory directory = await getApplicationDocumentsDirectory(); + final Directory directory = await getApplicationSupportDirectory(); expect( log, [ - isMethodCall('getApplicationDocumentsDirectory', arguments: null) + isMethodCall('getApplicationSupportDirectory', arguments: null) ], ); expect(directory, isNull); }); + test('getApplicationDocumentsDirectory test', () async { + response = null; + final Directory directory = await getApplicationDocumentsDirectory(); + expect( + log, + [isMethodCall('getApplicationDocumentsDirectory', arguments: null)], + ); + expect(directory, isNull); + }); + + test('getExternalStorageDirectory test', () async { + response = null; + final Directory directory = await getExternalStorageDirectory(); + expect( + log, + [isMethodCall('getStorageDirectory', arguments: null)], + ); + expect(directory, isNull); + }); + test('TemporaryDirectory path test', () async { final String fakePath = "/foo/bar/baz"; response = fakePath; @@ -52,10 +72,24 @@ void main() { expect(directory.path, equals(fakePath)); }); + test('ApplicationSupportDirectory path test', () async { + final String fakePath = "/foo/bar/baz"; + response = fakePath; + final Directory directory = await getApplicationSupportDirectory(); + expect(directory.path, equals(fakePath)); + }); + test('ApplicationDocumentsDirectory path test', () async { final String fakePath = "/foo/bar/baz"; response = fakePath; final Directory directory = await getApplicationDocumentsDirectory(); expect(directory.path, equals(fakePath)); }); + + test('ExternalStorageDirectory path test', () async { + final String fakePath = "/foo/bar/baz"; + response = fakePath; + final Directory directory = await getExternalStorageDirectory(); + expect(directory.path, equals(fakePath)); + }); } From 7323e371aac57aad61ae9dfefbb76ad2929547b0 Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Tue, 20 Aug 2019 14:15:32 +0100 Subject: [PATCH 3/8] Formatting --- packages/path_provider/test/path_provider_test.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/path_provider/test/path_provider_test.dart b/packages/path_provider/test/path_provider_test.dart index 134f258a00d7..ef62fe900bad 100644 --- a/packages/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/test/path_provider_test.dart @@ -50,7 +50,9 @@ void main() { final Directory directory = await getApplicationDocumentsDirectory(); expect( log, - [isMethodCall('getApplicationDocumentsDirectory', arguments: null)], + [ + isMethodCall('getApplicationDocumentsDirectory', arguments: null) + ], ); expect(directory, isNull); }); From b67cfe60d8057fe48fb64c0691d053ea19224fe5 Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Thu, 22 Aug 2019 11:01:35 +0100 Subject: [PATCH 4/8] extend the unit test with platform tests --- packages/path_provider/lib/path_provider.dart | 13 +++++++++++-- .../path_provider/test/path_provider_test.dart | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/path_provider/lib/path_provider.dart b/packages/path_provider/lib/path_provider.dart index c53468ae05ca..a6dc9f8a5f16 100644 --- a/packages/path_provider/lib/path_provider.dart +++ b/packages/path_provider/lib/path_provider.dart @@ -3,13 +3,22 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:io'; +import 'dart:io' show Directory; import 'package:flutter/services.dart'; +import 'package:meta/meta.dart'; +import 'package:platform/platform.dart'; const MethodChannel _channel = MethodChannel('plugins.flutter.io/path_provider'); +Platform _platform = const LocalPlatform(); + +@visibleForTesting +void pathProviderPrivate(Platform platform) { + _platform = platform; +} + /// Path to the temporary directory on the device that is not backed up and is /// suitable for storing caches of downloaded files. /// @@ -77,7 +86,7 @@ Future getApplicationDocumentsDirectory() async { /// /// On Android this uses the `getExternalFilesDir(null)`. Future getExternalStorageDirectory() async { - if (Platform.isIOS) + if (_platform.isIOS) throw UnsupportedError("Functionality not available on iOS"); final String path = await _channel.invokeMethod('getStorageDirectory'); diff --git a/packages/path_provider/test/path_provider_test.dart b/packages/path_provider/test/path_provider_test.dart index ef62fe900bad..749db82276ca 100644 --- a/packages/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/test/path_provider_test.dart @@ -7,6 +7,7 @@ import 'dart:io'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:platform/platform.dart'; void main() { const MethodChannel channel = @@ -19,6 +20,10 @@ void main() { return response; }); + setUp(() { + pathProviderPrivate(FakePlatform(operatingSystem: 'android')); + }); + tearDown(() { log.clear(); }); @@ -67,6 +72,18 @@ void main() { expect(directory, isNull); }); + test('getExternalStorageDirectory iOS test', () async { + pathProviderPrivate(FakePlatform(operatingSystem: 'ios')); + + response = null; + try { + await getExternalStorageDirectory(); + fail('should throw UnsupportedError'); + } catch (e) { + expect(e, isUnsupportedError); + } + }); + test('TemporaryDirectory path test', () async { final String fakePath = "/foo/bar/baz"; response = fakePath; From a9093ecc33a1abad243807e5892df3a75ec7e1ae Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Wed, 28 Aug 2019 09:48:31 +0100 Subject: [PATCH 5/8] Add platform & meta to pubspec.yaml --- packages/path_provider/pubspec.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/path_provider/pubspec.yaml b/packages/path_provider/pubspec.yaml index 579de5e165a0..e7e7555d93cc 100644 --- a/packages/path_provider/pubspec.yaml +++ b/packages/path_provider/pubspec.yaml @@ -14,6 +14,8 @@ flutter: dependencies: flutter: sdk: flutter + platform: ^2.0.0 + meta: ^1.0.5 dev_dependencies: flutter_test: From e0aa04e0bf119abd41b7799dd80baadf96445e49 Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Thu, 29 Aug 2019 09:24:31 +0100 Subject: [PATCH 6/8] setMockPathProviderPlatform --- packages/path_provider/lib/path_provider.dart | 2 +- packages/path_provider/test/path_provider_test.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/path_provider/lib/path_provider.dart b/packages/path_provider/lib/path_provider.dart index a6dc9f8a5f16..069973a5aca7 100644 --- a/packages/path_provider/lib/path_provider.dart +++ b/packages/path_provider/lib/path_provider.dart @@ -15,7 +15,7 @@ const MethodChannel _channel = Platform _platform = const LocalPlatform(); @visibleForTesting -void pathProviderPrivate(Platform platform) { +void setMockPathProviderPlatform(Platform platform) { _platform = platform; } diff --git a/packages/path_provider/test/path_provider_test.dart b/packages/path_provider/test/path_provider_test.dart index 2697349d0159..1e8afecab1cd 100644 --- a/packages/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/test/path_provider_test.dart @@ -23,7 +23,7 @@ void main() { }); setUp(() { - pathProviderPrivate(FakePlatform(operatingSystem: 'android')); + setMockPathProviderPlatform(FakePlatform(operatingSystem: 'android')); }); tearDown(() { @@ -75,7 +75,7 @@ void main() { }); test('getExternalStorageDirectory iOS test', () async { - pathProviderPrivate(FakePlatform(operatingSystem: 'ios')); + setMockPathProviderPlatform(FakePlatform(operatingSystem: 'ios')); response = null; try { From 9f2fd53ff0d9299882df8cd0fe68e310b21bb5b8 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Wed, 4 Sep 2019 16:25:07 -0700 Subject: [PATCH 7/8] Update CHANGELOG.md --- packages/path_provider/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/path_provider/CHANGELOG.md b/packages/path_provider/CHANGELOG.md index c59394b5c50e..c84b53b5b14d 100644 --- a/packages/path_provider/CHANGELOG.md +++ b/packages/path_provider/CHANGELOG.md @@ -1,7 +1,7 @@ ## 1.2.2 -* Correct the integration test for Androids `getApplicationSupportDirectory` call. -* Adds missing unit & integration tests. +* Correct the integration test for Android's `getApplicationSupportDirectory` call. +* Adds missing unit and integration tests. ## 1.2.1 From 831607bf9ceb637c426fc6bac0b127cfe61e2908 Mon Sep 17 00:00:00 2001 From: Collin Jackson Date: Wed, 4 Sep 2019 16:26:52 -0700 Subject: [PATCH 8/8] Update CHANGELOG.md --- packages/path_provider/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/path_provider/CHANGELOG.md b/packages/path_provider/CHANGELOG.md index c84b53b5b14d..498127adefe6 100644 --- a/packages/path_provider/CHANGELOG.md +++ b/packages/path_provider/CHANGELOG.md @@ -1,6 +1,7 @@ ## 1.2.2 * Correct the integration test for Android's `getApplicationSupportDirectory` call. +* Introduce `setMockPathProviderPlatform` for API for tests. * Adds missing unit and integration tests. ## 1.2.1