Files
sdk/pkg/dds/test/devtools_server/base_href_test.dart
Danny Tuppeny 560adc7dc6 [dds/devtools] Switch to always using a relative base href in DevTools pages
This avoids the server needing to know the exact URL path being used on the client, so proxies that rewrite the path (such as code-server) can still work.

See https://github.com/flutter/devtools/issues/8067#issuecomment-2236419703

Change-Id: I5b131d84232c63f5495ccbb533da727cce514de5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/376682
Reviewed-by: Kenzie Davisson <kenzieschmoll@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2024-09-26 15:19:54 +00:00

55 lines
1.7 KiB
Dart

// Copyright 2024 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:dds/src/devtools/handler.dart';
import 'package:test/test.dart';
void main() {
/// A set of test cases to verify base hrefs for.
///
/// The key is a suffix appended to / or /devtools/ depending on how DevTools
/// is hosted.
/// The value is the expected base href (which should always resolve back to
/// the root of where DevTools is being hosted).
final testBaseHrefs = {
'': '.',
'inspector': '.',
'inspector/': '..',
'inspector/foo': '..',
'inspector/foo/': '../..',
'inspector/foo/bar': '../..',
'inspector/foo/bar/baz': '../../..',
};
for (final MapEntry(key: suffix, value: expectedBaseHref)
in testBaseHrefs.entries) {
test('computes correct base href for /$suffix with devtools at root',
() async {
final actual = computeRelativeBaseHref(
'/',
Uri.parse('http://localhost/$suffix'),
);
expect(actual, expectedBaseHref);
});
test('computes correct base href for /$suffix with devtools at /devtools/',
() async {
final actual = computeRelativeBaseHref(
'/devtools/',
Uri.parse('http://localhost/devtools/$suffix'),
);
expect(actual, expectedBaseHref);
});
test('computes correct base href for /$suffix in a devtools extension',
() async {
final actual = computeRelativeBaseHref(
'/devtools/devtools_extension/foo/',
Uri.parse('http://localhost/devtools/devtools_extension/foo/$suffix'),
);
expect(actual, expectedBaseHref);
});
}
}