Simplify permission handling in widgets and services
Change-Id: I5050b0dad19f84eaf62e051978f0abc5c6a22800
diff --git a/dev/js/spec/pluginSpec.js b/dev/js/spec/pluginSpec.js
index e2dab8f..2a980ad 100644
--- a/dev/js/spec/pluginSpec.js
+++ b/dev/js/spec/pluginSpec.js
@@ -11,7 +11,7 @@
it('should add a widget', function () {
var manager = pluginServerClass.create();
var panel = panelClass.create();
- var id = manager.addWidget(panel, 'Example 1', 'about:blank');
+ var id = manager.addWidget(panel, {"name": 'Example 1', "src": 'about:blank'});
expect(id).toMatch(/^id-/);
var panelE = panel.element();
@@ -39,7 +39,7 @@
expect(e.getAttribute("id")).toBe("services");
expect(e.children.length).toBe(0);
- var id = manager.addService('Example 1', 'about:blank');
+ var id = manager.addService({"name":'Example 1', "src":'about:blank'});
expect(id).toMatch(/^id-/);
expect(e.children.length).toBe(1);
@@ -53,7 +53,7 @@
it('should close a widget', function () {
var manager = pluginServerClass.create();
var panel = panelClass.create();
- var id = manager.addWidget(panel, 'Example 2', 'about:blank');
+ var id = manager.addWidget(panel, {"name":'Example 2', "src":'about:blank'});
expect(id).toMatch(/^id-/);
var panelE = panel.element();
@@ -273,7 +273,7 @@
it('should be initializable', function () {
expect(function () { widgetClass.create() }).toThrow(new Error("Service not well defined"));
- widget = widgetClass.create("Test", "https://example", 56);
+ widget = widgetClass.create({"name" : "Test", "src":"https://example", "id":56});
expect(widget).toBeTruthy();
expect(widget.id).toEqual(56);
expect(widget.name).toEqual("Test");
@@ -281,9 +281,12 @@
});
it('should create a view element', function () {
- var widget = widgetClass.create("Test", "https://example", 56);
- widget.allow("allow-scripts");
- widget.allow("allow-forms");
+ var widget = widgetClass.create({
+ "name":"Test",
+ "src":"https://example",
+ "id":56,
+ "permissions":["allow-scripts","allow-forms"]
+ });
var we = widget.element();
expect(we.tagName).toEqual("DIV");
@@ -295,10 +298,6 @@
expect(iframe.getAttribute("sandbox")).toEqual("allow-forms allow-scripts");
expect(iframe.getAttribute("src")).toEqual("https://example");
expect(iframe.getAttribute("name")).toEqual("56");
-
-
- widget.allow(["allow-downloads","allow-everything"]);
- expect(iframe.getAttribute("sandbox")).toEqual("allow-downloads allow-everything allow-forms allow-scripts");
var btn = we.lastChild;
expect(btn.classList.contains("button-group")).toBeTruthy();
@@ -316,21 +315,9 @@
expect(btn.lastChild.firstChild.tagName).toEqual("SPAN");
expect(btn.lastChild.textContent).toEqual("Test");
})
-
- it('should have mutable permissions', function () {
- var widget = widgetClass.create("Test", "https://example", 56);
- var we = widget.element();
- var iframe = we.firstChild;
- expect(iframe.tagName).toEqual("IFRAME");
- expect(iframe.getAttribute("sandbox")).toEqual("");
- widget.allow("allow-scripts");
- widget.allow("allow-forms");
- expect(iframe.tagName).toEqual("IFRAME");
- expect(iframe.getAttribute("sandbox")).toEqual("allow-forms allow-scripts");
- });
it('should be resizable', function () {
- var widget = widgetClass.create("Test", "https://example", 56);
+ var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
var iframe = widget.show();
expect(iframe.style.height).toEqual('0px');
widget.resize({ height : 9 });
@@ -338,7 +325,7 @@
});
it('should be minimizable', function () {
- var widget = widgetClass.create("Test", "https://example", 56);
+ var widget = widgetClass.create({"name":"Test", "src":"https://example", "id":56});
var we = widget.element();
expect(we.classList.contains('show')).toBeTruthy();
widget.minimize();
@@ -350,7 +337,7 @@
it('should be initializable', function () {
expect(function () { serviceClass.create() }).toThrow(new Error("Service not well defined"));
- let service = serviceClass.create("Test", "https://example", 56);
+ let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
expect(service).toBeTruthy();
expect(service.id).toEqual(56);
expect(service.name).toEqual("Test");
@@ -358,7 +345,7 @@
});
it('should be loadable', function () {
- let service = serviceClass.create("Test", "https://example", 56);
+ let service = serviceClass.create({"name":"Test", "src":"https://example", "id":56});
expect(service).toBeTruthy();
let i = service.load();
@@ -502,7 +489,7 @@
describe('KorAP.Plugin communications', function () {
it('should receive messages', function () {
var manager = pluginServerClass.create();
- var id = manager.addService('Example 1', 'about:blank');
+ var id = manager.addService({"name":'Example 1', "src":'about:blank'});
expect(id).toMatch(/^id-/);
var temp = KorAP.koralQuery;
KorAP.koralQuery = { "@type" : "koral:test" };
@@ -526,7 +513,7 @@
KorAP.Pipe = pipeClass.create();
expect(KorAP.Pipe.toString()).toEqual("");
- var id = manager.addService('Example 2', 'about:blank');
+ var id = manager.addService({"name":'Example 2', "src":'about:blank'});
expect(id).toMatch(/^id-/);
manager._receiveMsg({
"data" : {
@@ -562,7 +549,7 @@
it('should reply to query information requests', function () {
var manager = pluginServerClass.create();
- var id = manager.addService('Service', 'about:blank');
+ var id = manager.addService({"name":'Service', "src":'about:blank'});
expect(id).toMatch(/^id-/);
var temp = KorAP.vc;
// Create form for query form information