package org.wikipedia.test;

import android.content.*;
import android.test.*;
import org.mediawiki.api.json.*;
import org.wikipedia.WikipediaApp;
import org.wikipedia.zero.*;

import java.util.concurrent.*;

public class WikipediaZeroTests extends ActivityUnitTestCase<TestDummyActivity> {
    private static final int TASK_COMPLETION_TIMEOUT = 20000;

    public WikipediaZeroTests() {
        super(TestDummyActivity.class);
    }

    public void testWikipediaZeroEligibilityCheck() throws Throwable {
        final CountDownLatch completionLatch = new CountDownLatch(1);
        startActivity(new Intent(), null, null);
        runTestOnUiThread(new Runnable() {
            @Override
            public void run() {
                new WikipediaZeroTask(new Api("en.wikipedia.org"), (WikipediaApp)getInstrumentation().getTargetContext().getApplicationContext()) {
                    @Override
                    public void onFinish(String result) {
                        assertNotNull(result);
                        completionLatch.countDown();
                    }
                }.execute();
            }
        });
        assertTrue(completionLatch.await(TASK_COMPLETION_TIMEOUT, TimeUnit.MILLISECONDS));
    }
}

@@ -67,24 +67,50 @@
 oid.test.*;%0A
+import java.util.HashMap;%0A
 import org.m
@@ -736,24 +736,160 @@
 oid run() %7B%0A
+                HashMap%3CString,String%3E customHeaders = new HashMap%3CString,String%3E();%0A                customHeaders.put(%22X-CS%22, %22TEST%22);%0A
             
@@ -926,16 +926,18 @@
 Api(%22en.
+m.
 wikipedi
@@ -942,16 +942,90 @@
 dia.org%22
+, %22WMF-Android-AutomationTest-testWikipediaZeroEligibility%22, customHeaders
 ), (Wiki

Make W0 task handler test play more nicely.