From 2c7b461077d83986c32dea89da9b2458a633f59f Mon Sep 17 00:00:00 2001 From: Clara Bayarri Date: Thu, 7 May 2015 15:18:27 +0100 Subject: Tests for WindowDecorActionBar's startActionMode implementation Change-Id: Ib7a79f3987fd565aabf4c5b093186ec669131522 --- core/tests/coretests/AndroidManifest.xml | 2 + .../internal/app/WindowDecorActionBarTest.java | 98 ++++++++++++++++++++++ .../app/WindowDecorActionBarTestActivity.java | 32 +++++++ 3 files changed, 132 insertions(+) create mode 100644 core/tests/coretests/src/com/android/internal/app/WindowDecorActionBarTest.java create mode 100644 core/tests/coretests/src/com/android/internal/app/WindowDecorActionBarTestActivity.java (limited to 'core/tests') diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index b07d338..1043b6f 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -1117,6 +1117,8 @@ + + diff --git a/core/tests/coretests/src/com/android/internal/app/WindowDecorActionBarTest.java b/core/tests/coretests/src/com/android/internal/app/WindowDecorActionBarTest.java new file mode 100644 index 0000000..57881af --- /dev/null +++ b/core/tests/coretests/src/com/android/internal/app/WindowDecorActionBarTest.java @@ -0,0 +1,98 @@ +/* + * 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. + */ + +package com.android.internal.app; + +import android.test.ActivityInstrumentationTestCase2; +import android.test.UiThreadTest; +import android.view.ActionMode; +import android.view.Menu; +import android.view.MenuItem; + +/** + * Tests for {@link WindowDecorActionBar}. + */ +public class WindowDecorActionBarTest + extends ActivityInstrumentationTestCase2 { + private WindowDecorActionBar mWindowDecorActionBar; + private MockActionModeCallback mCallback; + + public WindowDecorActionBarTest() { + super(WindowDecorActionBarTestActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + mWindowDecorActionBar = (WindowDecorActionBar) getActivity().getActionBar(); + mCallback = new MockActionModeCallback(); + } + + @UiThreadTest + public void testStartActionMode() { + ActionMode mode = mWindowDecorActionBar.startActionMode(mCallback); + + assertNotNull(mode); + assertTrue(mCallback.mIsCreateActionModeCalled); + } + + @UiThreadTest + public void testStartActionModeWhenCreateReturnsFalse() { + mCallback.mShouldCreateActionMode = false; + + ActionMode mode = mWindowDecorActionBar.startActionMode(mCallback); + + assertNull(mode); + assertTrue(mCallback.mIsCreateActionModeCalled); + } + + @UiThreadTest + public void testStartActionModeFinishesPreviousMode() { + ActionMode mode1 = mWindowDecorActionBar.startActionMode(mCallback); + ActionMode mode2 = mWindowDecorActionBar.startActionMode(new MockActionModeCallback()); + + assertNotNull(mode1); + assertNotNull(mode2); + assertTrue(mCallback.mIsDestroyActionModeCalled); + } + + private static final class MockActionModeCallback implements ActionMode.Callback { + private boolean mShouldCreateActionMode = true; + private boolean mIsCreateActionModeCalled = false; + private boolean mIsDestroyActionModeCalled = false; + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return true; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + mIsDestroyActionModeCalled = true; + } + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + mIsCreateActionModeCalled = true; + return mShouldCreateActionMode; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + return false; + } + } +} diff --git a/core/tests/coretests/src/com/android/internal/app/WindowDecorActionBarTestActivity.java b/core/tests/coretests/src/com/android/internal/app/WindowDecorActionBarTestActivity.java new file mode 100644 index 0000000..52bb38b --- /dev/null +++ b/core/tests/coretests/src/com/android/internal/app/WindowDecorActionBarTestActivity.java @@ -0,0 +1,32 @@ +/* + * 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. + */ + +package com.android.internal.app; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.view.Window; + +public class WindowDecorActionBarTestActivity extends Activity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().requestFeature(Window.FEATURE_ACTION_BAR); + setContentView(new View(this)); + } +} -- cgit v1.1