Search in sources :

Example 1 with PageBackStackItem

use of org.wikipedia.page.PageBackStackItem in project apps-android-wikipedia by wikimedia.

the class TabUnmarshaller method unmarshal.

@NonNull
public static List<Tab> unmarshal(@Nullable String json) {
    List<Tab> object = null;
    try {
        object = GsonUnmarshaller.unmarshal(TYPE_TOKEN, json);
    } catch (Exception e) {
        // Catch all. Any Exception can be thrown when unmarshalling.
        L.logRemoteErrorIfProd(new RemoteLogException(e).put("json", json));
    }
    if (object == null) {
        object = Collections.emptyList();
    }
    // T152980
    // When upgrading from much older versions (namely, 2.1.141 or earlier), the serialized
    // tab list may be in a format that causes WikiSite objects to have null Uri components.
    // If we encounter one of these occurrences, just clear out the entire tab list.
    // to be on the safe side.
    // TODO: Remove when the incidence of this is sufficiently diminished (April 2017?)
    boolean bad = false;
    for (Tab tab : object) {
        for (PageBackStackItem item : tab.getBackStack()) {
            if (TextUtils.isEmpty(item.getTitle().getWikiSite().authority()) || TextUtils.isEmpty(item.getHistoryEntry().getTitle().getWikiSite().authority())) {
                L.logRemoteErrorIfProd(new IllegalArgumentException("Format error in serialized tab list."));
                bad = true;
                break;
            }
        }
    }
    if (bad) {
        object.clear();
    }
    return object;
}
Also used : RemoteLogException(org.wikipedia.crash.RemoteLogException) Tab(org.wikipedia.page.tabs.Tab) PageBackStackItem(org.wikipedia.page.PageBackStackItem) RemoteLogException(org.wikipedia.crash.RemoteLogException) NonNull(android.support.annotation.NonNull)

Example 2 with PageBackStackItem

use of org.wikipedia.page.PageBackStackItem in project apps-android-wikipedia by wikimedia.

the class TabUnmarshallerTest method testUnmarshalSingle.

@Test
public void testUnmarshalSingle() {
    PageTitle page = new PageTitle("text", WikiSite.forLanguageCode("test"));
    HistoryEntry history = new HistoryEntry(page, new Date(0), HistoryEntry.SOURCE_SEARCH);
    Tab tab = new Tab();
    tab.getBackStack().add(new PageBackStackItem(page, history));
    List<Tab> tabs = singletonList(tab);
    assertThat(TabUnmarshaller.unmarshal(GsonMarshaller.marshal(tabs)), is(tabs));
}
Also used : Tab(org.wikipedia.page.tabs.Tab) PageTitle(org.wikipedia.page.PageTitle) HistoryEntry(org.wikipedia.history.HistoryEntry) PageBackStackItem(org.wikipedia.page.PageBackStackItem) Date(java.util.Date) Test(org.junit.Test)

Example 3 with PageBackStackItem

use of org.wikipedia.page.PageBackStackItem in project apps-android-wikipedia by wikimedia.

the class TabUnmarshallerTest method testUnmarshalNoHistoryEntryAuthority.

// T152980
@Test(expected = RuntimeException.class)
public void testUnmarshalNoHistoryEntryAuthority() {
    PageTitle page = new PageTitle("text", WikiSite.forLanguageCode("test"));
    PageTitle prevPage = new PageTitle("text", new WikiSite("", ""));
    HistoryEntry history = new HistoryEntry(prevPage, new Date(0), HistoryEntry.SOURCE_SEARCH);
    Tab tab = new Tab();
    tab.getBackStack().add(new PageBackStackItem(page, history));
    List<Tab> tabs = singletonList(tab);
    TabUnmarshaller.unmarshal(GsonMarshaller.marshal(tabs));
}
Also used : Tab(org.wikipedia.page.tabs.Tab) PageTitle(org.wikipedia.page.PageTitle) HistoryEntry(org.wikipedia.history.HistoryEntry) WikiSite(org.wikipedia.dataclient.WikiSite) PageBackStackItem(org.wikipedia.page.PageBackStackItem) Date(java.util.Date) Test(org.junit.Test)

Example 4 with PageBackStackItem

use of org.wikipedia.page.PageBackStackItem in project apps-android-wikipedia by wikimedia.

the class TabUnmarshallerTest method testUnmarshalNoPageTitleAuthority.

// T152980
@Test(expected = RuntimeException.class)
public void testUnmarshalNoPageTitleAuthority() {
    PageTitle page = new PageTitle("text", new WikiSite("", ""));
    HistoryEntry history = new HistoryEntry(page, new Date(0), HistoryEntry.SOURCE_SEARCH);
    Tab tab = new Tab();
    tab.getBackStack().add(new PageBackStackItem(page, history));
    List<Tab> tabs = singletonList(tab);
    TabUnmarshaller.unmarshal(GsonMarshaller.marshal(tabs));
}
Also used : Tab(org.wikipedia.page.tabs.Tab) PageTitle(org.wikipedia.page.PageTitle) HistoryEntry(org.wikipedia.history.HistoryEntry) WikiSite(org.wikipedia.dataclient.WikiSite) PageBackStackItem(org.wikipedia.page.PageBackStackItem) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PageBackStackItem (org.wikipedia.page.PageBackStackItem)4 Tab (org.wikipedia.page.tabs.Tab)4 Date (java.util.Date)3 Test (org.junit.Test)3 HistoryEntry (org.wikipedia.history.HistoryEntry)3 PageTitle (org.wikipedia.page.PageTitle)3 WikiSite (org.wikipedia.dataclient.WikiSite)2 NonNull (android.support.annotation.NonNull)1 RemoteLogException (org.wikipedia.crash.RemoteLogException)1