OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.distiller; |
| 6 |
| 7 public class PagePatternTest extends DomDistillerJsTestCase { |
| 8 |
| 9 public void testIsPagingUrl() { |
| 10 assertTrue(isPagingUrl("http://www.foo.com/a/b?queryA=v1&queryB=4&queryC
=v3", |
| 11 "http://www.foo.com/a/b?queryA=v1&queryB=[*!]&que
ryC=v3")); |
| 12 assertTrue(isPagingUrl("http://www.foo.com/a/b?queryA=v1&queryC=v3", |
| 13 "http://www.foo.com/a/b?queryA=v1&queryB=[*!]&que
ryC=v3")); |
| 14 assertTrue(isPagingUrl("http://www.foo.com/a/b?queryB=2&queryC=v3", |
| 15 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")); |
| 16 assertTrue(isPagingUrl("http://www.foo.com/a/b?queryC=v3", |
| 17 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")); |
| 18 assertTrue(isPagingUrl("http://www.foo.com/a/b", "http://www.foo.com/a/b
?page=[*!]")); |
| 19 assertTrue(isPagingUrl("http://www.foo.com/a/b?page=3", |
| 20 "http://www.foo.com/a/b?page=[*!]")); |
| 21 assertTrue(isPagingUrl("http://www.foo.com/a/b/", "http://www.foo.com/a/
b?page=[*!]")); |
| 22 assertTrue(isPagingUrl("http://www.foo.com/a/b.htm", "http://www.foo.com
/a/b?page=[*!]")); |
| 23 assertTrue(isPagingUrl("http://www.foo.com/a/b.html", "http://www.foo.co
m/a/b?page=[*!]")); |
| 24 assertFalse(isPagingUrl("http://www.foo.com/a/b?queryA=v1&queryC=v3", |
| 25 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3"))
; |
| 26 assertFalse(isPagingUrl("http://www.foo.com/a/b?queryB=bar&queryC=v3", |
| 27 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3"))
; |
| 28 assertFalse(isPagingUrl("http://www.foo.com/a/b?queryC=v3&queryB=3", |
| 29 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3"))
; |
| 30 assertFalse(isPagingUrl("http://www.foo.com/a/b?queryA=v1", |
| 31 "http://www.foo.com/a/b?queryA=v1&queryB=[*!]&qu
eryC=v3")); |
| 32 |
| 33 assertTrue(isPagingUrl("http://www.foo.com/a/abc-2.html", |
| 34 "http://www.foo.com/a/abc-[*!].html")); |
| 35 assertTrue(isPagingUrl("http://www.foo.com/a/abc.html", |
| 36 "http://www.foo.com/a/abc-[*!].html")); |
| 37 assertTrue(isPagingUrl("http://www.foo.com/a/abc", "http://www.foo.com/a
/abc-[*!]")); |
| 38 assertTrue(isPagingUrl("http://www.foo.com/a/abc-2", "http://www.foo.com
/a/abc-[*!]")); |
| 39 assertTrue(isPagingUrl("http://www.foo.com/a/b-c-3", "http://www.foo.com
/a/b-[*!]-c-3")); |
| 40 assertTrue(isPagingUrl("http://www.foo.com/a-c-3", "http://www.foo.com/a
-[*!]-c-3")); |
| 41 assertTrue(isPagingUrl("http://www.foo.com/a-p-1-c-3", "http://www.foo.c
om/a-p-[*!]-c-3")); |
| 42 assertFalse(isPagingUrl("http://www.foo.com/a/abc-page", "http://www.foo
.com/a/abc-[*!]")); |
| 43 assertFalse(isPagingUrl("http://www.foo.com/a/2", "http://www.foo.com/a/
abc-[*!]")); |
| 44 assertFalse(isPagingUrl("http://www.foo.com/a", "http://www.foo.com/a/ab
c-[*!]")); |
| 45 |
| 46 assertTrue(isPagingUrl("http://www.foo.com/a/page/2", "http://www.foo.co
m/a/page/[*!]")); |
| 47 assertTrue(isPagingUrl("http://www.foo.com/a", "http://www.foo.com/a/pag
e/[*!]")); |
| 48 assertTrue(isPagingUrl("http://www.foo.com/a/page/2/abc.html", |
| 49 "http://www.foo.com/a/page/[*!]/abc.html")); |
| 50 assertTrue(isPagingUrl("http://www.foo.com/a/abc.html", |
| 51 "http://www.foo.com/a/page/[*!]/abc.html")); |
| 52 assertTrue(isPagingUrl("http://www.foo.com/a/abc.html", |
| 53 "http://www.foo.com/a/[*!]/abc.html")); |
| 54 assertTrue(isPagingUrl("http://www.foo.com/a/2/abc.html", |
| 55 "http://www.foo.com/a/[*!]/abc.html")); |
| 56 assertTrue(isPagingUrl("http://www.foo.com/abc.html", |
| 57 "http://www.foo.com/a/[*!]/abc.html")); |
| 58 assertFalse(isPagingUrl("http://www.foo.com/a/page/b", "http://www.foo.c
om/a/page/[*!]")); |
| 59 assertFalse(isPagingUrl("http://www.foo.com/m/page/2", "http://www.foo.c
om/p/page/[*!]")); |
| 60 } |
| 61 |
| 62 public void testIsPagePatternValid() { |
| 63 assertTrue(isPagePatternValid("http://www.google.com/forum-12", |
| 64 "http://www.google.com/forum-12/page/[*!]")); |
| 65 assertTrue(isPagePatternValid("http://www.google.com/forum-12", |
| 66 "http://www.google.com/forum-12/[*!]")); |
| 67 assertTrue(isPagePatternValid("http://www.google.com/forum-12", |
| 68 "http://www.google.com/forum-12/page-[*!]")); |
| 69 assertTrue(isPagePatternValid("http://www.google.com/forum-12", |
| 70 "http://www.google.com/forum-12?page=[*!]")); |
| 71 assertTrue(isPagePatternValid("http://www.google.com/forum-12?sid=12345"
, |
| 72 "http://www.google.com/forum-12?page=[*!]&sort=d")); |
| 73 assertTrue(isPagePatternValid("http://www.google.com/forum-12/food", |
| 74 "http://www.google.com/forum-12/food/for/bar/[*!]")); |
| 75 assertTrue(isPagePatternValid("http://www.google.com/forum-12-food", |
| 76 "http://www.google.com/forum-12-food-[*!]")); |
| 77 |
| 78 assertFalse(isPagePatternValid("http://www.google.com/forum-12/food", |
| 79 "http://www.google.com/forum-12/food/2012/01/[*!]")); |
| 80 assertFalse(isPagePatternValid("http://www.google.com/forum-12/food/2012
/01/01", |
| 81 "http://www.google.com/forum-12/food/2012/01/[*!]")); |
| 82 assertFalse(isPagePatternValid("http://www.google.com/forum-12/food", |
| 83 "http://www.google.com/forum-12?page=[*!]")); |
| 84 |
| 85 assertTrue(isPagePatternValid("http://www.google.com/thread/12", |
| 86 "http://www.google.com/thread/12/page/[*!]")); |
| 87 assertFalse(isPagePatternValid("http://www.google.com/thread/12/foo", |
| 88 "http://www.google.com/thread/12/page/[*!]/foo")); |
| 89 assertTrue(isPagePatternValid("http://www.google.com/thread/12/foo", |
| 90 "http://www.google.com/thread/12/[*!]/foo")); |
| 91 } |
| 92 |
| 93 private static boolean isPagingUrl(String urlStr, String patternStr) { |
| 94 PagePattern pattern = PagePattern.create(patternStr); |
| 95 assertTrue(pattern != null); |
| 96 return pattern.isPagingUrl(urlStr); |
| 97 } |
| 98 |
| 99 private static boolean isPagePatternValid(String urlStr, String patternStr)
{ |
| 100 ParsedUrl parsedUrl = ParsedUrl.create(urlStr); |
| 101 assertTrue(parsedUrl != null); |
| 102 PagePattern pattern = PagePattern.create(patternStr); |
| 103 assertTrue(pattern != null); |
| 104 return pattern.isValidFor(parsedUrl); |
| 105 } |
| 106 |
| 107 } |
OLD | NEW |