OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.chrome.browser.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
6 | 6 |
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE; |
8 | 8 |
9 import android.app.Activity; | 9 import android.app.Activity; |
10 import android.app.Application; | 10 import android.app.Application; |
(...skipping 22 matching lines...) Expand all Loading... | |
33 import android.support.customtabs.CustomTabsSessionToken; | 33 import android.support.customtabs.CustomTabsSessionToken; |
34 import android.test.suitebuilder.annotation.SmallTest; | 34 import android.test.suitebuilder.annotation.SmallTest; |
35 import android.text.TextUtils; | 35 import android.text.TextUtils; |
36 import android.view.Menu; | 36 import android.view.Menu; |
37 import android.view.MenuItem; | 37 import android.view.MenuItem; |
38 import android.view.View; | 38 import android.view.View; |
39 import android.view.ViewGroup; | 39 import android.view.ViewGroup; |
40 import android.widget.EditText; | 40 import android.widget.EditText; |
41 import android.widget.ImageButton; | 41 import android.widget.ImageButton; |
42 | 42 |
43 import org.chromium.base.ContextUtils; | |
43 import org.chromium.base.PathUtils; | 44 import org.chromium.base.PathUtils; |
44 import org.chromium.base.ThreadUtils; | 45 import org.chromium.base.ThreadUtils; |
45 import org.chromium.base.library_loader.LibraryLoader; | 46 import org.chromium.base.library_loader.LibraryLoader; |
46 import org.chromium.base.library_loader.LibraryProcessType; | 47 import org.chromium.base.library_loader.LibraryProcessType; |
47 import org.chromium.base.test.util.CommandLineFlags; | 48 import org.chromium.base.test.util.CommandLineFlags; |
48 import org.chromium.base.test.util.Restriction; | 49 import org.chromium.base.test.util.Restriction; |
49 import org.chromium.base.test.util.RetryOnFailure; | 50 import org.chromium.base.test.util.RetryOnFailure; |
50 import org.chromium.chrome.R; | 51 import org.chromium.chrome.R; |
51 import org.chromium.chrome.browser.ChromeActivity; | 52 import org.chromium.chrome.browser.ChromeActivity; |
52 import org.chromium.chrome.browser.ChromeFeatureList; | 53 import org.chromium.chrome.browser.ChromeFeatureList; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 private static int sIdToIncrement = 1; | 109 private static int sIdToIncrement = 1; |
109 | 110 |
110 private CustomTabActivity mActivity; | 111 private CustomTabActivity mActivity; |
111 private String mTestPage; | 112 private String mTestPage; |
112 private String mTestPage2; | 113 private String mTestPage2; |
113 private EmbeddedTestServer mTestServer; | 114 private EmbeddedTestServer mTestServer; |
114 | 115 |
115 @Override | 116 @Override |
116 protected void setUp() throws Exception { | 117 protected void setUp() throws Exception { |
117 super.setUp(); | 118 super.setUp(); |
119 Context appContext = getInstrumentation().getTargetContext().getApplicat ionContext(); | |
120 ContextUtils.initApplicationContext(appContext); | |
Ted C
2016/09/21 18:36:51
I'll apologize in advance if this is a silly quest
Peter Wen
2016/09/28 15:55:16
Application constructor seems early enough to not
| |
118 mTestServer = EmbeddedTestServer.createAndStartFileServer( | 121 mTestServer = EmbeddedTestServer.createAndStartFileServer( |
119 getInstrumentation().getContext(), Environment.getExternalStorag eDirectory()); | 122 appContext, Environment.getExternalStorageDirectory()); |
120 mTestPage = mTestServer.getURL(TEST_PAGE); | 123 mTestPage = mTestServer.getURL(TEST_PAGE); |
121 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); | 124 mTestPage2 = mTestServer.getURL(TEST_PAGE_2); |
122 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, | 125 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, a ppContext); |
123 getInstrumentation().getTargetContext().getApplicationContext()) ; | 126 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized( ); |
124 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER) | |
125 .ensureInitialized(getInstrumentation().getTargetContext().getAp plicationContext()); | |
126 } | 127 } |
127 | 128 |
128 @Override | 129 @Override |
129 protected void tearDown() throws Exception { | 130 protected void tearDown() throws Exception { |
130 mTestServer.stopAndDestroyServer(); | 131 mTestServer.stopAndDestroyServer(); |
131 | 132 |
132 // finish() is called on a non-UI thread by the testing harness. Must hi de the menu | 133 // finish() is called on a non-UI thread by the testing harness. Must hi de the menu |
133 // first, otherwise the UI is manipulated on a non-UI thread. | 134 // first, otherwise the UI is manipulated on a non-UI thread. |
134 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 135 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
135 @Override | 136 @Override |
(...skipping 22 matching lines...) Expand all Loading... | |
158 } | 159 } |
159 | 160 |
160 /** | 161 /** |
161 * Add a bundle specifying a custom menu entry. | 162 * Add a bundle specifying a custom menu entry. |
162 * @param intent The intent to modify. | 163 * @param intent The intent to modify. |
163 * @return The pending intent associated with the menu entry. | 164 * @return The pending intent associated with the menu entry. |
164 */ | 165 */ |
165 private PendingIntent addMenuEntriesToIntent(Intent intent, int numEntries) { | 166 private PendingIntent addMenuEntriesToIntent(Intent intent, int numEntries) { |
166 PendingIntent pi = PendingIntent.getBroadcast(getInstrumentation().getTa rgetContext(), 0, | 167 PendingIntent pi = PendingIntent.getBroadcast(getInstrumentation().getTa rgetContext(), 0, |
167 new Intent(), 0); | 168 new Intent(), 0); |
168 ArrayList<Bundle> menuItems = new ArrayList<Bundle>(); | 169 ArrayList<Bundle> menuItems = new ArrayList<>(); |
169 for (int i = 0; i < numEntries; i++) { | 170 for (int i = 0; i < numEntries; i++) { |
170 Bundle bundle = new Bundle(); | 171 Bundle bundle = new Bundle(); |
171 bundle.putString(CustomTabsIntent.KEY_MENU_ITEM_TITLE, TEST_MENU_TIT LE); | 172 bundle.putString(CustomTabsIntent.KEY_MENU_ITEM_TITLE, TEST_MENU_TIT LE); |
172 bundle.putParcelable(CustomTabsIntent.KEY_PENDING_INTENT, pi); | 173 bundle.putParcelable(CustomTabsIntent.KEY_PENDING_INTENT, pi); |
173 menuItems.add(bundle); | 174 menuItems.add(bundle); |
174 } | 175 } |
175 intent.putParcelableArrayListExtra(CustomTabsIntent.EXTRA_MENU_ITEMS, me nuItems); | 176 intent.putParcelableArrayListExtra(CustomTabsIntent.EXTRA_MENU_ITEMS, me nuItems); |
176 return pi; | 177 return pi; |
177 } | 178 } |
178 | 179 |
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1554 if (jsonText.equalsIgnoreCase("null")) jsonText = ""; | 1555 if (jsonText.equalsIgnoreCase("null")) jsonText = ""; |
1555 value = jsonText; | 1556 value = jsonText; |
1556 } catch (InterruptedException | TimeoutException e) { | 1557 } catch (InterruptedException | TimeoutException e) { |
1557 e.printStackTrace(); | 1558 e.printStackTrace(); |
1558 return false; | 1559 return false; |
1559 } | 1560 } |
1560 return TextUtils.equals(mExpected, value); | 1561 return TextUtils.equals(mExpected, value); |
1561 } | 1562 } |
1562 } | 1563 } |
1563 } | 1564 } |
OLD | NEW |