diff options
author | Clara Bayarri <clarabayarri@google.com> | 2015-05-14 09:28:45 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-14 09:28:46 +0000 |
commit | e094b2aff04105d63fa930f873a948e4104ca0f0 (patch) | |
tree | d64249ff8cda6481c323ec2429cd213939d25796 /core/tests | |
parent | bff329b851a4806672842dc3e4608cee18ae9a1e (diff) | |
parent | 2c7b461077d83986c32dea89da9b2458a633f59f (diff) | |
download | frameworks_base-e094b2aff04105d63fa930f873a948e4104ca0f0.zip frameworks_base-e094b2aff04105d63fa930f873a948e4104ca0f0.tar.gz frameworks_base-e094b2aff04105d63fa930f873a948e4104ca0f0.tar.bz2 |
Merge "Tests for WindowDecorActionBar's startActionMode implementation" into mnc-dev
Diffstat (limited to 'core/tests')
3 files changed, 132 insertions, 0 deletions
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 @@ </activity> <activity android:name="android.app.activity.LaunchpadTabActivity" android:multiprocess="true"> </activity> + <activity android:name="com.android.internal.app.WindowDecorActionBarTestActivity"> + </activity> <receiver android:name="android.app.activity.AbortReceiver"> <intent-filter android:priority="1"> 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<WindowDecorActionBarTestActivity> { + 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)); + } +} |