This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[android_alarm_manager] Added Espresso test for background execution #2482
Merged
collinjackson
merged 45 commits into
flutter:master
from
bkonyi:alarm_manager_espresso_test
Mar 6, 2020
Merged
Changes from 3 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
6743105
Initial attempt at Espresso tests for package:android_alarm_manager
bkonyi 969b471
Added test for android_alarm_manager background execution
bkonyi 2309b31
Formatting and analysis fixes
bkonyi 20edffa
Fixed typo
bkonyi f56ba76
Fix AndroidManifest.xml
collinjackson f8e3e96
Implement code review feedback suggestions
collinjackson 1cd80ed
Fix test to be able to run more than once
collinjackson 3b80084
remove prints
collinjackson a8bb31e
Split espresso and e2e example apps
collinjackson 1c152a0
add shared_preferences:
collinjackson bd0c407
fix deprecation warning
collinjackson fc37fa2
Revert "fix deprecation warning"
collinjackson b4747bf
different fix for deprecation
collinjackson 9fe8165
Revert back to earlier version with combined example app
collinjackson 496ef94
different fix for deprecation
collinjackson c29ae2d
remove duplicate test
collinjackson 77da504
remove example/example
collinjackson b37c9cc
changes per Amir's feedback
collinjackson 650bad7
Move espresso test instructions
collinjackson 8d57d9a
Change Espresso to fix iOS build errors
collinjackson 68e10fe
Use development version of Espresso
collinjackson 458753c
reformat
collinjackson 22e8a5d
Re-enable background execution test on CI
collinjackson 89b5d6d
Fix ref to MainActivity
collinjackson efad3e6
Merge remote-tracking branch 'origin/master' into alarm_manager_espre…
collinjackson 7c88473
Update README
collinjackson aa8ee0e
revert EspressoPlugin.m
collinjackson 148ca20
Split out espresso changes
collinjackson 053d3bd
Rename method to appMain
collinjackson 5cd6695
Fix for race condition on test startup
collinjackson 7dff19e
fix formatting
collinjackson 47e1683
Add comments and fix race condition
collinjackson d44dac8
Update e2e package for release
collinjackson a95172c
reformat
collinjackson fc825a1
Tweaks to e2e code
collinjackson 420574a
Better fix for launchActivity issue
collinjackson 9ee1946
Update to point at new e2e release
collinjackson 2626dfe
Fix syntax error
collinjackson bfa4157
Revert e2e changes
collinjackson c6463b2
Indicate dependency_overrides shouldn't be landed
collinjackson 5c5fcd3
reformat
collinjackson 0e4fd83
Update runner reference
collinjackson 64b094b
remove dependency overrides
collinjackson 90c08f3
fix import
collinjackson d9afbdc
bump for release
collinjackson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
62 changes: 62 additions & 0 deletions
62
...roid/app/src/androidTest/java/io/plugins/androidalarmmanager/BackgroundExecutionTest.java
This file contains hidden or 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,62 @@ | ||
| // Copyright 2020 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. | ||
|
|
||
| package io.flutter.plugins.androidalarmmanagerexample; | ||
|
|
||
| import static androidx.test.espresso.Espresso.pressBackUnconditionally; | ||
| import static androidx.test.espresso.flutter.EspressoFlutter.onFlutterWidget; | ||
| import static androidx.test.espresso.flutter.action.FlutterActions.click; | ||
| import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withValueKey; | ||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import android.content.Context; | ||
| import android.content.SharedPreferences; | ||
| import androidx.test.InstrumentationRegistry; | ||
| import androidx.test.core.app.ActivityScenario; | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
| import androidx.test.rule.ActivityTestRule; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @RunWith(AndroidJUnit4.class) | ||
| public class BackgroundExecutionTest { | ||
| private SharedPreferences prefs; | ||
|
|
||
| @Rule | ||
| public ActivityTestRule<MainActivity> myActivityTestRule = | ||
| new ActivityTestRule<>(MainActivity.class, true, false); | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
| prefs = context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE); | ||
| ActivityScenario.launch(MainActivity.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void startBackgroundIsolate() throws Exception { | ||
| final String countKey = "flutter.count"; | ||
|
|
||
| // Register a one shot alarm which will go off in ~5 seconds. | ||
| onFlutterWidget(withValueKey("RegisterOneShotAlarm")).perform(click()); | ||
|
|
||
| // The alarm count should be 0 after installation. | ||
| assertEquals(prefs.getLong(countKey, -1), 0); | ||
|
|
||
| // Close the application to background it. | ||
| pressBackUnconditionally(); | ||
|
|
||
| // The alarm should eventually fire, wake up the application, create a | ||
| // background isolate, and then increment the counter in the shared | ||
| // preferences. Timeout after 20s, just to be safe. | ||
| int tries = 0; | ||
| while ((prefs.getLong(countKey, -1) == 0) && (tries < 200)) { | ||
| Thread.sleep(100); | ||
| ++tries; | ||
| } | ||
| assertEquals(prefs.getLong(countKey, -1), 1); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
8 changes: 8 additions & 0 deletions
8
packages/android_alarm_manager/example/test_driver/alarm_manager_test.dart
This file contains hidden or 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,8 @@ | ||
| import 'package:flutter_driver/driver_extension.dart'; | ||
| // ignore: avoid_relative_lib_import | ||
| import '../lib/main.dart' as app; | ||
|
|
||
| Future<void> main() async { | ||
| enableFlutterDriverExtension(); | ||
| await app.main(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.