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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java
index d40403d745a2a240504169124b6b29b104666730..22337dcc71b1f1fb708f54ead6c2d8ca20b3974d 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/UrlUtilitiesTest.java
@@ -104,4 +104,43 @@ public class UrlUtilitiesTest extends InstrumentationTestCase {
assertEquals("about:blank", UrlUtilities.getOriginForDisplay(uri, false));
}
+ @SmallTest
+ public void testValidateIntentUrl() {
+ String[] expectedTrue = {
+ "intent://10010#Intent;scheme=tel;action=com.google.android.apps."
+ + "authenticator.AUTHENTICATE;end",
+ "intent://scan/#Intent;package=com.google.zxing.client.android;"
+ + "scheme=zxing;end;",
+ "intent://wump-hey.example.com/#Intent;package=com.example.wump;"
+ + "scheme=yow;component=com.example.PUMPKIN;end;",
+ "intent://wump_hey.example.com/#Intent;package=com.example.wump;"
Yaron 2015/04/24 20:38:17 Please add a test with extras
+ + "scheme=eeek;action=frighten_children;end;"
+ };
+
+ for (int i = 0; i < expectedTrue.length; ++i) {
+ assertTrue(UrlUtilities.validateIntentUrl(expectedTrue[i]));
+ }
+
+ String[] expectedFalse = {
+ // Junk after end.
+ "intent://10010#Intent;scheme=tel;action=com.google.android.apps."
+ + "authenticator.AUTHENTICATE;end','*');"
+ + "alert(document.cookie);//",
+ // component appears twice.
+ "intent://wump-hey.example.com/#Intent;package=com.example.wump;"
+ + "scheme=yow;component=com.example.PUMPKIN;"
+ + "component=com.example.AVOCADO;end;",
+ // scheme contains illegal character.
+ "intent://wump-hey.example.com/#Intent;package=com.example.wump;"
+ + "scheme=hello+goodbye;component=com.example.PUMPKIN;end;",
+ // category contains illegal character.
+ "intent://wump-hey.example.com/#Intent;package=com.example.wump;"
+ + "category=42%_by_volume;end"
+ };
+
+ for (int i = 0; i < expectedFalse.length; ++i) {
+ assertFalse(UrlUtilities.validateIntentUrl(expectedFalse[i]));
+ }
+ }
+
}

Powered by Google App Engine
This is Rietveld 408576698