[Representation] Trust template URLs

Trust resource URLs to skip SCE-checking (which profiling
flags as a performance problem) for mct-include and
mct-representation; these URLs are pulled from bundles and
not user-entered, so should be trusted. WTD-1256.
This commit is contained in:
Victor Woeltjen
2015-06-18 14:43:14 -07:00
parent dc85d3c191
commit 275ca01692
5 changed files with 61 additions and 17 deletions

View File

@@ -31,6 +31,7 @@ define(
describe("The mct-include directive", function () {
var testTemplates,
mockSce,
mctInclude;
beforeEach(function () {
@@ -46,7 +47,14 @@ define(
templateUrl: "z/template.html"
}
];
mctInclude = new MCTInclude(testTemplates);
mockSce = jasmine.createSpyObj(
'$sce',
['trustAsResourceUrl']
);
mockSce.trustAsResourceUrl.andCallFake(function (url) {
return url;
});
mctInclude = new MCTInclude(testTemplates, mockSce);
});
it("has a built-in template, with ng-include src=inclusion", function () {
@@ -69,6 +77,12 @@ define(
expect(scope.inclusion).toEqual("x/y/z/template.html");
});
it("trusts template URLs", function () {
mctInclude.controller({ key: "xyz" });
expect(mockSce.trustAsResourceUrl)
.toHaveBeenCalledWith("x/y/z/template.html");
});
});
}
);
);

View File

@@ -38,6 +38,7 @@ define(
testViews,
mockRepresenters,
mockQ,
mockSce,
mockLog,
mockScope,
mockElement,
@@ -95,8 +96,16 @@ define(
});
mockQ = { when: mockPromise };
mockSce = jasmine.createSpyObj(
'$sce',
['trustAsResourceUrl']
);
mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS);
mockSce.trustAsResourceUrl.andCallFake(function (url) {
return url;
});
mockScope = jasmine.createSpyObj("scope", [ "$watch" ]);
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
@@ -125,9 +134,18 @@ define(
it("watches scope when linked", function () {
mctRepresentation.link(mockScope, mockElement);
expect(mockScope.$watch).toHaveBeenCalledWith("key", jasmine.any(Function));
expect(mockScope.$watch).toHaveBeenCalledWith("domainObject", jasmine.any(Function));
expect(mockScope.$watch).toHaveBeenCalledWith("domainObject.getModel().modified", jasmine.any(Function));
expect(mockScope.$watch).toHaveBeenCalledWith(
"key",
jasmine.any(Function)
);
expect(mockScope.$watch).toHaveBeenCalledWith(
"domainObject",
jasmine.any(Function)
);
expect(mockScope.$watch).toHaveBeenCalledWith(
"domainObject.getModel().modified",
jasmine.any(Function)
);
});
it("recognizes keys for representations", function () {
@@ -152,6 +170,18 @@ define(
expect(mockScope.inclusion).toEqual("x/y/z/template.html");
});
it("trusts template URLs", function () {
mctRepresentation.link(mockScope, mockElement);
mockScope.key = "xyz";
// Trigger the watch
mockScope.$watch.calls[0].args[1]();
expect(mockSce.trustAsResourceUrl)
.toHaveBeenCalledWith("x/y/z/template.html");
});
it("loads declared capabilities", function () {
mctRepresentation.link(mockScope, mockElement);
@@ -183,4 +213,4 @@ define(
});
});
}
);
);