8
0

basepath.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals beforeEach, describe, it, expect, window, document */
  6. 'use strict';
  7. bender.amd.require( 'ckeditor' );
  8. beforeEach( function() {
  9. // Ensure that no CKEDITOR_BASEPATH global is available.
  10. delete window.CKEDITOR_BASEPATH;
  11. // Remove all script elements from the document.
  12. removeScripts();
  13. } );
  14. describe( 'basePath', function( CKEDITOR ) {
  15. it( 'should work with script tags', function() {
  16. addScript( 'http://bar.com/ckeditor/ckeditor.js' );
  17. expect( CKEDITOR._getBasePath() ).to.equal( 'http://bar.com/ckeditor/' );
  18. } );
  19. it( 'should work with the CKEDITOR_BASEPATH global', function() {
  20. window.CKEDITOR_BASEPATH = 'http://foo.com/ckeditor/';
  21. expect( CKEDITOR._getBasePath() ).to.equal( 'http://foo.com/ckeditor/' );
  22. } );
  23. } );
  24. describe( 'This browser', function() {
  25. it( 'should not keep script URLs absolute or relative', function( done ) {
  26. // Browsers should convert absolute and relative URLs to full URLs.
  27. // If this test fails in any browser, _getBasePath() must be reviewed to deal with such case (v4 does it).
  28. test( '/absolute/url/ckeditor.js' );
  29. test( '../relative/url/ckeditor.js' );
  30. done();
  31. function test( url ) {
  32. removeScripts();
  33. var script = addScript( url );
  34. // Test if the src now contains '://'.
  35. expect( /:\/\//.test( script.src ) ).to.be.true();
  36. }
  37. } );
  38. } );
  39. function addScript( url ) {
  40. var script = document.createElement( 'script' );
  41. script.src = url;
  42. document.head.appendChild( script );
  43. return script;
  44. }
  45. function removeScripts() {
  46. var scripts = [].slice.call( document.getElementsByTagName( 'script' ) );
  47. var script;
  48. while ( ( script = scripts.shift() ) ) {
  49. script.parentNode.removeChild( script );
  50. }
  51. }