aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java
blob: 75197ac9e26f32a7c42a24359b33a08e1076b421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright (C) 2015 Vincent Breitmoser <look@my.amazin.horse>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package org.sufficientlysecure.keychain.actions;


import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.View;

import com.tokenautocomplete.TokenCompleteTextView;
import org.hamcrest.Matcher;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;

import static android.support.test.InstrumentationRegistry.getTargetContext;


public abstract class CustomActions {

    public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception {
        CanonicalizedPublicKeyRing ring =
                new ProviderHelper(getTargetContext()).getCanonicalizedPublicKeyRing(keyId);
        final Object item = new KeyAdapter.KeyItem(ring);

        return new ViewAction() {
            @Override
            public Matcher<View> getConstraints() {
                return ViewMatchers.isAssignableFrom(TokenCompleteTextView.class);
            }

            @Override
            public String getDescription() {
                return "add completion token";
            }

            @Override
            public void perform(UiController uiController, View view) {
                ((TokenCompleteTextView) view).addObject(item);
            }
        };
    }

    public static ViewAction tokenViewAddToken(final Object item) {
        return new ViewAction() {
            @Override
            public Matcher<View> getConstraints() {
                return ViewMatchers.isAssignableFrom(TokenCompleteTextView.class);
            }

            @Override
            public String getDescription() {
                return "add completion token";
            }

            @Override
            public void perform(UiController uiController, View view) {
                ((TokenCompleteTextView) view).addObject(item);
            }
        };
    }

}