-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(icon): Allow using data URLs #7547
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,11 +177,20 @@ describe('mdIcon directive', function() { | |
return { | ||
then: function(fn) { | ||
switch(id) { | ||
case 'android' : fn('<svg><g id="android"></g></svg>'); | ||
case 'cake' : fn('<svg><g id="cake"></g></svg>'); | ||
case 'android.svg' : fn('<svg><g id="android"></g></svg>'); | ||
case 'cake.svg' : fn('<svg><g id="cake"></g></svg>'); | ||
case 'image:android': fn(''); | ||
case 'android' : fn('<svg><g id="android"></g></svg>'); | ||
break; | ||
case 'cake' : fn('<svg><g id="cake"></g></svg>'); | ||
break; | ||
case 'android.svg' : fn('<svg><g id="android"></g></svg>'); | ||
break; | ||
case 'cake.svg' : fn('<svg><g id="cake"></g></svg>'); | ||
break; | ||
case 'image:android' : fn(''); | ||
break; | ||
default : | ||
if (/^data:/.test(id)) { | ||
fn(window.atob(id.split(',')[1])); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -240,6 +249,18 @@ describe('mdIcon directive', function() { | |
expect(el.html()).toEqual(''); | ||
})); | ||
|
||
describe('with a data URL', function() { | ||
it('should set mdSvgSrc from a function expression', inject(function() { | ||
var svgData = '<svg><g><circle r="50" cx="100" cy="100"></circle></g></svg>'; | ||
$scope.getData = function() { | ||
return 'data:image/svg+xml;base64,' + window.btoa(svgData); | ||
} | ||
console.log(svgData) | ||
el = make('<md-icon md-svg-src="{{ getData() }}"></md-icon>'); | ||
$scope.$digest(); | ||
expect(el[0].innerHTML).toEqual(svgData); | ||
})); | ||
}) | ||
}); | ||
|
||
describe('with ARIA support', function() { | ||
|
@@ -419,6 +440,29 @@ describe('mdIcon service', function() { | |
$scope.$digest(); | ||
}); | ||
|
||
describe('and the URL is a data URL', function() { | ||
var svgData = '<svg><g><circle r="50" cx="100" cy="100"></circle></g></svg>'; | ||
|
||
describe('and the data is base64 encoded', function() { | ||
it('should return correct SVG markup', function() { | ||
var data = 'data:image/svg+xml;base64,' + btoa(svgData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need another test for raw, base64 encoded (where we do not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I follow. Are you saying you want a test that passes this pre-encoded data
rather than encoding on-the-fly (as below)?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a function expression test in my last round of updates (in response to your initial set of comments). You can see it here (line 253): https://github.com/angular/material/pull/7547/files#diff-c132fcb7e577f14138c70b13aff4ea4fR253 |
||
$mdIcon(data).then(function(el) { | ||
expect(el.outerHTML).toEqual( updateDefaults(svgData) ); | ||
}) | ||
$scope.$digest(); | ||
}); | ||
}); | ||
|
||
describe('and the data is un-encoded', function() { | ||
it('should return correct SVG markup', function() { | ||
var data = 'data:image/svg+xml,' + svgData; | ||
$mdIcon(data).then(function(el) { | ||
expect(el.outerHTML).toEqual( updateDefaults(svgData) ); | ||
}) | ||
$scope.$digest(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('icon set URL is not found', function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment that this is base64 encoded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need spec test for getAndroidEncoded type of solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.