From 5652d175fedc87c796de3cfd354a9de961450690 Mon Sep 17 00:00:00 2001 From: Aga Wronska Date: Mon, 8 Feb 2016 12:00:38 -0800 Subject: [PATCH] Go to root from child directory when root tapped. Bug: 27060001 Change-Id: Iabe1f9f2c986904a4d827e74cf29b3de55e74f90 --- .../src/com/android/documentsui/BaseActivity.java | 4 +- .../src/com/android/documentsui/RootUiTest.java | 51 ++++++++++++++++++++++ .../tests/src/com/android/documentsui/UiBot.java | 10 +++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 packages/DocumentsUI/tests/src/com/android/documentsui/RootUiTest.java diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java index 3c21a214b19b..73d0f72f6001 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java @@ -219,8 +219,8 @@ public abstract class BaseActivity extends Activity void onStackRestored(boolean restored, boolean external) {} void onRootPicked(RootInfo root) { - // Skip refreshing if root didn't change - if(root.equals(getCurrentRoot())) { + // Skip refreshing if root nor directory didn't change + if (root.equals(getCurrentRoot()) && mState.stack.size() == 1) { return; } diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/RootUiTest.java b/packages/DocumentsUI/tests/src/com/android/documentsui/RootUiTest.java new file mode 100644 index 000000000000..1d1d3b5abd64 --- /dev/null +++ b/packages/DocumentsUI/tests/src/com/android/documentsui/RootUiTest.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 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. + */ + +package com.android.documentsui; + +import static com.android.documentsui.StubProvider.ROOT_0_ID; + +import android.support.test.uiautomator.Configurator; +import android.support.test.uiautomator.UiObject; +import android.support.test.uiautomator.UiObjectNotFoundException; +import android.test.InstrumentationTestCase; +import android.test.suitebuilder.annotation.LargeTest; +import android.view.MotionEvent; + +@LargeTest +public class RootUiTest extends ActivityTest { + + private static final String TAG = "RootUiTest"; + + public RootUiTest() { + super(FilesActivity.class); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + initTestFiles(); + bot.openRoot(ROOT_0_ID); + } + + public void testRootTapped_GoToRootFromChildDir() throws Exception { + bot.openDocument(dirName1); + bot.assertWindowTitle(dirName1); + bot.openRoot(ROOT_0_ID); + bot.assertWindowTitle(ROOT_0_ID); + assertDefaultContentOfTestDir0(); + } +} diff --git a/packages/DocumentsUI/tests/src/com/android/documentsui/UiBot.java b/packages/DocumentsUI/tests/src/com/android/documentsui/UiBot.java index 417fd24e2812..6ba214614377 100644 --- a/packages/DocumentsUI/tests/src/com/android/documentsui/UiBot.java +++ b/packages/DocumentsUI/tests/src/com/android/documentsui/UiBot.java @@ -24,6 +24,7 @@ import static junit.framework.Assert.assertFalse; import android.content.Context; import android.support.test.uiautomator.By; import android.support.test.uiautomator.BySelector; +import android.support.test.uiautomator.Configurator; import android.support.test.uiautomator.UiDevice; import android.support.test.uiautomator.UiObject; import android.support.test.uiautomator.UiObject2; @@ -32,6 +33,7 @@ import android.support.test.uiautomator.UiScrollable; import android.support.test.uiautomator.UiSelector; import android.support.test.uiautomator.Until; import android.util.Log; +import android.view.MotionEvent; import android.view.inputmethod.InputMethodManager; import junit.framework.Assert; @@ -192,6 +194,14 @@ class UiBot { assertNotNull(getSnackbar(mContext.getString(id))); } + void openDocument(String label) throws UiObjectNotFoundException { + int toolType = Configurator.getInstance().getToolType(); + Configurator.getInstance().setToolType(MotionEvent.TOOL_TYPE_FINGER); + UiObject doc = findDocument(label); + doc.click(); + Configurator.getInstance().setToolType(toolType); + } + void clickDocument(String label) throws UiObjectNotFoundException { findDocument(label).click(); } -- 2.11.0