// 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. import 'package:flutter_tools/src/html_utils.dart'; import '../src/common.dart'; const String htmlSample1 = '''
'''; const String htmlSample2 = '''
'''; String htmlSample2Replaced({ required String baseHref, required String serviceWorkerVersion, }) => '''
'''; const String htmlSample3 = '''
'''; void main() { test('can parse baseHref', () { expect(IndexHtml('').getBaseHref(), 'foo/111'); expect(IndexHtml(htmlSample1).getBaseHref(), 'foo/222'); expect(IndexHtml(htmlSample2).getBaseHref(), ''); // Placeholder base href. }); test('handles missing baseHref', () { expect(IndexHtml('').getBaseHref(), ''); expect(IndexHtml('').getBaseHref(), ''); expect(IndexHtml(htmlSample3).getBaseHref(), ''); }); test('throws on invalid baseHref', () { expect(() => IndexHtml('').getBaseHref(), throwsToolExit()); expect(() => IndexHtml('').getBaseHref(), throwsToolExit()); expect(() => IndexHtml('').getBaseHref(), throwsToolExit()); expect( () => IndexHtml('').getBaseHref(), throwsToolExit(), ); expect( () => IndexHtml('').getBaseHref(), throwsToolExit(), ); }); test('applies substitutions', () { final IndexHtml indexHtml = IndexHtml(htmlSample2); indexHtml.applySubstitutions( baseHref: '/foo/333/', serviceWorkerVersion: 'v123xyz', ); expect( indexHtml.content, htmlSample2Replaced( baseHref: '/foo/333/', serviceWorkerVersion: 'v123xyz', ), ); }); test('re-parses after substitutions', () { final IndexHtml indexHtml = IndexHtml(htmlSample2); expect(indexHtml.getBaseHref(), ''); // Placeholder base href. indexHtml.applySubstitutions( baseHref: '/foo/333/', serviceWorkerVersion: 'v123xyz', ); // The parsed base href should be updated after substitutions. expect(indexHtml.getBaseHref(), 'foo/333'); }); }