New issue
Advanced search Search tips

Issue 689142 link

Starred by 1 user

Issue metadata

Status: Untriaged
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

Improve test coverage for Android FRE code

Project Member Reported by asvitk...@chromium.org, Feb 6 2017

Issue description

Improve test coverage for Android FRE code.

The code has a lot of edge cases and is quite fragile.

We should add some tests to get some better test coverage of this.

Planning to give it a shot this week.
 
Just an update on this.

I explored different ways it could be tested.

First, I tried a JUnit test using Robolectric - which supposedly should be able to fake/mock enough stuff to run Activities as a JUnit test. However, it runs into an error:

java.lang.NoClassDefFoundError: android/support/graphics/drawable/AnimatedVectorDrawableCompat
	at android.support.v7.widget.AppCompatDrawableManager.installDefaultInflateDelegates(AppCompatDrawableManager.java:98)
	at android.support.v7.widget.AppCompatDrawableManager.get(AppCompatDrawableManager.java:84)
	at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
	at android.support.v7.app.AppCompatDelegateImplBase.__constructor__(AppCompatDelegateImplBase.java:127)
	at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java)
	at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java)
	at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java)
	at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java)
	at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:205)
	at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
	at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
	at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
	at org.chromium.chrome.browser.init.AsyncInitializationActivity.onCreateInternal(AsyncInitializationActivity.java:247)
	at org.chromium.chrome.browser.init.AsyncInitializationActivity.onCreate(AsyncInitializationActivity.java:225)
	at android.app.Activity.performCreate(Activity.java:5933)
	at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:195)
	at org.robolectric.util.ActivityController$1.run(ActivityController.java:122)
	at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:304)
	at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
	at org.robolectric.util.ActivityController.create(ActivityController.java:118)
	at org.robolectric.util.ActivityController.create(ActivityController.java:129)
	at org.robolectric.util.ActivityController.setup(ActivityController.java:210)
	at org.robolectric.Robolectric.setupActivity(Robolectric.java:46)

It's possible this is something that is fixed in Robolectric 3.2 - which we've not updated to yet (but it's in progress).

I then tried to just add a test under javatests. The case I was planning to write a test for is the race between native init and onFlowIsKnown() which I fixed for crbug.com/683048.

Unfortunately, there's no good way to do this because of the way the code is set up. Ideally, I want to control from the test the timing of the "native init" and "on flow is known" notifications. The second is possible with a bit of refactoring - e.g. going through sGlue to create the sequencer object and having a test version of the glue object that returns a test version of the sequencer. But the native init is invoked by the AsyncInitializationActivity base class so it's harder to mock.

Next, I thought maybe we could refactor most of the logic of the FirstRunActivity into a helper class that's not an Activity itself - so we can just call methods on that. I started on this, but it's quite a bit of work - FirstRunActivity depends on a ton of stuff and it's not obvious whether we can make them all parameters to be passed down from the FirstRunActivity to this class and mock them out or not. This approach still seems promising to me, so I'll keep working on it - but we'll have to see if I end up running into a roadblock.

Just thought I'd update here, since I think getting at least some basic test coverage for this would be good.
Now that we're on robolectric 3.2, thought I'd try it with FirstRunActivity again.

Different error this time:

android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f020052 in packages [android, org.robolectric.default]
	at org.robolectric.shadows.ShadowAssetManager.getResName(ShadowAssetManager.java:868)
	at org.robolectric.shadows.ShadowAssetManager.resolveResourceValue(ShadowAssetManager.java:676)
	at org.robolectric.shadows.ShadowAssetManager.resolve(ShadowAssetManager.java:636)
	at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:630)
	at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:263)
	at android.content.res.AssetManager.getResourceValue(AssetManager.java)
	at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:186)
	at android.content.res.Resources.getValue(Resources.java:1290)
	at android.support.v7.widget.AppCompatDrawableManager.createDrawableIfNeeded(AppCompatDrawableManager.java:234)
	at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
	at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
	at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:723)
	at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
	at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
	at android.support.v7.app.AppCompatDelegateImplBase.__constructor__(AppCompatDelegateImplBase.java:127)
	at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java)
	at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java)
	at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java)
	at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java)
	at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java)
	at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java)
	at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201)
	at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
	at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
	at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:74)
	at org.chromium.chrome.browser.init.AsyncInitializationActivity.onCreateInternal(AsyncInitializationActivity.java:241)
	at org.chromium.chrome.browser.init.AsyncInitializationActivity.onCreate(AsyncInitializationActivity.java:219)
	at android.app.Activity.performCreate(Activity.java:6679)


Owner: ----
Status: Untriaged (was: Assigned)
No longer working on this. Marking Untriaged so that the owners of Android FRE can decide if there's more that should be done here - or close WontFix if not.

Sign in to add a comment