Skip to content

Commit 834927c

Browse files
Jami Cogswellatorralba
authored andcommitted
update tests
1 parent 9a7cf7d commit 834927c

File tree

3 files changed

+172
-22
lines changed

3 files changed

+172
-22
lines changed

java/ql/test/library-tests/frameworks/android/intent/TestStartActivityToGetIntent.java

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,96 @@ static Object source(String kind) {
1111
static void sink(Object sink) {}
1212

1313
public void test(Context ctx, Activity act) {
14+
15+
// test all methods that start an activity
16+
{
17+
Intent intent = new Intent(null, SomeActivity.class);
18+
intent.putExtra("data", (String) source("ctx-start"));
19+
ctx.startActivity(intent);
20+
}
21+
{
22+
// Intent intent1 = new Intent(null, SomeActivity2.class);
23+
// intent1.putExtra("data", (String) source("ctx-starts"));
24+
// Intent intent2 = new Intent(null, SomeActivity3.class);
25+
// intent2.putExtra("data", (String) source("ctx-starts"));
26+
// Intent[] intents = {intent1, intent2};
27+
// ctx.startActivities(intents);
28+
}
29+
{
30+
Intent intent = new Intent(null, SomeActivity.class);
31+
intent.putExtra("data", (String) source("act-start"));
32+
act.startActivity(intent);
33+
}
1434
{
15-
Intent intentCtx = new Intent(null, SomeActivity.class);
16-
Intent intentAct = new Intent(null, SomeActivity.class);
17-
intentCtx.putExtra("data", (String) source("context"));
18-
intentAct.putExtra("data", (String) source("activity"));
19-
ctx.startActivity(intentCtx);
20-
act.startActivity(intentAct);
35+
// Intent[] intent = {new Intent(null, SomeActivity.class)};
36+
// intent[0].putExtra("data", (String) source("act-starts"));
37+
// act.startActivities(intent);
38+
}
39+
{
40+
Intent intent = new Intent(null, SomeActivity.class);
41+
intent.putExtra("data", (String) source("start-for-result"));
42+
act.startActivityForResult(intent, 0);
43+
}
44+
{
45+
Intent intent = new Intent(null, SomeActivity.class);
46+
intent.putExtra("data", (String) source("start-if-needed"));
47+
act.startActivityIfNeeded(intent, 0);
48+
}
49+
{
50+
Intent intent = new Intent(null, SomeActivity.class);
51+
intent.putExtra("data", (String) source("start-matching"));
52+
act.startNextMatchingActivity(intent);
53+
}
54+
{
55+
Intent intent = new Intent(null, SomeActivity.class);
56+
intent.putExtra("data", (String) source("start-from-child"));
57+
act.startActivityFromChild(null, intent, 0);
58+
}
59+
{
60+
Intent intent = new Intent(null, SomeActivity.class);
61+
intent.putExtra("data", (String) source("start-from-frag"));
62+
act.startActivityFromFragment(null, intent, 0);
2163
}
2264

65+
// test 4-arg Intent constructor
2366
{
24-
Intent intentCtx = new Intent(null, SafeActivity.class);
25-
Intent intentAct = new Intent(null, SafeActivity.class);
26-
ctx.startActivity(intentCtx);
27-
act.startActivity(intentAct);
67+
Intent intent = new Intent(null, null, null, SomeActivity.class);
68+
intent.putExtra("data", (String) source("4-arg"));
69+
ctx.startActivity(intent);
70+
}
71+
72+
// safe test
73+
{
74+
Intent intent = new Intent(null, SafeActivity.class);
75+
intent.putExtra("data", "safe");
76+
ctx.startActivity(intent);
2877
}
2978
}
3079

3180
static class SomeActivity extends Activity {
3281

3382
public void test() {
34-
sink(getIntent().getStringExtra("data")); // $ hasValueFlow=context hasValueFlow=activity
83+
sink(getIntent().getStringExtra("data")); // $ hasValueFlow=ctx-start hasValueFlow=act-start hasValueFlow=start-for-result hasValueFlow=start-if-needed hasValueFlow=start-matching hasValueFlow=start-from-child hasValueFlow=start-from-frag hasValueFlow=4-arg
3584
}
85+
3686
}
3787

88+
// static class SomeActivity2 extends Activity {
89+
90+
// public void test() {
91+
// sink(getIntent().getStringExtra("data")); // $ hasValueFlow=ctx-starts
92+
// }
93+
94+
// }
95+
96+
// static class SomeActivity3 extends Activity {
97+
98+
// public void test() {
99+
// sink(getIntent().getStringExtra("data")); // $ hasValueFlow=ctx-starts
100+
// }
101+
102+
// }
103+
38104
static class SafeActivity extends Activity {
39105

40106
public void test() {

java/ql/test/library-tests/frameworks/android/intent/TestStartBroadcastReceiverToIntent.java

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,82 @@
44

55
public class TestStartBroadcastReceiverToIntent {
66

7-
static Object source() {
7+
static Object source(String kind) {
88
return null;
99
}
1010

1111
static void sink(Object sink) {}
1212

1313
public void test(Context ctx) {
14+
15+
// test all methods that send a broadcast
16+
{
17+
Intent intent = new Intent(null, SomeBroadcastReceiver.class);
18+
intent.putExtra("data", (String) source("send"));
19+
ctx.sendBroadcast(intent);
20+
}
21+
{
22+
Intent intent = new Intent(null, SomeBroadcastReceiver.class);
23+
intent.putExtra("data", (String) source("send-as-user"));
24+
ctx.sendBroadcastAsUser(intent, null);
25+
}
1426
{
1527
Intent intent = new Intent(null, SomeBroadcastReceiver.class);
16-
intent.putExtra("data", (String) source());
28+
intent.putExtra("data", (String) source("send-with-perm"));
29+
ctx.sendBroadcastWithMultiplePermissions(intent, null);
30+
}
31+
{
32+
Intent intent = new Intent(null, SomeBroadcastReceiver.class);
33+
intent.putExtra("data", (String) source("send-ordered"));
34+
ctx.sendOrderedBroadcast(intent, null);
35+
}
36+
{
37+
Intent intent = new Intent(null, SomeBroadcastReceiver.class);
38+
intent.putExtra("data", (String) source("send-ordered-as-user"));
39+
ctx.sendOrderedBroadcastAsUser(intent, null, null, null, null, 0, null, null);
40+
}
41+
{
42+
Intent intent = new Intent(null, SomeBroadcastReceiver.class);
43+
intent.putExtra("data", (String) source("send-sticky"));
44+
ctx.sendStickyBroadcast(intent);
45+
}
46+
{
47+
Intent intent = new Intent(null, SomeBroadcastReceiver.class);
48+
intent.putExtra("data", (String) source("send-sticky-as-user"));
49+
ctx.sendStickyBroadcastAsUser(intent, null);
50+
}
51+
{
52+
Intent intent = new Intent(null, SomeBroadcastReceiver.class);
53+
intent.putExtra("data", (String) source("send-sticky-ordered"));
54+
ctx.sendStickyOrderedBroadcast(intent, null, null, 0, null, null);
55+
}
56+
{
57+
Intent intent = new Intent(null, SomeBroadcastReceiver.class);
58+
intent.putExtra("data", (String) source("send-sticky-ordered-as-user"));
59+
ctx.sendStickyOrderedBroadcastAsUser(intent, null, null, null, 0, null, null);
60+
}
61+
62+
// test 4-arg Intent constructor
63+
{
64+
Intent intent = new Intent(null, null, null, SomeBroadcastReceiver.class);
65+
intent.putExtra("data", (String) source("4-arg"));
1766
ctx.sendBroadcast(intent);
1867
}
1968

69+
// safe test
2070
{
2171
Intent intent = new Intent(null, SafeBroadcastReceiver.class);
72+
intent.putExtra("data", "safe");
2273
ctx.sendBroadcast(intent);
2374
}
2475
}
2576

2677
static class SomeBroadcastReceiver extends BroadcastReceiver {
2778

79+
// test method that receives an Intent as a parameter
2880
@Override
2981
public void onReceive(Context context, Intent intent) {
30-
sink(intent.getStringExtra("data")); // $ hasValueFlow
82+
sink(intent.getStringExtra("data")); // $ hasValueFlow=send hasValueFlow=send-as-user hasValueFlow=send-with-perm hasValueFlow=send-ordered hasValueFlow=send-ordered-as-user hasValueFlow=send-sticky hasValueFlow=send-sticky-as-user hasValueFlow=send-sticky-ordered hasValueFlow=send-sticky-ordered-as-user hasValueFlow=4-arg
3183
}
3284
}
3385

java/ql/test/library-tests/frameworks/android/intent/TestStartServiceToIntent.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,90 @@
55

66
public class TestStartServiceToIntent {
77

8-
static Object source() {
8+
static Object source(String kind) {
99
return null;
1010
}
1111

1212
static void sink(Object sink) {}
1313

1414
public void test(Context ctx) {
15+
16+
// test all methods that start a service
1517
{
1618
Intent intent = new Intent(null, SomeService.class);
17-
intent.putExtra("data", (String) source());
19+
intent.putExtra("data", (String) source("bind"));
20+
ctx.bindService(intent, null, 0);
21+
}
22+
{
23+
Intent intent = new Intent(null, SomeService.class);
24+
intent.putExtra("data", (String) source("bind-as-user"));
25+
ctx.bindServiceAsUser(intent, null, 0, null);
26+
}
27+
{
28+
Intent intent = new Intent(null, SomeService.class);
29+
intent.putExtra("data", (String) source("bind-isolated"));
30+
ctx.bindIsolatedService(intent, 0, null, null, null);
31+
}
32+
{
33+
Intent intent = new Intent(null, SomeService.class);
34+
intent.putExtra("data", (String) source("start"));
35+
ctx.startService(intent);
36+
}
37+
{
38+
Intent intent = new Intent(null, SomeService.class);
39+
intent.putExtra("data", (String) source("start-foreground"));
40+
ctx.startForegroundService(intent);
41+
}
42+
43+
// test 4-arg Intent constructor
44+
{
45+
Intent intent = new Intent(null, null, null, SomeService.class);
46+
intent.putExtra("data", (String) source("4-arg"));
1847
ctx.startService(intent);
1948
}
2049

50+
// safe test
2151
{
2252
Intent intent = new Intent(null, SafeService.class);
53+
intent.putExtra("data", "safe");
2354
ctx.startService(intent);
2455
}
2556
}
2657

2758
static class SomeService extends Service {
2859

60+
// test methods that receive an Intent as a parameter
2961
@Override
3062
public void onStart(Intent intent, int startId) {
31-
sink(intent.getStringExtra("data")); // $ hasValueFlow
63+
sink(intent.getStringExtra("data")); // $ hasValueFlow=bind hasValueFlow=bind-as-user hasValueFlow=bind-isolated hasValueFlow=start hasValueFlow=start-foreground hasValueFlow=4-arg
3264
}
3365

3466
@Override
3567
public int onStartCommand(Intent intent, int flags, int startId) {
36-
sink(intent.getStringExtra("data")); // $ hasValueFlow
68+
sink(intent.getStringExtra("data")); // $ hasValueFlow=bind hasValueFlow=bind-as-user hasValueFlow=bind-isolated hasValueFlow=start hasValueFlow=start-foreground hasValueFlow=4-arg
3769
return -1;
3870
}
3971

4072
@Override
4173
public IBinder onBind(Intent intent) {
42-
sink(intent.getStringExtra("data")); // $ hasValueFlow
74+
sink(intent.getStringExtra("data")); // $ hasValueFlow=bind hasValueFlow=bind-as-user hasValueFlow=bind-isolated hasValueFlow=start hasValueFlow=start-foreground hasValueFlow=4-arg
4375
return null;
4476
}
4577

4678
@Override
4779
public boolean onUnbind(Intent intent) {
48-
sink(intent.getStringExtra("data")); // $ hasValueFlow
80+
sink(intent.getStringExtra("data")); // $ hasValueFlow=bind hasValueFlow=bind-as-user hasValueFlow=bind-isolated hasValueFlow=start hasValueFlow=start-foreground hasValueFlow=4-arg
4981
return false;
5082
}
5183

5284
@Override
5385
public void onRebind(Intent intent) {
54-
sink(intent.getStringExtra("data")); // $ hasValueFlow
86+
sink(intent.getStringExtra("data")); // $ hasValueFlow=bind hasValueFlow=bind-as-user hasValueFlow=bind-isolated hasValueFlow=start hasValueFlow=start-foreground hasValueFlow=4-arg
5587
}
5688

5789
@Override
5890
public void onTaskRemoved(Intent intent) {
59-
sink(intent.getStringExtra("data")); // $ hasValueFlow
91+
sink(intent.getStringExtra("data")); // $ hasValueFlow=bind hasValueFlow=bind-as-user hasValueFlow=bind-isolated hasValueFlow=start hasValueFlow=start-foreground hasValueFlow=4-arg
6092
}
6193
}
6294

0 commit comments

Comments
 (0)