<commit_before>'use strict';

describe('Services: requestAnimation & cancelAnimation', function () {
  var windowMock,
      timeoutMockObject;

  beforeEach(function() {
    var timeoutCancel;
    timeoutMockObject = {};
    timeoutMockObject.timeout = {};
    timeoutMockObject.timeout.cancel = jasmine.createSpy('timeoutCancelMock');
    timeoutCancel = timeoutMockObject.timeout.cancel;
    timeoutMockObject.timeout = jasmine.createSpy('timeoutMock');
    timeoutMockObject.timeout.cancel = timeoutCancel;
    
    windowMock = {
      requestAnimationFrame: function () {
        return 'requestAnimationFrame';
      },
      cancelAnimationFrame: function () {
        return 'cancelAnimationFrame';
      },
      webkitRequestAnimationFrame: function () {
        return 'webkitRequestAnimationFrame';
      },
      webkitCancelAnimationFrame: function () {
        return 'webkitCancelAnimationFrame';
      },
      webkitCancelRequestAnimationFrame: function () {
        return 'webkitCancelRequestAnimationFrame';
      },
      mozRequestAnimationFrame: function () {
        return 'mozRequestAnimationFrame';
      },
      mozCancelAnimationFrame: function () {
        return 'mozCancelAnimationFrame';
      },
      navigator: {
        userAgent: ''
      }
    };
    
    module('snapscroll');

    module(function ($provide) {
      $provide.value('$window', windowMock);
      $provide.value('$timeout', timeoutMockObject.timeout);
    });    
  });
  
  describe('on modern browsers', function () {
    beforeEach(function () {
    });
    
    it('return the unprefixed functions', inject(function (requestAnimation, cancelAnimation) {
      expect(requestAnimation()).toBe('requestAnimationFrame');
      expect(cancelAnimation()).toBe('cancelAnimationFrame');
      expect(timeoutMockObject.timeout).not.toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
    }));
  });
  
  describe('on old webkit browsers', function () {
    beforeEach(function () {
      windowMock.requestAnimationFrame = undefined;
      windowMock.cancelAnimationFrame = undefined;
    });
  
    it('return the legacy webkit functions', inject(function (requestAnimation, cancelAnimation) {
      expect(requestAnimation()).toBe('webkitRequestAnimationFrame');
      expect(cancelAnimation()).toBe('webkitCancelAnimationFrame');
      expect(timeoutMockObject.timeout).not.toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
    }));
  });
  
  describe('on old webkit browsers, cancelAnimation', function () {
    beforeEach(function () {
      windowMock.cancelAnimationFrame = undefined;
      windowMock.mozCancelAnimationFrame = undefined;
      windowMock.webkitCancelAnimationFrame = undefined;
    });
  
    it('may also return webkitCancelRequestAnimationFrame', inject(function (cancelAnimation) {
      expect(cancelAnimation()).toBe('webkitCancelRequestAnimationFrame');
      expect(timeoutMockObject.timeout).not.toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
    }));
  });
  
  describe('on old mozilla browsers', function () {
    beforeEach(function () {
      windowMock.requestAnimationFrame = undefined;
      windowMock.cancelAnimationFrame = undefined;
      windowMock.webkitRequestAnimationFrame = undefined;
      windowMock.webkitCancelAnimationFrame = undefined;
      windowMock.webkitCancelRequestAnimationFrame = undefined;
    });
  
    it('return the legacy mozilla functions', inject(function (requestAnimation, cancelAnimation) {
      expect(requestAnimation()).toBe('mozRequestAnimationFrame');
      expect(cancelAnimation()).toBe('mozCancelAnimationFrame');
      expect(timeoutMockObject.timeout).not.toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
    }));
  });
  
  describe('on old browsers', function () {
    beforeEach(function () {
      windowMock.requestAnimationFrame = undefined;
      windowMock.cancelAnimationFrame = undefined;
      windowMock.webkitRequestAnimationFrame = undefined;
      windowMock.webkitCancelAnimationFrame = undefined;
      windowMock.webkitCancelRequestAnimationFrame = undefined;
      windowMock.mozRequestAnimationFrame = undefined;
      windowMock.mozCancelAnimationFrame = undefined;
    });

    it('return a timeout promise and cancel function respectively', inject(function (requestAnimation, cancelAnimation) {
      requestAnimation();
      expect(timeoutMockObject.timeout).toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
      cancelAnimation();
      expect(timeoutMockObject.timeout.cancel).toHaveBeenCalled();
    }));
  });

  describe('on iOS 6', function () {
    beforeEach(function () {
      windowMock.navigator.userAgent = 'iPhone OS 6';
    });

    it('return a timeout promise and cancel function respectively', inject(function (requestAnimation, cancelAnimation) {
      requestAnimation();
      expect(timeoutMockObject.timeout).toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
      cancelAnimation();
      expect(timeoutMockObject.timeout.cancel).toHaveBeenCalled();
    }));
  });
});<commit_msg>as attribute: added correctness test for iOS 7<commit_after>'use strict';

