Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 5 | import 'dart:async'; |
| 6 | |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 7 | import 'package:file/file.dart'; |
| 8 | import 'package:file/memory.dart'; |
Emmanuel Garcia | 3e65bb0 | 2019-05-01 09:49:39 -0700 | [diff] [blame] | 9 | import 'package:flutter_tools/src/base/context.dart'; |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 10 | import 'package:flutter_tools/src/base/file_system.dart'; |
Emmanuel Garcia | 3e65bb0 | 2019-05-01 09:49:39 -0700 | [diff] [blame] | 11 | import 'package:flutter_tools/src/base/logger.dart'; |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 12 | import 'package:flutter_tools/src/cache.dart'; |
| 13 | import 'package:flutter_tools/src/flutter_manifest.dart'; |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 14 | |
Ian Hickson | d919e69 | 2019-07-13 11:51:44 -0700 | [diff] [blame] | 15 | import '../src/common.dart'; |
| 16 | import '../src/context.dart'; |
| 17 | import '../src/pubspec_schema.dart'; |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 18 | |
| 19 | void main() { |
| 20 | setUpAll(() { |
| 21 | Cache.flutterRoot = getFlutterRoot(); |
| 22 | }); |
| 23 | |
| 24 | group('FlutterManifest', () { |
Sarah Zakarias | 3cbbbf0 | 2017-09-26 23:14:20 +0200 | [diff] [blame] | 25 | testUsingContext('is empty when the pubspec.yaml file is empty', () async { |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 26 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(''); |
Sarah Zakarias | 3cbbbf0 | 2017-09-26 23:14:20 +0200 | [diff] [blame] | 27 | expect(flutterManifest.isEmpty, true); |
| 28 | expect(flutterManifest.appName, ''); |
| 29 | expect(flutterManifest.usesMaterialDesign, false); |
| 30 | expect(flutterManifest.fontsDescriptor, isEmpty); |
| 31 | expect(flutterManifest.fonts, isEmpty); |
| 32 | expect(flutterManifest.assets, isEmpty); |
| 33 | }); |
| 34 | |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 35 | test('has no fonts or assets when the "flutter" section is empty', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 36 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 37 | name: test |
| 38 | dependencies: |
| 39 | flutter: |
| 40 | sdk: flutter |
| 41 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 42 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 43 | expect(flutterManifest, isNotNull); |
Sarah Zakarias | 3cbbbf0 | 2017-09-26 23:14:20 +0200 | [diff] [blame] | 44 | expect(flutterManifest.isEmpty, false); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 45 | expect(flutterManifest.appName, 'test'); |
| 46 | expect(flutterManifest.usesMaterialDesign, false); |
| 47 | expect(flutterManifest.fontsDescriptor, isEmpty); |
| 48 | expect(flutterManifest.fonts, isEmpty); |
| 49 | expect(flutterManifest.assets, isEmpty); |
| 50 | }); |
| 51 | |
| 52 | test('knows if material design is used', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 53 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 54 | name: test |
| 55 | dependencies: |
| 56 | flutter: |
| 57 | sdk: flutter |
| 58 | flutter: |
| 59 | uses-material-design: true |
| 60 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 61 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 62 | expect(flutterManifest.usesMaterialDesign, true); |
| 63 | }); |
| 64 | |
| 65 | test('has two assets', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 66 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 67 | name: test |
| 68 | dependencies: |
| 69 | flutter: |
| 70 | sdk: flutter |
| 71 | flutter: |
| 72 | uses-material-design: true |
| 73 | assets: |
| 74 | - a/foo |
| 75 | - a/bar |
| 76 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 77 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 78 | expect(flutterManifest.assets.length, 2); |
| 79 | expect(flutterManifest.assets[0], Uri.parse('a/foo')); |
| 80 | expect(flutterManifest.assets[1], Uri.parse('a/bar')); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 81 | }); |
| 82 | |
| 83 | test('has one font family with one asset', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 84 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 85 | name: test |
| 86 | dependencies: |
| 87 | flutter: |
| 88 | sdk: flutter |
| 89 | flutter: |
| 90 | uses-material-design: true |
| 91 | fonts: |
| 92 | - family: foo |
| 93 | fonts: |
| 94 | - asset: a/bar |
| 95 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 96 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 97 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
| 98 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 99 | final List<Font> fonts = flutterManifest.fonts; |
| 100 | expect(fonts.length, 1); |
| 101 | final Font font = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 102 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 103 | expect(font.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 104 | expect(font.familyName, 'foo'); |
| 105 | final List<FontAsset> assets = font.fontAssets; |
| 106 | expect(assets.length, 1); |
| 107 | final FontAsset fontAsset = assets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 108 | expect(fontAsset.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 109 | expect(fontAsset.weight, isNull); |
| 110 | expect(fontAsset.style, isNull); |
| 111 | }); |
| 112 | |
| 113 | test('has one font family with a simple asset and one with weight', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 114 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 115 | name: test |
| 116 | dependencies: |
| 117 | flutter: |
| 118 | sdk: flutter |
| 119 | flutter: |
| 120 | uses-material-design: true |
| 121 | fonts: |
| 122 | - family: foo |
| 123 | fonts: |
| 124 | - asset: a/bar |
| 125 | - asset: a/bar |
| 126 | weight: 400 |
| 127 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 128 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 129 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
| 130 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 131 | final List<Font> fonts = flutterManifest.fonts; |
| 132 | expect(fonts.length, 1); |
| 133 | final Font font = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 134 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 135 | expect(font.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 136 | expect(font.familyName, 'foo'); |
| 137 | final List<FontAsset> assets = font.fontAssets; |
| 138 | expect(assets.length, 2); |
| 139 | final FontAsset fontAsset0 = assets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 140 | expect(fontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 141 | expect(fontAsset0.weight, isNull); |
| 142 | expect(fontAsset0.style, isNull); |
| 143 | final FontAsset fontAsset1 = assets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 144 | expect(fontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 145 | expect(fontAsset1.weight, 400); |
| 146 | expect(fontAsset1.style, isNull); |
| 147 | }); |
| 148 | |
| 149 | test('has one font family with a simple asset and one with weight and style', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 150 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 151 | name: test |
| 152 | dependencies: |
| 153 | flutter: |
| 154 | sdk: flutter |
| 155 | flutter: |
| 156 | uses-material-design: true |
| 157 | fonts: |
| 158 | - family: foo |
| 159 | fonts: |
| 160 | - asset: a/bar |
| 161 | - asset: a/bar |
| 162 | weight: 400 |
| 163 | style: italic |
| 164 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 165 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 166 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 167 | |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 168 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 169 | final List<Font> fonts = flutterManifest.fonts; |
| 170 | expect(fonts.length, 1); |
| 171 | final Font font = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 172 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 173 | expect(font.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 174 | expect(font.familyName, 'foo'); |
| 175 | final List<FontAsset> assets = font.fontAssets; |
| 176 | expect(assets.length, 2); |
| 177 | final FontAsset fontAsset0 = assets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 178 | expect(fontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 179 | expect(fontAsset0.weight, isNull); |
| 180 | expect(fontAsset0.style, isNull); |
| 181 | final FontAsset fontAsset1 = assets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 182 | expect(fontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 183 | expect(fontAsset1.weight, 400); |
| 184 | expect(fontAsset1.style, 'italic'); |
| 185 | }); |
| 186 | |
| 187 | test('has two font families, each with one simple asset and one with weight and style', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 188 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 189 | name: test |
| 190 | dependencies: |
| 191 | flutter: |
| 192 | sdk: flutter |
| 193 | flutter: |
| 194 | uses-material-design: true |
| 195 | fonts: |
| 196 | - family: foo |
| 197 | fonts: |
| 198 | - asset: a/bar |
| 199 | - asset: a/bar |
| 200 | weight: 400 |
| 201 | style: italic |
| 202 | - family: bar |
| 203 | fonts: |
| 204 | - asset: a/baz |
| 205 | - weight: 400 |
| 206 | asset: a/baz |
| 207 | style: italic |
| 208 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 209 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 210 | final dynamic expectedFontsDescriptor = <dynamic>[ |
Alexandre Ardhuin | f11c341 | 2019-09-27 10:46:45 +0200 | [diff] [blame] | 211 | {'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}, // ignore: always_specify_types |
| 212 | {'fonts': [{'asset': 'a/baz'}, {'style': 'italic', 'weight': 400, 'asset': 'a/baz'}], 'family': 'bar'}, // ignore: always_specify_types |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 213 | ]; |
| 214 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 215 | final List<Font> fonts = flutterManifest.fonts; |
| 216 | expect(fonts.length, 2); |
| 217 | |
| 218 | final Font fooFont = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 219 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 220 | expect(fooFont.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 221 | expect(fooFont.familyName, 'foo'); |
| 222 | final List<FontAsset> fooAassets = fooFont.fontAssets; |
| 223 | expect(fooAassets.length, 2); |
| 224 | final FontAsset fooFontAsset0 = fooAassets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 225 | expect(fooFontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 226 | expect(fooFontAsset0.weight, isNull); |
| 227 | expect(fooFontAsset0.style, isNull); |
| 228 | final FontAsset fooFontAsset1 = fooAassets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 229 | expect(fooFontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 230 | expect(fooFontAsset1.weight, 400); |
| 231 | expect(fooFontAsset1.style, 'italic'); |
| 232 | |
| 233 | final Font barFont = fonts[1]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 234 | const String fontDescriptor = '{family: bar, fonts: [{asset: a/baz}, {weight: 400, style: italic, asset: a/baz}]}'; // ignore: always_specify_types |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 235 | expect(barFont.descriptor.toString(), fontDescriptor); |
| 236 | expect(barFont.familyName, 'bar'); |
| 237 | final List<FontAsset> barAssets = barFont.fontAssets; |
| 238 | expect(barAssets.length, 2); |
| 239 | final FontAsset barFontAsset0 = barAssets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 240 | expect(barFontAsset0.assetUri.path, 'a/baz'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 241 | expect(barFontAsset0.weight, isNull); |
| 242 | expect(barFontAsset0.style, isNull); |
| 243 | final FontAsset barFontAsset1 = barAssets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 244 | expect(barFontAsset1.assetUri.path, 'a/baz'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 245 | expect(barFontAsset1.weight, 400); |
| 246 | expect(barFontAsset1.style, 'italic'); |
| 247 | }); |
| 248 | |
Josh Soref | c5a5945 | 2018-03-07 00:36:03 -0500 | [diff] [blame] | 249 | testUsingContext('has only one of two font families when one declaration is missing the "family" option', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 250 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 251 | name: test |
| 252 | dependencies: |
| 253 | flutter: |
| 254 | sdk: flutter |
| 255 | flutter: |
| 256 | uses-material-design: true |
| 257 | fonts: |
| 258 | - family: foo |
| 259 | fonts: |
| 260 | - asset: a/bar |
| 261 | - asset: a/bar |
| 262 | weight: 400 |
| 263 | style: italic |
| 264 | - fonts: |
| 265 | - asset: a/baz |
| 266 | - asset: a/baz |
| 267 | weight: 400 |
| 268 | style: italic |
| 269 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 270 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 271 | |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 272 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
| 273 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 274 | final List<Font> fonts = flutterManifest.fonts; |
| 275 | expect(fonts.length, 1); |
| 276 | final Font fooFont = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 277 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 278 | expect(fooFont.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 279 | expect(fooFont.familyName, 'foo'); |
| 280 | final List<FontAsset> fooAassets = fooFont.fontAssets; |
| 281 | expect(fooAassets.length, 2); |
| 282 | final FontAsset fooFontAsset0 = fooAassets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 283 | expect(fooFontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 284 | expect(fooFontAsset0.weight, isNull); |
| 285 | expect(fooFontAsset0.style, isNull); |
| 286 | final FontAsset fooFontAsset1 = fooAassets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 287 | expect(fooFontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 288 | expect(fooFontAsset1.weight, 400); |
| 289 | expect(fooFontAsset1.style, 'italic'); |
| 290 | }); |
| 291 | |
Josh Soref | c5a5945 | 2018-03-07 00:36:03 -0500 | [diff] [blame] | 292 | testUsingContext('has only one of two font families when one declaration is missing the "fonts" option', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 293 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 294 | name: test |
| 295 | dependencies: |
| 296 | flutter: |
| 297 | sdk: flutter |
| 298 | flutter: |
| 299 | uses-material-design: true |
| 300 | fonts: |
| 301 | - family: foo |
| 302 | fonts: |
| 303 | - asset: a/bar |
| 304 | - asset: a/bar |
| 305 | weight: 400 |
| 306 | style: italic |
| 307 | - family: bar |
| 308 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 309 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 310 | final dynamic expectedFontsDescriptor = [{'fonts': [{'asset': 'a/bar'}, {'style': 'italic', 'weight': 400, 'asset': 'a/bar'}], 'family': 'foo'}]; // ignore: always_specify_types |
| 311 | expect(flutterManifest.fontsDescriptor, expectedFontsDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 312 | final List<Font> fonts = flutterManifest.fonts; |
| 313 | expect(fonts.length, 1); |
| 314 | final Font fooFont = fonts[0]; |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 315 | final dynamic fooFontDescriptor = {'family': 'foo', 'fonts': [{'asset': 'a/bar'}, {'weight': 400, 'style': 'italic', 'asset': 'a/bar'}]}; // ignore: always_specify_types |
| 316 | expect(fooFont.descriptor, fooFontDescriptor); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 317 | expect(fooFont.familyName, 'foo'); |
| 318 | final List<FontAsset> fooAassets = fooFont.fontAssets; |
| 319 | expect(fooAassets.length, 2); |
| 320 | final FontAsset fooFontAsset0 = fooAassets[0]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 321 | expect(fooFontAsset0.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 322 | expect(fooFontAsset0.weight, isNull); |
| 323 | expect(fooFontAsset0.style, isNull); |
| 324 | final FontAsset fooFontAsset1 = fooAassets[1]; |
Michael Goderbauer | 84580b5 | 2018-01-24 13:16:23 -0800 | [diff] [blame] | 325 | expect(fooFontAsset1.assetUri.path, 'a/bar'); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 326 | expect(fooFontAsset1.weight, 400); |
| 327 | expect(fooFontAsset1.style, 'italic'); |
| 328 | }); |
| 329 | |
| 330 | testUsingContext('has no font family when declaration is missing the "asset" option', () async { |
Alexandre Ardhuin | 841d5d7 | 2018-02-01 07:51:26 +0100 | [diff] [blame] | 331 | const String manifest = ''' |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 332 | name: test |
| 333 | dependencies: |
| 334 | flutter: |
| 335 | sdk: flutter |
| 336 | flutter: |
| 337 | uses-material-design: true |
| 338 | fonts: |
| 339 | - family: foo |
| 340 | fonts: |
| 341 | - weight: 400 |
| 342 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 343 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 344 | |
Jason Simmons | 3581b3a | 2018-10-01 14:14:48 -0700 | [diff] [blame] | 345 | expect(flutterManifest.fontsDescriptor, <dynamic>[]); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 346 | final List<Font> fonts = flutterManifest.fonts; |
| 347 | expect(fonts.length, 0); |
| 348 | }); |
Victor Choueiri | 7edd5c8 | 2018-03-19 23:55:54 +0200 | [diff] [blame] | 349 | |
| 350 | test('allows a blank flutter section', () async { |
| 351 | const String manifest = ''' |
| 352 | name: test |
| 353 | dependencies: |
| 354 | flutter: |
| 355 | sdk: flutter |
| 356 | flutter: |
| 357 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 358 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Victor Choueiri | 7edd5c8 | 2018-03-19 23:55:54 +0200 | [diff] [blame] | 359 | expect(flutterManifest.isEmpty, false); |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 360 | expect(flutterManifest.isModule, false); |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 361 | expect(flutterManifest.isPlugin, false); |
| 362 | expect(flutterManifest.androidPackage, null); |
| 363 | }); |
| 364 | |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 365 | test('allows a module declaration', () async { |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 366 | const String manifest = ''' |
| 367 | name: test |
| 368 | flutter: |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 369 | module: |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 370 | androidPackage: com.example |
| 371 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 372 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Greg Spencer | 0ff9e8a | 2018-10-10 11:01:40 -0700 | [diff] [blame] | 373 | expect(flutterManifest.isModule, true); |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 374 | expect(flutterManifest.androidPackage, 'com.example'); |
| 375 | }); |
| 376 | |
Kaushik Iska | fc05c37 | 2019-08-29 21:51:31 -0700 | [diff] [blame] | 377 | test('allows a legacy plugin declaration', () async { |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 378 | const String manifest = ''' |
| 379 | name: test |
| 380 | flutter: |
| 381 | plugin: |
| 382 | androidPackage: com.example |
| 383 | '''; |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 384 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Mikkel Nygaard Ravn | 651c5ab | 2018-08-02 19:16:32 +0200 | [diff] [blame] | 385 | expect(flutterManifest.isPlugin, true); |
| 386 | expect(flutterManifest.androidPackage, 'com.example'); |
Victor Choueiri | 7edd5c8 | 2018-03-19 23:55:54 +0200 | [diff] [blame] | 387 | }); |
Kaushik Iska | fc05c37 | 2019-08-29 21:51:31 -0700 | [diff] [blame] | 388 | test('allows a multi-plat plugin declaration', () async { |
| 389 | const String manifest = ''' |
| 390 | name: test |
| 391 | flutter: |
| 392 | plugin: |
| 393 | platforms: |
| 394 | android: |
| 395 | package: com.example |
| 396 | pluginClass: TestPlugin |
| 397 | '''; |
| 398 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
| 399 | expect(flutterManifest.isPlugin, true); |
| 400 | expect(flutterManifest.androidPackage, 'com.example'); |
| 401 | }); |
| 402 | |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 403 | |
| 404 | Future<void> checkManifestVersion({ |
| 405 | String manifest, |
| 406 | String expectedAppVersion, |
| 407 | String expectedBuildName, |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 408 | String expectedBuildNumber, |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 409 | }) async { |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 410 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 411 | expect(flutterManifest.appVersion, expectedAppVersion); |
| 412 | expect(flutterManifest.buildName, expectedBuildName); |
| 413 | expect(flutterManifest.buildNumber, expectedBuildNumber); |
| 414 | } |
| 415 | |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 416 | test('parses major.minor.patch+build version clause 1', () async { |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 417 | const String manifest = ''' |
| 418 | name: test |
| 419 | version: 1.0.0+2 |
| 420 | dependencies: |
| 421 | flutter: |
| 422 | sdk: flutter |
| 423 | flutter: |
| 424 | '''; |
| 425 | await checkManifestVersion( |
| 426 | manifest: manifest, |
| 427 | expectedAppVersion: '1.0.0+2', |
| 428 | expectedBuildName: '1.0.0', |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 429 | expectedBuildNumber: '2', |
| 430 | ); |
| 431 | }); |
| 432 | |
Jenn Magder | dd1fb3b | 2019-07-31 16:18:09 -0700 | [diff] [blame] | 433 | test('parses major.minor.patch with no build version', () async { |
| 434 | const String manifest = ''' |
| 435 | name: test |
| 436 | version: 0.0.1 |
| 437 | dependencies: |
| 438 | flutter: |
| 439 | sdk: flutter |
| 440 | flutter: |
| 441 | '''; |
| 442 | await checkManifestVersion( |
| 443 | manifest: manifest, |
| 444 | expectedAppVersion: '0.0.1', |
| 445 | expectedBuildName: '0.0.1', |
| 446 | expectedBuildNumber: null, |
| 447 | ); |
| 448 | }); |
| 449 | |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 450 | test('parses major.minor.patch+build version clause 2', () async { |
| 451 | const String manifest = ''' |
| 452 | name: test |
| 453 | version: 1.0.0-beta+exp.sha.5114f85 |
| 454 | dependencies: |
| 455 | flutter: |
| 456 | sdk: flutter |
| 457 | flutter: |
| 458 | '''; |
| 459 | await checkManifestVersion( |
| 460 | manifest: manifest, |
| 461 | expectedAppVersion: '1.0.0-beta+exp.sha.5114f85', |
| 462 | expectedBuildName: '1.0.0-beta', |
| 463 | expectedBuildNumber: 'exp.sha.5114f85', |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 464 | ); |
| 465 | }); |
| 466 | |
| 467 | test('parses major.minor+build version clause', () async { |
| 468 | const String manifest = ''' |
| 469 | name: test |
| 470 | version: 1.0+2 |
| 471 | dependencies: |
| 472 | flutter: |
| 473 | sdk: flutter |
| 474 | flutter: |
| 475 | '''; |
| 476 | await checkManifestVersion( |
| 477 | manifest: manifest, |
| 478 | expectedAppVersion: '1.0+2', |
| 479 | expectedBuildName: '1.0', |
KyleWong | 4b4a9400 | 2019-02-13 23:48:03 +0800 | [diff] [blame] | 480 | expectedBuildNumber: '2', |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 481 | ); |
| 482 | }); |
| 483 | |
| 484 | test('parses empty version clause', () async { |
| 485 | const String manifest = ''' |
| 486 | name: test |
| 487 | version: |
| 488 | dependencies: |
| 489 | flutter: |
| 490 | sdk: flutter |
| 491 | flutter: |
| 492 | '''; |
| 493 | await checkManifestVersion( |
| 494 | manifest: manifest, |
| 495 | expectedAppVersion: null, |
| 496 | expectedBuildName: null, |
| 497 | expectedBuildNumber: null, |
| 498 | ); |
| 499 | }); |
Emmanuel Garcia | 3e65bb0 | 2019-05-01 09:49:39 -0700 | [diff] [blame] | 500 | |
Ralph Bergmann | c65e9d1 | 2018-05-30 16:51:25 +0200 | [diff] [blame] | 501 | test('parses no version clause', () async { |
| 502 | const String manifest = ''' |
| 503 | name: test |
| 504 | dependencies: |
| 505 | flutter: |
| 506 | sdk: flutter |
| 507 | flutter: |
| 508 | '''; |
| 509 | await checkManifestVersion( |
| 510 | manifest: manifest, |
| 511 | expectedAppVersion: null, |
| 512 | expectedBuildName: null, |
| 513 | expectedBuildNumber: null, |
| 514 | ); |
| 515 | }); |
Emmanuel Garcia | 3e65bb0 | 2019-05-01 09:49:39 -0700 | [diff] [blame] | 516 | |
| 517 | // Regression test for https://github.com/flutter/flutter/issues/31764 |
| 518 | testUsingContext('Returns proper error when font detail is malformed', () async { |
| 519 | final BufferLogger logger = context.get<Logger>(); |
| 520 | const String manifest = ''' |
| 521 | name: test |
| 522 | dependencies: |
| 523 | flutter: |
| 524 | sdk: flutter |
| 525 | flutter: |
| 526 | fonts: |
| 527 | - family: foo |
| 528 | fonts: |
| 529 | -asset: a/bar |
| 530 | '''; |
| 531 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
| 532 | |
| 533 | expect(flutterManifest, null); |
| 534 | expect(logger.errorText, contains('Expected "fonts" to either be null or a list.')); |
| 535 | }); |
Zachary Anderson | 500d7c5 | 2019-08-05 13:14:57 -0700 | [diff] [blame] | 536 | |
Zachary Anderson | d220631 | 2019-08-14 07:57:30 -0700 | [diff] [blame] | 537 | testUsingContext('Returns proper error when font is a map instead of a list', () async { |
| 538 | final BufferLogger logger = context.get<Logger>(); |
| 539 | const String manifest = ''' |
| 540 | name: test |
| 541 | dependencies: |
| 542 | flutter: |
| 543 | sdk: flutter |
| 544 | flutter: |
| 545 | fonts: |
| 546 | family: foo |
| 547 | fonts: |
| 548 | -asset: a/bar |
| 549 | '''; |
| 550 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
| 551 | |
| 552 | expect(flutterManifest, null); |
| 553 | expect(logger.errorText, contains('Expected "fonts" to be a list')); |
| 554 | }); |
| 555 | |
Zachary Anderson | 500d7c5 | 2019-08-05 13:14:57 -0700 | [diff] [blame] | 556 | testUsingContext('Returns proper error when second font family is invalid', () async { |
| 557 | final BufferLogger logger = context.get<Logger>(); |
| 558 | const String manifest = ''' |
| 559 | name: test |
| 560 | dependencies: |
| 561 | flutter: |
| 562 | sdk: flutter |
| 563 | flutter: |
| 564 | uses-material-design: true |
| 565 | fonts: |
| 566 | - family: foo |
| 567 | fonts: |
| 568 | - asset: a/bar |
| 569 | - string |
| 570 | '''; |
| 571 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
| 572 | expect(flutterManifest, null); |
| 573 | expect(logger.errorText, contains('Expected a map.')); |
| 574 | }); |
Jonah Williams | 0af2a84 | 2019-10-02 12:45:51 -0700 | [diff] [blame] | 575 | |
| 576 | testUsingContext('Does not crash on empty entry', () async { |
| 577 | final BufferLogger logger = context.get<Logger>(); |
| 578 | const String manifest = ''' |
| 579 | name: test |
| 580 | dependencies: |
| 581 | flutter: |
| 582 | sdk: flutter |
| 583 | flutter: |
| 584 | uses-material-design: true |
| 585 | assets: |
| 586 | - lib/gallery/example_code.dart |
| 587 | - |
| 588 | '''; |
| 589 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
| 590 | final List<Uri> assets = flutterManifest.assets; |
| 591 | |
| 592 | expect(logger.errorText, contains('Asset manifest contains a null or empty uri.')); |
| 593 | expect(assets.length, 1); |
| 594 | }); |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 595 | }); |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 596 | |
| 597 | group('FlutterManifest with MemoryFileSystem', () { |
Alexandre Ardhuin | 774ca2f | 2018-09-11 07:14:04 +0200 | [diff] [blame] | 598 | Future<void> assertSchemaIsReadable() async { |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 599 | const String manifest = ''' |
| 600 | name: test |
| 601 | dependencies: |
| 602 | flutter: |
| 603 | sdk: flutter |
| 604 | flutter: |
| 605 | '''; |
| 606 | |
Jonah Williams | 4ff4671 | 2019-04-29 08:21:32 -0700 | [diff] [blame] | 607 | final FlutterManifest flutterManifest = FlutterManifest.createFromString(manifest); |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 608 | expect(flutterManifest.isEmpty, false); |
| 609 | } |
| 610 | |
Alexandre Ardhuin | 5169ab5 | 2019-02-21 09:27:07 +0100 | [diff] [blame] | 611 | void testUsingContextAndFs( |
| 612 | String description, |
| 613 | FileSystem filesystem, |
| 614 | dynamic testMethod(), |
| 615 | ) { |
Alexandre Ardhuin | 440ce8f | 2019-03-07 21:09:28 +0100 | [diff] [blame] | 616 | testUsingContext( |
| 617 | description, |
| 618 | () async { |
| 619 | writeEmptySchemaFile(filesystem); |
| 620 | testMethod(); |
| 621 | }, |
| 622 | overrides: <Type, Generator>{ |
| 623 | FileSystem: () => filesystem, |
| 624 | }, |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 625 | ); |
| 626 | } |
| 627 | |
Alexandre Ardhuin | 774ca2f | 2018-09-11 07:14:04 +0200 | [diff] [blame] | 628 | testUsingContext('Validate manifest on original fs', () { |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 629 | assertSchemaIsReadable(); |
| 630 | }); |
| 631 | |
Alexandre Ardhuin | 440ce8f | 2019-03-07 21:09:28 +0100 | [diff] [blame] | 632 | testUsingContextAndFs( |
| 633 | 'Validate manifest on Posix FS', |
| 634 | MemoryFileSystem(style: FileSystemStyle.posix), |
| 635 | () { |
| 636 | assertSchemaIsReadable(); |
| 637 | }, |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 638 | ); |
| 639 | |
Alexandre Ardhuin | 440ce8f | 2019-03-07 21:09:28 +0100 | [diff] [blame] | 640 | testUsingContextAndFs( |
| 641 | 'Validate manifest on Windows FS', |
| 642 | MemoryFileSystem(style: FileSystemStyle.windows), |
| 643 | () { |
| 644 | assertSchemaIsReadable(); |
| 645 | }, |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 646 | ); |
| 647 | |
| 648 | }); |
| 649 | |
Sarah Zakarias | 49ba974 | 2017-09-26 14:48:52 +0200 | [diff] [blame] | 650 | } |
fmatosqg | 197d431 | 2018-05-21 10:52:33 +1000 | [diff] [blame] | 651 | |