Repository: angular/angular.js
File: test/ng/compileSpec.js (JavaScript)

Code before:
            '<span>dorothy</span>' +
            '<minion>kevin</minion>' +
          '</minion-component>')($rootScope);
        $rootScope.$apply();
        expect(element.children().eq(0).text()).toEqual('default boss content');
        expect(element.children().eq(1).text()).toEqual('stuartkevin');
        expect(element.children().eq(2).text()).toEqual('dorothy');
      });
    });
  });

  describe('*[src] context requirement', function() {

    it('should NOT require trusted values for img src', inject(function($rootScope, $compile, $sce) {
      element = $compile('<img src="{{testUrl}}"></img>')($rootScope);
      $rootScope.testUrl = 'http://example.com/image.png';
      $rootScope.$digest();
      expect(element.attr('src')).toEqual('http://example.com/image.png');
      // But it should accept trusted values anyway.
      $rootScope.testUrl = $sce.trustAsUrl('http://example.com/image2.png');
      $rootScope.$digest();
      expect(element.attr('src')).toEqual('http://example.com/image2.png');
    }));

    // IE9 rejects the video / audio tag with "Error: Not implemented" and the source tag with
    // "Unable to get value of the property 'childNodes': object is null or undefined"
    if (!msie || msie > 9) {
      they('should NOT require trusted values for $prop src', ['video', 'audio', 'source'],
      function(tag) {
        inject(function($rootScope, $compile, $sce) {
          element = $compile('<' + tag + ' src="{{testUrl}}"></' + tag + '>')($rootScope);
          $rootScope.testUrl = 'http://example.com/image.mp4';
          $rootScope.$digest();
          expect(element.attr('src')).toEqual('http://example.com/image.mp4');

          // But it should accept trusted values anyway.
          $rootScope.testUrl = $sce.trustAsUrl('http://example.com/image2.mp4');
          $rootScope.$digest();
          expect(element.attr('src')).toEqual('http://example.com/image2.mp4');

          // and trustedResourceUrls for retrocompatibility
          $rootScope.testUrl = $sce.trustAsResourceUrl('http://example.com/image3.mp4');
          $rootScope.$digest();
          expect(element.attr('src')).toEqual('http://example.com/image3.mp4');
        });
      });
    }
  });

  describe('img[src] sanitization', function() {


Review comment (suggestion):
I've looked at a couple of pages used for e2e tests and they all have a DOCTYPE. The template used by Karma also specifies a DOCTYPE. So this shouldn't be a problem.


Code after:
            '<span>dorothy</span>' +
            '<minion>kevin</minion>' +
          '</minion-component>')($rootScope);
        $rootScope.$apply();
        expect(element.children().eq(0).text()).toEqual('default boss content');
        expect(element.children().eq(1).text()).toEqual('stuartkevin');
        expect(element.children().eq(2).text()).toEqual('dorothy');
      });
    });
  });

  describe('*[src] context requirement', function() {

    it('should NOT require trusted values for img src', inject(function($rootScope, $compile, $sce) {
      element = $compile('<img src="{{testUrl}}"></img>')($rootScope);
      $rootScope.testUrl = 'http://example.com/image.png';
      $rootScope.$digest();
      expect(element.attr('src')).toEqual('http://example.com/image.png');
      // But it should accept trusted values anyway.
      $rootScope.testUrl = $sce.trustAsUrl('http://example.com/image2.png');
      $rootScope.$digest();
      expect(element.attr('src')).toEqual('http://example.com/image2.png');
    }));

    // IE9 rejects the video / audio tag with "Error: Not implemented" and the source tag with
    // "Unable to get value of the property 'childNodes': object is null or undefined"
    if (!msie || msie > 9) {
      they('should NOT require trusted values for $prop src', ['video', 'audio'],
      function(tag) {
        inject(function($rootScope, $compile, $sce) {
          element = $compile('<' + tag + ' src="{{testUrl}}"></' + tag + '>')($rootScope);
          $rootScope.testUrl = 'http://example.com/image.mp4';
          $rootScope.$digest();
          expect(element.attr('src')).toEqual('http://example.com/image.mp4');

          // But it should accept trusted values anyway.
          $rootScope.testUrl = $sce.trustAsUrl('http://example.com/image2.mp4');
          $rootScope.$digest();
          expect(element.attr('src')).toEqual('http://example.com/image2.mp4');

          // and trustedResourceUrls for retrocompatibility
          $rootScope.testUrl = $sce.trustAsResourceUrl('http://example.com/image3.mp4');
          $rootScope.$digest();
          expect(element.attr('src')).toEqual('http://example.com/image3.mp4');
        });
      });

      they('should NOT require trusted values for $prop src', ['source', 'track'],
      function(tag) {
        inject(function($rootScope, $compile, $sce) {
          element = $compile('<video><' + tag + ' src="{{testUrl}}"></' + tag + '></video>')($rootScope);