1 // Copyright (c) 2013 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.
7 var handleReply = function(reply) {
8 chrome.test.log('handle reply: ' + reply);
9 // |reply| is the next command for the extension.
10 if (reply == 'idle') {
11 // Do nothing, wait for events.
12 } else if (reply.indexOf('get-policy-') == 0) {
13 // Send a policy value back.
14 chrome.storage.managed.get(reply.substr(11), function(policy) {
15 chrome.test.log('sending policy value: ' + JSON.stringify(policy));
16 chrome.test.sendMessage(JSON.stringify(policy), handleReply);
19 // Unexpected reply, make the test fail.
20 chrome.test.sendMessage('fail');
24 chrome.storage.onChanged.addListener(function(changes, namespace) {
25 if (namespace == 'managed') {
26 chrome.test.log('change event: ' + JSON.stringify(changes));
28 chrome.test.sendMessage('event', handleReply);
32 chrome.test.log('main body done, sending ready');
33 // Send the initial 'ready' message, and start waiting for replies.
34 chrome.test.sendMessage('ready', handleReply);