mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

* Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs
291 lines
9.1 KiB
Dart
291 lines
9.1 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:args/command_runner.dart';
|
|
import 'package:flutter_tools/src/android/android_sdk.dart';
|
|
import 'package:flutter_tools/src/android/android_studio.dart';
|
|
import 'package:flutter_tools/src/base/common.dart';
|
|
import 'package:flutter_tools/src/base/config.dart';
|
|
import 'package:flutter_tools/src/base/context.dart';
|
|
import 'package:flutter_tools/src/build_info.dart';
|
|
import 'package:flutter_tools/src/cache.dart';
|
|
import 'package:flutter_tools/src/commands/config.dart';
|
|
import 'package:flutter_tools/src/reporting/reporting.dart';
|
|
import 'package:flutter_tools/src/version.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
import '../../src/common.dart';
|
|
import '../../src/context.dart';
|
|
|
|
void main() {
|
|
MockAndroidStudio mockAndroidStudio;
|
|
MockAndroidSdk mockAndroidSdk;
|
|
MockFlutterVersion mockFlutterVersion;
|
|
MockUsage mockUsage;
|
|
|
|
setUpAll(() {
|
|
Cache.disableLocking();
|
|
});
|
|
|
|
setUp(() {
|
|
mockAndroidStudio = MockAndroidStudio();
|
|
mockAndroidSdk = MockAndroidSdk();
|
|
mockFlutterVersion = MockFlutterVersion();
|
|
mockUsage = MockUsage();
|
|
|
|
when(mockUsage.isFirstRun).thenReturn(false);
|
|
});
|
|
|
|
void verifyNoAnalytics() {
|
|
verifyNever(mockUsage.sendCommand(
|
|
any,
|
|
parameters: anyNamed('parameters'),
|
|
));
|
|
verifyNever(mockUsage.sendEvent(
|
|
any,
|
|
any,
|
|
label: anyNamed('label'),
|
|
value: anyNamed('value'),
|
|
parameters: anyNamed('parameters'),
|
|
));
|
|
verifyNever(mockUsage.sendTiming(
|
|
any,
|
|
any,
|
|
any,
|
|
label: anyNamed('label'),
|
|
));
|
|
}
|
|
|
|
group('config', () {
|
|
testUsingContext('machine flag', () async {
|
|
final ConfigCommand command = ConfigCommand();
|
|
await command.handleMachine();
|
|
|
|
expect(testLogger.statusText, isNotEmpty);
|
|
final dynamic jsonObject = json.decode(testLogger.statusText);
|
|
expect(jsonObject, isMap);
|
|
|
|
expect(jsonObject.containsKey('android-studio-dir'), true);
|
|
expect(jsonObject['android-studio-dir'], isNotNull);
|
|
|
|
expect(jsonObject.containsKey('android-sdk'), true);
|
|
expect(jsonObject['android-sdk'], isNotNull);
|
|
verifyNoAnalytics();
|
|
}, overrides: <Type, Generator>{
|
|
AndroidStudio: () => mockAndroidStudio,
|
|
AndroidSdk: () => mockAndroidSdk,
|
|
Usage: () => mockUsage,
|
|
});
|
|
|
|
testUsingContext('Can set build-dir', () async {
|
|
final ConfigCommand configCommand = ConfigCommand();
|
|
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
|
|
|
|
await commandRunner.run(<String>[
|
|
'config',
|
|
'--build-dir=foo',
|
|
]);
|
|
|
|
expect(getBuildDirectory(), 'foo');
|
|
verifyNoAnalytics();
|
|
}, overrides: <Type, Generator>{
|
|
Usage: () => mockUsage,
|
|
});
|
|
|
|
testUsingContext('throws error on absolute path to build-dir', () async {
|
|
final ConfigCommand configCommand = ConfigCommand();
|
|
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
|
|
|
|
expect(() => commandRunner.run(<String>[
|
|
'config',
|
|
'--build-dir=/foo',
|
|
]), throwsA(isInstanceOf<ToolExit>()));
|
|
verifyNoAnalytics();
|
|
}, overrides: <Type, Generator>{
|
|
Usage: () => mockUsage,
|
|
});
|
|
|
|
testUsingContext('allows setting and removing feature flags', () async {
|
|
final ConfigCommand configCommand = ConfigCommand();
|
|
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
|
|
|
|
await commandRunner.run(<String>[
|
|
'config',
|
|
'--enable-web',
|
|
'--enable-linux-desktop',
|
|
'--enable-windows-desktop',
|
|
'--enable-macos-desktop',
|
|
]);
|
|
|
|
expect(Config.instance.getValue('enable-web'), true);
|
|
expect(Config.instance.getValue('enable-linux-desktop'), true);
|
|
expect(Config.instance.getValue('enable-windows-desktop'), true);
|
|
expect(Config.instance.getValue('enable-macos-desktop'), true);
|
|
|
|
await commandRunner.run(<String>[
|
|
'config', '--clear-features',
|
|
]);
|
|
|
|
expect(Config.instance.getValue('enable-web'), null);
|
|
expect(Config.instance.getValue('enable-linux-desktop'), null);
|
|
expect(Config.instance.getValue('enable-windows-desktop'), null);
|
|
expect(Config.instance.getValue('enable-macos-desktop'), null);
|
|
|
|
await commandRunner.run(<String>[
|
|
'config',
|
|
'--no-enable-web',
|
|
'--no-enable-linux-desktop',
|
|
'--no-enable-windows-desktop',
|
|
'--no-enable-macos-desktop',
|
|
]);
|
|
|
|
expect(Config.instance.getValue('enable-web'), false);
|
|
expect(Config.instance.getValue('enable-linux-desktop'), false);
|
|
expect(Config.instance.getValue('enable-windows-desktop'), false);
|
|
expect(Config.instance.getValue('enable-macos-desktop'), false);
|
|
verifyNoAnalytics();
|
|
}, overrides: <Type, Generator>{
|
|
AndroidStudio: () => mockAndroidStudio,
|
|
AndroidSdk: () => mockAndroidSdk,
|
|
Usage: () => mockUsage,
|
|
});
|
|
|
|
testUsingContext('warns the user to reload IDE', () async {
|
|
final ConfigCommand configCommand = ConfigCommand();
|
|
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
|
|
|
|
await commandRunner.run(<String>[
|
|
'config',
|
|
'--enable-web'
|
|
]);
|
|
|
|
expect(testLogger.statusText, contains('You may need to restart any open editors'));
|
|
}, overrides: <Type, Generator>{
|
|
Usage: () => mockUsage,
|
|
});
|
|
|
|
testUsingContext('displays which config settings are available on stable', () async {
|
|
when(mockFlutterVersion.channel).thenReturn('stable');
|
|
final ConfigCommand configCommand = ConfigCommand();
|
|
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
|
|
|
|
await commandRunner.run(<String>[
|
|
'config',
|
|
'--enable-web',
|
|
'--enable-linux-desktop',
|
|
'--enable-windows-desktop',
|
|
'--enable-macos-desktop',
|
|
]);
|
|
|
|
await commandRunner.run(<String>[
|
|
'config',
|
|
]);
|
|
|
|
expect(testLogger.statusText, contains('enable-web: true (Unavailable)'));
|
|
expect(testLogger.statusText, contains('enable-linux-desktop: true (Unavailable)'));
|
|
expect(testLogger.statusText, contains('enable-windows-desktop: true (Unavailable)'));
|
|
expect(testLogger.statusText, contains('enable-macos-desktop: true (Unavailable)'));
|
|
verifyNoAnalytics();
|
|
}, overrides: <Type, Generator>{
|
|
AndroidStudio: () => mockAndroidStudio,
|
|
AndroidSdk: () => mockAndroidSdk,
|
|
FlutterVersion: () => mockFlutterVersion,
|
|
Usage: () => mockUsage,
|
|
});
|
|
|
|
testUsingContext('no-analytics flag flips usage flag and sends event', () async {
|
|
final ConfigCommand configCommand = ConfigCommand();
|
|
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
|
|
|
|
await commandRunner.run(<String>[
|
|
'config',
|
|
'--no-analytics',
|
|
]);
|
|
|
|
expect(mockUsage.enabled, false);
|
|
|
|
// Verify that we only send the analytics disable event, and no other
|
|
// info.
|
|
verifyNever(mockUsage.sendCommand(
|
|
any,
|
|
parameters: anyNamed('parameters'),
|
|
));
|
|
verifyNever(mockUsage.sendTiming(
|
|
any,
|
|
any,
|
|
any,
|
|
label: anyNamed('label'),
|
|
));
|
|
|
|
expect(verify(mockUsage.sendEvent(
|
|
captureAny,
|
|
captureAny,
|
|
label: captureAnyNamed('label'),
|
|
value: anyNamed('value'),
|
|
parameters: anyNamed('parameters'),
|
|
)).captured,
|
|
<dynamic>['analytics', 'enabled', 'false'],
|
|
);
|
|
}, overrides: <Type, Generator>{
|
|
Usage: () => mockUsage,
|
|
});
|
|
|
|
testUsingContext('analytics flag flips usage flag and sends event', () async {
|
|
final ConfigCommand configCommand = ConfigCommand();
|
|
final CommandRunner<void> commandRunner = createTestCommandRunner(configCommand);
|
|
|
|
await commandRunner.run(<String>[
|
|
'config',
|
|
'--analytics',
|
|
]);
|
|
|
|
expect(mockUsage.enabled, true);
|
|
|
|
// Verify that we only send the analytics disable event, and no other
|
|
// info.
|
|
verifyNever(mockUsage.sendCommand(
|
|
any,
|
|
parameters: anyNamed('parameters'),
|
|
));
|
|
verifyNever(mockUsage.sendTiming(
|
|
any,
|
|
any,
|
|
any,
|
|
label: anyNamed('label'),
|
|
));
|
|
|
|
expect(verify(mockUsage.sendEvent(
|
|
captureAny,
|
|
captureAny,
|
|
label: captureAnyNamed('label'),
|
|
value: anyNamed('value'),
|
|
parameters: anyNamed('parameters'),
|
|
)).captured,
|
|
<dynamic>['analytics', 'enabled', 'true'],
|
|
);
|
|
}, overrides: <Type, Generator>{
|
|
Usage: () => mockUsage,
|
|
});
|
|
});
|
|
}
|
|
|
|
class MockAndroidStudio extends Mock implements AndroidStudio, Comparable<AndroidStudio> {
|
|
@override
|
|
String get directory => 'path/to/android/stdio';
|
|
}
|
|
|
|
class MockAndroidSdk extends Mock implements AndroidSdk {
|
|
@override
|
|
String get directory => 'path/to/android/sdk';
|
|
}
|
|
|
|
class MockFlutterVersion extends Mock implements FlutterVersion {}
|
|
|
|
class MockUsage extends Mock implements Usage {
|
|
@override
|
|
bool enabled = true;
|
|
}
|