blob: 660ade5e7048f6027db6f853f4b360a5c6604993 [file] [log] [blame]
Kevin Lubick644d8e72018-08-09 13:58:04 -04001
2describe('PathKit\'s Path Behavior', function() {
3 // Note, don't try to print the PathKit object - it can cause Karma/Jasmine to lock up.
4 var PathKit = null;
5 const LoadPathKit = new Promise(function(resolve, reject){
6 if (PathKit) {
7 resolve();
8 } else {
9 PathKitInit({
10 locateFile: (file) => '/base/npm-wasm/bin/test/'+file,
11 }).then((_PathKit) => {
12 PathKit = _PathKit;
13 resolve();
14 });
15 }
16 });
17
18 it('dynamically updates getBounds()', function(done){
19 LoadPathKit.then(() => {
20 // Based on test_bounds_crbug_513799
21 let path = PathKit.NewPath();
22 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(0, 0, 0, 0));
23 path.moveTo(-5, -8);
24 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(-5, -8, -5, -8));
25 path.rect(1, 2, 2, 2);
26 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(-5, -8, 3, 4));
27 path.moveTo(1, 2);
28 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(-5, -8, 3, 4));
29 path.delete();
30 done();
31 });
32 });
33
34 it('has getBounds() and computeTightBounds()', function(done){
35 LoadPathKit.then(() => {
36 // Based on PathOpsTightBoundsIllBehaved
37 let path = PathKit.NewPath();
38 path.moveTo(1, 1);
39 path.quadraticCurveTo(4, 3, 2, 2);
40 expect(path.getBounds()).toEqual(PathKit.MakeLTRBRect(1, 1, 4, 3));
41 expect(path.computeTightBounds()).toEqual(PathKit.MakeLTRBRect(1, 1,
42 PathKit.SkBits2FloatUnsigned(parseInt("0x40333334")), // 2.8
43 PathKit.SkBits2FloatUnsigned(parseInt("0x40155556")))); // 2.3333333
44 path.delete();
45
46 done();
47 });
48 });
49
50});