ios_content_validation_test.dart 4.31 KB
Newer Older
1 2 3 4
// 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.

5 6
import 'dart:io';

7 8
import 'package:flutter_devicelab/framework/apk_utils.dart';
import 'package:flutter_devicelab/framework/framework.dart';
9
import 'package:flutter_devicelab/framework/task_result.dart';
10 11 12 13 14 15 16
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;

Future<void> main() async {
  await task(() async {
    try {
      await runProjectTest((FlutterProject flutterProject) async {
17 18 19
        section('Archive');

        await inDirectory(flutterProject.rootPath, () async {
20 21 22 23 24 25 26 27 28 29 30 31 32 33
          final File appIconFile = File(path.join(
              flutterProject.rootPath,
              'ios',
              'Runner',
              'Assets.xcassets',
              'AppIcon.appiconset',
              'Icon-App-20x20@1x.png',
          ));
          // Resizes app icon to 123x456 (it is supposed to be 20x20).
          appIconFile.writeAsBytesSync(appIconFile.readAsBytesSync()
            ..buffer.asByteData().setInt32(16, 123)
            ..buffer.asByteData().setInt32(20, 456)
          );

34
          final String output = await evalFlutter('build', options: <String>[
35
            'xcarchive',
36
            '-v',
37
          ]);
38 39 40 41 42 43

          // Note this isBot so usage won't actually be sent,
          // this log line is printed whenever the app is archived.
          if (!output.contains('Sending archive event if usage enabled')) {
            throw TaskResult.failure('Usage archive event not sent');
          }
44

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
          // The output contains extra time related prefix, so cannot use a single string.
          const List<String> expectedValidationMessages = <String>[
            '[!] App Settings Validation\n',
            '    • Version Number: 1.0.0\n',
            '    • Build Number: 1\n',
            '    • Display Name: Hello\n',
            '    • Deployment Target: 11.0\n',
            '    • Bundle Identifier: com.example.hello\n',
            '    ! Your application still contains the default "com.example" bundle identifier.\n',
            '[!] App Icon and Launch Image Assets Validation\n',
            '    ! App icon is set to the default placeholder icon. Replace with unique icons.\n',
            '    ! App icon is using the incorrect size (e.g. Icon-App-20x20@1x.png).\n',
            '    ! Launch image is set to the default placeholder icon. Replace with unique launch image.\n',
            'To update the settings, please refer to https://docs.flutter.dev/deployment/ios\n',
          ];
          if (expectedValidationMessages.any((String message) => !output.contains(message))) {
            throw TaskResult.failure('Must have the expected validation message');
62
          }
63 64
        });

65
        final String archivePath = path.join(
66 67 68 69 70
          flutterProject.rootPath,
          'build',
          'ios',
          'archive',
          'Runner.xcarchive',
71 72
        );

73 74 75
        final String products = path.join(archivePath, 'Products');

        checkDirectoryExists(products);
76 77 78 79 80 81

        checkDirectoryExists(path.join(
          archivePath,
          'dSYMs',
          'Runner.app.dSYM',
        ));
82 83 84 85 86
        final Directory applications = Directory(path.join(products, 'Applications'));

        final Directory appBundle = applications
            .listSync()
            .whereType<Directory>()
87
            .singleWhere((Directory directory) => path.extension(directory.path) == '.app');
88 89 90 91 92 93 94 95

        final String flutterFramework = path.join(
          appBundle.path,
          'Frameworks',
          'Flutter.framework',
          'Flutter',
        );
        // Exits 0 only if codesigned.
96 97
        final Future<String> flutterCodesign =
            eval('xcrun', <String>['codesign', '--verify', flutterFramework]);
98 99 100 101 102 103 104

        final String appFramework = path.join(
          appBundle.path,
          'Frameworks',
          'App.framework',
          'App',
        );
105 106 107 108
        final Future<String> appCodesign =
            eval('xcrun', <String>['codesign', '--verify', appFramework]);
        await flutterCodesign;
        await appCodesign;
109
      });
110

111 112 113 114 115 116 117 118
      return TaskResult.success(null);
    } on TaskResult catch (taskResult) {
      return taskResult;
    } catch (e) {
      return TaskResult.failure(e.toString());
    }
  });
}