-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix exception clearing after onDestroy in a second RequestManager.
Sequence is either: 1. Obtain a RequestManager for a Fragment 2. Wait for Fragment to be destroyed 3. Start a new load with the RequestManager for the destroyed Fragment 4. Clear the new load with the application RequestManager (or any RequestManager other than the one the load was started with). Or: 1. Obtain a RequestManager for a Fragment 2. Obtain a RequestBuilder from the Fragment RequestManager 3. Pass the RequestBuilder to a background thread 4. Wait for the Fragment to be destroyed 5. Start a load with the RequestBuilder on the background thread 6. Clear the target returned from submit using the application manager.
- Loading branch information
Showing
9 changed files
with
277 additions
and
15 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
instrumentation/src/androidTest/java/com/bumptech/glide/RequestManagerTest.java
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,95 @@ | ||
package com.bumptech.glide; | ||
|
||
import android.content.Context; | ||
import android.graphics.drawable.Drawable; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.widget.ImageView; | ||
import com.bumptech.glide.manager.Lifecycle; | ||
import com.bumptech.glide.manager.LifecycleListener; | ||
import com.bumptech.glide.manager.RequestManagerTreeNode; | ||
import com.bumptech.glide.request.FutureTarget; | ||
import com.bumptech.glide.test.ConcurrencyHelper; | ||
import com.bumptech.glide.test.ResourceIds; | ||
import com.bumptech.glide.test.ResourceIds.raw; | ||
import com.bumptech.glide.test.TearDownGlide; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class RequestManagerTest { | ||
@Rule public TearDownGlide tearDownGlide = new TearDownGlide(); | ||
@Mock private RequestManagerTreeNode treeNode; | ||
|
||
private ConcurrencyHelper concurrency = new ConcurrencyHelper(); | ||
private RequestManager requestManager; | ||
private Context context; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
context = InstrumentationRegistry.getTargetContext(); | ||
Glide glide = Glide.get(context); | ||
requestManager = new RequestManager(glide, new Lifecycle() { | ||
@Override | ||
public void addListener(LifecycleListener listener) { | ||
listener.onStart(); | ||
} | ||
|
||
@Override | ||
public void removeListener(LifecycleListener listener) { | ||
// Do nothing. | ||
} | ||
}, treeNode, context); | ||
} | ||
|
||
/** | ||
* Tests #2262. | ||
*/ | ||
@Test | ||
public void clear_withNonOwningRequestManager_afterOwningManagerIsDestroyed_doesNotThrow() { | ||
// First destroy our Fragment/Activity RequestManager. | ||
requestManager.onDestroy(); | ||
|
||
final ImageView imageView = new ImageView(context); | ||
imageView.measure(100, 100); | ||
imageView.layout(0, 0, 100, 100); | ||
// Then start a new load with our now destroyed RequestManager. | ||
concurrency.loadOnMainThread(requestManager.load(ResourceIds.raw.canonical), imageView); | ||
|
||
// Finally clear our new load with any RequestManager other than the one we used to start it. | ||
concurrency.runOnMainThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
Glide.with(context).clear(imageView); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Tests b/69361054. | ||
*/ | ||
@Test | ||
public void clear_withNonOwningRequestManager_onBackgroundTHread_doesNotThrow() { | ||
concurrency.runOnMainThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
requestManager.onDestroy(); | ||
} | ||
}); | ||
|
||
final FutureTarget<Drawable> target = | ||
concurrency.wait(requestManager.load(raw.canonical).submit()); | ||
|
||
concurrency.runOnMainThread(new Runnable() { | ||
@Override | ||
public void run() { | ||
Glide.with(context).clear(target); | ||
} | ||
}); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.