Index: javatests/org/chromium/distiller/PagePatternTest.java |
diff --git a/javatests/org/chromium/distiller/PagePatternTest.java b/javatests/org/chromium/distiller/PagePatternTest.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..534b7e30f36cfac0cc36d531c590e012dada8bef |
--- /dev/null |
+++ b/javatests/org/chromium/distiller/PagePatternTest.java |
@@ -0,0 +1,107 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.distiller; |
+ |
+public class PagePatternTest extends DomDistillerJsTestCase { |
+ |
+ public void testIsPagingUrl() { |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b?queryA=v1&queryB=4&queryC=v3", |
+ "http://www.foo.com/a/b?queryA=v1&queryB=[*!]&queryC=v3")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b?queryA=v1&queryC=v3", |
+ "http://www.foo.com/a/b?queryA=v1&queryB=[*!]&queryC=v3")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b?queryB=2&queryC=v3", |
+ "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b?queryC=v3", |
+ "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b", "http://www.foo.com/a/b?page=[*!]")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b?page=3", |
+ "http://www.foo.com/a/b?page=[*!]")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b/", "http://www.foo.com/a/b?page=[*!]")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b.htm", "http://www.foo.com/a/b?page=[*!]")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b.html", "http://www.foo.com/a/b?page=[*!]")); |
+ assertFalse(isPagingUrl("http://www.foo.com/a/b?queryA=v1&queryC=v3", |
+ "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")); |
+ assertFalse(isPagingUrl("http://www.foo.com/a/b?queryB=bar&queryC=v3", |
+ "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")); |
+ assertFalse(isPagingUrl("http://www.foo.com/a/b?queryC=v3&queryB=3", |
+ "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")); |
+ assertFalse(isPagingUrl("http://www.foo.com/a/b?queryA=v1", |
+ "http://www.foo.com/a/b?queryA=v1&queryB=[*!]&queryC=v3")); |
+ |
+ assertTrue(isPagingUrl("http://www.foo.com/a/abc-2.html", |
+ "http://www.foo.com/a/abc-[*!].html")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/abc.html", |
+ "http://www.foo.com/a/abc-[*!].html")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/abc", "http://www.foo.com/a/abc-[*!]")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/abc-2", "http://www.foo.com/a/abc-[*!]")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/b-c-3", "http://www.foo.com/a/b-[*!]-c-3")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a-c-3", "http://www.foo.com/a-[*!]-c-3")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a-p-1-c-3", "http://www.foo.com/a-p-[*!]-c-3")); |
+ assertFalse(isPagingUrl("http://www.foo.com/a/abc-page", "http://www.foo.com/a/abc-[*!]")); |
+ assertFalse(isPagingUrl("http://www.foo.com/a/2", "http://www.foo.com/a/abc-[*!]")); |
+ assertFalse(isPagingUrl("http://www.foo.com/a", "http://www.foo.com/a/abc-[*!]")); |
+ |
+ assertTrue(isPagingUrl("http://www.foo.com/a/page/2", "http://www.foo.com/a/page/[*!]")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a", "http://www.foo.com/a/page/[*!]")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/page/2/abc.html", |
+ "http://www.foo.com/a/page/[*!]/abc.html")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/abc.html", |
+ "http://www.foo.com/a/page/[*!]/abc.html")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/abc.html", |
+ "http://www.foo.com/a/[*!]/abc.html")); |
+ assertTrue(isPagingUrl("http://www.foo.com/a/2/abc.html", |
+ "http://www.foo.com/a/[*!]/abc.html")); |
+ assertTrue(isPagingUrl("http://www.foo.com/abc.html", |
+ "http://www.foo.com/a/[*!]/abc.html")); |
+ assertFalse(isPagingUrl("http://www.foo.com/a/page/b", "http://www.foo.com/a/page/[*!]")); |
+ assertFalse(isPagingUrl("http://www.foo.com/m/page/2", "http://www.foo.com/p/page/[*!]")); |
+ } |
+ |
+ public void testIsPagePatternValid() { |
+ assertTrue(isPagePatternValid("http://www.google.com/forum-12", |
+ "http://www.google.com/forum-12/page/[*!]")); |
+ assertTrue(isPagePatternValid("http://www.google.com/forum-12", |
+ "http://www.google.com/forum-12/[*!]")); |
+ assertTrue(isPagePatternValid("http://www.google.com/forum-12", |
+ "http://www.google.com/forum-12/page-[*!]")); |
+ assertTrue(isPagePatternValid("http://www.google.com/forum-12", |
+ "http://www.google.com/forum-12?page=[*!]")); |
+ assertTrue(isPagePatternValid("http://www.google.com/forum-12?sid=12345", |
+ "http://www.google.com/forum-12?page=[*!]&sort=d")); |
+ assertTrue(isPagePatternValid("http://www.google.com/forum-12/food", |
+ "http://www.google.com/forum-12/food/for/bar/[*!]")); |
+ assertTrue(isPagePatternValid("http://www.google.com/forum-12-food", |
+ "http://www.google.com/forum-12-food-[*!]")); |
+ |
+ assertFalse(isPagePatternValid("http://www.google.com/forum-12/food", |
+ "http://www.google.com/forum-12/food/2012/01/[*!]")); |
+ assertFalse(isPagePatternValid("http://www.google.com/forum-12/food/2012/01/01", |
+ "http://www.google.com/forum-12/food/2012/01/[*!]")); |
+ assertFalse(isPagePatternValid("http://www.google.com/forum-12/food", |
+ "http://www.google.com/forum-12?page=[*!]")); |
+ |
+ assertTrue(isPagePatternValid("http://www.google.com/thread/12", |
+ "http://www.google.com/thread/12/page/[*!]")); |
+ assertFalse(isPagePatternValid("http://www.google.com/thread/12/foo", |
+ "http://www.google.com/thread/12/page/[*!]/foo")); |
+ assertTrue(isPagePatternValid("http://www.google.com/thread/12/foo", |
+ "http://www.google.com/thread/12/[*!]/foo")); |
+ } |
+ |
+ private static boolean isPagingUrl(String urlStr, String patternStr) { |
+ PagePattern pattern = PagePattern.create(patternStr); |
+ assertTrue(pattern != null); |
+ return pattern.isPagingUrl(urlStr); |
+ } |
+ |
+ private static boolean isPagePatternValid(String urlStr, String patternStr) { |
+ ParsedUrl parsedUrl = ParsedUrl.create(urlStr); |
+ assertTrue(parsedUrl != null); |
+ PagePattern pattern = PagePattern.create(patternStr); |
+ assertTrue(pattern != null); |
+ return pattern.isValidFor(parsedUrl); |
+ } |
+ |
+} |