2009-04-30 17:14:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.email.activity.setup;
|
|
|
|
|
|
|
|
import com.android.email.R;
|
2009-06-15 21:40:06 +00:00
|
|
|
import com.android.email.provider.EmailContent;
|
2010-02-03 18:38:27 +00:00
|
|
|
import com.android.email.provider.ProviderTestUtils;
|
|
|
|
import com.android.email.provider.EmailContent.Account;
|
|
|
|
import com.android.email.provider.EmailContent.HostAuth;
|
2009-04-30 17:14:00 +00:00
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.test.ActivityInstrumentationTestCase2;
|
|
|
|
import android.test.UiThreadTest;
|
|
|
|
import android.test.suitebuilder.annotation.MediumTest;
|
2010-02-03 18:38:27 +00:00
|
|
|
import android.view.View;
|
2009-04-30 17:14:00 +00:00
|
|
|
import android.widget.Button;
|
2010-02-03 18:38:27 +00:00
|
|
|
import android.widget.CheckBox;
|
2009-04-30 17:14:00 +00:00
|
|
|
import android.widget.EditText;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests of the basic UI logic in the Account Setup Incoming (IMAP / POP3) screen.
|
|
|
|
*/
|
|
|
|
@MediumTest
|
2010-01-27 16:55:48 +00:00
|
|
|
public class AccountSetupExchangeTests extends
|
2009-04-30 17:14:00 +00:00
|
|
|
ActivityInstrumentationTestCase2<AccountSetupExchange> {
|
2010-02-02 23:06:52 +00:00
|
|
|
//EXCHANGE-REMOVE-SECTION-START
|
2009-04-30 17:14:00 +00:00
|
|
|
private AccountSetupExchange mActivity;
|
|
|
|
private EditText mServerView;
|
|
|
|
private Button mNextButton;
|
2010-02-03 18:38:27 +00:00
|
|
|
private CheckBox mSslRequiredCheckbox;
|
|
|
|
private CheckBox mTrustAllCertificatesCheckbox;
|
2010-02-02 23:06:52 +00:00
|
|
|
//EXCHANGE-REMOVE-SECTION-END
|
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
public AccountSetupExchangeTests() {
|
|
|
|
super("com.android.email", AccountSetupExchange.class);
|
|
|
|
}
|
|
|
|
|
2010-02-02 23:06:52 +00:00
|
|
|
//EXCHANGE-REMOVE-SECTION-START
|
2009-04-30 17:14:00 +00:00
|
|
|
/**
|
|
|
|
* Common setup code for all tests. Sets up a default launch intent, which some tests
|
|
|
|
* will use (others will override).
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
|
|
|
|
// This sets up a default URI which can be used by any of the test methods below.
|
|
|
|
// Individual test methods can replace this with a custom URI if they wish
|
|
|
|
// (except those that run on the UI thread - for them, it's too late to change it.)
|
2009-09-05 22:14:46 +00:00
|
|
|
Intent i = getTestIntent("eas://user:password@server.com");
|
2009-04-30 17:14:00 +00:00
|
|
|
setActivityIntent(i);
|
|
|
|
}
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
/**
|
|
|
|
* Test processing with a complete, good URI -> good fields
|
|
|
|
*/
|
|
|
|
public void testGoodUri() {
|
2009-09-05 22:14:46 +00:00
|
|
|
Intent i = getTestIntent("eas://user:password@server.com");
|
2009-04-30 17:14:00 +00:00
|
|
|
setActivityIntent(i);
|
|
|
|
getActivityAndFields();
|
|
|
|
assertTrue(mNextButton.isEnabled());
|
|
|
|
}
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-09-05 22:14:46 +00:00
|
|
|
// TODO Add tests for valid usernames in eas
|
|
|
|
// They would be <name> or <name>\<domain> or <name>/<domain> or a valid email address
|
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
/**
|
|
|
|
* No user is not OK - not enabled
|
|
|
|
*/
|
|
|
|
public void testBadUriNoUser() {
|
2009-09-05 22:14:46 +00:00
|
|
|
Intent i = getTestIntent("eas://:password@server.com");
|
2009-04-30 17:14:00 +00:00
|
|
|
setActivityIntent(i);
|
|
|
|
getActivityAndFields();
|
|
|
|
assertFalse(mNextButton.isEnabled());
|
|
|
|
}
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
/**
|
|
|
|
* No password is not OK - not enabled
|
|
|
|
*/
|
|
|
|
public void testBadUriNoPassword() {
|
2009-09-05 22:14:46 +00:00
|
|
|
Intent i = getTestIntent("eas://user@server.com");
|
2009-04-30 17:14:00 +00:00
|
|
|
setActivityIntent(i);
|
|
|
|
getActivityAndFields();
|
|
|
|
assertFalse(mNextButton.isEnabled());
|
|
|
|
}
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
/**
|
|
|
|
* Test for non-standard but OK server names
|
|
|
|
*/
|
|
|
|
@UiThreadTest
|
|
|
|
public void testGoodServerVariants() {
|
|
|
|
getActivityAndFields();
|
|
|
|
assertTrue(mNextButton.isEnabled());
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
mServerView.setText(" server.com ");
|
|
|
|
assertTrue(mNextButton.isEnabled());
|
|
|
|
}
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
/**
|
|
|
|
* Test for non-empty but non-OK server names
|
|
|
|
*/
|
|
|
|
@UiThreadTest
|
|
|
|
public void testBadServerVariants() {
|
|
|
|
getActivityAndFields();
|
|
|
|
assertTrue(mNextButton.isEnabled());
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
mServerView.setText(" ");
|
|
|
|
assertFalse(mNextButton.isEnabled());
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
mServerView.setText("serv$er.com");
|
|
|
|
assertFalse(mNextButton.isEnabled());
|
|
|
|
}
|
2010-02-03 18:38:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test aspects of loadFields()
|
|
|
|
*
|
|
|
|
* TODO: More cases
|
|
|
|
*/
|
|
|
|
@UiThreadTest
|
|
|
|
public void testLoadFields() {
|
|
|
|
// The default URI has no SSL and no "trust"
|
|
|
|
getActivityAndFields();
|
|
|
|
assertFalse(mSslRequiredCheckbox.isChecked());
|
|
|
|
assertFalse(mTrustAllCertificatesCheckbox.isChecked());
|
|
|
|
assertFalse(mTrustAllCertificatesCheckbox.getVisibility() == View.VISIBLE);
|
|
|
|
|
|
|
|
// Setup host auth with variants of SSL enabled and check. This also enables the
|
|
|
|
// "trust certificates" checkbox (not checked, but visible now).
|
|
|
|
Account account =
|
|
|
|
ProviderTestUtils.setupAccount("account", false, mActivity.getBaseContext());
|
|
|
|
account.mHostAuthRecv =
|
|
|
|
ProviderTestUtils.setupHostAuth("hostauth", 1, false, mActivity.getBaseContext());
|
|
|
|
account.mHostAuthRecv.mFlags |= HostAuth.FLAG_SSL;
|
|
|
|
account.mHostAuthRecv.mFlags &= ~HostAuth.FLAG_TRUST_ALL_CERTIFICATES;
|
|
|
|
mActivity.loadFields(account);
|
|
|
|
assertTrue(mSslRequiredCheckbox.isChecked());
|
|
|
|
assertFalse(mTrustAllCertificatesCheckbox.isChecked());
|
|
|
|
assertTrue(mTrustAllCertificatesCheckbox.getVisibility() == View.VISIBLE);
|
|
|
|
|
|
|
|
// Setup host auth with variants of SSL enabled and check. This also enables the
|
|
|
|
// "trust certificates" checkbox (not checked, but visible now).
|
|
|
|
account.mHostAuthRecv.mFlags |= HostAuth.FLAG_TRUST_ALL_CERTIFICATES;
|
|
|
|
mActivity.loadFields(account);
|
|
|
|
assertTrue(mSslRequiredCheckbox.isChecked());
|
|
|
|
assertTrue(mTrustAllCertificatesCheckbox.isChecked());
|
|
|
|
assertTrue(mTrustAllCertificatesCheckbox.getVisibility() == View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: Directly test validateFields() checking boolean result
|
|
|
|
*/
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
/**
|
|
|
|
* Get the activity (which causes it to be started, using our intent) and get the UI fields
|
|
|
|
*/
|
|
|
|
private void getActivityAndFields() {
|
|
|
|
mActivity = getActivity();
|
|
|
|
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
|
|
|
mNextButton = (Button) mActivity.findViewById(R.id.next);
|
2010-02-03 18:38:27 +00:00
|
|
|
mSslRequiredCheckbox = (CheckBox) mActivity.findViewById(R.id.account_ssl);
|
|
|
|
mTrustAllCertificatesCheckbox =
|
|
|
|
(CheckBox) mActivity.findViewById(R.id.account_trust_certificates);
|
2009-04-30 17:14:00 +00:00
|
|
|
}
|
2010-02-02 23:06:52 +00:00
|
|
|
|
2009-04-30 17:14:00 +00:00
|
|
|
/**
|
|
|
|
* Create an intent with the Account in it
|
|
|
|
*/
|
|
|
|
private Intent getTestIntent(String storeUriString) {
|
2009-06-15 21:40:06 +00:00
|
|
|
EmailContent.Account account = new EmailContent.Account();
|
2009-06-09 21:46:30 +00:00
|
|
|
account.setStoreUri(getInstrumentation().getTargetContext(), storeUriString);
|
2009-04-30 17:14:00 +00:00
|
|
|
Intent i = new Intent(Intent.ACTION_MAIN);
|
2010-01-27 16:55:48 +00:00
|
|
|
i.putExtra(AccountSetupExchange.EXTRA_ACCOUNT, account);
|
|
|
|
i.putExtra(AccountSetupExchange.EXTRA_DISABLE_AUTO_DISCOVER, true);
|
2009-04-30 17:14:00 +00:00
|
|
|
return i;
|
|
|
|
}
|
2010-02-02 23:06:52 +00:00
|
|
|
//EXCHANGE-REMOVE-SECTION-END
|
2009-04-30 17:14:00 +00:00
|
|
|
}
|