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

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: Allow Extras; require that standard keys appear only once; use Matchers; more test cases. Created 5 years, 8 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
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 String[] expectedTrue = {
110 "intent://10010#Intent;scheme=tel;action=com.google.android.apps."
111 + "authenticator.AUTHENTICATE;end",
112 "intent://scan/#Intent;package=com.google.zxing.client.android;"
113 + "scheme=zxing;end;",
114 "intent://wump-hey.example.com/#Intent;package=com.example.wump;"
115 + "scheme=yow;component=com.example.PUMPKIN;end;",
116 "intent://wump_hey.example.com/#Intent;package=com.example.wump;"
Yaron 2015/04/24 20:38:17 Please add a test with extras
117 + "scheme=eeek;action=frighten_children;end;"
118 };
119
120 for (int i = 0; i < expectedTrue.length; ++i) {
121 assertTrue(UrlUtilities.validateIntentUrl(expectedTrue[i]));
122 }
123
124 String[] expectedFalse = {
125 // Junk after end.
126 "intent://10010#Intent;scheme=tel;action=com.google.android.apps."
127 + "authenticator.AUTHENTICATE;end','*');"
128 + "alert(document.cookie);//",
129 // component appears twice.
130 "intent://wump-hey.example.com/#Intent;package=com.example.wump;"
131 + "scheme=yow;component=com.example.PUMPKIN;"
132 + "component=com.example.AVOCADO;end;",
133 // scheme contains illegal character.
134 "intent://wump-hey.example.com/#Intent;package=com.example.wump;"
135 + "scheme=hello+goodbye;component=com.example.PUMPKIN;end;",
136 // category contains illegal character.
137 "intent://wump-hey.example.com/#Intent;package=com.example.wump;"
138 + "category=42%_by_volume;end"
139 };
140
141 for (int i = 0; i < expectedFalse.length; ++i) {
142 assertFalse(UrlUtilities.validateIntentUrl(expectedFalse[i]));
143 }
144 }
145
107 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698