Merge "Add to ewk api for setting/getting the User Agent by using system info library...
[framework/web/webkit-efl.git] / LayoutTests / webintents / web-intents-obj-constructor.html
1 <html>
2   <head>
3     <script src="../fast/js/resources/js-test-pre.js"></script>
4     <script src="resources/web-intents-testing.js"></script>
5     <script>
6     function shouldNotThrow(expression)
7     {
8         try {
9             eval(expression);
10             testPassed(expression + " did not throw exception.");
11         } catch(e) {
12             testFailed(expression + " should not throw exception. Threw exception " + e);
13         }
14     }
15
16     function dummy() {}
17
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");
34
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");
41
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'");
47
48         // |data| must be cloneable.
49         shouldThrow("new WebKitIntent({'action':'a','type':'b','data':window})", "'Error: DataCloneError: DOM Exception 25'");
50
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']})");
58
59         var simpleIntent = new WebKitIntent(
60             {"action":"action1",
61              "type":"text/plain",
62              "data":"message"});
63         navigator.webkitStartActivity(simpleIntent);
64         debug("* sent object intent");
65
66         var explicitIntent = new WebKitIntent(
67             {"action":"action1",
68              "type":"text/plain+explicit",
69              "data":"message",
70              "service" : "http://explicit.com/"});
71         navigator.webkitStartActivity(explicitIntent);
72         debug("* sent explicit intent");
73
74         var extrasIntent = new WebKitIntent(
75             {"action":"action1",
76              "type":"text/plain+extras",
77              "data":"message",
78              "extras":{"a":"b"}});
79         navigator.webkitStartActivity(extrasIntent);
80         debug("* sent intent with extras");
81
82         var channel = new MessageChannel();
83         channel.port2.onMessage = function() {
84             debug("* got message");
85         };
86         var portIntent = new WebKitIntent(
87             {"action":"action1",
88              "type":"text/plain+port",
89              "data":channel.port1,
90              "transfer":[channel.port1]});
91         navigator.webkitStartActivity(portIntent);
92         debug("* sent intent with port");
93
94         // Ports, if present, must be put in |transfer|.
95         var badchannel = new MessageChannel();
96         badchannel.port2.onMessage = function() {
97             debug("* got message");
98         }
99         badPortIntentObj = 
100             {"action":"action1",
101              "type":"text/plain+badport",
102              "data":badchannel.port1};
103         shouldThrow("new WebKitIntent(badPortIntentObj)", "'Error: DataCloneError: DOM Exception 25'");
104
105         suggestionsIntent =
106             {"action":"action1",
107              "type":"text/plain+suggestions",
108              "data":"message",
109              "suggestions":["www.example.com/", "http://ww2.example.com"]};
110         shouldThrow("new WebKitIntent(suggestionsIntent)", "'Error: SyntaxError: DOM Exception 12'");
111
112         suggestionsIntent.suggestions = [15];
113         shouldThrow("new WebKitIntent(suggestionsIntent)", "'Error: SyntaxError: DOM Exception 12'");
114
115         suggestionsIntent.suggestions = ["http://www.example.com/"];
116         navigator.webkitStartActivity(new WebKitIntent(suggestionsIntent));
117         debug("* sent intent with suggestions");
118
119     }
120     </script>
121   </head>
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>
125 </body>
126 </html>