| <?xml version="1.0" encoding="UTF-8" ?> |
| <!-- |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| --> |
| <Module> |
| <ModulePrefs title="gadgets.rpc Performance/correctness tests: Gadget"> |
| <Require feature="rpc"/> |
| </ModulePrefs> |
| <Content type="html"> |
| <![CDATA[ |
| <script> |
| // Pre-onload message send. |
| gadgets.rpc.call(null, 'initial_gadget_message', null, 'Hello there! Pre-onload message sent successfully.'); |
| |
| var cachebust = 'cachebust=1';// + Math.random(); |
| document.write('<scr' + 'ipt language="JavaScript" type="text/javascript" src="/container/rpctest_perf.js?' + cachebust + '"></scr' + 'ipt>'); |
| </script> |
| <script> |
| // Register ping handler. |
| gadgets.rpc.register('gadget_service_ping', function() { |
| var queryConsole = document.getElementById('queryconsole'); |
| var numQueries = queryConsole.innerHTML; |
| ++numQueries; |
| queryConsole.innerHTML = numQueries; |
| var whoAsked = document.getElementById('whoasked'); |
| whoAsked.innerHTML = this.f; |
| }); |
| |
| function appendChildGadget() { |
| var childgadgetdiv = document.getElementById('childgadgetdiv'); |
| var parentDomain = gadgets.rpc.getOrigin(gadgets.util.getUrlParameters().parent); |
| var myDomain = gadgets.rpc.getOrigin(window.location.href); |
| var rpctoken = Math.round(Math.random() * 10000000); |
| var rpctx = gadgets.util.getUrlParameters()["rpctx"] || ""; |
| var childGadgetUrl = parentDomain + '/gadgets/ifr?url=' + parentDomain + '/container/rpctest_childgadget.xml&parent=' + myDomain + '&libs=rpc&debug=1&rpctx=' + rpctx + '#rpctoken=' + rpctoken; |
| childgadgetdiv.innerHTML = '<div><input type="button" value="Ping Parent (Container)" onclick="callGadgetServicePing();"/><hr/>' + |
| '<div>Who-am-I query count: <span id="queryconsole">0</span>, last q from: <span id="whoasked"></span></div>' + |
| '<div><iframe id="childgadget" name="childgadget" height=100 width=200 src="about:blank"></iframe></div>'; |
| document.getElementById("childgadget").src = childGadgetUrl; |
| gadgets.rpc.setRelayUrl('childgadget', parentDomain); |
| gadgets.rpc.setAuthToken('childgadget', rpctoken); |
| } |
| |
| function callGadgetServicePing() { |
| gadgets.rpc.call(null, 'gadget_service_ping'); |
| } |
| |
| // Initialize performance test onLoad. |
| gadgets.util.registerOnLoadHandler(initPerfTest); |
| </script> |
| <div>gadgets.rpc Performance: "Gadget" page</div><hr/> |
| <script> |
| document.write("<div>Parent relay: " + gadgets.rpc.getRelayUrl('..') + "<br/>method: " + gadgets.rpc.getRelayChannel() + "</div><hr/>"); |
| </script> |
| <div>Test<br/> |
| <ul> |
| <li>Number of messages to send: |
| <select name="num_msgs" id="num_msgs"> |
| <option value="1" selected>1</option> |
| <option value="10">10</option> |
| <option value="100">100</option> |
| <option value="1000">1000</option> |
| </select> |
| </li> |
| <li>Message size: |
| <select name="msg_size" id="msg_size"> |
| <option value="10">10 B</option> |
| <option value="100">100 B</option> |
| <option value="1024" selected>1 kB</option> |
| <option value="10240">10 kB</option> |
| <option value="102400">100 kB</option> |
| <option value="1048576">1 MB</option> |
| </select> |
| </li> |
| <li> |
| <input type="button" value="Start The Test!" onclick="runPerfTest();" /> |
| </li> |
| </ul> |
| </div> |
| <div id="test_running" style="display:none;"> |
| Running test... |
| </div> |
| <div id="results" style="display:none;"> |
| Results: Gadget-to-Container<br/> |
| Messages: <span id="results_num_received"></span>, Bytes: <span id="results_bytes_received"></span> <span id="in_or_out"></span><br/> |
| Time elapsed for test run: <span id="results_time_used"></span><br/> |
| Messages/second: <span id="results_msgs_per_sec"></span><br/> |
| Bytes/second: <span id="results_bytes_per_sec"></span><br/> |
| Referrer: <span id="results_referrer"></span> |
| </div><hr/> |
| <div>Callback<br/> |
| <ul> |
| <li>Input: <input type="text" value="test-value" size="20" id="echo_test_input"/> <input type="button" value="Sync Callback Test" onclick="runCallbackTest(null,true);"/> <input type="button" value="Async Callback Test" onclick="runCallbackTest(null,false);"/></li> |
| <li>Result: <span id="echo_test_result"></span></li> |
| </ul> |
| </div><hr/> |
| <div id="childgadgetdiv"><input type="button" value="Child Gadget Tests" onclick="appendChildGadget();"/></div> |
| ]]> |
| </Content> |
| </Module> |