Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java

Issue 2708243004: Auto convert content shell tests to JUnit4 (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.support.test.filters.MediumTest; 7 import android.support.test.filters.MediumTest;
8 8
9 import org.junit.Assert;
10 import org.junit.Before;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14
9 import org.chromium.base.CommandLine; 15 import org.chromium.base.CommandLine;
10 import org.chromium.base.annotations.SuppressFBWarnings; 16 import org.chromium.base.annotations.SuppressFBWarnings;
17 import org.chromium.base.test.BaseJUnit4ClassRunner;
11 import org.chromium.base.test.util.Feature; 18 import org.chromium.base.test.util.Feature;
12 import org.chromium.content.browser.test.NativeLibraryTestBase; 19 import org.chromium.content.browser.test.NativeLibraryTestRule;
13 import org.chromium.content_shell_apk.ContentShellApplication; 20 import org.chromium.content_shell_apk.ContentShellApplication;
14 21
15 /** 22 /**
16 * Test class for command lines. 23 * Test class for command lines.
17 */ 24 */
18 public class ContentCommandLineTest extends NativeLibraryTestBase { 25 @RunWith(BaseJUnit4ClassRunner.class)
26 public class ContentCommandLineTest {
27 @Rule
28 public NativeLibraryTestRule mActivityTestRule = new NativeLibraryTestRule() ;
29
19 // A reference command line. Note that switch2 is [brea\d], switch3 is [and "butter"], 30 // A reference command line. Note that switch2 is [brea\d], switch3 is [and "butter"],
20 // and switch4 is [a "quoted" 'food'!] 31 // and switch4 is [a "quoted" 'food'!]
21 static final String INIT_SWITCHES[] = { "init_command", "--switch", "Arg", 32 static final String INIT_SWITCHES[] = { "init_command", "--switch", "Arg",
22 "--switch2=brea\\d", "--switch3=and \"butter\"", 33 "--switch2=brea\\d", "--switch3=and \"butter\"",
23 "--switch4=a \"quoted\" 'food'!", 34 "--switch4=a \"quoted\" 'food'!",
24 "--", "--actually_an_arg" }; 35 "--", "--actually_an_arg" };
25 36
26 // The same command line, but in quoted string format. 37 // The same command line, but in quoted string format.
27 static final char INIT_SWITCHES_BUFFER[] = 38 static final char INIT_SWITCHES_BUFFER[] =
28 ("init_command --switch Arg --switch2=brea\\d --switch3=\"and \\\"butt\" er\\\" " 39 ("init_command --switch Arg --switch2=brea\\d --switch3=\"and \\\"butt\" er\\\" "
29 + "--switch4='a \"quoted\" \\'food\\'!' " 40 + "--switch4='a \"quoted\" \\'food\\'!' "
30 + "-- --actually_an_arg").toCharArray(); 41 + "-- --actually_an_arg").toCharArray();
31 42
32 static final String CL_ADDED_SWITCH = "zappo-dappo-doggy-trainer"; 43 static final String CL_ADDED_SWITCH = "zappo-dappo-doggy-trainer";
33 static final String CL_ADDED_SWITCH_2 = "username"; 44 static final String CL_ADDED_SWITCH_2 = "username";
34 static final String CL_ADDED_VALUE_2 = "bozo"; 45 static final String CL_ADDED_VALUE_2 = "bozo";
35 46
36 @Override 47 @Before
37 public void setUp() throws Exception { 48 public void setUp() throws Exception {
38 super.setUp();
39 CommandLine.reset(); 49 CommandLine.reset();
40 } 50 }
41 51
42 void loadJni() { 52 void loadJni() {
43 assertFalse(CommandLine.getInstance().isNativeImplementation()); 53 Assert.assertFalse(CommandLine.getInstance().isNativeImplementation());
44 loadNativeLibraryNoBrowserProcess(); 54 mActivityTestRule.loadNativeLibraryNoBrowserProcess();
45 assertTrue(CommandLine.getInstance().isNativeImplementation()); 55 Assert.assertTrue(CommandLine.getInstance().isNativeImplementation());
46 } 56 }
47 57
48 void checkInitSwitches() { 58 void checkInitSwitches() {
49 CommandLine cl = CommandLine.getInstance(); 59 CommandLine cl = CommandLine.getInstance();
50 assertFalse(cl.hasSwitch("init_command")); 60 Assert.assertFalse(cl.hasSwitch("init_command"));
51 assertTrue(cl.hasSwitch("switch")); 61 Assert.assertTrue(cl.hasSwitch("switch"));
52 assertFalse(cl.hasSwitch("--switch")); 62 Assert.assertFalse(cl.hasSwitch("--switch"));
53 assertFalse(cl.hasSwitch("arg")); 63 Assert.assertFalse(cl.hasSwitch("arg"));
54 assertFalse(cl.hasSwitch("actually_an_arg")); 64 Assert.assertFalse(cl.hasSwitch("actually_an_arg"));
55 assertEquals("brea\\d", cl.getSwitchValue("switch2")); 65 Assert.assertEquals("brea\\d", cl.getSwitchValue("switch2"));
56 assertEquals("and \"butter\"", cl.getSwitchValue("switch3")); 66 Assert.assertEquals("and \"butter\"", cl.getSwitchValue("switch3"));
57 assertEquals("a \"quoted\" 'food'!", cl.getSwitchValue("switch4")); 67 Assert.assertEquals("a \"quoted\" 'food'!", cl.getSwitchValue("switch4") );
58 assertNull(cl.getSwitchValue("switch")); 68 Assert.assertNull(cl.getSwitchValue("switch"));
59 assertNull(cl.getSwitchValue("non-existant")); 69 Assert.assertNull(cl.getSwitchValue("non-existant"));
60 } 70 }
61 71
62 void checkSettingThenGetting() { 72 void checkSettingThenGetting() {
63 CommandLine cl = CommandLine.getInstance(); 73 CommandLine cl = CommandLine.getInstance();
64 74
65 // Add a plain switch. 75 // Add a plain switch.
66 assertFalse(cl.hasSwitch(CL_ADDED_SWITCH)); 76 Assert.assertFalse(cl.hasSwitch(CL_ADDED_SWITCH));
67 cl.appendSwitch(CL_ADDED_SWITCH); 77 cl.appendSwitch(CL_ADDED_SWITCH);
68 assertTrue(cl.hasSwitch(CL_ADDED_SWITCH)); 78 Assert.assertTrue(cl.hasSwitch(CL_ADDED_SWITCH));
69 79
70 // Add a switch paired with a value. 80 // Add a switch paired with a value.
71 assertFalse(cl.hasSwitch(CL_ADDED_SWITCH_2)); 81 Assert.assertFalse(cl.hasSwitch(CL_ADDED_SWITCH_2));
72 assertNull(cl.getSwitchValue(CL_ADDED_SWITCH_2)); 82 Assert.assertNull(cl.getSwitchValue(CL_ADDED_SWITCH_2));
73 cl.appendSwitchWithValue(CL_ADDED_SWITCH_2, CL_ADDED_VALUE_2); 83 cl.appendSwitchWithValue(CL_ADDED_SWITCH_2, CL_ADDED_VALUE_2);
74 assertTrue(CL_ADDED_VALUE_2.equals(cl.getSwitchValue(CL_ADDED_SWITCH_2)) ); 84 Assert.assertTrue(CL_ADDED_VALUE_2.equals(cl.getSwitchValue(CL_ADDED_SWI TCH_2)));
75 85
76 // Append a few new things. 86 // Append a few new things.
77 final String switchesAndArgs[] = { "dummy", "--superfast", "--speed=turb o" }; 87 final String switchesAndArgs[] = { "dummy", "--superfast", "--speed=turb o" };
78 assertFalse(cl.hasSwitch("dummy")); 88 Assert.assertFalse(cl.hasSwitch("dummy"));
79 assertFalse(cl.hasSwitch("superfast")); 89 Assert.assertFalse(cl.hasSwitch("superfast"));
80 assertNull(cl.getSwitchValue("speed")); 90 Assert.assertNull(cl.getSwitchValue("speed"));
81 cl.appendSwitchesAndArguments(switchesAndArgs); 91 cl.appendSwitchesAndArguments(switchesAndArgs);
82 assertFalse(cl.hasSwitch("dummy")); 92 Assert.assertFalse(cl.hasSwitch("dummy"));
83 assertFalse(cl.hasSwitch("command")); 93 Assert.assertFalse(cl.hasSwitch("command"));
84 assertTrue(cl.hasSwitch("superfast")); 94 Assert.assertTrue(cl.hasSwitch("superfast"));
85 assertTrue("turbo".equals(cl.getSwitchValue("speed"))); 95 Assert.assertTrue("turbo".equals(cl.getSwitchValue("speed")));
86 } 96 }
87 97
88 void checkAppendedSwitchesPassedThrough() { 98 void checkAppendedSwitchesPassedThrough() {
89 CommandLine cl = CommandLine.getInstance(); 99 CommandLine cl = CommandLine.getInstance();
90 assertTrue(cl.hasSwitch(CL_ADDED_SWITCH)); 100 Assert.assertTrue(cl.hasSwitch(CL_ADDED_SWITCH));
91 assertTrue(cl.hasSwitch(CL_ADDED_SWITCH_2)); 101 Assert.assertTrue(cl.hasSwitch(CL_ADDED_SWITCH_2));
92 assertTrue(CL_ADDED_VALUE_2.equals(cl.getSwitchValue(CL_ADDED_SWITCH_2)) ); 102 Assert.assertTrue(CL_ADDED_VALUE_2.equals(cl.getSwitchValue(CL_ADDED_SWI TCH_2)));
93 } 103 }
94 104
105 @Test
95 @MediumTest 106 @MediumTest
96 @Feature({"Android-AppBase"}) 107 @Feature({"Android-AppBase"})
97 public void testJavaNativeTransition() { 108 public void testJavaNativeTransition() {
98 CommandLine.init(INIT_SWITCHES); 109 CommandLine.init(INIT_SWITCHES);
99 checkInitSwitches(); 110 checkInitSwitches();
100 loadJni(); 111 loadJni();
101 checkInitSwitches(); 112 checkInitSwitches();
102 checkSettingThenGetting(); 113 checkSettingThenGetting();
103 } 114 }
104 115
116 @Test
105 @MediumTest 117 @MediumTest
106 @Feature({"Android-AppBase"}) 118 @Feature({"Android-AppBase"})
107 public void testJavaNativeTransitionAfterAppends() { 119 public void testJavaNativeTransitionAfterAppends() {
108 CommandLine.init(INIT_SWITCHES); 120 CommandLine.init(INIT_SWITCHES);
109 checkInitSwitches(); 121 checkInitSwitches();
110 checkSettingThenGetting(); 122 checkSettingThenGetting();
111 loadJni(); 123 loadJni();
112 checkInitSwitches(); 124 checkInitSwitches();
113 checkAppendedSwitchesPassedThrough(); 125 checkAppendedSwitchesPassedThrough();
114 } 126 }
115 127
128 @Test
116 @MediumTest 129 @MediumTest
117 @Feature({"Android-AppBase"}) 130 @Feature({"Android-AppBase"})
118 public void testNativeInitialization() { 131 public void testNativeInitialization() {
119 CommandLine.init(null); 132 CommandLine.init(null);
120 loadJni(); 133 loadJni();
121 // Drop the program name for use with appendSwitchesAndArguments. 134 // Drop the program name for use with appendSwitchesAndArguments.
122 String[] args = new String[INIT_SWITCHES.length - 1]; 135 String[] args = new String[INIT_SWITCHES.length - 1];
123 System.arraycopy(INIT_SWITCHES, 1, args, 0, args.length); 136 System.arraycopy(INIT_SWITCHES, 1, args, 0, args.length);
124 CommandLine.getInstance().appendSwitchesAndArguments(args); 137 CommandLine.getInstance().appendSwitchesAndArguments(args);
125 checkInitSwitches(); 138 checkInitSwitches();
126 checkSettingThenGetting(); 139 checkSettingThenGetting();
127 } 140 }
128 141
142 @Test
129 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") 143 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
130 @MediumTest 144 @MediumTest
131 @Feature({"Android-AppBase"}) 145 @Feature({"Android-AppBase"})
132 public void testFileInitialization() { 146 public void testFileInitialization() {
133 CommandLine.initFromFile(ContentShellApplication.COMMAND_LINE_FILE); 147 CommandLine.initFromFile(ContentShellApplication.COMMAND_LINE_FILE);
134 loadJni(); 148 loadJni();
135 checkSettingThenGetting(); 149 checkSettingThenGetting();
136 } 150 }
137 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698