
package org.wikipedia.test;

import android.content.Intent;
import android.test.ActivityUnitTestCase;
import org.wikipedia.Site;
import org.wikipedia.WikipediaApp;
import org.wikipedia.editing.EditTokenStorage;
import org.wikipedia.login.LoginResult;
import org.wikipedia.login.LoginTask;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

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

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

    public void testLogin() throws Throwable {
        startActivity(new Intent(), null, null);
        final Site testWiki = new Site("test.wikipedia.org");
        final String username = getInstrumentation().getContext().getString(R.string.test_username);
        final String password = getInstrumentation().getContext().getString(R.string.test_password);
        final WikipediaApp app = (WikipediaApp)getInstrumentation().getTargetContext().getApplicationContext();

        if (username.equals("Insert-your-test-username-here")) {
            throw new RuntimeException("Use a custom username and password in wikipedia-it/res/values/credentials.xml");
        }

        final CountDownLatch completionLatch = new CountDownLatch(1);
        runTestOnUiThread(new Runnable() {
            @Override
            public void run() {
                new LoginTask(getInstrumentation().getTargetContext(), testWiki, username, password) {
                    @Override
                    public void onFinish(LoginResult result) {
                        super.onFinish(result);
                        assertNotNull(result);
                        assertEquals(result.getCode(), "Success");
                        app.getEditTokenStorage().get(testWiki, new EditTokenStorage.TokenRetreivedCallback() {
                            @Override
                            public void onTokenRetreived(String token) {
                                assertNotNull(token);
                                assertFalse(token.equals("+\\"));
                                completionLatch.countDown();
                            }
                        });
                    }
                }.execute();
            }
        });
        assertTrue(completionLatch.await(TASK_COMPLETION_TIMEOUT, TimeUnit.MILLISECONDS));
    }
}


@@ -1872,18 +1872,18 @@
 okenRetr
-e
 i
+e
 vedCallb
@@ -1983,10 +1983,10 @@
 Retr
-e
 i
+e
 ved(
@@ -2117,24 +2117,24 @@
 ls(%22+%5C%5C%22));%0A
-
             
@@ -2203,32 +2203,248 @@
                %7D
+%0A%0A                            @Override%0A                            public void onTokenFailed(Throwable caught) %7B%0A                                fail(%22onTokenFailed called: %22 + caught);%0A                            %7D
 %0A               

Fix LoginTaskTests