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

Side by Side Diff: javatests/org/chromium/distiller/QueryParamPagePatternTest.java

Issue 1029593003: implement validations of pagination URLs (Closed) Base URL: https://github.com/chromium/dom-distiller.git@master
Patch Set: addr chris's comments 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
« no previous file with comments | « javatests/org/chromium/distiller/PathComponentPagePatternTest.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
(Empty)
1 // Copyright 2015 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 QueryParamPagePatternTest extends DomDistillerJsTestCase {
8 private static final String PAGE_PARAM_VALUE = "8";
9
10 public void testIsPagingUrl() {
11 assertTrue(isPagingUrl("http://www.foo.com/a/b?queryA=v1&queryB=4&queryC =v3",
12 "http://www.foo.com/a/b?queryA=v1&queryB=[*!]&que ryC=v3"));
13 assertTrue(isPagingUrl("http://www.foo.com/a/b?queryA=v1&queryC=v3",
14 "http://www.foo.com/a/b?queryA=v1&queryB=[*!]&que ryC=v3"));
15 assertTrue(isPagingUrl("http://www.foo.com/a/b?queryB=2&queryC=v3",
16 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3"));
17 assertTrue(isPagingUrl("http://www.foo.com/a/b?queryC=v3",
18 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3"));
19 assertTrue(isPagingUrl("http://www.foo.com/a/b", "http://www.foo.com/a/b ?page=[*!]"));
20 assertTrue(isPagingUrl("http://www.foo.com/a/b?page=3",
21 "http://www.foo.com/a/b?page=[*!]"));
22 assertTrue(isPagingUrl("http://www.foo.com/a/b/", "http://www.foo.com/a/ b?page=[*!]"));
23 assertTrue(isPagingUrl("http://www.foo.com/a/b.htm", "http://www.foo.com /a/b?page=[*!]"));
24 assertTrue(isPagingUrl("http://www.foo.com/a/b.html", "http://www.foo.co m/a/b?page=[*!]"));
25 assertFalse(isPagingUrl("http://www.foo.com/a/b?queryA=v1&queryC=v3",
26 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")) ;
27 assertFalse(isPagingUrl("http://www.foo.com/a/b?queryB=bar&queryC=v3",
28 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")) ;
29 assertFalse(isPagingUrl("http://www.foo.com/a/b?queryC=v3&queryB=3",
30 "http://www.foo.com/a/b?queryB=[*!]&queryC=v3")) ;
31 assertFalse(isPagingUrl("http://www.foo.com/a/b?queryA=v1",
32 "http://www.foo.com/a/b?queryA=v1&queryB=[*!]&qu eryC=v3"));
33 }
34
35 public void testIsPagePatternValid() {
36 assertTrue(isPagePatternValid("http://www.google.com/forum-12",
37 "http://www.google.com/forum-12?page=[*!]"));
38 assertTrue(isPagePatternValid("http://www.google.com/forum-12?sid=12345" ,
39 "http://www.google.com/forum-12?page=[*!]&sort=d"));
40 assertFalse(isPagePatternValid("http://www.google.com/a/forum-12?sid=123 45",
41 "http://www.google.com/b/forum-12?page=[*!]&sort=d"));
42 assertFalse(isPagePatternValid("http://www.google.com/forum-11?sid=12345 ",
43 "http://www.google.com/forum-12?page=[*!]&sort=d"));
44 }
45
46 private static boolean isPagingUrl(String urlStr, String patternStr) {
47 PageParameterDetector.PagePattern pattern = createPagePattern(patternStr );
48 assertTrue(pattern != null);
49 return pattern.isPagingUrl(urlStr);
50 }
51
52 private static boolean isPagePatternValid(String urlStr, String patternStr) {
53 ParsedUrl url = ParsedUrl.create(urlStr);
54 assertTrue(url != null);
55 PageParameterDetector.PagePattern pattern = createPagePattern(patternStr );
56 assertTrue(pattern != null);
57 return pattern.isValidFor(url);
58 }
59
60 private static PageParameterDetector.PagePattern createPagePattern(String pa tternStr) {
61 ParsedUrl url = ParsedUrl.create(patternStr);
62 String[][] queryParams = url.getQueryParams();
63 assertTrue(queryParams.length > 0);
64 for (String[] nameValue : queryParams) {
65 final String queryName = nameValue[0];
66 final String queryValue = nameValue[1];
67 if (queryValue.contains(PageParameterDetector.PAGE_PARAM_PLACEHOLDER )) {
68 return QueryParamPagePattern.create(ParsedUrl.create(
69 url.replaceQueryValue(queryName, queryValue, PAGE_PARAM_ VALUE)),
70 queryName, PAGE_PARAM_VALUE);
71 }
72 }
73 return null;
74 }
75
76 }
OLDNEW
« no previous file with comments | « javatests/org/chromium/distiller/PathComponentPagePatternTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698