flutter/packages/flutter_web_plugins/test/navigation/utils_test.dart
Mouad Debbar d87656559c
[web] Use 'Uri' instead of 'dart:html' to extract pathname (#127983)
- Use `Uri.parse()` to extract pathname.
- Remove unused code from `utils.dart`.
- Add test for URL encoding.

(need to wait for https://github.com/flutter/flutter/pull/126851 to make it into Google3)
2023-06-06 03:46:02 +00:00

42 lines
1.6 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@TestOn('browser') // Uses web-only Flutter SDK
library;
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_web_plugins/src/navigation/utils.dart';
void main() {
test('checks base href', () {
expect(() => checkBaseHref(null), throwsException);
expect(() => checkBaseHref('foo'), throwsException);
expect(() => checkBaseHref('/foo'), throwsException);
expect(() => checkBaseHref('foo/bar'), throwsException);
expect(() => checkBaseHref('/foo/bar'), throwsException);
expect(() => checkBaseHref('/'), returnsNormally);
expect(() => checkBaseHref('/foo/'), returnsNormally);
expect(() => checkBaseHref('/foo/bar/'), returnsNormally);
});
test('extracts pathname from URL', () {
expect(extractPathname('/'), '/');
expect(extractPathname('/foo'), '/foo');
expect(extractPathname('/foo/'), '/foo/');
expect(extractPathname('/foo/bar'), '/foo/bar');
expect(extractPathname('/foo/bar/'), '/foo/bar/');
expect(extractPathname('https://example.com'), '/');
expect(extractPathname('https://example.com/'), '/');
expect(extractPathname('https://example.com/foo'), '/foo');
expect(extractPathname('https://example.com/foo#bar'), '/foo');
expect(extractPathname('https://example.com/foo/#bar'), '/foo/');
// URL encoding.
expect(extractPathname('/foo bar'), '/foo%20bar');
expect(extractPathname('https://example.com/foo bar'), '/foo%20bar');
});
}