features_test.dart 14.3 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_tools/src/base/config.dart';
6
import 'package:flutter_tools/src/base/platform.dart';
7
import 'package:flutter_tools/src/features.dart';
8
import 'package:flutter_tools/src/flutter_features.dart';
9 10

import '../src/common.dart';
11
import '../src/fakes.dart';
12 13 14

void main() {
  group('Features', () {
15 16 17
    late Config testConfig;
    late FakePlatform platform;
    late FlutterFeatureFlags featureFlags;
18 19

    setUp(() {
20
      testConfig = Config.test();
21
      platform = FakePlatform(environment: <String, String>{});
22 23

      for (final Feature feature in allFeatures) {
24
        testConfig.setValue(feature.configSetting!, false);
25
      }
26 27

      featureFlags = FlutterFeatureFlags(
28
        flutterVersion: FakeFlutterVersion(),
29
        config: testConfig,
30
        platform: platform,
31
      );
32 33
    });

34 35 36 37 38 39 40 41
    FeatureFlags createFlags(String channel) {
      return FlutterFeatureFlags(
        flutterVersion: FakeFlutterVersion(channel: channel),
        config: testConfig,
        platform: platform,
      );
    }

42
    testWithoutContext('setting has safe defaults', () {
43 44 45 46 47 48
      const FeatureChannelSetting featureSetting = FeatureChannelSetting();

      expect(featureSetting.available, false);
      expect(featureSetting.enabledByDefault, false);
    });

49
    testWithoutContext('has safe defaults', () {
50 51 52 53 54 55 56
      const Feature feature = Feature(name: 'example');

      expect(feature.name, 'example');
      expect(feature.environmentOverride, null);
      expect(feature.configSetting, null);
    });

57
    testWithoutContext('retrieves the correct setting for each branch', () {
58 59 60 61
      const FeatureChannelSetting masterSetting = FeatureChannelSetting(available: true);
      const FeatureChannelSetting betaSetting = FeatureChannelSetting(available: true);
      const FeatureChannelSetting stableSetting = FeatureChannelSetting(available: true);
      const Feature feature = Feature(
62 63 64 65 66 67 68 69 70 71 72 73
        name: 'example',
        master: masterSetting,
        beta: betaSetting,
        stable: stableSetting,
      );

      expect(feature.getSettingForChannel('master'), masterSetting);
      expect(feature.getSettingForChannel('beta'), betaSetting);
      expect(feature.getSettingForChannel('stable'), stableSetting);
      expect(feature.getSettingForChannel('unknown'), masterSetting);
    });

74
    testWithoutContext('env variables are only enabled with "true" string', () {
75
      platform.environment = <String, String>{'FLUTTER_WEB': 'hello'};
76 77 78

      expect(featureFlags.isWebEnabled, false);

79
      platform.environment = <String, String>{'FLUTTER_WEB': 'true'};
80 81

      expect(featureFlags.isWebEnabled, true);
82
    });
83

84
    testWithoutContext('Flutter web help string', () {
85 86
      expect(flutterWebFeature.generateHelpMessage(),
      'Enable or disable Flutter for web. '
87
      'This setting will take effect on the master, beta, and stable channels.');
88 89
    });

90
    testWithoutContext('Flutter macOS desktop help string', () {
91
      expect(flutterMacOSDesktopFeature.generateHelpMessage(),
92
      'Enable or disable beta-quality support for desktop on macOS. '
93
      'This setting will take effect on the master, beta, and stable channels. '
94
      'Newer beta versions are available on the beta channel.');
95 96
    });

97
    testWithoutContext('Flutter Linux desktop help string', () {
98
      expect(flutterLinuxDesktopFeature.generateHelpMessage(),
99
      'Enable or disable beta-quality support for desktop on Linux. '
100
      'This setting will take effect on the master, beta, and stable channels. '
101
      'Newer beta versions are available on the beta channel.');
102 103
    });

104
    testWithoutContext('Flutter Windows desktop help string', () {
105
      expect(flutterWindowsDesktopFeature.generateHelpMessage(),
106
      'Enable or disable support for desktop on Windows. '
107
      'This setting will take effect on the master, beta, and stable channels.');
108 109
    });

110 111
    testWithoutContext('help string on multiple channels', () {
      const Feature testWithoutContextFeature = Feature(
112 113 114 115 116 117 118
        name: 'example',
        master: FeatureChannelSetting(available: true),
        beta: FeatureChannelSetting(available: true),
        stable: FeatureChannelSetting(available: true),
        configSetting: 'foo',
      );

119
      expect(testWithoutContextFeature.generateHelpMessage(), 'Enable or disable example. '
120
          'This setting will take effect on the master, beta, and stable channels.');
121 122 123 124
    });

    /// Flutter Web

125
    testWithoutContext('Flutter web off by default on master', () {
126
      final FeatureFlags featureFlags = createFlags('master');
127 128

      expect(featureFlags.isWebEnabled, false);
129
    });
130

131
    testWithoutContext('Flutter web enabled with config on master', () {
132
      final FeatureFlags featureFlags = createFlags('master');
133
      testConfig.setValue('enable-web', true);
134 135

      expect(featureFlags.isWebEnabled, true);
136
    });
137

138
    testWithoutContext('Flutter web enabled with environment variable on master', () {
139 140
      final FeatureFlags featureFlags = createFlags('master');
      platform.environment = <String, String>{'FLUTTER_WEB': 'true'};
141 142

      expect(featureFlags.isWebEnabled, true);
143
    });
144

145
    testWithoutContext('Flutter web off by default on beta', () {
146
      final FeatureFlags featureFlags = createFlags('beta');
147 148

      expect(featureFlags.isWebEnabled, false);
149
    });
150

151
    testWithoutContext('Flutter web enabled with config on beta', () {
152
      final FeatureFlags featureFlags = createFlags('beta');
153
      testConfig.setValue('enable-web', true);
154

155
      expect(featureFlags.isWebEnabled, true);
156
    });
157

158
    testWithoutContext('Flutter web not enabled with environment variable on beta', () {
159 160
     final FeatureFlags featureFlags = createFlags('beta');
      platform.environment = <String, String>{'FLUTTER_WEB': 'true'};
161

162
      expect(featureFlags.isWebEnabled, true);
163
    });
164

165
    testWithoutContext('Flutter web on by default on stable', () {
166
      final FeatureFlags featureFlags = createFlags('stable');
167
      testConfig.removeValue('enable-web');
168

169
      expect(featureFlags.isWebEnabled, true);
170
    });
171

172
    testWithoutContext('Flutter web enabled with config on stable', () {
173
      final FeatureFlags featureFlags = createFlags('stable');
174
      testConfig.setValue('enable-web', true);
175

176
      expect(featureFlags.isWebEnabled, true);
177
    });
178

179
    testWithoutContext('Flutter web not enabled with environment variable on stable', () {
180 181
      final FeatureFlags featureFlags = createFlags('stable');
      platform.environment = <String, String>{'FLUTTER_WEB': 'enabled'};
182 183

      expect(featureFlags.isWebEnabled, false);
184
    });
185 186 187

    /// Flutter macOS desktop.

188
    testWithoutContext('Flutter macos desktop off by default on master', () {
189
      final FeatureFlags featureFlags = createFlags('master');
190 191

      expect(featureFlags.isMacOSEnabled, false);
192
    });
193

194
    testWithoutContext('Flutter macos desktop enabled with config on master', () {
195
      final FeatureFlags featureFlags = createFlags('master');
196
      testConfig.setValue('enable-macos-desktop', true);
197 198

      expect(featureFlags.isMacOSEnabled, true);
199
    });
200

201
    testWithoutContext('Flutter macos desktop enabled with environment variable on master', () {
202 203
      final FeatureFlags featureFlags = createFlags('master');
      platform.environment = <String, String>{'FLUTTER_MACOS': 'true'};
204 205

      expect(featureFlags.isMacOSEnabled, true);
206
    });
207

208
    testWithoutContext('Flutter macos desktop off by default on beta', () {
209
      final FeatureFlags featureFlags = createFlags('beta');
210 211

      expect(featureFlags.isMacOSEnabled, false);
212
    });
213

214
    testWithoutContext('Flutter macos desktop enabled with config on beta', () {
215
      final FeatureFlags featureFlags = createFlags('beta');
216
      testConfig.setValue('enable-macos-desktop', true);
217

218
      expect(featureFlags.isMacOSEnabled, true);
219
    });
220

221
    testWithoutContext('Flutter macos desktop enabled with environment variable on beta', () {
222 223
      final FeatureFlags featureFlags = createFlags('beta');
      platform.environment = <String, String>{'FLUTTER_MACOS': 'true'};
224

225
      expect(featureFlags.isMacOSEnabled, true);
226
    });
227

228
    testWithoutContext('Flutter macos desktop off by default on stable', () {
229
      final FeatureFlags featureFlags = createFlags('stable');
230 231

      expect(featureFlags.isMacOSEnabled, false);
232
    });
233

234
    testWithoutContext('Flutter macos desktop enabled with config on stable', () {
235
      final FeatureFlags featureFlags = createFlags('stable');
236
      testConfig.setValue('enable-macos-desktop', true);
237

238
      expect(featureFlags.isMacOSEnabled, true);
239
    });
240

241
    testWithoutContext('Flutter macos desktop enabled with environment variable on stable', () {
242 243
      final FeatureFlags featureFlags = createFlags('stable');
      platform.environment = <String, String>{'FLUTTER_MACOS': 'true'};
244

245
      expect(featureFlags.isMacOSEnabled, true);
246
    });
247 248

    /// Flutter Linux Desktop
249
    testWithoutContext('Flutter linux desktop off by default on master', () {
250
      final FeatureFlags featureFlags = createFlags('stable');
251 252

      expect(featureFlags.isLinuxEnabled, false);
253
    });
254

255
    testWithoutContext('Flutter linux desktop enabled with config on master', () {
256
      final FeatureFlags featureFlags = createFlags('master');
257
      testConfig.setValue('enable-linux-desktop', true);
258 259

      expect(featureFlags.isLinuxEnabled, true);
260
    });
261

262
    testWithoutContext('Flutter linux desktop enabled with environment variable on master', () {
263 264
      final FeatureFlags featureFlags = createFlags('master');
      platform.environment = <String, String>{'FLUTTER_LINUX': 'true'};
265 266

      expect(featureFlags.isLinuxEnabled, true);
267
    });
268

269
    testWithoutContext('Flutter linux desktop off by default on beta', () {
270
      final FeatureFlags featureFlags = createFlags('beta');
271 272

      expect(featureFlags.isLinuxEnabled, false);
273
    });
274

275
    testWithoutContext('Flutter linux desktop enabled with config on beta', () {
276
      final FeatureFlags featureFlags = createFlags('beta');
277
      testConfig.setValue('enable-linux-desktop', true);
278

279
      expect(featureFlags.isLinuxEnabled, true);
280
    });
281

282
    testWithoutContext('Flutter linux desktop enabled with environment variable on beta', () {
283 284
      final FeatureFlags featureFlags = createFlags('beta');
      platform.environment = <String, String>{'FLUTTER_LINUX': 'true'};
285

286
      expect(featureFlags.isLinuxEnabled, true);
287
    });
288

289
    testWithoutContext('Flutter linux desktop off by default on stable', () {
290
      final FeatureFlags featureFlags = createFlags('stable');
291 292

      expect(featureFlags.isLinuxEnabled, false);
293
    });
294

295
    testWithoutContext('Flutter linux desktop enabled with config on stable', () {
296
      final FeatureFlags featureFlags = createFlags('stable');
297
      testConfig.setValue('enable-linux-desktop', true);
298

299
      expect(featureFlags.isLinuxEnabled, true);
300
    });
301

302
    testWithoutContext('Flutter linux desktop enabled with environment variable on stable', () {
303 304
      final FeatureFlags featureFlags = createFlags('stable');
      platform.environment = <String, String>{'FLUTTER_LINUX': 'true'};
305

306
      expect(featureFlags.isLinuxEnabled, true);
307
    });
308 309

    /// Flutter Windows desktop.
310
    testWithoutContext('Flutter Windows desktop off by default on master', () {
311
      final FeatureFlags featureFlags = createFlags('master');
312 313

      expect(featureFlags.isWindowsEnabled, false);
314
    });
315

316
    testWithoutContext('Flutter Windows desktop enabled with config on master', () {
317
      final FeatureFlags featureFlags = createFlags('master');
318
      testConfig.setValue('enable-windows-desktop', true);
319 320

      expect(featureFlags.isWindowsEnabled, true);
321
    });
322

323
    testWithoutContext('Flutter Windows desktop enabled with environment variable on master', () {
324 325
      final FeatureFlags featureFlags = createFlags('master');
      platform.environment = <String, String>{'FLUTTER_WINDOWS': 'true'};
326 327

      expect(featureFlags.isWindowsEnabled, true);
328
    });
329

330
    testWithoutContext('Flutter Windows desktop off by default on beta', () {
331
      final FeatureFlags featureFlags = createFlags('beta');
332 333

      expect(featureFlags.isWindowsEnabled, false);
334
    });
335

336
    testWithoutContext('Flutter Windows desktop enabled with config on beta', () {
337
      final FeatureFlags featureFlags = createFlags('beta');
338
      testConfig.setValue('enable-windows-desktop', true);
339

340
      expect(featureFlags.isWindowsEnabled, true);
341
    });
342

343
    testWithoutContext('Flutter Windows desktop enabled with environment variable on beta', () {
344 345
      final FeatureFlags featureFlags = createFlags('beta');
      platform.environment = <String, String>{'FLUTTER_WINDOWS': 'true'};
346

347
      expect(featureFlags.isWindowsEnabled, true);
348
    });
349

350
    testWithoutContext('Flutter Windows desktop off by default on stable', () {
351
      final FeatureFlags featureFlags = createFlags('stable');
352 353

      expect(featureFlags.isWindowsEnabled, false);
354
    });
355

356
    testWithoutContext('Flutter Windows desktop enabled with config on stable', () {
357
      final FeatureFlags featureFlags = createFlags('stable');
358
      testConfig.setValue('enable-windows-desktop', true);
359

360
      expect(featureFlags.isWindowsEnabled, true);
361
    });
362

363
    testWithoutContext('Flutter Windows desktop enabled with environment variable on stable', () {
364 365
      final FeatureFlags featureFlags = createFlags('stable');
      platform.environment = <String, String>{'FLUTTER_WINDOWS': 'true'};
366

367
      expect(featureFlags.isWindowsEnabled, true);
368
    });
369 370 371 372

    // Windows UWP desktop

    testWithoutContext('Flutter Windows UWP desktop off by default on master', () {
373
      final FeatureFlags featureFlags = createFlags('master');
374 375 376 377 378

      expect(featureFlags.isWindowsUwpEnabled, false);
    });

    testWithoutContext('Flutter Windows UWP desktop enabled with config on master', () {
379
      final FeatureFlags featureFlags = createFlags('master');
380 381 382 383 384 385
      testConfig.setValue('enable-windows-uwp-desktop', true);

      expect(featureFlags.isWindowsUwpEnabled, true);
    });

    testWithoutContext('Flutter Windows UWP desktop off by default on stable', () {
386
      final FeatureFlags featureFlags = createFlags('stable');
387 388 389 390 391

      expect(featureFlags.isWindowsUwpEnabled, false);
    });

    testWithoutContext('Flutter Windows UWP desktop not enabled with config on stable', () {
392
      final FeatureFlags featureFlags = createFlags('stable');
393 394 395 396
      testConfig.setValue('enable-windows-uwp-desktop', true);

      expect(featureFlags.isWindowsUwpEnabled, false);
    });
397 398
  });
}