Unverified Commit 68d8c4b3 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] open chrome to correct base URL (#73962)

parent bf4a5484
......@@ -707,9 +707,9 @@ class WebDevFS implements DevFS {
webAssetServer.webRenderer = WebRendererMode.canvaskit;
}
if (hostname == 'any') {
_baseUri = Uri.http('localhost:$selectedPort', '');
_baseUri = Uri.http('localhost:$selectedPort', webAssetServer.basePath);
} else {
_baseUri = Uri.http('$hostname:$selectedPort', '');
_baseUri = Uri.http('$hostname:$selectedPort', webAssetServer.basePath);
}
return _baseUri;
}
......
......@@ -1002,6 +1002,62 @@ void main() {
);
expect(response.statusCode, 404);
}));
test('DevFS URI includes any specified base path.', () => testbed.run(() async {
final File outputFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
..createSync(recursive: true);
const String htmlContent = '<html><head><base href="/foo/"></head><body id="test"></body></html>';
globals.fs.currentDirectory
.childDirectory('web')
.childFile('index.html')
..createSync(recursive: true)
..writeAsStringSync(htmlContent);
outputFile.parent.childFile('a.sources').writeAsStringSync('');
outputFile.parent.childFile('a.json').writeAsStringSync('{}');
outputFile.parent.childFile('a.map').writeAsStringSync('{}');
outputFile.parent.childFile('a.metadata').writeAsStringSync('{}');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(
any,
any,
outputPath: anyNamed('outputPath'),
packageConfig: anyNamed('packageConfig'),
)).thenAnswer((Invocation invocation) async {
return const CompilerOutput('a', 0, <Uri>[]);
});
final WebDevFS webDevFS = WebDevFS(
hostname: 'localhost',
port: 0,
packagesFilePath: '.packages',
urlTunneller: null,
useSseForDebugProxy: true,
useSseForDebugBackend: true,
nullAssertions: true,
nativeNullAssertions: true,
buildInfo: BuildInfo.debug,
enableDwds: false,
entrypoint: Uri.base,
testMode: true,
expressionCompiler: null,
chromiumLauncher: null,
nullSafetyMode: NullSafetyMode.unsound,
);
webDevFS.requireJS.createSync(recursive: true);
webDevFS.stackTraceMapper.createSync(recursive: true);
final Uri uri = await webDevFS.create();
// served on localhost
expect(uri.host, 'localhost');
// Matches base URI specified in html.
expect(uri.path, '/foo');
await webDevFS.destroy();
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
}));
}
class MockHttpServer extends Mock implements HttpServer {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment