New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace RoboWindow with PhoneWindow #659
Conversation
@@ -39,6 +39,7 @@ public Dependency getSystemResourceDependency() { | |||
realAndroidDependency("android-base"), | |||
realAndroidDependency("android-kxml2"), | |||
realAndroidDependency("android-luni"), | |||
realAndroidDependency("android-policy"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the reference to the jar that will need uploaded to Maven to make this work properly.
@buddhistpirate and I can test this out since we are currently trying to run some tests with our ActionBar. |
+1 works for me. |
} | ||
|
||
@Test | ||
public void contentViewShouldBeMeasuredWithSpecExactly() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for me this test should be kept somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this change switches out the RoboWindow
for the PhoneWindow
(which is the same code that runs on the phone) it will use the 'correct' (whatever Android thinks is correct 😉) MeasureSpec. I wrote up a quick modification to the test that doesn't use RoboWindow
here.
The test passes but we don't really need to care as PhoneWindow
will do the correct thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yeah, it makes sense.
I'm trying it with AppCompat library and getting
I do not call |
@roman-mazur Thanks for trying this out! ❤️ Hmmm. Somehow What does the test you're running look like exactly? |
@seadowg Here is an example: https://gist.github.com/roman-mazur/6316618 |
@roman-mazur I can't see anything immediately obvious... We'll have a look at it tomorrow. Thanks! |
@roman-mazur we believe we've fixed the problem with feature requests. Would you be able to pull the change in and try it if you get time? It seems that we have to delay setting up the Activity with it's |
If memory serves, |
Should we try this again? |
@tjohn your issue seems to be caused by another problem in Robolectric that the PhoneWindow exposes (by calling |
@JakeWharton Yeah that seems to be true but Android weirdly doesn't add the decor view to the Activity's Currently we're setting |
@@ -178,6 +183,18 @@ public void run() { | |||
return this; | |||
} | |||
|
|||
public ActivityController<T> visible() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be called in tests that deal with View.isShown
. It operation could happen at the end of postResume
but I feel this is more explicit (and mirrors real life more accurately as it really happens sometime after postResume
when the Activity is on screen).
This does make everything quite verbose though. Maybe there needs to be a simpler helper that runs through the whole initialization life cycle (including visible
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there needs to be a simpler helper that runs through the whole initialization life cycle (including
visible
)?
Yes. Sounds reasonable and useful.
Another thing to consider is that the lifecycle is a state machine. Perhaps this class should mirror that state machine more closely by playing any missing steps automatically. This way, calling something like destroy()
would automatically hit onPause
, onStop
, and then onDestroy
.
@seadowg I'll be able to try it again next week only. Actually in real world I may add views to a window without calling
|
This looks promising! It's a big change though. Seems like we should try to get this code into as many Robolectric 2.0 projects as we can, to be sure that it doesn't break people in weird ways. @seadowg, would it be worthwhile to post a message to the Robolectric google group to see if more people will try this fork and give feedback? |
@roman-mazur Thanks! Adding a fragment like this will work as @mag Good idea! We'll post a message there. |
@seadowg I've tried it once more. Here is the error stacktrace I'm getting
|
Hi Roman, Thanks a lot for documenting this problem. We (@coreydowning and I) spent some time looking at this yesterday. Unfortunately this pull request isn't working correctly with AppCompat. Here's our naive understanding of why: The base Theme used by AppCompat sets android:windowNoTitle to 'true'. According to the comment on line 94 of
PhoneWindow sees this attribute and decides there is no ActionBar...and whatever is supposed to put it back is not happening (or at least, not at the right time). We haven't quite figured out what the appropriate approach to this would be. We believe that this pull request shouldn't be blocked by an incompatibility with AppCompat, as you will be no worse off with this change than you were before. However, if we get this through, a new issue should be raised to flag this problem. |
OK, pushing up the rebase now. Also looking into pushing this to sonatype which sounds reasonable on our end. |
In other news: @coreydowning and I ran some loose experiments with one of our internal projects, and this branch actually ran our tests a bit faster (~10 seconds faster on ~1.25 minute test suite). So while that's just one project, we are confident this doesn't slow things down much if at all. |
…of RoboWindowManager
…to it (with getViews) The Shadow calls the real object in the @implementation methods so no reality is lost.
…s might break realism but makes everything work)
…g errors in PhoneWindow.measure().
…vity create This also makes the ActionBar feature work by default which may be problematic for older applications.
This means that ActivityController.create now has to set up the Activity window to be visible
This value needs to be set to the Window's decor view and this can not be accessed until after onCreate is called or feature requests will fail within onCreate.
This just switches the tests to use a View that follows a standard lifecycle rather than setting the contentView after resuming.
…visible This method adds the Activity's window decor view to the window manager. This is required for `View.isShown` to return true as otherwise the Activity's view hierarchy won't have a parent. In real life this happens some time after the Activity resumes (in `ActivityThread`) so it really needs to be its own lifecycle operation (even though its not part of the 'official' lifecycle).
Conflicts: .pairs src/main/java/org/robolectric/shadows/ShadowActivity.java src/main/java/org/robolectric/util/ActivityController.java Also removed `ShadowActivity#setContentView` because we can use the real one now 😄
This allows the phone-window branch to work without manually mavenizing the Android policy jar. This should probably be removed once the policy jar is in maven central. :sunglasses:
@coreydowning 😆 Travis passing? Nice one guys! |
👍 Good to merge then? |
@JakeWharton Sure, go for it. We think this is pretty safe at this point and no major objections have been raised in the community. @coreydowning says SHIP IT 🌋 |
Replace RoboWindow with PhoneWindow
... ☁️ 🔌 🐑 ❓ |
Any news as to when will AppCompat will be compatible with Robolectric 2.2? I have been trying to make my 2.1 tests to pass with 2.2 but they simple wot pass. What is happening in my tests is that the Theme.AppCompat is being set but when ActionBarActivityDelegate runs onCreate the first thing it does is to get I've been debuging the latest master and it seems that the method ShadowResources.attrsToTypedArray can't handle getting the attributes for the Theme.AppCompat. Not sure what is the problem, even debugging I don't know enough of robolectrics internals to find the issue. And God is it hard to debug with the custom class loaders and shadows popping every single step XD. |
Basic motivation for this was to allow for
Activity.getActionBar()
to return a realActionBar
instance.This changes a lot of the code but hopefully benefits Robolectric in a large way as the real Window code is being utilized. There's probably still some work to be done here but we wanted to get a dialog going. Any concerns we have we'll put in line notes on the file changes (Github doesn't let you do this until after posting the request 😕).
This change also requires an extra Android dependency with the compiled
PhoneWindow
code. This jar would need to be uploaded to org.robolectric on Maven but we currently have a version of the jar with a script for Mavenizing you can grab here.In other news, this does currently pass all the tests and RobolectricSample runs with this version just fine 😄.