Commit ff5c1a03 authored by Jian Li's avatar Jian Li Committed by Commit Bot

[Feed v2] Unset RecyclerView.adapter after unbinding

After unbinding from NativeViewListRenderer, we should unset
the adapter of its RecyclerView.

Bug: 1129268
Change-Id: I48a888823647ddcd3e7aad4868d7eb37dec958bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422426Reviewed-by: default avatarDan H <harringtond@chromium.org>
Commit-Queue: Jian Li <jianli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809079}
parent 43373a22
......@@ -89,6 +89,8 @@ public class NativeViewListRenderer extends RecyclerView.Adapter<NativeViewListR
public void unbind() {
mManager.removeObserver(this);
onItemRangeRemoved(0, mManager.getItemCount());
mView.setAdapter(null);
mView.setLayoutManager(null);
mManager = null;
}
......
......@@ -7,6 +7,8 @@ package org.chromium.chrome.browser.feed.v2;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
......@@ -97,6 +99,21 @@ public class NativeViewListRendererTest {
verify(mManager, times(1)).bindNativeView(2, viewHolder.itemView);
}
@Test
@SmallTest
public void testUnbind() {
mManager.addContents(
0, ImmutableList.of(createContent("1"), createContent("2"), createContent("3")));
RecyclerView view = (RecyclerView) mRenderer.bind(mManager);
assertNotNull(view.getAdapter());
assertNotNull(view.getLayoutManager());
mRenderer.unbind();
assertNull(view.getAdapter());
assertNull(view.getLayoutManager());
verify(mRenderer, times(1)).notifyItemRangeRemoved(0, 3);
}
@Test
public void testObserver_itemsAddedOnBind() {
mManager.addContents(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment