- loopback dev-server URLs are no longer opened on the phone's network: the panel binds a local 127.0.0.1 TCP listener and pipes each connection over an authenticated WebSocket to the host's /api/dev-tunnel, which dials its own loopback port; the WebView keeps the original address in the bar while the page, absolute URLs, cookies and HMR sockets use the tunneled origin - the empty state lists /api/dev-servers results for the project (only ports that answered with a web page), with title, URL and command; tapping one opens it through the tunnel - relay transports mint oc_url_token themselves; a direct connection mints and caches /auth/url-token and also sends the bearer - a new loopback port opened from a tunnelled page gets its own tunnel - version 0.7.1+701; tests cover the URL mapping and tunnel helpers
84 lines
2.4 KiB
Dart
84 lines
2.4 KiB
Dart
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:openchamber/api/client.dart';
|
|
import 'package:openchamber/api/transport.dart';
|
|
import 'package:openchamber/l10n.dart';
|
|
import 'package:openchamber/screens/browser_panel.dart';
|
|
import 'package:openchamber/screens/files_panel.dart';
|
|
import 'package:openchamber/state.dart';
|
|
|
|
class _FakeTransport implements Transport {
|
|
@override
|
|
Future<TransportResponse> send(TransportRequest r) async {
|
|
final body = switch (r.path) {
|
|
'/api/fs/list' => {'entries': <dynamic>[]},
|
|
_ => <String, dynamic>{},
|
|
};
|
|
return TransportResponse(
|
|
200,
|
|
const {'content-type': 'application/json'},
|
|
Stream.value(Uint8List.fromList(utf8.encode(jsonEncode(body)))),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<TransportSocket> webSocket(String path,
|
|
{String? rawQuery, Map<String, String> headers = const {}}) async =>
|
|
throw UnimplementedError();
|
|
|
|
@override
|
|
void setBearerToken(String? token) {}
|
|
|
|
@override
|
|
void close() {}
|
|
}
|
|
|
|
void main() {
|
|
setUp(() => L10n.instance.apply(AppLanguage.en));
|
|
tearDown(() => L10n.instance.apply(AppLanguage.zh));
|
|
|
|
testWidgets('the browser tab shows the mobile-only hint on desktop',
|
|
(tester) async {
|
|
final app = AppState();
|
|
addTearDown(app.dispose);
|
|
await tester.pumpWidget(MaterialApp(
|
|
home: Scaffold(body: BrowserPanel(app: app, directory: '/home/me')),
|
|
));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byIcon(Icons.public_off), findsOneWidget);
|
|
expect(find.text('Browser is only available on Android and iOS'),
|
|
findsOneWidget);
|
|
});
|
|
|
|
testWidgets('the panel tabs are icons with tooltips and open the browser',
|
|
(tester) async {
|
|
final app = AppState();
|
|
addTearDown(app.dispose);
|
|
app.client =
|
|
Client(Uri.parse('http://test'), transport: _FakeTransport());
|
|
|
|
await tester.pumpWidget(MaterialApp(
|
|
home: Scaffold(body: FilesPanel(app: app, directory: '/home/me')),
|
|
));
|
|
await tester.pumpAndSettle();
|
|
|
|
for (final label in [
|
|
'Files',
|
|
'Project knowledge',
|
|
'Terminal',
|
|
'Browser',
|
|
]) {
|
|
expect(find.byTooltip(label), findsOneWidget, reason: label);
|
|
}
|
|
|
|
await tester.tap(find.byTooltip('Browser'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Browser is only available on Android and iOS'),
|
|
findsOneWidget);
|
|
});
|
|
}
|