OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.test.InstrumentationTestCase; | 7 import android.test.InstrumentationTestCase; |
8 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
10 | 10 |
| 11 import org.chromium.base.CommandLine; |
11 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
12 import org.chromium.content.app.LibraryLoader; | 13 import org.chromium.content.app.LibraryLoader; |
13 import org.chromium.content.common.CommandLine; | |
14 import org.chromium.content.common.ProcessInitException; | 14 import org.chromium.content.common.ProcessInitException; |
15 import org.chromium.content_shell_apk.ContentShellActivity; | 15 import org.chromium.content_shell_apk.ContentShellActivity; |
16 import org.chromium.content_shell_apk.ContentShellApplication; | 16 import org.chromium.content_shell_apk.ContentShellApplication; |
17 | 17 |
18 public class CommandLineTest extends InstrumentationTestCase { | 18 public class ContentCommandLineTest extends InstrumentationTestCase { |
19 // A reference command line. Note that switch2 is [brea\d], switch3 is [and
"butter"], | 19 // A reference command line. Note that switch2 is [brea\d], switch3 is [and
"butter"], |
20 // and switch4 is [a "quoted" 'food'!] | 20 // and switch4 is [a "quoted" 'food'!] |
21 static final String INIT_SWITCHES[] = { "init_command", "--SWITCH", "Arg", | 21 static final String INIT_SWITCHES[] = { "init_command", "--SWITCH", "Arg", |
22 "--switch2=brea\\d", "--switch3=and \"butter\"", | 22 "--switch2=brea\\d", "--switch3=and \"butter\"", |
23 "--switch4=a \"quoted\" 'food'!", | 23 "--switch4=a \"quoted\" 'food'!", |
24 "--", "--actually_an_arg" }; | 24 "--", "--actually_an_arg" }; |
25 | 25 |
26 // The same command line, but in quoted string format. | 26 // The same command line, but in quoted string format. |
27 static final char INIT_SWITCHES_BUFFER[] = | 27 static final char INIT_SWITCHES_BUFFER[] = |
28 ("init_command --SWITCH Arg --switch2=brea\\d --switch3=\"and \\\"butt\"
er\\\" " | 28 ("init_command --SWITCH Arg --switch2=brea\\d --switch3=\"and \\\"butt\"
er\\\" " |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 assertTrue("turbo".equals(cl.getSwitchValue("speed"))); | 95 assertTrue("turbo".equals(cl.getSwitchValue("speed"))); |
96 } | 96 } |
97 | 97 |
98 void checkAppendedSwitchesPassedThrough() { | 98 void checkAppendedSwitchesPassedThrough() { |
99 CommandLine cl = CommandLine.getInstance(); | 99 CommandLine cl = CommandLine.getInstance(); |
100 assertTrue(cl.hasSwitch(CL_ADDED_SWITCH)); | 100 assertTrue(cl.hasSwitch(CL_ADDED_SWITCH)); |
101 assertTrue(cl.hasSwitch(CL_ADDED_SWITCH_2)); | 101 assertTrue(cl.hasSwitch(CL_ADDED_SWITCH_2)); |
102 assertTrue(CL_ADDED_VALUE_2.equals(cl.getSwitchValue(CL_ADDED_SWITCH_2))
); | 102 assertTrue(CL_ADDED_VALUE_2.equals(cl.getSwitchValue(CL_ADDED_SWITCH_2))
); |
103 } | 103 } |
104 | 104 |
105 void checkTokenizer(String[] expected, String toParse) { | |
106 String[] actual = CommandLine.tokenizeQuotedAruments(toParse.toCharArray
()); | |
107 assertEquals(expected.length, actual.length); | |
108 for (int i = 0; i < expected.length; ++i) { | |
109 assertEquals("comparing element " + i, expected[i], actual[i]); | |
110 } | |
111 } | |
112 | |
113 @SmallTest | |
114 @Feature({"Android-AppBase"}) | |
115 public void testJavaInitialization() { | |
116 CommandLine.init(INIT_SWITCHES); | |
117 checkInitSwitches(); | |
118 checkSettingThenGetting(); | |
119 } | |
120 | |
121 @MediumTest | 105 @MediumTest |
122 @Feature({"Android-AppBase"}) | 106 @Feature({"Android-AppBase"}) |
123 public void testJavaNativeTransition() { | 107 public void testJavaNativeTransition() { |
124 CommandLine.init(INIT_SWITCHES); | 108 CommandLine.init(INIT_SWITCHES); |
125 checkInitSwitches(); | 109 checkInitSwitches(); |
126 loadJni(); | 110 loadJni(); |
127 checkInitSwitches(); | 111 checkInitSwitches(); |
128 checkSettingThenGetting(); | 112 checkSettingThenGetting(); |
129 } | 113 } |
130 | 114 |
(...skipping 14 matching lines...) Expand all Loading... |
145 CommandLine.init(null); | 129 CommandLine.init(null); |
146 loadJni(); | 130 loadJni(); |
147 // Drop the program name for use with appendSwitchesAndArguments. | 131 // Drop the program name for use with appendSwitchesAndArguments. |
148 String[] args = new String[INIT_SWITCHES.length - 1]; | 132 String[] args = new String[INIT_SWITCHES.length - 1]; |
149 System.arraycopy(INIT_SWITCHES, 1, args, 0, args.length); | 133 System.arraycopy(INIT_SWITCHES, 1, args, 0, args.length); |
150 CommandLine.getInstance().appendSwitchesAndArguments(args); | 134 CommandLine.getInstance().appendSwitchesAndArguments(args); |
151 checkInitSwitches(); | 135 checkInitSwitches(); |
152 checkSettingThenGetting(); | 136 checkSettingThenGetting(); |
153 } | 137 } |
154 | 138 |
155 @SmallTest | |
156 @Feature({"Android-AppBase"}) | |
157 public void testBufferInitialization() { | |
158 CommandLine.init(CommandLine.tokenizeQuotedAruments(INIT_SWITCHES_BUFFER
)); | |
159 checkInitSwitches(); | |
160 checkSettingThenGetting(); | |
161 } | |
162 | |
163 @SmallTest | |
164 @Feature({"Android-AppBase"}) | |
165 public void testArgumentTokenizer() { | |
166 String toParse = " a\"\\bc de\\\"f g\"\\h ij k\" \"lm"; | |
167 String[] expected = { "a\\bc de\"f g\\h", | |
168 "ij", | |
169 "k lm" }; | |
170 checkTokenizer(expected, toParse); | |
171 | |
172 toParse = ""; | |
173 expected = new String[0]; | |
174 checkTokenizer(expected, toParse); | |
175 | |
176 toParse = " \t\n"; | |
177 checkTokenizer(expected, toParse); | |
178 | |
179 toParse = " \"a'b\" 'c\"d' \"e\\\"f\" 'g\\'h' \"i\\'j\" 'k\\\"l'" + | |
180 " m\"n\\'o\"p q'r\\\"s't"; | |
181 expected = new String[] { "a'b", | |
182 "c\"d", | |
183 "e\"f", | |
184 "g'h", | |
185 "i\\'j", | |
186 "k\\\"l", | |
187 "mn\\'op", | |
188 "qr\\\"st",}; | |
189 checkTokenizer(expected, toParse); | |
190 } | |
191 | |
192 @MediumTest | 139 @MediumTest |
193 @Feature({"Android-AppBase"}) | 140 @Feature({"Android-AppBase"}) |
194 public void testFileInitialization() { | 141 public void testFileInitialization() { |
195 CommandLine.initFromFile(ContentShellActivity.COMMAND_LINE_FILE); | 142 CommandLine.initFromFile(ContentShellActivity.COMMAND_LINE_FILE); |
196 loadJni(); | 143 loadJni(); |
197 checkSettingThenGetting(); | 144 checkSettingThenGetting(); |
198 } | 145 } |
199 } | 146 } |
OLD | NEW |