Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/fwfh_webview/lib/src/internal.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const kTagIframe = 'iframe';
const kAttributeIframeDataSrc = 'data-src';
const kAttributeIframeHeight = 'height';
const kAttributeIframeSandbox = 'sandbox';
const kAttributeIframeSandboxAllowScripts = 'allow-scripts';
Expand Down
6 changes: 5 additions & 1 deletion packages/fwfh_webview/lib/src/web_view_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ mixin WebViewFactory on WidgetFactory {
}

final a = meta.element.attributes;
final src = urlFull(a[kAttributeIframeSrc] ?? '');
final dataSrc = a[kAttributeIframeDataSrc];
final srcAttr = a[kAttributeIframeSrc];
final src = urlFull(
(srcAttr?.isNotEmpty == true) ? srcAttr! : (dataSrc ?? '')
);
if (src == null) {
return widgets;
}
Expand Down
32 changes: 32 additions & 0 deletions packages/fwfh_webview/test/web_view_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,32 @@ void main() {
});
});

group('data-src attribute', () {
testWidgets('renders with data-src', (tester) async {
const html = '<iframe data-src="$src"></iframe>';
final explained = await explain(tester, html);
expect(explained, contains('url=$src,'));
});

testWidgets('src takes priority over data-src', (tester) async {
const html = '<iframe data-src="$src/1" src="$src/2"></iframe>';
final explained = await explain(tester, html);
expect(explained, contains('url=$src/2,'));
});

testWidgets('falls back to data-src when src is empty', (tester) async {
const html = '<iframe data-src="$src" src=""></iframe>';
final explained = await explain(tester, html);
expect(explained, contains('url=$src,'));
});

testWidgets('uses src when data-src is missing', (tester) async {
const html = '<iframe src="$src"></iframe>';
final explained = await explain(tester, html);
expect(explained, contains('url=$src,'));
});
});

group('errors', () {
testWidgets('no src', (tester) async {
const html = '<iframe></iframe>';
Expand All @@ -330,6 +356,12 @@ void main() {
final explained = await explain(tester, html);
expect(explained, equals('[widget0]'));
});

testWidgets('bad data-src (cannot build full url)', (tester) async {
const html = '<iframe data-src="bad"></iframe>';
final explained = await explain(tester, html);
expect(explained, equals('[widget0]'));
});
});
}

Expand Down
Loading