aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2025-02-22 07:36:43 +0100
committerGitHub <noreply@github.com>2025-02-22 07:36:43 +0100
commit5e921311c75276d407cb144b8024b8bdd75328d0 (patch)
tree58396a6ab7ad83deb0061aafcfd89ecbb39655f7 /src/parser.js
parent85f89126c127a318e90ef79e49af655795b3d122 (diff)
parentd61b7e4b233b025f9084c8c0219a9d9f7bd9bd8a (diff)
downloadsvg.js-master.tar.gz
svg.js-master.zip
Merge pull request #1334 from kcooney/gboxHEADmaster
Remove gbox() from G in svg.js.d.ts
Diffstat (limited to 'src/parser.js')
0 files changed, 0 insertions, 0 deletions
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
/*
 * Copyright 2013, The gwtquery team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.query.client.ajax;

import junit.framework.Assert;

import com.google.gwt.http.client.Response;
import com.google.gwt.junit.DoNotRunWith;
import com.google.gwt.junit.Platform;
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.query.client.IsProperties;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.GQ;
import com.google.gwt.query.client.Promise;
import com.google.gwt.query.client.plugins.ajax.Ajax;
import com.google.gwt.query.client.plugins.ajax.Ajax.Settings;

/**
 * Common Tests for Data Binding and Ajax which can run either in JVM and GWT
 */
public abstract class AjaxTests extends GWTTestCase {

  protected String echoUrl, echoUrlCORS;
  protected IsProperties json, jsonGET;
  protected String servletPath = "test.json";
  
  private Function failFunction = new Function() {
    public void f() {
      fail();
    }
  };
  
  private Function finishFunction = new Function() {
    public void f() {
      finishTest();
    }
  };
  
  public AjaxTests() {
    jsonGET = GQ.create("data: {a: abc, d: def}", true);
    json = GQ.create("a: abc, d: def", true);
  }
  
  private Promise performAjaxJsonTest(Settings s) {
    delayTestFinish(5000);
    return Ajax.ajax(s)
      .done(new Function(){public void f() {
        IsProperties p = arguments(0);
        assertEquals("abc", p.get("a"));
        finishTest();
      }})
      .fail(failFunction);
  }
  
  private Promise performAjaxJsonTest_CORS(Settings s) {
    return performAjaxJsonTest(s)
      .done(new Function() {public void f() {
        Response r = arguments(3);
        assertNotNull(r.getHeader("Access-Control-Allow-Origin"));
      }});
  }

  public void testAjaxJsonPost() {
    delayTestFinish(5000);
    Settings s = Ajax.createSettings()
      .setUrl(echoUrl)
      .setData(json)
      .setDataType("json")
      .setUsername("testuser")
      .setPassword("testpassword");

    performAjaxJsonTest(s);
  }

  // This test needs htmlunit at least 2.11
  // https://groups.google.com/forum/#!msg/google-web-toolkit/dmyTt1Bh0pM/lBTIFiTyrpkJ
  //
  // It is necessary to patch RunStyleHtmlUnit because GWT default browser is FF3 since
  // minimun version in htmlunit-2.1x is FF3.6
  // It is necessary to patch BrowserChannel as well because convertFromJavaValue receives
  // non string objects under certain circumstances.
  @DoNotRunWith(Platform.HtmlUnitBug)
  public void testAjaxJsonPost_CORS() {
    delayTestFinish(5000);
    Settings s = Ajax.createSettings()
      .setUrl(echoUrlCORS)
      .setData(json)
      .setDataType("json");
    
    performAjaxJsonTest_CORS(s);
  }
  
  public void testAjaxJsonGet() {
    Settings s = Ajax.createSettings()
      .setType("get")
      .setUrl(echoUrl)
      .setData(jsonGET)
      .setDataType("json");

    performAjaxJsonTest(s);
  }
  
  @DoNotRunWith(Platform.HtmlUnitBug)
  public void testAjaxJsonGet_CORS() {
    Settings s = Ajax.createSettings()
      .setType("get")
      .setUrl(echoUrlCORS)
      .setData(jsonGET)
      .setDataType("json");

    performAjaxJsonTest_CORS(s)
      .done(new Function() {
          public void f() {
            Response r = arguments(3);
            Assert.assertNotNull(r.getHeader("Access-Control-Allow-Origin"));
            Assert.assertNull(r.getHeader("Access-Control-Allow-Credentials"));
          }
        });
  }
  
