blob: 30c86bfb41a312c6b5766af0b5eba2c4aa02986f [file] [log] [blame]
/*
* 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 android.view.inputmethod.cts;
import android.content.ClipDescription;
import android.net.Uri;
import android.os.Parcel;
import android.test.AndroidTestCase;
import android.view.inputmethod.InputContentInfo;
import java.lang.NullPointerException;
import java.security.InvalidParameterException;
public class InputContentInfoTest extends AndroidTestCase {
public void testInputContentInfo() {
InputContentInfo info = new InputContentInfo(
Uri.parse("content://com.example/path"),
new ClipDescription("sample content", new String[]{"image/png"}),
Uri.parse("https://example.com"));
assertEquals(Uri.parse("content://com.example/path"), info.getContentUri());
assertEquals(1, info.getDescription().getMimeTypeCount());
assertEquals("image/png", info.getDescription().getMimeType(0));
assertEquals("sample content", info.getDescription().getLabel());
assertEquals(Uri.parse("https://example.com"), info.getLinkUri());
Parcel p = Parcel.obtain();
info.writeToParcel(p, 0);
p.setDataPosition(0);
InputContentInfo targetInfo = InputContentInfo.CREATOR.createFromParcel(p);
p.recycle();
assertEquals(info.getContentUri(), targetInfo.getContentUri());
assertEquals(info.getDescription().getMimeTypeCount(),
targetInfo.getDescription().getMimeTypeCount());
assertEquals(info.getDescription().getMimeType(0),
targetInfo.getDescription().getMimeType(0));
assertEquals(info.getDescription().getLabel(), targetInfo.getDescription().getLabel());
assertEquals(info.getLinkUri(), targetInfo.getLinkUri());
}
public void testContentUri() {
try {
InputContentInfo info = new InputContentInfo(
null, new ClipDescription("sample content", new String[]{"image/png"}),
Uri.parse("https://example.com"));
fail("InputContentInfo must not accept a null content URI.");
} catch (NullPointerException e) {
// OK.
} catch (Exception e) {
fail("Unexpected exception=" + e);
}
try {
InputContentInfo info = new InputContentInfo(
Uri.parse("https://example.com"),
new ClipDescription("sample content", new String[]{"image/png"}),
Uri.parse("https://example.com"));
fail("InputContentInfo must accept content URI only.");
} catch (InvalidParameterException e) {
// OK.
} catch (Exception e) {
fail("Unexpected exception=" + e);
}
}
public void testMimeType() {
try {
InputContentInfo info = new InputContentInfo(
Uri.parse("content://com.example/path"), null,
Uri.parse("https://example.com"));
fail("InputContentInfo must not accept a null description.");
} catch (NullPointerException e) {
// OK.
} catch (Exception e) {
fail("Unexpected exception=" + e);
}
}
public void testLinkUri() {
try {
InputContentInfo info = new InputContentInfo(
Uri.parse("content://com.example/path"),
new ClipDescription("sample content", new String[]{"image/png"}),
null);
} catch (Exception e) {
fail("InputContentInfo must accept a null link Uri.");
}
try {
InputContentInfo info = new InputContentInfo(
Uri.parse("content://com.example/path"),
new ClipDescription("sample content", new String[]{"image/png"}),
Uri.parse("http://example.com/path"));
} catch (Exception e) {
fail("InputContentInfo must accept http link Uri.");
}
try {
InputContentInfo info = new InputContentInfo(
Uri.parse("content://com.example/path"),
new ClipDescription("sample content", new String[]{"image/png"}),
Uri.parse("https://example.com/path"));
} catch (Exception e) {
fail("InputContentInfo must accept https link Uri.");
}
try {
InputContentInfo info = new InputContentInfo(
Uri.parse("content://com.example/path"),
new ClipDescription("sample content", new String[]{"image/png"}),
Uri.parse("ftp://example.com/path"));
fail("InputContentInfo must accept http and https link Uri only.");
} catch (InvalidParameterException e) {
// OK.
} catch (Exception e) {
fail("Unexpected exception=" + e);
}
try {
InputContentInfo info = new InputContentInfo(
Uri.parse("content://com.example/path"),
new ClipDescription("sample content", new String[]{"image/png"}),
Uri.parse("content://com.example/path"));
fail("InputContentInfo must accept http and https link Uri only.");
} catch (InvalidParameterException e) {
// OK.
} catch (Exception e) {
fail("Unexpected exception=" + e);
}
}
}