Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 93 additions & 7 deletions test/flutter_system_proxy_test.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,106 @@
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_system_proxy/flutter_system_proxy.dart';

void main() {
const MethodChannel channel = MethodChannel('flutter_system_proxy');

TestWidgetsFlutterBinding.ensureInitialized();

setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
});
});

tearDown(() {
channel.setMockMethodCallHandler(null);
});

test('getSystemProxy', () async {});
group('getSystemProxy', () {
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
});
});

test('getSystemProxy', () async {});
});

group('findProxyFromEnvironment', () {
test('returns PROXY string when host and port are valid', () async {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return <String, dynamic>{'host': '127.0.0.1', 'port': '8080'};
});

final result =
await FlutterSystemProxy.findProxyFromEnvironment('https://example.com/v1:drop');

expect(result, 'PROXY 127.0.0.1:8080');
});

test('falls back to HttpClient.findProxyFromEnvironment when host is empty',
() async {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return <String, dynamic>{'host': '', 'port': '8080'};
});

final result =
await FlutterSystemProxy.findProxyFromEnvironment('https://example.com');

expect(result,
HttpClient.findProxyFromEnvironment(Uri.parse('https://example.com')));
});

test('falls back to HttpClient.findProxyFromEnvironment when host is null',
() async {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return <String, dynamic>{'host': null, 'port': '8080'};
});

final result =
await FlutterSystemProxy.findProxyFromEnvironment('https://example.com');

expect(result,
HttpClient.findProxyFromEnvironment(Uri.parse('https://example.com')));
});

test(
'falls back to HttpClient.findProxyFromEnvironment when port is invalid',
() async {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return <String, dynamic>{'host': '127.0.0.1', 'port': 'not-a-port'};
});

final result =
await FlutterSystemProxy.findProxyFromEnvironment('https://example.com');

expect(result,
HttpClient.findProxyFromEnvironment(Uri.parse('https://example.com')));
});

test(
'falls back to HttpClient.findProxyFromEnvironment when port is out of range',
() async {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return <String, dynamic>{'host': '127.0.0.1', 'port': '70000'};
});

final result =
await FlutterSystemProxy.findProxyFromEnvironment('https://example.com');

expect(result,
HttpClient.findProxyFromEnvironment(Uri.parse('https://example.com')));
});

test(
'falls back to HttpClient.findProxyFromEnvironment when port is out of range',
() async {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return <String, dynamic>{'host': '127.0.0.1', 'port': '70000'};
});

final result =
await FlutterSystemProxy.findProxyFromEnvironment('https://example.com/v1:drop');

expect(result,
HttpClient.findProxyFromEnvironment(Uri.parse('https://example.com/v1:drop')));
});
});
}