corsxmlhttpfactory_test.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2013 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.net.CorsXmlHttpFactoryTest');
  15. goog.setTestOnly('goog.net.CorsXmlHttpFactoryTest');
  16. goog.require('goog.net.CorsXmlHttpFactory');
  17. goog.require('goog.net.IeCorsXhrAdapter');
  18. goog.require('goog.testing.jsunit');
  19. goog.require('goog.userAgent');
  20. function testBrowserSupport() {
  21. var requestFactory = new goog.net.CorsXmlHttpFactory();
  22. if (goog.userAgent.IE) {
  23. if (goog.userAgent.isVersionOrHigher('10')) {
  24. // Continue: IE10 supports CORS requests using native XMLHttpRequest.
  25. } else if (goog.userAgent.isVersionOrHigher('8')) {
  26. assertTrue(
  27. requestFactory.createInstance() instanceof goog.net.IeCorsXhrAdapter);
  28. return;
  29. } else {
  30. try {
  31. requestFactory.createInstance();
  32. fail('Error expected.');
  33. } catch (e) {
  34. assertEquals('Unsupported browser', e.message);
  35. return;
  36. }
  37. }
  38. }
  39. // All other browsers support CORS requests using native XMLHttpRequest.
  40. assertTrue(requestFactory.createInstance() instanceof XMLHttpRequest);
  41. }