Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | package org.mozilla.gecko.background.sync; |
michael@0 | 5 | |
michael@0 | 6 | import java.util.Arrays; |
michael@0 | 7 | |
michael@0 | 8 | import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; |
michael@0 | 9 | import org.mozilla.gecko.sync.setup.activities.WebURLFinder; |
michael@0 | 10 | |
michael@0 | 11 | /** |
michael@0 | 12 | * These tests are on device because the WebKit APIs are stubs on desktop. |
michael@0 | 13 | */ |
michael@0 | 14 | public class TestWebURLFinder extends AndroidSyncTestCase { |
michael@0 | 15 | public String find(String string) { |
michael@0 | 16 | return new WebURLFinder(string).bestWebURL(); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | public String find(String[] strings) { |
michael@0 | 20 | return new WebURLFinder(Arrays.asList(strings)).bestWebURL(); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | public void testNoEmail() { |
michael@0 | 24 | assertNull(find("test@test.com")); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | public void testSchemeFirst() { |
michael@0 | 28 | assertEquals("http://scheme.com", find("test.com http://scheme.com")); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | public void testFullURL() { |
michael@0 | 32 | assertEquals("http://scheme.com:8080/inner#anchor&arg=1", find("test.com http://scheme.com:8080/inner#anchor&arg=1")); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | public void testNoScheme() { |
michael@0 | 36 | assertEquals("noscheme.com", find("noscheme.com")); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | public void testNoBadScheme() { |
michael@0 | 40 | assertNull(find("file:///test javascript:///test.js")); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | public void testStrings() { |
michael@0 | 44 | assertEquals("http://test.com", find(new String[] { "http://test.com", "noscheme.com" })); |
michael@0 | 45 | assertEquals("http://test.com", find(new String[] { "noschemefirst.com", "http://test.com" })); |
michael@0 | 46 | assertEquals("http://test.com/inner#test", find(new String[] { "noschemefirst.com", "http://test.com/inner#test", "http://second.org/fark" })); |
michael@0 | 47 | assertEquals("http://test.com", find(new String[] { "javascript:///test.js", "http://test.com" })); |
michael@0 | 48 | } |
michael@0 | 49 | } |