• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.angleIntegrationTest.driverTestSecondary;
18 
19 import static org.junit.Assert.fail;
20 
21 import androidx.test.rule.ActivityTestRule;
22 import androidx.test.runner.AndroidJUnit4;
23 
24 import com.android.angleIntegrationTest.common.AngleIntegrationTestActivity;
25 import com.android.angleIntegrationTest.common.GlesView;
26 
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 
31 @RunWith(AndroidJUnit4.class)
32 public class AngleDriverTestActivity {
33 
34     private final String TAG = this.getClass().getSimpleName();
35 
36     @Rule
37     public ActivityTestRule<AngleIntegrationTestActivity> rule =
38             new ActivityTestRule<>(AngleIntegrationTestActivity.class);
39 
validateDeveloperOption(boolean angleEnabled)40     private void validateDeveloperOption(boolean angleEnabled) throws Exception {
41         AngleIntegrationTestActivity activity = rule.getActivity();
42         GlesView glesView = activity.getGlesView();
43         String renderer = glesView.getRenderer();
44 
45         if (angleEnabled) {
46             if (!renderer.toLowerCase().contains("ANGLE".toLowerCase())) {
47                 fail("Failure - ANGLE was not loaded: '" + renderer + "'");
48             }
49         } else {
50             if (renderer.toLowerCase().contains("ANGLE".toLowerCase())) {
51                 fail("Failure - ANGLE was loaded: '" + renderer + "'");
52             }
53         }
54 
55     }
56 
57     @Test
testUseDefaultDriver()58     public void testUseDefaultDriver() throws Exception {
59         // The rules file does not enable ANGLE for this app
60         validateDeveloperOption(false);
61     }
62 
63     @Test
testUseAngleDriver()64     public void testUseAngleDriver() throws Exception {
65         validateDeveloperOption(true);
66     }
67 
68     @Test
testUseNativeDriver()69     public void testUseNativeDriver() throws Exception {
70         validateDeveloperOption(false);
71     }
72 }
73