Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java

Issue 1059413004: Add a validator for intent:// URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Why are the presubmit checks different on the bots vs. local? import org.chromium.base.Log; Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/UrlUtilities.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/UrlUtilities.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698