26
26
import java .util .ArrayList ;
27
27
28
28
import org .catrobat .catroid .ProjectManager ;
29
+ import org .catrobat .catroid .R ;
29
30
import org .catrobat .catroid .common .Constants ;
30
31
import org .catrobat .catroid .common .SoundInfo ;
31
32
import org .catrobat .catroid .soundrecorder .SoundRecorderActivity ;
33
+ import org .catrobat .catroid .ui .MainMenuActivity ;
32
34
import org .catrobat .catroid .ui .ScriptTabActivity ;
33
35
import org .catrobat .catroid .uitest .util .UiTestUtils ;
34
36
import org .catrobat .catroid .utils .Utils ;
35
37
38
+ import android .content .pm .ActivityInfo ;
39
+ import android .content .pm .PackageManager ;
40
+ import android .content .pm .PackageManager .NameNotFoundException ;
41
+ import android .content .res .Configuration ;
36
42
import android .test .ActivityInstrumentationTestCase2 ;
37
- import org .catrobat .catroid .R ;
38
43
39
44
import com .jayway .android .robotium .solo .Solo ;
40
45
41
- public class SoundRecorderTest extends ActivityInstrumentationTestCase2 <ScriptTabActivity > {
46
+ public class SoundRecorderTest extends ActivityInstrumentationTestCase2 <MainMenuActivity > {
42
47
43
48
private Solo solo ;
44
49
45
50
public SoundRecorderTest () {
46
- super (ScriptTabActivity .class );
51
+ super (MainMenuActivity .class );
47
52
}
48
53
49
54
@ Override
@@ -53,6 +58,7 @@ public void setUp() throws Exception {
53
58
UiTestUtils .createTestProject ();
54
59
55
60
solo = new Solo (getInstrumentation (), getActivity ());
61
+ UiTestUtils .getIntoScriptTabActivityFromMainMenu (solo );
56
62
}
57
63
58
64
@ Override
@@ -64,6 +70,29 @@ public void tearDown() throws Exception {
64
70
solo = null ;
65
71
}
66
72
73
+ public void testOrientation () throws NameNotFoundException {
74
+ prepareRecording ();
75
+ solo .waitForActivity (SoundRecorderActivity .class .getSimpleName ());
76
+ /// Method 1: Assert it is currently in portrait mode.
77
+ assertEquals ("SoundRecorderActivity not in Portrait mode!" , Configuration .ORIENTATION_PORTRAIT , solo
78
+ .getCurrentActivity ().getResources ().getConfiguration ().orientation );
79
+
80
+ /// Method 2: Retreive info about Activity as collected from AndroidManifest.xml
81
+ // https://developer.android.com/reference/android/content/pm/ActivityInfo.html
82
+ PackageManager packageManager = solo .getCurrentActivity ().getPackageManager ();
83
+ ActivityInfo activityInfo = packageManager .getActivityInfo (solo .getCurrentActivity ().getComponentName (),
84
+ PackageManager .GET_ACTIVITIES );
85
+
86
+ // Note that the activity is _indeed_ rotated on your device/emulator!
87
+ // Robotium can _force_ the activity to be in landscape mode (and so could we, programmatically)
88
+ solo .setActivityOrientation (Solo .LANDSCAPE );
89
+ solo .sleep (200 );
90
+
91
+ assertEquals (SoundRecorderActivity .class .getSimpleName ()
92
+ + " not set to be in portrait mode in AndroidManifest.xml!" , ActivityInfo .SCREEN_ORIENTATION_PORTRAIT ,
93
+ activityInfo .screenOrientation );
94
+ }
95
+
67
96
public void testRecordMultipleSounds () throws InterruptedException {
68
97
prepareRecording ();
69
98
recordSoundWithChangingOrientation ();
@@ -77,22 +106,18 @@ public void testRecordMultipleSounds() throws InterruptedException {
77
106
public void recordSoundWithChangingOrientation () throws InterruptedException {
78
107
solo .waitForActivity (SoundRecorderActivity .class .getSimpleName ());
79
108
solo .clickOnText (solo .getString (R .string .soundrecorder_record_start ));
80
- solo .setActivityOrientation (Solo .LANDSCAPE );
81
- solo .setActivityOrientation (Solo .PORTRAIT );
109
+ solo .sleep (500 );
82
110
solo .clickOnText (solo .getString (R .string .soundrecorder_record_stop ));
83
111
}
84
112
85
113
public void recordSoundGoBackWhileRecording () throws InterruptedException {
86
114
solo .waitForActivity (SoundRecorderActivity .class .getSimpleName ());
87
115
solo .clickOnText (solo .getString (R .string .soundrecorder_record_start ));
88
- solo .setActivityOrientation (Solo .LANDSCAPE );
89
-
116
+ solo .sleep (500 );
90
117
solo .goBack ();
91
- solo .setActivityOrientation (Solo .PORTRAIT );
92
118
}
93
119
94
120
private void prepareRecording () {
95
- solo .setActivityOrientation (Solo .PORTRAIT );
96
121
solo .clickOnText (solo .getString (R .string .sounds ));
97
122
98
123
UiTestUtils .clickOnActionBar (solo , R .id .menu_add );
0 commit comments