1// Copyright (c) 2012 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
5document.body.innerHTML = "";
6
7function addButton(name, cb) {
8  var a = document.createElement("button");
9  a.innerText = name;
10  a.onclick = cb;
11  document.body.appendChild(document.createElement("br"));
12  document.body.appendChild(a);
13}
14
15function log(str) {
16  console.log(str);
17  logDiv.innerHTML += str + "<br>";
18}
19
20addButton("Clear logs", function() {
21  logDiv.innerHTML = "";
22});
23
24addButton("Send message with delayed response", function() {
25  chrome.runtime.sendMessage({delayedResponse: true}, function(response) {
26    log("Background page responded: " + response);
27  });
28});
29
30addButton("Show counters", function() {
31  chrome.runtime.sendMessage({getCounters: true}, function(response) {
32    log("In-memory counter is: " + response.counter);
33    log("Persisted counter is: " + response.persistentCounter);
34  });
35});
36
37addButton("Set an alarm", function() {
38  chrome.runtime.sendMessage({setAlarm: true});
39});
40
41chrome.runtime.onMessage.addListener(function(msg, _, sendResponse) {
42  log("Got message from background page: " + msg);
43});
44
45var logDiv = document.createElement("div");
46logDiv.style.border = "1px dashed black";
47document.body.appendChild(document.createElement("br"));
48document.body.appendChild(logDiv);
49
50log("Ready.");
51