1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview.test;
7 import android.test.suitebuilder.annotation.SmallTest;
8 import android.util.Pair;
10 import org.chromium.android_webview.AwContents;
11 import org.chromium.android_webview.test.TestAwContentsClient.OnReceivedLoginRequestHelper;
12 import org.chromium.base.test.util.Feature;
13 import org.chromium.net.test.util.TestWebServer;
15 import java.util.ArrayList;
16 import java.util.List;
19 * Tests for the AwContentsClient.onReceivedLoginRequest callback.
21 public class AwContentsClientAutoLoginTest extends AwTestBase {
22 private TestAwContentsClient mContentsClient = new TestAwContentsClient();
24 private void autoLoginTestHelper(final String testName, final String xAutoLoginHeader,
25 final String expectedRealm, final String expectedAccount, final String expectedArgs)
27 AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient);
28 AwContents awContents = testView.getAwContents();
29 final OnReceivedLoginRequestHelper loginRequestHelper =
30 mContentsClient.getOnReceivedLoginRequestHelper();
32 final String path = "/" + testName + ".html";
33 final String html = testName;
34 List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>();
35 headers.add(Pair.create("x-auto-login", xAutoLoginHeader));
37 TestWebServer webServer = null;
39 webServer = new TestWebServer(false);
40 final String pageUrl = webServer.setResponse(path, html, headers);
41 final int callCount = loginRequestHelper.getCallCount();
42 loadUrlAsync(awContents, pageUrl);
43 loginRequestHelper.waitForCallback(callCount);
45 assertEquals(expectedRealm, loginRequestHelper.getRealm());
46 assertEquals(expectedAccount, loginRequestHelper.getAccount());
47 assertEquals(expectedArgs, loginRequestHelper.getArgs());
49 if (webServer != null) webServer.shutdown();
53 @Feature({"AndroidWebView"})
55 public void testAutoLoginOnGoogleCom() throws Throwable {
57 "testAutoLoginOnGoogleCom", /* testName */
58 "realm=com.google&account=foo%40bar.com&args=random_string", /* xAutoLoginHeader */
59 "com.google", /* expectedRealm */
60 "foo@bar.com", /* expectedAccount */
61 "random_string" /* expectedArgs */);
65 @Feature({"AndroidWebView"})
67 public void testAutoLoginWithNullAccount() throws Throwable {
69 "testAutoLoginOnGoogleCom", /* testName */
70 "realm=com.google&args=not.very.inventive", /* xAutoLoginHeader */
71 "com.google", /* expectedRealm */
72 null, /* expectedAccount */
73 "not.very.inventive" /* expectedArgs */);
76 @Feature({"AndroidWebView"})
78 public void testAutoLoginOnNonGoogle() throws Throwable {
80 "testAutoLoginOnGoogleCom", /* testName */
81 "realm=com.bar&account=foo%40bar.com&args=args", /* xAutoLoginHeader */
82 "com.bar", /* expectedRealm */
83 "foo@bar.com", /* expectedAccount */
84 "args" /* expectedArgs */);