Merge "Fixing broken instrumentation tests when run from command line" into ub-launcher3-calgary

This commit is contained in:
Sunny Goyal
2016-03-19 00:52:41 +00:00
committed by Android (Google) Code Review
7 changed files with 25 additions and 49 deletions
-1
View File
@@ -40,7 +40,6 @@ android {
androidTest {
java.srcDirs = ['tests/src']
res.srcDirs = ['tests/res']
manifest.srcFile "tests/AndroidManifest.xml"
}
}
+17 -20
View File
@@ -527,13 +527,8 @@ public class LauncherProvider extends ContentProvider {
private long mMaxScreenId = -1;
DatabaseHelper(Context context, LauncherProvider provider) {
super(new NoLocaleSqliteContext(context), LauncherFiles.LAUNCHER_DB,
null, DATABASE_VERSION);
mContext = context;
mProvider = provider;
mAppWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
this(context, provider, LauncherFiles.LAUNCHER_DB,
new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID));
// Table creation sometimes fails silently, which leads to a crash loop.
// This way, we will try to create a table every time after crash, so the device
// would eventually be able to recover.
@@ -544,6 +539,21 @@ public class LauncherProvider extends ContentProvider {
addWorkspacesTable(getWritableDatabase(), true);
}
initIds();
}
/**
* Constructor used only in tests.
*/
public DatabaseHelper(
Context context, LauncherProvider provider, String tableName, AppWidgetHost host) {
super(new NoLocaleSqliteContext(context), tableName, null, DATABASE_VERSION);
mContext = context;
mProvider = provider;
mAppWidgetHost = host;
}
protected void initIds() {
// In the case where neither onCreate nor onUpgrade gets called, we read the maxId from
// the DB here
if (mMaxItemId == -1) {
@@ -554,19 +564,6 @@ public class LauncherProvider extends ContentProvider {
}
}
/**
* Constructor used only in tests.
*/
public DatabaseHelper(Context context, LauncherProvider provider, String tableName) {
super(new NoLocaleSqliteContext(context), tableName, null, DATABASE_VERSION);
mContext = context;
mProvider = provider;
mAppWidgetHost = null;
mMaxItemId = initializeMaxItemId(getWritableDatabase());
mMaxScreenId = initializeMaxScreenId(getWritableDatabase());
}
private boolean tableExists(String tableName) {
Cursor c = getReadableDatabase().query(
true, "sqlite_master", new String[] {"tbl_name"},
-3
View File
@@ -16,13 +16,10 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
src_dirs := src
LOCAL_MODULE_TAGS := tests
LOCAL_STATIC_JAVA_LIBRARIES := android-support-test ub-uiautomator
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs))
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_SDK_VERSION := 23
+4 -2
View File
@@ -20,12 +20,14 @@
<uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/>
<application>
<application android:debuggable="true">
<uses-library android:name="android.test.runner" />
</application>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:functionalTest="false"
android:handleProfiling="false"
android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.launcher3" >
</instrumentation>
</manifest>
-21
View File
@@ -1,21 +0,0 @@
<!-- Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Dummy string for tests. [DO NOT TRANSLATE] -->
<string name="dummy" >Dummy string for tests.</string>
</resources>
@@ -109,7 +109,7 @@ public class BindWidgetTest extends InstrumentationTestCase {
public void testUnboundWidget_removed() throws Exception {
LauncherAppWidgetProviderInfo info = findWidgetProvider(false);
LauncherAppWidgetInfo item = createWidgetInfo(info, false);
item.appWidgetId = 33;
item.appWidgetId = -33;
// Since there is no widget to verify, just wait until the workspace is ready.
setupAndVerifyContents(item, Workspace.class, null);
@@ -253,6 +253,7 @@ public class BindWidgetTest extends InstrumentationTestCase {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
LauncherClings.markFirstRunClingDismissed(mTargetContext);
ManagedProfileHeuristic.markExistingUsersForNoFolderCreation(mTargetContext);
LauncherAppState.getInstance().getModel().resetLoadedState(true, true);
}
@@ -26,7 +26,8 @@ public class TestLauncherProvider extends LauncherProvider {
private static class MyDatabaseHelper extends DatabaseHelper {
public MyDatabaseHelper(Context context, LauncherProvider provider) {
super(context, provider, null);
super(context, provider, null, null);
initIds();
}
@Override