4a5e5a9b62bd54599af5bba0d01326aea1246dac
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / gcd_private / api / wifi_message.js
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.
4
5 onload = function() {
6   chrome.test.runTests([
7     function wifiMessage() {
8       var messagesNeeded = 3;
9       var sessionId = -1;
10
11       function onSessionEstablished(newSessionId) {
12         sessionId = newSessionId;
13         chrome.gcdPrivate.startPairing(sessionId, "embeddedCode",
14                                        onPairingStarted);
15       }
16
17       function onPairingStarted(status) {
18         chrome.test.assertEq("success", status);
19         chrome.gcdPrivate.confirmCode(sessionId, "1234", onCodeConfirmed);
20       }
21
22       function onCodeConfirmed(status) {
23         chrome.test.assertEq("success", status);
24         chrome.gcdPrivate.sendMessage(sessionId, "/privet/v3/setup/start", {
25           "wifi" : {
26           }
27         }, onMessageSent.bind(null, "setupParseError"));
28
29         chrome.gcdPrivate.sendMessage(sessionId, "/privet/v3/setup/start", {
30           "wifi" : {
31             "passphrase": "Blah"
32           }
33         }, onMessageSent.bind(null, "setupParseError"));
34
35         chrome.gcdPrivate.sendMessage(sessionId, "/privet/v3/setup/start", {
36           "wifi" : {
37             "ssid": "Blah"
38           }
39         }, onMessageSent.bind(null, "wifiPasswordError"));
40       }
41
42       function onMessageSent(expected_status, status, output) {
43         chrome.test.assertEq(expected_status, status);
44         messagesNeeded--;
45         console.log("Messages needed " + messagesNeeded);
46
47         if (messagesNeeded == 0) {
48           chrome.test.notifyPass();
49         }
50       }
51
52       chrome.gcdPrivate.establishSession("1.2.3.4", 9090, onSessionEstablished);
53     }
54   ]);
55 };