Skip to content

Commit

Permalink
Don't show domain errors when they are just warnings (flutter#8344)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannah-hyj authored Sep 27, 2024
1 parent 2689417 commit e83d965
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const postHeader = {'Content-Type': 'application/json'};
// The keys used in both android and ios domain validation API.
const _domainNameKey = 'domainName';
const _checkNameKey = 'checkName';
const _severityLevelKey = 'severityLevel';
const _severityLevelError = 'ERROR';
const _failedChecksKey = 'failedChecks';
const _domainBatchSize = 500;

Expand Down Expand Up @@ -194,7 +196,8 @@ class DeepLinksService {
for (final failedCheck in failedChecks) {
final checkName = failedCheck[_checkNameKey] as String;
final domainError = iosCheckNameToDomainError[checkName];
if (domainError != null) {
final severityLevel = failedCheck[_severityLevelKey] as String;
if (domainError != null && severityLevel == _severityLevelError) {
domainErrors
.putIfAbsent(domainName, () => <DomainError>[])
.add(domainError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,8 @@ void main() {
(WidgetTester tester) async {
final deepLinksController = TestDeepLinksController(
hasAndroidDomainErrors: true,
hasIosDomainErrors: true,
iosValidationResponse: iosValidationResponseWithError,
);

deepLinksController
..selectedProject.value = FlutterProject(
path: '/abc',
Expand Down Expand Up @@ -269,7 +268,7 @@ void main() {
(WidgetTester tester) async {
final deepLinksController = TestDeepLinksController(
hasAndroidDomainErrors: true,
hasIosDomainErrors: true,
iosValidationResponse: iosValidationResponseWithError,
);

deepLinksController
Expand Down Expand Up @@ -298,6 +297,44 @@ void main() {
},
);

testWidgetsWithWindowSize(
'Don\'t show domain errors when they are just warnings',
windowSize,
(WidgetTester tester) async {
final deepLinksController = TestDeepLinksController(
iosValidationResponse: iosValidationResponseWithWarning,
);

deepLinksController
..selectedProject.value = FlutterProject(
path: '/abc',
androidVariants: ['debug', 'release'],
iosBuildOptions: xcodeBuildOptions,
)
..fakeAndroidDeepLinks = [
androidDeepLinkJson('www.domain1.com'),
androidDeepLinkJson('www.google.com'),
]
..fakeIosDomains = [defaultDomain];

await pumpDeepLinkScreen(
tester,
controller: deepLinksController,
);

expect(find.text('www.domain1.com'), findsOneWidget);
expect(find.text('example.com'), findsOneWidget);
expect(find.text('www.google.com'), findsOneWidget);

await tester.tap(find.text('example.com'));
await tester.pumpAndSettle(const Duration(milliseconds: 500));

final domainErrors =
deepLinksController.selectedLink.value!.domainErrors;
expect(domainErrors.length, 0);
},
);

testWidgetsWithWindowSize(
'search links',
windowSize,
Expand Down Expand Up @@ -394,8 +431,9 @@ void main() {
'filter links with validation result',
windowSize,
(WidgetTester tester) async {
final deepLinksController =
TestDeepLinksController(hasIosDomainErrors: true);
final deepLinksController = TestDeepLinksController(
iosValidationResponse: iosValidationResponseWithError,
);

deepLinksController
..selectedProject.value = FlutterProject(
Expand Down Expand Up @@ -448,16 +486,17 @@ void main() {
'sort links',
windowSize,
(WidgetTester tester) async {
final deepLinksController = TestDeepLinksController();
final deepLinksController = TestDeepLinksController(
iosValidationResponse: iosValidationResponseWithError,
);

deepLinksController
..selectedProject.value = FlutterProject(
path: '/abc',
androidVariants: ['debug', 'release'],
iosBuildOptions: xcodeBuildOptions,
)
..fakeIosDomains = [defaultDomain, 'domain1.com', 'domain2.com']
..hasIosDomainErrors = true;
..fakeIosDomains = [defaultDomain, 'domain1.com', 'domain2.com'];

await pumpDeepLinkScreen(
tester,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,84 @@ const iosValidationResponseWithNoError = '''
}
''';

const iosValidationResponseWithWarning = '''
{
"validationResults": [
{
"domainName": "example.com",
"passedChecks": [
{
"checkName": "HTTPS_ACCESSIBILITY",
"resultType": "PASSED",
"severityLevel": "ERROR"
},
{
"checkName": "NON_REDIRECT",
"resultType": "PASSED",
"severityLevel": "ERROR"
},
{
"checkName": "EXISTENCE",
"resultType": "PASSED",
"severityLevel": "ERROR"
},
{
"checkName": "APP_IDENTIFIER",
"resultType": "PASSED",
"severityLevel": "ERROR"
},
{
"checkName": "FILE_FORMAT",
"resultType": "PASSED",
"severityLevel": "ERROR"
}
],
"failedChecks": [
{
"checkName": "DEFAULTS_FORMAT",
"resultType": "FAILED_INDEPENDENTLY",
"severityLevel": "WARNING"
}
],
"status": "VALIDATION_COMPLETE",
"aasaAppPaths": [
{
"aasaAppId": {
"bundleId": "bundle.id",
"teamId": "AAABBB"
},
"aasaPaths": [
{
"path": "/ios-path1",
"queryParams": [
{
"key": "dplnk",
"value": "?*"
}
],
"isCaseSensitive": true,
"isPercentEncoded": true
},
{
"path": "/ios-path2",
"isExcluded": true,
"queryParams": [
{
"key": "dplnk",
"value": "?*"
}
],
"isCaseSensitive": true,
"isPercentEncoded": true
}
]
}
]
}
]
}
''';

const iosValidationResponseWithError = '''
{
"validationResults": [
Expand Down
16 changes: 6 additions & 10 deletions packages/devtools_app/test/test_infra/utils/deep_links_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final defaultAndroidDeeplink = androidDeepLinkJson(defaultDomain);
class TestDeepLinksService extends DeepLinksService {
TestDeepLinksService({
this.hasAndroidDomainErrors = false,
this.hasIosDomainErrors = false,
this.iosValidationResponse = '',
}) {
// Create a mock client to return fake responses.
_client = MockClient((request) async {
Expand All @@ -28,11 +28,7 @@ class TestDeepLinksService extends DeepLinksService {
}
}
if (request.url == Uri.parse(iosDomainValidationURL)) {
if (hasIosDomainErrors) {
return Response(iosValidationResponseWithError, 200);
} else {
return Response(iosValidationResponseWithNoError, 200);
}
return Response(iosValidationResponse, 200);
}
return Response('this is a body', 404);
});
Expand All @@ -44,24 +40,24 @@ class TestDeepLinksService extends DeepLinksService {
Client get client => _client;

final bool hasAndroidDomainErrors;
final bool hasIosDomainErrors;
final String iosValidationResponse;
}

class TestDeepLinksController extends DeepLinksController {
TestDeepLinksController({
this.hasAndroidDomainErrors = false,
this.hasIosDomainErrors = false,
this.iosValidationResponse = iosValidationResponseWithNoError,
}) {
_deepLinksService = TestDeepLinksService(
hasAndroidDomainErrors: hasAndroidDomainErrors,
hasIosDomainErrors: hasIosDomainErrors,
iosValidationResponse: iosValidationResponse,
);
}

List<String> fakeAndroidDeepLinks = [];
bool hasAndroidDomainErrors = false;
bool hasAndroidPathErrors = false;
bool hasIosDomainErrors = false;
String iosValidationResponse = '';
List<String> fakeIosDomains = [];

late DeepLinksService _deepLinksService;
Expand Down

0 comments on commit e83d965

Please sign in to comment.