forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[google_adsense] Tighten exports and docs. (flutter#8233)
* **Breaking changes**: Reshuffles API exports: * Removes the `adUnit` method, and instead exports the `AdUnitWidget` directly. * Renames `experimental/google_adsense` to `experimental/ad_unit_widget.dart`. * Removes the `AdStatus` and `AdUnitParams` exports. * Removes the "stub" files, so this package is now web-only and must be used through a conditional import. * Tweaks several documentation pages to remove references to internal APIs. * Splits tests to reflect the new code structure. ## Issue * Continuation of: flutter#6871 * Part of: flutter/flutter#40376
- Loading branch information
Showing
21 changed files
with
489 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
## 0.0.2 | ||
|
||
* **Breaking changes**: Reshuffles API exports: | ||
* Makes `adSense.initialize` async. | ||
* Removes the `adUnit` method, and instead exports the `AdUnitWidget` directly. | ||
* Renames `experimental/google_adsense` to `experimental/ad_unit_widget.dart`. | ||
* Removes the `AdStatus` and `AdUnitParams` exports. | ||
* Removes the "stub" files, so this package is now web-only and must be used | ||
through a conditional import. | ||
* Tweaks several documentation pages to remove references to internal APIs. | ||
* Splits tests to reflect the new code structure. | ||
|
||
## 0.0.1 | ||
|
||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/google_adsense/example/integration_test/core_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2013 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. | ||
|
||
// TO run the test: | ||
// 1. Run chrome driver with --port=4444 | ||
// 2. Run the test from example folder with: flutter drive -d web-server --web-port 7357 --browser-name chrome --driver test_driver/integration_test.dart --target integration_test/ad_widget_test.dart | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:google_adsense/google_adsense.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:web/web.dart' as web; | ||
|
||
import 'adsense_test_js_interop.dart'; | ||
|
||
const String testClient = 'test_client'; | ||
const String testScriptUrl = | ||
'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-$testClient'; | ||
|
||
void main() async { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
late AdSense adSense; | ||
|
||
setUp(() async { | ||
adSense = AdSense(); | ||
}); | ||
|
||
tearDown(() { | ||
clearAdsByGoogleMock(); | ||
}); | ||
|
||
group('adSense.initialize', () { | ||
testWidgets('adds AdSense script tag.', (WidgetTester _) async { | ||
final web.HTMLElement target = web.HTMLDivElement(); | ||
// Given | ||
|
||
await adSense.initialize(testClient, jsLoaderTarget: target); | ||
|
||
final web.HTMLScriptElement? injected = | ||
target.lastElementChild as web.HTMLScriptElement?; | ||
|
||
expect(injected, isNotNull); | ||
expect(injected!.src, testScriptUrl); | ||
expect(injected.crossOrigin, 'anonymous'); | ||
expect(injected.async, true); | ||
}); | ||
|
||
testWidgets('Skips initialization if script is already present.', | ||
(WidgetTester _) async { | ||
final web.HTMLScriptElement script = web.HTMLScriptElement() | ||
..id = 'previously-injected' | ||
..src = testScriptUrl; | ||
final web.HTMLElement target = web.HTMLDivElement()..appendChild(script); | ||
|
||
await adSense.initialize(testClient, jsLoaderTarget: target); | ||
|
||
expect(target.childElementCount, 1); | ||
expect(target.firstElementChild?.id, 'previously-injected'); | ||
}); | ||
|
||
testWidgets('Skips initialization if adsense object is already present.', | ||
(WidgetTester _) async { | ||
final web.HTMLElement target = web.HTMLDivElement(); | ||
|
||
// Write an empty noop object | ||
mockAdsByGoogle(() {}); | ||
|
||
await adSense.initialize(testClient, jsLoaderTarget: target); | ||
|
||
expect(target.firstElementChild, isNull); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.