OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.test.InstrumentationTestCase; | 7 import android.test.InstrumentationTestCase; |
8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
9 | 9 |
10 import org.chromium.base.test.util.Feature; | 10 import org.chromium.base.test.util.Feature; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 uri = URI.create("chrome://settings:443"); | 98 uri = URI.create("chrome://settings:443"); |
99 assertEquals("chrome://settings:443", UrlUtilities.getOriginForDisplay(u
ri, true)); | 99 assertEquals("chrome://settings:443", UrlUtilities.getOriginForDisplay(u
ri, true)); |
100 assertEquals("settings:443", UrlUtilities.getOriginForDisplay(uri, false
)); | 100 assertEquals("settings:443", UrlUtilities.getOriginForDisplay(uri, false
)); |
101 | 101 |
102 uri = URI.create("about:blank"); | 102 uri = URI.create("about:blank"); |
103 assertEquals("about:blank", UrlUtilities.getOriginForDisplay(uri, true))
; | 103 assertEquals("about:blank", UrlUtilities.getOriginForDisplay(uri, true))
; |
104 assertEquals("about:blank", UrlUtilities.getOriginForDisplay(uri, false)
); | 104 assertEquals("about:blank", UrlUtilities.getOriginForDisplay(uri, false)
); |
105 } | 105 } |
106 | 106 |
| 107 @SmallTest |
| 108 public void testValidateIntentUrl() { |
| 109 // Valid action, hostname, and (empty) path. |
| 110 assertTrue(UrlUtilities.validateIntentUrl( |
| 111 "intent://10010#Intent;scheme=tel;action=com.google.android.apps
." |
| 112 + "authenticator.AUTHENTICATE;end")); |
| 113 // Valid package, scheme, hostname, and path. |
| 114 assertTrue(UrlUtilities.validateIntentUrl( |
| 115 "intent://scan/#Intent;package=com.google.zxing.client.android;" |
| 116 + "scheme=zxing;end;")); |
| 117 // Valid package, scheme, component, hostname, and path. |
| 118 assertTrue(UrlUtilities.validateIntentUrl( |
| 119 "intent://wump-hey.example.com/#Intent;package=com.example.wump;
" |
| 120 + "scheme=yow;component=com.example.PUMPKIN;end;")); |
| 121 // Valid package, scheme, action, hostname, and path. |
| 122 assertTrue(UrlUtilities.validateIntentUrl( |
| 123 "intent://wump-hey.example.com/#Intent;package=com.example.wump;
" |
| 124 + "scheme=eeek;action=frighten_children;end;")); |
| 125 // Valid package, component, String extra, hostname, and path. |
| 126 assertTrue(UrlUtilities.validateIntentUrl( |
| 127 "intent://testing/#Intent;package=cybergoat.noodle.crumpet;" |
| 128 + "component=wump.noodle/Crumpet;S.goat=leg;end")); |
| 129 |
| 130 // Valid package, component, int extra (with URL-encoded key), String |
| 131 // extra, hostname, and path. |
| 132 assertTrue(UrlUtilities.validateIntentUrl( |
| 133 "intent://testing/#Intent;package=cybergoat.noodle.crumpet;" |
| 134 + "component=wump.noodle/Crumpet;i.pumpkinCount%3D=42;" |
| 135 + "S.goat=leg;end")); |
| 136 |
| 137 // Junk after end. |
| 138 assertFalse(UrlUtilities.validateIntentUrl( |
| 139 "intent://10010#Intent;scheme=tel;action=com.google.android.apps
." |
| 140 + "authenticator.AUTHENTICATE;end','*');" |
| 141 + "alert(document.cookie);//")); |
| 142 // component appears twice. |
| 143 assertFalse(UrlUtilities.validateIntentUrl( |
| 144 "intent://wump-hey.example.com/#Intent;package=com.example.wump;
" |
| 145 + "scheme=yow;component=com.example.PUMPKIN;" |
| 146 + "component=com.example.AVOCADO;end;")); |
| 147 // scheme contains illegal character. |
| 148 assertFalse(UrlUtilities.validateIntentUrl( |
| 149 "intent://wump-hey.example.com/#Intent;package=com.example.wump;
" |
| 150 + "scheme=hello+goodbye;component=com.example.PUMPKIN;end;")); |
| 151 // category contains illegal character. |
| 152 assertFalse(UrlUtilities.validateIntentUrl( |
| 153 "intent://wump-hey.example.com/#Intent;package=com.example.wump;
" |
| 154 + "category=42%_by_volume;end")); |
| 155 // Incorrectly URL-encoded. |
| 156 assertFalse(UrlUtilities.validateIntentUrl( |
| 157 "intent://testing/#Intent;package=cybergoat.noodle.crumpet;" |
| 158 + "component=wump.noodle/Crumpet;i.pumpkinCount%%3D=42;" |
| 159 + "S.goat=⋚end")); |
| 160 } |
| 161 |
107 } | 162 } |
OLD | NEW |