calabash-android 0.4.0.pre1 → 0.4.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/bin/calabash-android-build.rb +6 -0
  2. data/bin/calabash-android-setup.rb +2 -3
  3. data/lib/calabash-android/canned_steps.md +1 -1
  4. data/lib/calabash-android/helpers.rb +35 -2
  5. data/lib/calabash-android/lib/TestServer.apk +0 -0
  6. data/lib/calabash-android/operations.rb +13 -6
  7. data/lib/calabash-android/version.rb +1 -1
  8. data/test-server/instrumentation-backend/.classpath +2 -1
  9. data/test-server/instrumentation-backend/antlr.sh +2 -0
  10. data/test-server/instrumentation-backend/antlr/UIQuery.g +70 -0
  11. data/test-server/instrumentation-backend/antlr/UIQuery.tokens +12 -0
  12. data/test-server/instrumentation-backend/build-libs/antlr-3.4-complete.jar +0 -0
  13. data/test-server/instrumentation-backend/build-libs/junit.jar +0 -0
  14. data/test-server/instrumentation-backend/build.xml +56 -0
  15. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRFileStream.java +78 -0
  16. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRInputStream.java +70 -0
  17. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRReaderStream.java +95 -0
  18. data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRStringStream.java +230 -0
  19. data/test-server/instrumentation-backend/src/org/antlr/runtime/BaseRecognizer.java +894 -0
  20. data/test-server/instrumentation-backend/src/org/antlr/runtime/BitSet.java +325 -0
  21. data/test-server/instrumentation-backend/src/org/antlr/runtime/BufferedTokenStream.java +272 -0
  22. data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStream.java +57 -0
  23. data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStreamState.java +45 -0
  24. data/test-server/instrumentation-backend/src/org/antlr/runtime/ClassicToken.java +141 -0
  25. data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonToken.java +191 -0
  26. data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonTokenStream.java +153 -0
  27. data/test-server/instrumentation-backend/src/org/antlr/runtime/DFA.java +250 -0
  28. data/test-server/instrumentation-backend/src/org/antlr/runtime/EarlyExitException.java +41 -0
  29. data/test-server/instrumentation-backend/src/org/antlr/runtime/FailedPredicateException.java +54 -0
  30. data/test-server/instrumentation-backend/src/org/antlr/runtime/IntStream.java +122 -0
  31. data/test-server/instrumentation-backend/src/org/antlr/runtime/LegacyCommonTokenStream.java +394 -0
  32. data/test-server/instrumentation-backend/src/org/antlr/runtime/Lexer.java +340 -0
  33. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedNotSetException.java +41 -0
  34. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedRangeException.java +45 -0
  35. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedSetException.java +44 -0
  36. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTokenException.java +45 -0
  37. data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTreeNodeException.java +49 -0
  38. data/test-server/instrumentation-backend/src/org/antlr/runtime/MissingTokenException.java +56 -0
  39. data/test-server/instrumentation-backend/src/org/antlr/runtime/NoViableAltException.java +57 -0
  40. data/test-server/instrumentation-backend/src/org/antlr/runtime/Parser.java +98 -0
  41. data/test-server/instrumentation-backend/src/org/antlr/runtime/ParserRuleReturnScope.java +52 -0
  42. data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognitionException.java +180 -0
  43. data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognizerSharedState.java +144 -0
  44. data/test-server/instrumentation-backend/src/org/antlr/runtime/RuleReturnScope.java +42 -0
  45. data/test-server/instrumentation-backend/src/org/antlr/runtime/SerializedGrammar.java +204 -0
  46. data/test-server/instrumentation-backend/src/org/antlr/runtime/Token.java +92 -0
  47. data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenRewriteStream.java +569 -0
  48. data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenSource.java +54 -0
  49. data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenStream.java +75 -0
  50. data/test-server/instrumentation-backend/src/org/antlr/runtime/UnbufferedTokenStream.java +82 -0
  51. data/test-server/instrumentation-backend/src/org/antlr/runtime/UnwantedTokenException.java +53 -0
  52. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/BlankDebugEventListener.java +77 -0
  53. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventHub.java +292 -0
  54. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventListener.java +323 -0
  55. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventRepeater.java +88 -0
  56. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventSocketProxy.java +358 -0
  57. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugParser.java +101 -0
  58. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTokenStream.java +156 -0
  59. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeAdaptor.java +250 -0
  60. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeNodeStream.java +155 -0
  61. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeParser.java +112 -0
  62. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/ParseTreeBuilder.java +109 -0
  63. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Profiler.java +772 -0
  64. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/RemoteDebugEventSocketListener.java +541 -0
  65. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/TraceDebugEventListener.java +108 -0
  66. data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Tracer.java +69 -0
  67. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/DoubleKeyMap.java +62 -0
  68. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/FastQueue.java +100 -0
  69. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/IntArray.java +87 -0
  70. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/LookaheadStream.java +161 -0
  71. data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/Stats.java +189 -0
  72. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTree.java +349 -0
  73. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTreeAdaptor.java +279 -0
  74. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BufferedTreeNodeStream.java +489 -0
  75. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonErrorNode.java +108 -0
  76. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTree.java +185 -0
  77. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeAdaptor.java +168 -0
  78. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeNodeStream.java +171 -0
  79. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/ParseTree.java +119 -0
  80. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteCardinalityException.java +47 -0
  81. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEarlyExitException.java +39 -0
  82. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEmptyStreamException.java +35 -0
  83. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleElementStream.java +210 -0
  84. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleNodeStream.java +70 -0
  85. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleSubtreeStream.java +86 -0
  86. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleTokenStream.java +76 -0
  87. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/Tree.java +127 -0
  88. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeAdaptor.java +263 -0
  89. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeFilter.java +135 -0
  90. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeIterator.java +132 -0
  91. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeNodeStream.java +106 -0
  92. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeParser.java +169 -0
  93. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternLexer.java +135 -0
  94. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternParser.java +154 -0
  95. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRewriter.java +124 -0
  96. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRuleReturnScope.java +41 -0
  97. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitor.java +69 -0
  98. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitorAction.java +47 -0
  99. data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeWizard.java +531 -0
  100. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java +22 -7
  101. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +4 -4
  102. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +0 -1
  103. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java +161 -129
  104. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetActivityOrientation.java +5 -7
  105. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetViewProperty.java +1 -7
  106. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Query.java +70 -61
  107. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/UIQuery.tokens +12 -0
  108. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +63 -0
  109. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQuery.tokens +10 -0
  110. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryLexer.java +945 -0
  111. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryParser.java +463 -0
  112. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/InvalidUIQueryException.java +10 -0
  113. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryAST.java +8 -0
  114. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTClassName.java +115 -0
  115. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +157 -0
  116. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryDirection.java +5 -0
  117. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java +205 -0
  118. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +135 -0
  119. data/test-server/instrumentation-backend/tests/sh/calaba/instrumentationbackend/query/tests/UIQueryTest.java +134 -0
  120. metadata +106 -3
  121. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetOrientation.java +0 -39
