3 <script src="../fast/js/resources/js-test-pre.js"></script>
4 <script src="resources/web-intents-testing.js"></script>
6 function shouldNotThrow(expression)
10 testPassed(expression + " did not throw exception.");
12 testFailed(expression + " should not throw exception. Threw exception " + e);
18 function buttonClicked() {
19 // |action| and |type| are required to be present and non-empty.
20 shouldThrow("new WebKitIntent({})", "'Error: SyntaxError: DOM Exception 12'");
21 shouldThrow("new WebKitIntent(dummy)", "'Error: SyntaxError: DOM Exception 12'");
22 shouldThrow("new WebKitIntent(null)", "'Error: SyntaxError: DOM Exception 12'");
23 shouldThrow("new WebKitIntent(undefined)", "'Error: SyntaxError: DOM Exception 12'");
24 shouldThrow("new WebKitIntent(5)", "'Error: SyntaxError: DOM Exception 12'");
25 shouldThrow("new WebKitIntent('six')", "'Error: SyntaxError: DOM Exception 12'");
26 shouldThrow("new WebKitIntent(['six'])", "'Error: SyntaxError: DOM Exception 12'");
27 shouldThrow("new WebKitIntent({'a':'b'})", "'Error: SyntaxError: DOM Exception 12'");
28 shouldThrow("new WebKitIntent({'action':'b'})", "'Error: SyntaxError: DOM Exception 12'");
29 shouldThrow("new WebKitIntent({'type':'b'})", "'Error: SyntaxError: DOM Exception 12'");
30 shouldThrow("new WebKitIntent({'action':'', 'type':'b'})", "'Error: SyntaxError: DOM Exception 12'");
31 shouldThrow("new WebKitIntent({'action':'a', 'type':''})", "'Error: SyntaxError: DOM Exception 12'");
32 shouldBeEqualToString("(new WebKitIntent({'action':'a','type':'b'})).action", "a");
33 shouldBeEqualToString("(new WebKitIntent({'action':'a','type':'b'})).type", "b");
35 // These will get converted to literals "null" and "undefined". Awkward
36 // names, but idiomatic usage.
37 shouldBeEqualToString("(new WebKitIntent({'action':null,'type':'b'})).action", "null");
38 shouldBeEqualToString("(new WebKitIntent({'action':undefined,'type':'b'})).action", "undefined");
39 shouldBeEqualToString("(new WebKitIntent({'action':'a','type':null})).type", "null");
40 shouldBeEqualToString("(new WebKitIntent({'action':'a','type':undefined})).type", "undefined");
42 // |service|, if present, must be a valid url.
43 shouldNotThrow("new WebKitIntent({'action':'a','type':'b','service':''})");
44 shouldThrow("new WebKitIntent({'action':'a','type':'b','service':null})", "'Error: SyntaxError: DOM Exception 12'");
45 shouldThrow("new WebKitIntent({'action':'a','type':'b','service':undefined})", "'Error: SyntaxError: DOM Exception 12'");
46 shouldThrow("new WebKitIntent({'action':'a','type':'b','service':'not a url'})", "'Error: SyntaxError: DOM Exception 12'");
48 // |data| must be cloneable.
49 shouldThrow("new WebKitIntent({'action':'a','type':'b','data':window})", "'Error: DataCloneError: DOM Exception 25'");
51 // |extras|, if present, must be a dictionary.
52 shouldNotThrow("new WebKitIntent({'action':'a','type':'b','extras':null})");
53 shouldNotThrow("new WebKitIntent({'action':'a','type':'b','extras':undefined})");
54 shouldNotThrow("new WebKitIntent({'action':'a','type':'b','extras':''})");
55 shouldNotThrow("new WebKitIntent({'action':'a','type':'b','extras':'not a dict'})");
56 shouldNotThrow("new WebKitIntent({'action':'a','type':'b','extras':42})");
57 shouldNotThrow("new WebKitIntent({'action':'a','type':'b','extras':['a','b']})");
59 var simpleIntent = new WebKitIntent(
63 navigator.webkitStartActivity(simpleIntent);
64 debug("* sent object intent");
66 var explicitIntent = new WebKitIntent(
68 "type":"text/plain+explicit",
70 "service" : "http://explicit.com/"});
71 navigator.webkitStartActivity(explicitIntent);
72 debug("* sent explicit intent");
74 var extrasIntent = new WebKitIntent(
76 "type":"text/plain+extras",
79 navigator.webkitStartActivity(extrasIntent);
80 debug("* sent intent with extras");
82 var channel = new MessageChannel();
83 channel.port2.onMessage = function() {
84 debug("* got message");
86 var portIntent = new WebKitIntent(
88 "type":"text/plain+port",
90 "transfer":[channel.port1]});
91 navigator.webkitStartActivity(portIntent);
92 debug("* sent intent with port");
94 // Ports, if present, must be put in |transfer|.
95 var badchannel = new MessageChannel();
96 badchannel.port2.onMessage = function() {
97 debug("* got message");
101 "type":"text/plain+badport",
102 "data":badchannel.port1};
103 shouldThrow("new WebKitIntent(badPortIntentObj)", "'Error: DataCloneError: DOM Exception 25'");
107 "type":"text/plain+suggestions",
109 "suggestions":["www.example.com/", "http://ww2.example.com"]};
110 shouldThrow("new WebKitIntent(suggestionsIntent)", "'Error: SyntaxError: DOM Exception 12'");
112 suggestionsIntent.suggestions = [15];
113 shouldThrow("new WebKitIntent(suggestionsIntent)", "'Error: SyntaxError: DOM Exception 12'");
115 suggestionsIntent.suggestions = ["http://www.example.com/"];
116 navigator.webkitStartActivity(new WebKitIntent(suggestionsIntent));
117 debug("* sent intent with suggestions");
122 <body onload="simulateButtonPress()">
123 <input type="button" id="button" value="Start Web Intent" onmouseup="buttonClicked()">
124 <script src="../fast/js/resources/js-test-post.js"></script>