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 = TestWebServer.start();
39 final String pageUrl = webServer.setResponse(path, html, headers);
40 final int callCount = loginRequestHelper.getCallCount();
41 loadUrlAsync(awContents, pageUrl);
42 loginRequestHelper.waitForCallback(callCount);
44 assertEquals(expectedRealm, loginRequestHelper.getRealm());
45 assertEquals(expectedAccount, loginRequestHelper.getAccount());
46 assertEquals(expectedArgs, loginRequestHelper.getArgs());
52 @Feature({"AndroidWebView"})
54 public void testAutoLoginOnGoogleCom() throws Throwable {
56 "testAutoLoginOnGoogleCom", /* testName */
57 "realm=com.google&account=foo%40bar.com&args=random_string", /* xAutoLoginHeader */
58 "com.google", /* expectedRealm */
59 "foo@bar.com", /* expectedAccount */
60 "random_string" /* expectedArgs */);
64 @Feature({"AndroidWebView"})
66 public void testAutoLoginWithNullAccount() throws Throwable {
68 "testAutoLoginOnGoogleCom", /* testName */
69 "realm=com.google&args=not.very.inventive", /* xAutoLoginHeader */
70 "com.google", /* expectedRealm */
71 null, /* expectedAccount */
72 "not.very.inventive" /* expectedArgs */);
75 @Feature({"AndroidWebView"})
77 public void testAutoLoginOnNonGoogle() throws Throwable {
79 "testAutoLoginOnGoogleCom", /* testName */
80 "realm=com.bar&account=foo%40bar.com&args=args", /* xAutoLoginHeader */
81 "com.bar", /* expectedRealm */
82 "foo@bar.com", /* expectedAccount */
83 "args" /* expectedArgs */);