2 * Copyright 2007 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.result;
19 import junit.framework.TestCase;
20 import com.google.zxing.Result;
21 import com.google.zxing.BarcodeFormat;
24 * Tests {@link URIParsedResult}.
28 public final class URIParsedResultTestCase extends TestCase {
30 public void testBookmarkDocomo() {
31 doTest("MEBKM:URL:google.com;;", "http://google.com", null);
32 doTest("MEBKM:URL:http://google.com;;", "http://google.com", null);
33 doTest("MEBKM:URL:google.com;TITLE:Google;", "http://google.com", "Google");
36 public void testURI() {
37 doTest("google.com", "http://google.com", null);
38 doTest("http://google.com", "http://google.com", null);
39 doTest("https://google.com", "https://google.com", null);
40 doTest("google.com:443", "http://google.com:443", null);
41 doTest("https://www.google.com/calendar/hosted/google.com/embed?mode=AGENDA&force_login=true&src=google.com_726f6f6d5f6265707075@resource.calendar.google.com",
42 "https://www.google.com/calendar/hosted/google.com/embed?mode=AGENDA&force_login=true&src=google.com_726f6f6d5f6265707075@resource.calendar.google.com",
46 public void testURLTO() {
47 doTest("urlto::bar.com", "http://bar.com", null);
48 doTest("urlto::http://bar.com", "http://bar.com", null);
49 doTest("urlto:foo:bar.com", "http://bar.com", "foo");
52 public void testIsPossiblyMalicious() {
53 doTestIsPossiblyMalicious("http://google.com", false);
54 doTestIsPossiblyMalicious("http://google.com@evil.com", true);
55 doTestIsPossiblyMalicious("http://google.com:@evil.com", true);
56 doTestIsPossiblyMalicious("google.com:@evil.com", true);
57 doTestIsPossiblyMalicious("https://google.com:443", false);
58 doTestIsPossiblyMalicious("http://google.com/foo@bar", false);
61 private static void doTest(String contents, String uri, String title) {
62 Result fakeResult = new Result(contents, null, null, BarcodeFormat.QR_CODE);
63 ParsedResult result = ResultParser.parseResult(fakeResult);
64 assertEquals(ParsedResultType.URI, result.getType());
65 URIParsedResult uriResult = (URIParsedResult) result;
66 assertEquals(uri, uriResult.getURI());
67 assertEquals(title, uriResult.getTitle());
70 private static void doTestIsPossiblyMalicious(String uri, boolean expected) {
71 URIParsedResult result = new URIParsedResult(uri, null);
72 assertEquals(expected, result.isPossiblyMaliciousURI());