  @DoNotRunWith(Platform.HtmlUnitBug)
  public void testAjaxJsonGet_CORS_WithCredentials_Supported() {
    Settings s = Ajax.createSettings()
      .setType("get")
      // Enable credentials in servlet 
      .setUrl(echoUrlCORS + "&credentials=true")
      .setData(jsonGET)
      .setDataType("json")
      .setWithCredentials(true);

    performAjaxJsonTest_CORS(s)
      .done(new Function() {
        public void f() {
          Response r = arguments(3);
          Assert.assertNotNull(r.getHeader("Access-Control-Allow-Origin"));
          Assert.assertNotNull(r.getHeader("Access-Control-Allow-Credentials"));
        }
      });
  }
  
  @DoNotRunWith(Platform.HtmlUnitBug)
  public void testAjaxJsonGet_CORS_WithCredentials_Unsupported() {
    Settings s = Ajax.createSettings()
      .setType("get")
      // Disable credentials in servlet 
      .setUrl(echoUrlCORS)
      .setData(jsonGET)
      .setDataType("json")
      .setWithCredentials(true);
    
    Ajax.ajax(s)
      .fail(finishFunction)
      .done(failFunction);
  }
  
  public void testAjaxGetJsonP() {
    delayTestFinish(5000);
    Settings s = Ajax.createSettings()
      .setType("post")
      .setUrl(echoUrlCORS)
      .setData(jsonGET)
      .setDataType("jsonp");

    performAjaxJsonTest(s);
  }
  
  public void testJsonValidService() {
    delayTestFinish(5000);
    // Use a public json service supporting callback parameter
    Ajax.getJSONP("https://www.googleapis.com/blogger/v2/blogs/user_id/posts/post_id?callback=?&key=NO-KEY")
      .done(new Function(){
        public void f() {
          IsProperties p = arguments(0);
          // It should return error since we do not use a valid key
          // {"error":{"errors":[{"domain":"usageLimits","reason":"keyInvalid","message":"Bad Request"}],"code":400,"message":"Bad Request"}}
          assertEquals(400, p.<IsProperties>get("error").<Number>get("code").intValue());
          finishTest();
        }
      })
      .fail(failFunction);
  }
  
  public void testInvalidOrigin() {
    delayTestFinish(5000);
    Settings s = Ajax.createSettings()
      // Use a public json service non CORS enabled
      .setUrl("https://www.googleapis.com/blogger/v2/blogs/user_id/posts/post_id?key=NO-KEY")
      .setDataType("json")
      .setTimeout(1000);
    
    Ajax.ajax(s)
      .done(failFunction)
      .fail(finishFunction);
  }
  
  public void testJsonInvalidService() {
    delayTestFinish(5000);
    Settings s = Ajax.createSettings()
      // Use a valid javascript which does not wrap content in a callback
      .setUrl("http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js")
      .setDataType("jsonp")
      .setTimeout(1000);
    
    Ajax.ajax(s)
      .done(failFunction)
      .fail(finishFunction);
  }
  
  // For some reason htmlunit 2.16 does not raises a timeout, 2.9 does though, 
  // when server sleeps or connection lasts a while. Tested with htmlunit 2.16
  //  @DoNotRunWith(Platform.HtmlUnitBug)
  public void testAjaxTimeout() {
    delayTestFinish(5000);
    Settings s = Ajax.createSettings()
      .setTimeout(100)
      .setType("get")
      // Connecting to private networks out of our LAN raises a timeout because
      // there is no route for them in public networks.  
      .setUrl("http://10.32.45.67:7654");

    Ajax.ajax(s)
      .done(failFunction)
      .fail(finishFunction);
  }
  
  public void testJsonpTimeout() {
    delayTestFinish(5000);
    Settings s = Ajax.createSettings()
      .setTimeout(1000)
      .setDataType("jsonp")
      .setUrl(echoUrl + "?timeout=2000");

    Ajax.ajax(s)
      .done(failFunction)
      .fail(finishFunction);     
  }
  
  public void testAjaxError() {
    delayTestFinish(5000);
    String url = "http://127.0.0.1/nopage";

    Ajax.ajax(Ajax.createSettings().setTimeout(1000).setUrl(url))
      .done(new Function(){
        public void f() {
          fail();
        }
      }).fail(new Function(){
        public void f() {
          finishTest();
        }
      });
  }
  
  public void testLoadScript() {
    delayTestFinish(5000);
    String url = "http://code.jquery.com/jquery-2.0.3.min.js";
    Ajax.loadScript(url)
      .done(new Function(){
        public void f() {
          finishTest();
        }
      }).fail(new Function(){
        public void f() {
          fail();
        }
      });
  }

  public void testGetScriptFail() {
    delayTestFinish(5000);
    String url = "http://127.0.0.1/nopage";
    Ajax.getScript(url)
      .done(new Function(){
        public void f() {
          fail();
        }
      }).fail(new Function(){
        public void f() {
          finishTest();
        }
      });
  }  
}