Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <script type="text/javascript">
- /* #### PLEASE SET THIS TO THE CORRECT PROXY OR COMMENT IT OUT #### */
- // Titanium.Network.setHTTPProxy("http://HOST:PORT");
- </script>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
- <style>
- </style>
- </head>
- <body>
- <div id="main" style="width:100%; height:100%">
- Duck Duck Go Query Simulation
- <script type="text/javascript">
- /* +----------------------+
- * | BEGIN TEST HARNESS |
- * +----------------------+
- */
- /* +--------------------------+
- * | BEGIN HELPER FUNCTIONS |
- * +--------------------------+
- */
- function parseArguments(args, handlers) {
- var al = parseInt(args.length);
- for (var i = 0; i < al; ++i) {
- if (args[i] in handlers) {
- var argData = null;
- if (i+1 < args.length) {
- argData = args[i+1];
- }
- var eatNext = handlers[args[i]](argData);
- i += 1;
- if (eatNext) {
- i += 1;
- }
- }
- }
- }
- function hitch(obj, fn){
- return function(){
- return fn.apply(obj, arguments);
- };
- }
- /* END HELPER FUNCTIONS */
- function TestRunner(testCases, css, removeWhenDone) {
- var iframe = document.createElement("iframe");
- for (var attr in css) {
- $(iframe).css(attr, css[attr]);
- }
- this._iframe = iframe;
- this.testIndex = -1;
- this.testCases = testCases;
- this.context = { };
- this.removeWhenDone = removeWhenDone;
- iframe.src = "about:blank";
- iframe.onload = hitch(this, this._onIFrameLoaded);
- }
- TestRunner.prototype = {
- _onIFrameLoaded: function() {
- ++this.testIndex;
- if (this.testIndex >= this.testCases.length) {
- if (this.removeWhenDone) {
- $(this._iframe).remove();
- }
- return;
- }
- this.testCases[this.testIndex](this._iframe, this._iframe.contentWindow, this.context);
- },
- run: function() {
- document.body.appendChild(this._iframe);
- }
- };
- /* END TEST HARNESS */
- /* +-------------------------+
- * | BEGIN TEST DDG SEARCH |
- * +-------------------------+
- */
- /* This use case is the one where the user logs in */
- var test_ddg_search = function(query, removeWhenDone, callback) {
- var cases = [ ];
- cases.push(function(iframe, win, context, harness) {
- /* Load Duck Duck Go's home page */
- iframe.src = "http://duckduckgo.com/";
- });
- cases.push(function(iframe, win, context) {
- /* Make the query */
- var jQueryInclude = document.createElement('script');
- jQueryInclude.setAttribute('type', 'text/javascript');
- jQueryInclude.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
- win.document.body.appendChild(jQueryInclude);
- console.log(win.$);
- /* Wait for the jQuery script to be included in the context of
- * Duck Duck Go's home page
- */
- setTimeout(function() {
- try {
- /* Simulate typing... ;) */
- var currPos = 1;
- var corrected = false;
- var ival = setInterval(function() {
- if (currPos > query.length) {
- clearInterval(ival);
- win.$("form input[type=button]")[0].click();
- }
- else {
- if (currPos == 6 && !corrected) {
- currPos -= 2;
- corrected = true;
- }
- win.$("form input[type=text]").val(query.slice(0, currPos));
- currPos += 1;
- }
- }, 300);
- }
- catch (ex) {
- console.error("Exception: " + ex.toString());
- }
- }, 2000);
- });
- cases.push(function(iframe, win, context) {
- /* Fire the callback */
- callback();
- });
- var tester = new TestRunner(cases, { width: "700px", height: "500px" }, removeWhenDone);
- tester.run();
- };
- /* END TEST DDG SEARCH */
- /* +-------------------+
- * | Our Entry Point |
- * +-------------------+
- */
- function main(argc, argv) {
- var query_string = false;
- var argHandlers = {
- "--query": function(qs) {
- query_string = qs;
- /* Tell the arguments parser that we consumed a token
- * from the input. This enables the arguments parser
- * to skip that token while processing.
- */
- return true;
- }
- };
- parseArguments(argv, argHandlers);
- test_ddg_search(query_string, true, function() { alert("done..."); });
- return 0;
- }
- $().ready(function() {
- main(Titanium.App.getArguments().length, Titanium.App.getArguments());
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement