- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / webstore_inline_install / argument_validation.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <link rel="chrome-webstore-item">
5 </head>
6 <body>
7 <script>
8   console.log('Page loaded');
9
10   function runTest(galleryUrl, index) {
11     var storeUrl = galleryUrl + '/detail/ecglahbcnmdpdciemllbhojghbkagdje';
12     // Link URL has to be generated dynamically in order to include the right
13     // port number. The ID corresponds to the data in the "extension" directory.
14     document.getElementsByTagName('link')[0].href = storeUrl;
15
16     function shouldPass(func) {
17       return {
18         func: func,
19         shouldPass: true
20       }
21     }
22
23     function shouldFail(func) {
24       return {
25         func: func,
26         shouldPass: false
27       }
28     }
29
30     var cwi = chrome.webstore.install;
31     var callback = function() {
32     };
33
34     var testCases = [
35       shouldPass(function() {cwi()}),
36       shouldPass(function() {cwi(undefined)}),
37       shouldPass(function() {cwi(undefined, undefined)}),
38       shouldPass(function() {cwi(undefined, undefined, undefined)}),
39
40       shouldPass(function() {cwi(storeUrl)}),
41       shouldPass(function() {cwi(undefined, callback)}),
42       shouldPass(function() {cwi(undefined, undefined, callback)}),
43       shouldPass(function() {cwi(undefined, callback, callback)}),
44
45       shouldFail(function() {cwi(callback)}),
46       shouldFail(function() {cwi(callback, callback)}),
47       shouldFail(function() {cwi(callback, callback, callback)}),
48
49       shouldFail(function() {cwi(123)}),
50       shouldFail(function() {cwi(undefined, 123)}),
51       shouldFail(function() {cwi(undefined, undefined, 123)}),
52       shouldFail(function() {cwi(undefined, callback, 123)})
53     ];
54
55     var successResult = (index < testCases.length - 1 ? 'KEEPGOING' : 'DONE');
56     var failureResult = 'FAILED';
57
58     function runTestCase(test) {
59       var failed = false;
60       console.log('Testing ' + test.func);
61       if (test.shouldPass) {
62         try {
63           test.func();
64         } catch (e) {
65           console.log('unexpected exception: ' + e);
66           failed = true;
67         }
68       } else {
69         try {
70           test.func();
71           console.log('unexpected pass: ' + func);
72           failed = true;
73         } catch (e) {
74           // Expected exception
75         }
76       }
77
78       console.log('Ran test, sending response');
79       window.domAutomationController.send(failed ? failureResult : successResult);
80       console.log('Test complete');
81     }
82
83     runTestCase(testCases[index]);
84   }
85 </script>
86
87 </body>
88 </html>