describe('Services: requestAnimation & cancelAnimation', function () {
  var windowMock,
      timeoutMockObject;

  beforeEach(function() {
    var timeoutCancel;
    timeoutMockObject = {};
    timeoutMockObject.timeout = {};
    timeoutMockObject.timeout.cancel = jasmine.createSpy('timeoutCancelMock');
    timeoutCancel = timeoutMockObject.timeout.cancel;
    timeoutMockObject.timeout = jasmine.createSpy('timeoutMock');
    timeoutMockObject.timeout.cancel = timeoutCancel;
    
    windowMock = {
      requestAnimationFrame: function () {
        return 'requestAnimationFrame';
      },
      cancelAnimationFrame: function () {
        return 'cancelAnimationFrame';
      },
      webkitRequestAnimationFrame: function () {
        return 'webkitRequestAnimationFrame';
      },
      webkitCancelAnimationFrame: function () {
        return 'webkitCancelAnimationFrame';
      },
      webkitCancelRequestAnimationFrame: function () {
        return 'webkitCancelRequestAnimationFrame';
      },
      mozRequestAnimationFrame: function () {
        return 'mozRequestAnimationFrame';
      },
      mozCancelAnimationFrame: function () {
        return 'mozCancelAnimationFrame';
      },
      navigator: {
        userAgent: ''
      }
    };
    
    module('snapscroll');

    module(function ($provide) {
      $provide.value('$window', windowMock);
      $provide.value('$timeout', timeoutMockObject.timeout);
    });    
  });
  
  describe('on modern browsers', function () {
    beforeEach(function () {
    });
    
    it('return the unprefixed functions', inject(function (requestAnimation, cancelAnimation) {
      expect(requestAnimation()).toBe('requestAnimationFrame');
      expect(cancelAnimation()).toBe('cancelAnimationFrame');
      expect(timeoutMockObject.timeout).not.toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
    }));
  });
  
  describe('on old webkit browsers', function () {
    beforeEach(function () {
      windowMock.requestAnimationFrame = undefined;
      windowMock.cancelAnimationFrame = undefined;
    });
  
    it('return the legacy webkit functions', inject(function (requestAnimation, cancelAnimation) {
      expect(requestAnimation()).toBe('webkitRequestAnimationFrame');
      expect(cancelAnimation()).toBe('webkitCancelAnimationFrame');
      expect(timeoutMockObject.timeout).not.toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
    }));
  });
  
  describe('on old webkit browsers, cancelAnimation', function () {
    beforeEach(function () {
      windowMock.cancelAnimationFrame = undefined;
      windowMock.mozCancelAnimationFrame = undefined;
      windowMock.webkitCancelAnimationFrame = undefined;
    });
  
    it('may also return webkitCancelRequestAnimationFrame', inject(function (cancelAnimation) {
      expect(cancelAnimation()).toBe('webkitCancelRequestAnimationFrame');
      expect(timeoutMockObject.timeout).not.toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
    }));
  });
  
  describe('on old mozilla browsers', function () {
    beforeEach(function () {
      windowMock.requestAnimationFrame = undefined;
      windowMock.cancelAnimationFrame = undefined;
      windowMock.webkitRequestAnimationFrame = undefined;
      windowMock.webkitCancelAnimationFrame = undefined;
      windowMock.webkitCancelRequestAnimationFrame = undefined;
    });
  
    it('return the legacy mozilla functions', inject(function (requestAnimation, cancelAnimation) {
      expect(requestAnimation()).toBe('mozRequestAnimationFrame');
      expect(cancelAnimation()).toBe('mozCancelAnimationFrame');
      expect(timeoutMockObject.timeout).not.toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
    }));
  });
  
  describe('on old browsers', function () {
    beforeEach(function () {
      windowMock.requestAnimationFrame = undefined;
      windowMock.cancelAnimationFrame = undefined;
      windowMock.webkitRequestAnimationFrame = undefined;
      windowMock.webkitCancelAnimationFrame = undefined;
      windowMock.webkitCancelRequestAnimationFrame = undefined;
      windowMock.mozRequestAnimationFrame = undefined;
      windowMock.mozCancelAnimationFrame = undefined;
    });

    it('return a timeout promise and cancel function respectively', inject(function (requestAnimation, cancelAnimation) {
      requestAnimation();
      expect(timeoutMockObject.timeout).toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
      cancelAnimation();
      expect(timeoutMockObject.timeout.cancel).toHaveBeenCalled();
    }));
  });

  describe('on iOS 6', function () {
    beforeEach(function () {
      windowMock.navigator.userAgent = 'iPhone OS 6';
    });

    it('return a timeout promise and cancel function respectively', inject(function (requestAnimation, cancelAnimation) {
      requestAnimation();
      expect(timeoutMockObject.timeout).toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
      cancelAnimation();
      expect(timeoutMockObject.timeout.cancel).toHaveBeenCalled();
    }));
  });

  describe('on iOS 7', function () {
    beforeEach(function () {
      windowMock.navigator.userAgent = 'iPhone OS 7';
    });
    
    it('return the unprefixed functions', inject(function (requestAnimation, cancelAnimation) {
      expect(requestAnimation()).toBe('requestAnimationFrame');
      expect(cancelAnimation()).toBe('cancelAnimationFrame');
      expect(timeoutMockObject.timeout).not.toHaveBeenCalled();
      expect(timeoutMockObject.timeout.cancel).not.toHaveBeenCalled();
    }));
  });
});
{'fraction_non_alphanumeric': 0.11531173869890823, 'fraction_numerical': 0.000631597942795272, 'mean_word_length': 3.9838129496402876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '917016', 'n_tokens_mistral': 2775, 'n_tokens_neox': 2733, 'n_words': 443}