~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to gears/test/manual/console_test.html

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--
 
2
Copyright 2008, Google Inc.
 
3
 
 
4
Redistribution and use in source and binary forms, with or without 
 
5
modification, are permitted provided that the following conditions are met:
 
6
 
 
7
 1. Redistributions of source code must retain the above copyright notice, 
 
8
    this list of conditions and the following disclaimer.
 
9
 2. Redistributions in binary form must reproduce the above copyright notice,
 
10
    this list of conditions and the following disclaimer in the documentation
 
11
    and/or other materials provided with the distribution.
 
12
 3. Neither the name of Google Inc. nor the names of its contributors may be
 
13
    used to endorse or promote products derived from this software without
 
14
    specific prior written permission.
 
15
 
 
16
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
17
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
18
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 
19
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
20
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
21
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
22
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
23
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 
24
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
25
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
26
-->
 
27
 
 
28
<!DOCTYPE html>
 
29
 
 
30
<html>
 
31
 
 
32
  <head>
 
33
    <title>Gears Console Test Page</title>
 
34
  </head>
 
35
 
 
36
  <body>
 
37
 
 
38
    <h1>Gears Console Test Page</h1>
 
39
 
 
40
    <div>
 
41
      <p>Log Message:</p>
 
42
      <textarea id="message" rows="6" cols="80"></textarea>
 
43
      <p>Message Arguments:<br />
 
44
      (Comma separated list of values, will be interpolated into message
 
45
      replacing instances of %s.)</p>
 
46
      [ <input id="arguments" /> ]
 
47
      <p>Log Type:</p>
 
48
      <button onclick="log('debug',
 
49
          document.getElementById('message').value);" disabled="disabled">
 
50
        debug
 
51
      </button>
 
52
      <button onclick="log('info',
 
53
          document.getElementById('message').value);" disabled="disabled">
 
54
        info
 
55
      </button>
 
56
      <button onclick="log('warn',
 
57
          document.getElementById('message').value);" disabled="disabled">
 
58
        warn
 
59
      </button>
 
60
      <button onclick="log('error',
 
61
          document.getElementById('message').value);" disabled="disabled">
 
62
        error
 
63
      </button>
 
64
      <input id="other-type" value="Custom type..."
 
65
          onfocus="if(this.value == 'Custom type...') this.value = '';" />
 
66
      <button onclick="log(
 
67
          document.getElementById('other-type').value,
 
68
          document.getElementById('message').value);" disabled="disabled">
 
69
        Custom
 
70
      </button>
 
71
    </div>
 
72
    <p>
 
73
      <input type="checkbox" id="wp" />
 
74
      <label for="wp">Send the log message from a WorkerPool process</label>
 
75
    </p>
 
76
    <p>
 
77
      <button onclick="document.getElementById('status').innerHTML = '';">
 
78
        Clear
 
79
      </button>
 
80
    </p>
 
81
    <p id="status"></p>
 
82
 
 
83
<!-- ====================================== -->
 
84
<!--            JavaScript code             -->
 
85
 
 
86
<script type="text/javascript" src="../../sdk/gears_init.js"></script>
 
87
<script type="text/javascript">
 
88
var console;
 
89
var workerPool;
 
90
var loggerWorkerId;
 
91
 
 
92
function addStatus(msg) {
 
93
  document.getElementById('status').insertBefore(
 
94
      document.createElement('br'),
 
95
      document.getElementById('status').firstChild);
 
96
  document.getElementById('status').insertBefore(
 
97
      document.createTextNode(msg),
 
98
      document.getElementById('status').firstChild);
 
99
}
 
100
 
 
101
function onlogHandler(log_event) {
 
102
  // TODO(aa): We could just call addStatus here to avoid duplication,
 
103
  // but the handler throws an exception about addStatus not being
 
104
  // defined if we log events too early for some reason. The exception stops
 
105
  // being thrown after a few seconds. Need to investigate the cause, but
 
106
  // this works ok for now.
 
107
  document.getElementById('status').insertBefore(
 
108
      document.createElement('br'),
 
109
      document.getElementById('status').firstChild);
 
110
  document.getElementById('status').insertBefore(
 
111
      document.createTextNode(
 
112
        "(" + log_event.type + "): " + log_event.message +
 
113
        " (" + log_event.sourceUrl + ") (" +
 
114
        // TODO(aa): Change this when log_event.date actually returns a
 
115
        // JavaScript Date object.
 
116
        Date(log_event.date) +
 
117
        ")" ),
 
118
      document.getElementById('status').firstChild);
 
119
}
 
120
 
 
121
function log(type, msg) {
 
122
  try {
 
123
    args = "[]";
 
124
    if (document.getElementById('arguments').value != '') {
 
125
      args = "[" + document.getElementById('arguments').value + "]";
 
126
    }
 
127
    if (document.getElementById('wp').checked) {
 
128
      addStatus('Logging message from WorkerPool process...');
 
129
      workerPool.sendMessage(type + ":_:_:" + msg + ":_:_:" + args,
 
130
                             loggerWorkerId);
 
131
    } else {
 
132
      console.log(type, msg, eval(args));
 
133
    }
 
134
  } catch (e) {
 
135
    addStatus(e.message);
 
136
  }
 
137
}
 
138
 
 
139
function childInit() {
 
140
  parentId = null;
 
141
  wp = google.gears.workerPool;
 
142
  wp.onmessage = childHandler;
 
143
  wp.onerror = function(e) {
 
144
                 wp.sendMessage(e.message, parentId);
 
145
                 return true;
 
146
               };
 
147
  console = google.gears.factory.create('beta.console');
 
148
}
 
149
 
 
150
function childHandler(message, sender) {
 
151
  parentId = sender;
 
152
  var split_message = message.split(":_:_:", 3);
 
153
  var type = split_message[0];
 
154
  var msg = split_message[1];
 
155
  var args = eval(split_message[2]);
 
156
  console.log(type, msg, args);
 
157
}
 
158
 
 
159
function init() {
 
160
  if (!window.google || !google.gears) {
 
161
    addStatus('Google Gears is not installed', 'error');
 
162
    return;
 
163
  }
 
164
  try {
 
165
    console = google.gears.factory.create('beta.console');
 
166
    console.onlog = onlogHandler;
 
167
 
 
168
    workerPool = google.gears.factory.create('beta.workerpool');
 
169
    workerPool.onmessage = function(message, sender) { addStatus(message); };
 
170
 
 
171
    loggerWorkerId = workerPool.createWorker(
 
172
        String(childInit) +
 
173
        String(childHandler) +
 
174
        "childInit();"
 
175
        );
 
176
 
 
177
  } catch (ex) {
 
178
    return;
 
179
  }
 
180
  addStatus('Ready.');
 
181
  addStatus('');
 
182
  addStatus('Messages logged here can also be viewed' +
 
183
      ' in the Log Viewer Tool.');
 
184
  addStatus('Open two copies of this page side by side' +
 
185
      ' to log between them.');
 
186
  addStatus('');
 
187
  var buttons = document.getElementsByTagName('button');
 
188
  for (var i = 0, el; el = buttons[i]; i++) {
 
189
    el.disabled = null;
 
190
  }
 
191
}
 
192
 
 
193
init();
 
194
 
 
195
</script>
 
196
 
 
197
</body>
 
198
</html>