@@ -1,12 +1,13 @@
1
1
  package sh.calaba.instrumentationbackend;
2
2
 
3
- import android.content.Context;
3
+ import java.io.File;
4
+
5
+ import android.accounts.Account;
6
+ import android.accounts.AccountManager;
7
+ import android.annotation.SuppressLint;
4
8
  import android.os.Bundle;
5
9
  import android.test.InstrumentationTestRunner;
6
- import sh.calaba.instrumentationbackend.actions.HttpServer;
7
10
 
8
- import java.io.File;
9
- import java.lang.reflect.Method;
10
11
 
11
12
  public class ClearAppData extends InstrumentationTestRunner {
12
13
  @Override
@@ -17,8 +18,22 @@ public class ClearAppData extends InstrumentationTestRunner {
17
18
  if (cacheDir() != null) {
18
19
  delete(cacheDir().getParentFile());
19
20
  }
21
+ try {
22
+ final AccountManager manager = AccountManager.get(getTargetContext());
23
+ final Account[] accounts = manager.getAccounts();
24
+
25
+ for (Account account : accounts) {
26
+ try {
27
+ manager.removeAccount(account, null, null);
28
+ } catch (Exception e) {
29
+ System.out.println("Unable to remove " + account.name + " of type " + account.type);
30
+ }
31
+ }
32
+ } catch (Exception e) {
33
+ System.out.println("Error removing accounts");
34
+ }
20
35
  }
21
-
36
+
22
37
  //If provided a file will delete it.
23
38
  //If provided a directory will recursively delete files but preserve directories
24
39
  private void delete(File file_or_directory) {
@@ -36,8 +51,8 @@ public class ClearAppData extends InstrumentationTestRunner {
36
51
  file_or_directory.delete();
37
52
  }
38
53
  }
39
-
40
- private File externalCacheDir() {
54
+
55
+ private File externalCacheDir() {
41
56
  return getTargetContext().getExternalCacheDir();
42
57
  }
43
58
 
@@ -1,17 +1,17 @@
1
1
  package sh.calaba.instrumentationbackend;
2
2
 
3
- import android.Manifest;
4
- import android.content.pm.PackageManager;
5
- import com.jayway.android.robotium.solo.PublicViewFetcher;
6
3
  import sh.calaba.instrumentationbackend.actions.Actions;
7
4
  import sh.calaba.instrumentationbackend.actions.HttpServer;
5
+ import android.Manifest;
8
6
  import android.app.Activity;
9
7
  import android.app.Instrumentation;
10
8
  import android.content.Context;
11
- import android.test.ActivityInstrumentationTestCase2;
9
+ import android.content.pm.PackageManager;
12
10
  import android.location.LocationManager;
11
+ import android.test.ActivityInstrumentationTestCase2;
13
12
  import android.util.Log;
14
13
 
14
+ import com.jayway.android.robotium.solo.PublicViewFetcher;
15
15
  import com.jayway.android.robotium.solo.SoloEnhanced;
16
16
 
17
17
  public class InstrumentationBackend extends ActivityInstrumentationTestCase2 {
@@ -1,6 +1,5 @@
1
1
  package sh.calaba.instrumentationbackend;
2
2
 
3
- import java.io.BufferedWriter;
4
3
  import java.io.CharArrayWriter;
5
4
  import java.io.PrintWriter;
6
5
  import java.util.ArrayList;
@@ -1,156 +1,188 @@
1
1
  package sh.calaba.instrumentationbackend.actions;
2
2
 
3
- import java.io.*;
3
+ import java.io.ByteArrayInputStream;
4
+ import java.io.ByteArrayOutputStream;
5
+ import java.io.File;
6
+ import java.io.IOException;
7
+ import java.io.PrintWriter;
8
+ import java.io.StringWriter;
9
+ import java.util.List;
4
10
  import java.util.Map;
5
11
  import java.util.Properties;
6
- import java.util.List;
7
12
  import java.util.concurrent.locks.Condition;
8
13
  import java.util.concurrent.locks.Lock;
9
14
  import java.util.concurrent.locks.ReentrantLock;
10
15
 
11
- import android.Manifest;
12
- import android.app.Activity;
13
- import android.app.ActivityManager;
14
- import android.content.pm.PackageManager;
15
- import android.graphics.Bitmap;
16
- import android.view.View;
17
16
  import sh.calaba.instrumentationbackend.Command;
18
17
  import sh.calaba.instrumentationbackend.InstrumentationBackend;
19
18
  import sh.calaba.instrumentationbackend.Result;
20
- import sh.calaba.instrumentationbackend.query.QueryResult;
21
19
  import sh.calaba.instrumentationbackend.query.Query;
20
+ import sh.calaba.instrumentationbackend.query.QueryResult;
22
21
  import sh.calaba.org.codehaus.jackson.map.DeserializationConfig.Feature;
23
22
  import sh.calaba.org.codehaus.jackson.map.ObjectMapper;
24
- import android.util.Log;
25
23
  import sh.calaba.org.codehaus.jackson.type.TypeReference;
24
+ import android.graphics.Bitmap;
25
+ import android.util.Log;
26
+ import android.view.View;
26
27
 
27
28
  public class HttpServer extends NanoHTTPD {
28
29
  private static final String TAG = "InstrumentationBackend";
29
- private boolean running = true;
30
- private boolean ready = false;
30
+ private boolean running = true;
31
+ private boolean ready = false;
31
32
 
32
- private final Lock lock = new ReentrantLock();
33
- private final Condition shutdownCondition = lock.newCondition();
33
+ private final Lock lock = new ReentrantLock();
34
+ private final Condition shutdownCondition = lock.newCondition();
34
35
 
35
36
  private final ObjectMapper mapper = createJsonMapper();
36
37
 
37
- private static HttpServer instance;
38
-
39
- /**
40
- * Creates and returns the singleton instance for HttpServer.
41
- *
42
- * Can only be called once. Otherwise, you'll get an IllegalStateException.
43
- */
44
- public synchronized static HttpServer instantiate() {
45
- if(instance != null) {
46
- throw new IllegalStateException("Can only instantiate once!");
47
- }
48
- instance = new HttpServer();
49
- return instance;
50
- }
51
-
52
- /**
53
- * Returns the singleton instance for HttpServer.
54
- *
55
- * If {@link #instantiate()} hasn't already been called, an IllegalStateException is thrown.
56
- */
57
- public synchronized static HttpServer getInstance() {
58
- if(instance == null) {
59
- throw new IllegalStateException("Must be initialized!");
60
- }
61
- return instance;
62
- }
38
+ private static HttpServer instance;
39
+
40
+ /**
41
+ * Creates and returns the singleton instance for HttpServer.
42
+ *
43
+ * Can only be called once. Otherwise, you'll get an IllegalStateException.
44
+ */
45
+ public synchronized static HttpServer instantiate() {
46
+ if (instance != null) {
47
+ throw new IllegalStateException("Can only instantiate once!");
48
+ }
49
+ instance = new HttpServer();
50
+ return instance;
51
+ }
52
+
53
+ /**
54
+ * Returns the singleton instance for HttpServer.
55
+ *
56
+ * If {@link #instantiate()} hasn't already been called, an
57
+ * IllegalStateException is thrown.
58
+ */
59
+ public synchronized static HttpServer getInstance() {
60
+ if (instance == null) {
61
+ throw new IllegalStateException("Must be initialized!");
62
+ }
63
+ return instance;
64
+ }
63
65
 
64
66
  private HttpServer() {
65
67
  super(7102, new File("/"));
66
68
  }
67
69
 
68
- public Response serve( String uri, String method, Properties header, Properties params, Properties files )
69
- {
70
- System.out.println("URI: " + uri);
71
- if (uri.endsWith("/ping")) {
72
- return new NanoHTTPD.Response( HTTP_OK, MIME_HTML, "pong");
73
-
74
- } else if (uri.endsWith("/query")) {
75
- try {
76
- String commandString = params.getProperty("json");
77
- ObjectMapper mapper = new ObjectMapper();
78
- Map<String, String> command = mapper.readValue(commandString, new TypeReference<Map<String, String>>() {});
79
- QueryResult result = new Query(command.get("query")).execute();
80
- return new NanoHTTPD.Response( HTTP_OK, MIME_HTML, result.asJson());
81
- } catch (IOException e) {
70
+ @SuppressWarnings("rawtypes")
71
+ public Response serve(String uri, String method, Properties header,
72
+ Properties params, Properties files) {
73
+ System.out.println("URI: " + uri);
74
+ if (uri.endsWith("/ping")) {
75
+ return new NanoHTTPD.Response(HTTP_OK, MIME_HTML, "pong");
76
+
77
+ } else if (uri.endsWith("/map")) {
78
+ try {
79
+ String commandString = params.getProperty("json");
80
+ ObjectMapper mapper = new ObjectMapper();
81
+ Map command = mapper.readValue(commandString, Map.class);
82
+
83
+ String uiQuery = (String) command.get("query");
84
+ Map op = (Map) command.get("operation");
85
+ String methodName = (String) op.get("method_name");
86
+ List arguments = (List) op.get("arguments");
87
+
88
+ QueryResult queryResult = new Query(uiQuery,arguments).execute();
89
+
90
+ return new NanoHTTPD.Response(HTTP_OK, "application/json;charset=utf-8",
91
+ queryResult.asJson());
92
+ } catch (IOException e) {
93
+ e.printStackTrace();
94
+ } catch (Exception e ) {
95
+ System.err.println("Query failed!");
82
96
  e.printStackTrace();
83
- return new Response(HTTP_INTERNALERROR, MIME_PLAINTEXT, "Could not parse arguments as JSON");
84
97
  }
85
- } else if (uri.endsWith("/kill")) {
86
- lock.lock();
87
- try {
88
- running = false;
89
- System.out.println("Stopping test server");
90
- stop();
91
-
92
- shutdownCondition.signal();
93
- return new NanoHTTPD.Response( HTTP_OK, MIME_HTML, "Affirmative!");
94
- } finally {
95
- lock.unlock();
96
- }
97
-
98
- } else if (uri.endsWith("/ready")) {
99
- return new Response(HTTP_OK, MIME_HTML, Boolean.toString(ready));
100
-
98
+ return new NanoHTTPD.Response(HTTP_INTERNALERROR, MIME_HTML, "Query failed");
99
+ } else if (uri.endsWith("/query")) {
100
+ try {
101
+ String commandString = params.getProperty("json");
102
+ ObjectMapper mapper = new ObjectMapper();
103
+ Map<String, String> command = mapper.readValue(commandString,
104
+ new TypeReference<Map<String, String>>() {
105
+ });
106
+ QueryResult result = new Query(command.get("query")).executeInMainThread();
107
+ return new NanoHTTPD.Response(HTTP_OK, MIME_HTML,
108
+ result.asJson());
109
+ } catch (IOException e) {
110
+ e.printStackTrace();
111
+ return new Response(HTTP_INTERNALERROR, MIME_PLAINTEXT,
112
+ "Could not parse arguments as JSON");
113
+ }
114
+ } else if (uri.endsWith("/kill")) {
115
+ lock.lock();
116
+ try {
117
+ running = false;
118
+ System.out.println("Stopping test server");
119
+ stop();
120
+
121
+ shutdownCondition.signal();
122
+ return new NanoHTTPD.Response(HTTP_OK, MIME_HTML,
123
+ "Affirmative!");
124
+ } finally {
125
+ lock.unlock();
126
+ }
127
+
128
+ } else if (uri.endsWith("/ready")) {
129
+ return new Response(HTTP_OK, MIME_HTML, Boolean.toString(ready));
101
130
 
102
131
  } else if (uri.endsWith("/screenshot")) {
103
- try {
104
- Bitmap bitmap;
105
- View rootView = getRootView();
106
- rootView.setDrawingCacheEnabled(true);
107
- rootView.buildDrawingCache(true);
108
- bitmap = Bitmap.createBitmap(rootView.getDrawingCache());
109
- rootView.setDrawingCacheEnabled(false);
110
-
111
- ByteArrayOutputStream out = new ByteArrayOutputStream();
112
- bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
113
- return new NanoHTTPD.Response( HTTP_OK, "image/png", new ByteArrayInputStream(out.toByteArray()));
114
- } catch (Exception e) {
115
- StringWriter sw = new StringWriter();
116
- PrintWriter pw = new PrintWriter(sw);
117
- e.printStackTrace(pw);
118
- return new NanoHTTPD.Response( HTTP_INTERNALERROR, null, sw.toString());
119
- }
120
- }
121
-
122
- System.out.println("header: "+ header);
123
- System.out.println("params: "+ params);
124
- System.out.println("files: "+ files);
132
+ try {
133
+ Bitmap bitmap;
134
+ View rootView = getRootView();
135
+ rootView.setDrawingCacheEnabled(true);
136
+ rootView.buildDrawingCache(true);
137
+ bitmap = Bitmap.createBitmap(rootView.getDrawingCache());
138
+ rootView.setDrawingCacheEnabled(false);
139
+
140
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
141
+ bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
142
+ return new NanoHTTPD.Response(HTTP_OK, "image/png",
143
+ new ByteArrayInputStream(out.toByteArray()));
144
+ } catch (Exception e) {
145
+ StringWriter sw = new StringWriter();
146
+ PrintWriter pw = new PrintWriter(sw);
147
+ e.printStackTrace(pw);
148
+ return new NanoHTTPD.Response(HTTP_INTERNALERROR, null,
149
+ sw.toString());
150
+ }
151
+ }
125
152
 
153
+ System.out.println("header: " + header);
154
+ System.out.println("params: " + params);
155
+ System.out.println("files: " + files);
126
156
 
127
- String commandString = params.getProperty("json");
128
- System.out.println("command: "+ commandString);
157
+ String commandString = params.getProperty("json");
158
+ System.out.println("command: " + commandString);
129
159
  String result = toJson(runCommand(commandString));
130
160
  System.out.println("result:" + result);
131
-
132
- return new NanoHTTPD.Response( HTTP_OK, MIME_HTML, result);
161
+
162
+ return new NanoHTTPD.Response(HTTP_OK, MIME_HTML, result);
133
163
  }
134
164
 
135
- private View getRootView() {
136
- for ( int i = 0; i < 25; i++) {
137
- try {
138
- View decorView = InstrumentationBackend.solo.getCurrentActivity().getWindow().getDecorView();
139
- if (decorView != null) {
140
- View rootView = decorView.findViewById(android.R.id.content);
141
- if (rootView != null) {
142
- return rootView;
143
- }
144
- }
145
- System.out.println("Retry: " + i);
146
-
147
- Thread.sleep(200);
148
- } catch (Exception e) {
149
- }
150
- }
151
-
152
- throw new RuntimeException("Could not find any views");
153
- }
165
+ private View getRootView() {
166
+ for (int i = 0; i < 25; i++) {
167
+ try {
168
+ View decorView = InstrumentationBackend.solo
169
+ .getCurrentActivity().getWindow().getDecorView();
170
+ if (decorView != null) {
171
+ View rootView = decorView
172
+ .findViewById(android.R.id.content);
173
+ if (rootView != null) {
174
+ return rootView;
175
+ }
176
+ }
177
+ System.out.println("Retry: " + i);
178
+
179
+ Thread.sleep(200);
180
+ } catch (Exception e) {
181
+ }
182
+ }
183
+
184
+ throw new RuntimeException("Could not find any views");
185
+ }
154
186
 
155
187
  private ObjectMapper createJsonMapper() {
156
188
  ObjectMapper mapper = new ObjectMapper();
@@ -177,22 +209,22 @@ public class HttpServer extends NanoHTTPD {
177
209
  }
178
210
  }
179
211
 
180
- public void waitUntilShutdown() throws InterruptedException {
181
- lock.lock();
182
- try {
183
- while(running) {
184
- shutdownCondition.await();
185
- }
186
- } finally {
187
- lock.unlock();
188
- }
189
- }
212
+ public void waitUntilShutdown() throws InterruptedException {
213
+ lock.lock();
214
+ try {
215
+ while (running) {
216
+ shutdownCondition.await();
217
+ }
218
+ } finally {
219
+ lock.unlock();
220
+ }
221
+ }
190
222
 
191
223
  public static void log(String message) {
192
224
  Log.i(TAG, message);
193
225
  }
194
226
 
195
- public void setReady() {
196
- ready = true;
197
- }
227
+ public void setReady() {
228
+ ready = true;
229
+ }
198
230
  }
@@ -8,19 +8,17 @@ public class SetActivityOrientation implements Action {
8
8
 
9
9
  @Override
10
10
  public Result execute(String... args) {
11
- if (args.length == 0) {
11
+ if (args == null || args.length == 0) {
12
12
  throw new IllegalArgumentException("No orientation provided. Use 'landscape' or 'portrait'");
13
13
  }
14
14
  String orientation = args[0].toLowerCase();
15
15
 
16
- if (orientation != "landscape" && orientation != "portrait") {
17
- throw new IllegalArgumentException("Invalid orientation '" + orientation + "'. Use 'landscape' or 'portrait'");
18
- }
19
-
20
- if (orientation == "landscape") {
16
+ if (orientation.equals("landscape")) {
21
17
  InstrumentationBackend.solo.setActivityOrientation(0);
22
- } else {
18
+ } else if(orientation.equals("portrait")) {
23
19
  InstrumentationBackend.solo.setActivityOrientation(1);
20
+ } else {
21
+ throw new IllegalArgumentException("Invalid orientation '" + orientation + "'. Use 'landscape' or 'portrait'");
24
22
  }
25
23
  // Wait 100ms for orientation change to happen.
26
24
  sleep(100);
@@ -23,13 +23,7 @@ public class GetViewProperty extends WaitForViewById implements Action {
23
23
  try {
24
24
  View view = getViewById(viewId, 60000);
25
25
  if( view != null ) {
26
- // Result result = new Result(true);
27
- //
28
- // String propertyName = args[1].toLowerCase();
29
- // String value = getPropertyValue(propertyName, view, args);
30
- // result.setMessage( value );
31
-
32
- String propertyName = args[1].toLowerCase();
26
+ String propertyName = args[1];
33
27
  return getPropertyValue(propertyName, view, args);
34
28
  } else {
35
29
  return new Result(false, "Timed out while waiting for view with id:'" + viewId + "'");