OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 var common = {}; |
| 6 common.step_index = 0; |
| 7 common.fail = false; |
| 8 |
| 9 var test_steps = []; |
| 10 |
| 11 function send(msg) { |
| 12 return function() { |
| 13 chrome.test.sendMessage(msg); |
| 14 }; |
| 15 } |
| 16 |
| 17 var waiting = false; |
| 18 function sendAndWait(msg, expected) { |
| 19 return function() { |
| 20 waiting = true; |
| 21 chrome.test.sendMessage(msg, function(response) { |
| 22 waiting = false; |
| 23 if (common.step_index < test_steps.length) { |
| 24 var current = test_steps[common.step_index]; |
| 25 if (typeof(current) == "function") { |
| 26 common.step_index++; |
| 27 current.call(); |
| 28 } |
| 29 } |
| 30 }); |
| 31 }; |
| 32 } |
| 33 |
| 34 function makeListener (event) { |
| 35 return function(info) { |
| 36 if (common.fail || waiting || common.step_index >= test_steps.length) |
| 37 return; |
| 38 var id = (event == "uninstall") ? info : info.id; |
| 39 var expected = test_steps[common.step_index]; |
| 40 if (event != expected[0] || id != expected[1]) { |
| 41 console.log("failure: expected " + JSON.stringify(expected) + ", got " + |
| 42 event + " " + id); |
| 43 common.fail = true; |
| 44 return; |
| 45 } |
| 46 common.step_index++; |
| 47 |
| 48 while (!waiting && common.step_index < test_steps.length) { |
| 49 // If the next step is a function, call it. |
| 50 var next = test_steps[common.step_index]; |
| 51 if (typeof(next) == "function") { |
| 52 common.step_index++; |
| 53 next.call(); |
| 54 } else { |
| 55 break; |
| 56 } |
| 57 } |
| 58 }; |
| 59 } |
| 60 |
| 61 chrome.management.onInstalled.addListener(makeListener("install")); |
| 62 chrome.management.onUninstalled.addListener(makeListener("uninstall")); |
| 63 chrome.management.onEnabled.addListener(makeListener("enable")); |
| 64 chrome.management.onDisabled.addListener(makeListener("disable")); |
| 65 |
| 66 function enableTheme1() { |
| 67 chrome.management.setEnabled("iamefpfkojoapidjnbafmgkgncegbkad", true); |
| 68 } |
| 69 |
| 70 function disableTheme1() { |
| 71 chrome.management.setEnabled("iamefpfkojoapidjnbafmgkgncegbkad", false); |
| 72 } |
| 73 |
| 74 function enableTheme2() { |
| 75 chrome.management.setEnabled("pjpgmfcmabopnnfonnhmdjglfpjjfkbf", true); |
| 76 } |
| 77 |
| 78 function disableTheme2() { |
| 79 chrome.management.setEnabled("pjpgmfcmabopnnfonnhmdjglfpjjfkbf", false); |
| 80 } |
OLD | NEW |