Add an UMA stat to be able to see if the User pods are show on start screen,
[chromium-blink-merge.git] / extensions / test / data / app_view / apitest / main.js
blob4bc514dc1574c57a0afa9be211bd4dc28d9c3772
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var util = {};
6 var embedder = {};
8 window.runTest = function(testName, appToEmbed) {
9   if (!embedder.test.testList[testName]) {
10     window.console.log('Incorrect testName: ' + testName);
11     embedder.test.fail();
12     return;
13   }
15   // Run the test.
16   embedder.test.testList[testName](appToEmbed);
19 var LOG = function(msg) {
20   window.console.log(msg);
23 embedder.test = {};
24 embedder.test.succeed = function() {
25   chrome.test.sendMessage('TEST_PASSED');
28 embedder.test.fail = function() {
29   chrome.test.sendMessage('TEST_FAILED');
32 embedder.test.assertEq = function(a, b) {
33   if (a != b) {
34     console.log('Assertion failed: ' + a + ' != ' + b);
35     embedder.test.fail();
36   }
39 embedder.test.assertTrue = function(condition) {
40   if (!condition) {
41     console.log('Assertion failed: true != ' + condition);
42     embedder.test.fail();
43   }
46 embedder.test.assertFalse = function(condition) {
47   if (condition) {
48     console.log('Assertion failed: false != ' + condition);
49     embedder.test.fail();
50   }
53 // Tests begin.
54 function testAppViewGoodDataShouldSucceed(appToEmbed) {
55   var appview = new AppView();
56   LOG('appToEmbed  ' + appToEmbed);
57   document.body.appendChild(appview);
58   LOG('Attempting to connect to app with good params.');
59   // Step 2: Attempt to connect to an app with good params.
60   appview.connect(appToEmbed, {'foo': 'bleep'}, function(success) {
61     // Make sure we don't fail.
62     if (!success) {
63       LOG('FAILED TO CONNECT.');
64       embedder.test.fail();
65       return;
66     }
67     LOG('Connected.');
68     embedder.test.succeed();
69   });
72 function testAppViewMediaRequest(appToEmbed) {
73   var appview = new AppView();
74   window.console.log('appToEmbed  ' + appToEmbed);
75   document.body.appendChild(appview);
76   window.console.log('Attempting to connect to app.');
77   appview.connect(appToEmbed, {}, function(success) {
78     // Make sure we don't fail.
79     if (!success) {
80       window.console.log('Failed to connect.');
81       embedder.test.fail();
82       return;
83     }
84     window.console.log('Connected.');
85     embedder.test.succeed();
86   });
89 function testAppViewRefusedDataShouldFail(appToEmbed) {
90   var appview = new AppView();
91   LOG('appToEmbed  ' + appToEmbed);
92   document.body.appendChild(appview);
93   LOG('Attempting to connect to app with refused params.');
94   appview.connect(appToEmbed, {'foo': 'bar'}, function(success) {
95     // Make sure we fail.
96     if (success) {
97       LOG('UNEXPECTED CONNECTION.');
98       embedder.test.fail();
99       return;
100     }
101     LOG('Failed to connect.');
102     embedder.test.succeed();
103   });
106 function testAppViewWithUndefinedDataShouldSucceed(appToEmbed) {
107   var appview = new AppView();
108   LOG('appToEmbed  ' + appToEmbed);
109   document.body.appendChild(appview);
110   // Step 1: Attempt to connect to a non-existant app (abc123).
111   LOG('Attempting to connect to non-existant app.');
112   appview.connect('abc123', undefined, function(success) {
113     // Make sure we fail.
114     if (success) {
115       LOG('UNEXPECTED CONNECTION.');
116       embedder.test.fail();
117       return;
118     }
119     LOG('failed to connect to non-existant app.');
120     LOG('attempting to connect to known app.');
121     // Step 2: Attempt to connect to an app we know exists.
122     appview.connect(appToEmbed, undefined, function(success) {
123       // Make sure we don't fail.
124       if (!success) {
125         LOG('FAILED TO CONNECT.');
126         embedder.test.fail();
127         return;
128       }
129       LOG('Connected.');
130       embedder.test.succeed();
131     });
132   });
135 embedder.test.testList = {
136   'testAppViewGoodDataShouldSucceed': testAppViewGoodDataShouldSucceed,
137   'testAppViewMediaRequest': testAppViewMediaRequest,
138   'testAppViewRefusedDataShouldFail': testAppViewRefusedDataShouldFail,
139   'testAppViewWithUndefinedDataShouldSucceed':
140       testAppViewWithUndefinedDataShouldSucceed
143 onload = function() {
144   chrome.test.sendMessage('LAUNCHED');