Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: utils/org.chromium.sdk.tests.system/src/org/chromium/sdk/tests/system/Main.java

Issue 12316003: Fix tests compilation (Closed) Base URL: https://chromedevtools.googlecode.com/svn/trunk
Patch Set: format Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/ScriptManager.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.sdk.tests.system; 5 package org.chromium.sdk.tests.system;
6 6
7 import java.io.IOException; 7 import java.io.IOException;
8 import java.net.InetSocketAddress; 8 import java.net.InetSocketAddress;
9 import java.util.ArrayList; 9 import java.util.ArrayList;
10 import java.util.Arrays; 10 import java.util.Arrays;
11 import java.util.Collection; 11 import java.util.Collection;
12 import java.util.LinkedHashMap; 12 import java.util.LinkedHashMap;
13 import java.util.List; 13 import java.util.List;
14 import java.util.Map; 14 import java.util.Map;
15 15
16 import org.chromium.sdk.Breakpoint; 16 import org.chromium.sdk.Breakpoint;
17 import org.chromium.sdk.CallFrame; 17 import org.chromium.sdk.CallFrame;
18 import org.chromium.sdk.CallbackSemaphore; 18 import org.chromium.sdk.CallbackSemaphore;
19 import org.chromium.sdk.ConnectionLogger; 19 import org.chromium.sdk.ConnectionLogger;
20 import org.chromium.sdk.ConnectionLogger.Factory; 20 import org.chromium.sdk.ConnectionLogger.Factory;
21 import org.chromium.sdk.DebugContext; 21 import org.chromium.sdk.DebugContext;
22 import org.chromium.sdk.JavascriptVm; 22 import org.chromium.sdk.JavascriptVm;
23 import org.chromium.sdk.JsEvaluateContext; 23 import org.chromium.sdk.JsEvaluateContext;
24 import org.chromium.sdk.JsEvaluateContext.ResultOrException;
24 import org.chromium.sdk.JsObject; 25 import org.chromium.sdk.JsObject;
25 import org.chromium.sdk.JsScope; 26 import org.chromium.sdk.JsScope;
27 import org.chromium.sdk.JsScope.Declarative;
28 import org.chromium.sdk.JsScope.ObjectBased;
26 import org.chromium.sdk.JsValue; 29 import org.chromium.sdk.JsValue;
27 import org.chromium.sdk.JsVariable; 30 import org.chromium.sdk.JsVariable;
28 import org.chromium.sdk.RelayOk; 31 import org.chromium.sdk.RelayOk;
29 import org.chromium.sdk.Script; 32 import org.chromium.sdk.Script;
30 import org.chromium.sdk.wip.WipBackend; 33 import org.chromium.sdk.wip.WipBackend;
31 import org.chromium.sdk.wip.WipBackendFactory; 34 import org.chromium.sdk.wip.WipBackendFactory;
32 import org.chromium.sdk.wip.WipBrowser; 35 import org.chromium.sdk.wip.WipBrowser;
33 import org.chromium.sdk.wip.WipBrowserFactory; 36 import org.chromium.sdk.wip.WipBrowserFactory;
34 37
35 /** 38 /**
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 stateManager.expectEvent(EXPECT_RESUMED_VISITOR); 104 stateManager.expectEvent(EXPECT_RESUMED_VISITOR);
102 } 105 }
103 106
104 // Second time check variables and expressions. 107 // Second time check variables and expressions.
105 { 108 {
106 DebugContext context = stateManager.expectEvent(EXPECT_SUSPENDED_VISITOR); 109 DebugContext context = stateManager.expectEvent(EXPECT_SUSPENDED_VISITOR);
107 110
108 { 111 {
109 // Check cache dropping. 112 // Check cache dropping.
110 JsObject root = evaluateSync(context.getGlobalEvaluateContext(), 113 JsObject root = evaluateSync(context.getGlobalEvaluateContext(),
111 "(debug_value_1 = {a:2})").getValue().asObject(); 114 "(debug_value_1 = {a:2})").asObject();
112 if (root == null) { 115 if (root == null) {
113 throw new RuntimeException(); 116 throw new RuntimeException();
114 } 117 }
115 String aValue; 118 String aValue;
116 aValue = root.getProperty("a").getValue().getValueString(); 119 aValue = root.getProperty("a").getValue().getValueString();
117 if (!"2".equals(aValue)) { 120 if (!"2".equals(aValue)) {
118 throw new SmokeException(); 121 throw new SmokeException();
119 } 122 }
120 evaluateSync(context.getGlobalEvaluateContext(), "debug_value_1.a = 3"); 123 evaluateSync(context.getGlobalEvaluateContext(), "debug_value_1.a = 3");
121 124
122 root.getRemoteValueMapping().clearCaches(); 125 root.getRemoteValueMapping().clearCaches();
123 126
124 aValue = root.getProperty("a").getValue().getValueString(); 127 aValue = root.getProperty("a").getValue().getValueString();
125 if (!"3".equals(aValue)) { 128 if (!"3".equals(aValue)) {
126 throw new SmokeException(); 129 throw new SmokeException();
127 } 130 }
128 } 131 }
129 132
130 { 133 {
131 // Check literals. 134 // Check literals.
132 for (LiteralTestCase literal : TEST_LITERALS) { 135 for (LiteralTestCase literal : TEST_LITERALS) {
133 JsVariable resultVar = evaluateSync(context.getGlobalEvaluateContext() , 136 JsValue resultValue = evaluateSync(context.getGlobalEvaluateContext(),
134 literal.javaScriptExpression); 137 literal.javaScriptExpression);
135 JsValue resultValue = resultVar.getValue();
136 if (resultValue.getType() != literal.expectedType) { 138 if (resultValue.getType() != literal.expectedType) {
137 throw new SmokeException("Unexpected type of '" + literal.javaScript Expression + 139 throw new SmokeException("Unexpected type of '" + literal.javaScript Expression +
138 "': " + resultValue.getType()); 140 "': " + resultValue.getType());
139 } 141 }
140 if (!literal.expectedDescription.equals(resultValue.getValueString())) { 142 if (!literal.expectedDescription.equals(resultValue.getValueString())) {
141 throw new SmokeException("Unexpected string value of '" + 143 throw new SmokeException("Unexpected string value of '" +
142 literal.javaScriptExpression + "': " + resultValue.getValueStrin g()); 144 literal.javaScriptExpression + "': " + resultValue.getValueStrin g());
143 } 145 }
144 } 146 }
145 } 147 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 293 }
292 return firstTab.attach(stateManager.getTabListener()).getJavascriptVm(); 294 return firstTab.attach(stateManager.getTabListener()).getJavascriptVm();
293 } 295 }
294 }; 296 };
295 297
296 public abstract JavascriptVm connect(InetSocketAddress address, StateManager stateManager, 298 public abstract JavascriptVm connect(InetSocketAddress address, StateManager stateManager,
297 Factory connectionLoggerFactory) throws SmokeException, IOException; 299 Factory connectionLoggerFactory) throws SmokeException, IOException;
298 } 300 }
299 301
300 private static JsVariable getVariable(JsScope scope, String name) throws Smoke Exception { 302 private static JsVariable getVariable(JsScope scope, String name) throws Smoke Exception {
301 for (JsVariable var : scope.getVariables()) { 303 Collection<? extends JsVariable> variables = scope.accept(
304 new JsScope.Visitor<Collection<? extends JsVariable>>() {
305 @Override
306 public Collection<? extends JsVariable> visitDeclarative(Declarative d eclarativeScope) {
307 return declarativeScope.getVariables();
308 }
309 @Override
310 public Collection<? extends JsVariable> visitObject(ObjectBased object Scope) {
311 return objectScope.getScopeObject().getProperties();
312 }
313 });
314 for (JsVariable var : variables) {
302 if (name.equals(var.getName())) { 315 if (name.equals(var.getName())) {
303 return var; 316 return var;
304 } 317 }
305 } 318 }
306 throw new SmokeException("Failed to find variable " + name); 319 throw new SmokeException("Failed to find variable " + name);
307 } 320 }
308 321
309 /** 322 /**
310 * Calls fibonacci expression in context for stack frame and checks the result value. 323 * Calls fibonacci expression in context for stack frame and checks the result value.
311 */ 324 */
312 private static void checkExpression(CallFrame frame) throws SmokeException { 325 private static void checkExpression(CallFrame frame) throws SmokeException {
313 final ValueHolder<JsVariable> variableHolder = new ValueHolder<JsVariable>() ; 326 final ValueHolder<JsValue> variableHolder = new ValueHolder<JsValue>();
314 JsEvaluateContext.EvaluateCallback callback = new JsEvaluateContext.Evaluate Callback() { 327 JsEvaluateContext.EvaluateCallback callback = new JsEvaluateContext.Evaluate Callback() {
315 public void failure(String errorMessage) { 328 @Override
316 variableHolder.setException(new Exception(errorMessage)); 329 public void success(ResultOrException result) {
330 result.accept(new ResultOrException.Visitor<Void>() {
331 @Override
332 public Void visitResult(JsValue value) {
333 variableHolder.setValue(value);
334 return null;
335 }
336
337 @Override
338 public Void visitException(JsValue exception) {
339 variableHolder.setException(
340 new Exception("Caught exception: " + exception.getValueString()) );
341 return null;
342 }
343 });
317 } 344 }
318 public void success(JsVariable variable) { 345
319 variableHolder.setValue(variable); 346 @Override public void failure(Exception cause) {
347 variableHolder.setException(new Exception(cause));
320 } 348 }
321 }; 349 };
322 frame.getEvaluateContext().evaluateSync(FIBONACCI_EXPRESSION, null, callback ); 350 frame.getEvaluateContext().evaluateSync(FIBONACCI_EXPRESSION, null, callback );
323 JsVariable variable = variableHolder.get(); 351 JsValue value = variableHolder.get();
324 String resString = variable.getValue().getValueString(); 352 String resString = value.getValueString();
325 if (!"24".equals(resString)) { 353 if (!"24".equals(resString)) {
326 throw new SmokeException("Wrong expression value"); 354 throw new SmokeException("Wrong expression value");
327 } 355 }
328 } 356 }
329 357
330 private static class LiteralTestCase { 358 private static class LiteralTestCase {
331 final String javaScriptExpression; 359 final String javaScriptExpression;
332 final JsValue.Type expectedType; 360 final JsValue.Type expectedType;
333 final String expectedDescription; 361 final String expectedDescription;
334 362
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 549 }
522 T get() throws SmokeException { 550 T get() throws SmokeException {
523 if (exception != null) { 551 if (exception != null) {
524 throw new SmokeException(exception); 552 throw new SmokeException(exception);
525 } 553 }
526 return val; 554 return val;
527 } 555 }
528 } 556 }
529 557
530 static class EvalCallbackImpl implements JsEvaluateContext.EvaluateCallback { 558 static class EvalCallbackImpl implements JsEvaluateContext.EvaluateCallback {
531 JsVariable variable = null; 559 JsValue value = null;
532 String failure = null; 560 Exception failure = null;
533 @Override 561
534 public void success(JsVariable variable) { 562 JsValue get() {
535 this.variable = variable; 563 if (failure != null) {
564 throw new RuntimeException("Failed to evaluate: " + failure);
565 }
566 return value;
536 } 567 }
537 568
538 @Override 569 @Override
539 public void failure(String errorMessage) { 570 public void success(ResultOrException result) {
540 this.failure = errorMessage; 571 result.accept(new ResultOrException.Visitor<Void>() {
572 @Override
573 public Void visitResult(JsValue value) {
574 EvalCallbackImpl.this.value = value;
575 return null;
576 }
577
578 @Override
579 public Void visitException(JsValue exception) {
580 failure = new Exception("JavaScript exception: " + exception.getValueS tring());
581 return null;
582 }
583 });
541 } 584 }
542 JsVariable get() { 585
543 if (failure != null) { 586 @Override
544 throw new RuntimeException("Failed to evaluate: " + failure); 587 public void failure(Exception cause) {
545 } 588 this.failure = cause;
546 return variable;
547 } 589 }
548 } 590 }
549 591
550 private static JsVariable evaluateSync(JsEvaluateContext evaluateContext, Stri ng expression) { 592 private static JsValue evaluateSync(JsEvaluateContext evaluateContext, String expression) {
551 EvalCallbackImpl callbackImpl = new EvalCallbackImpl(); 593 EvalCallbackImpl callbackImpl = new EvalCallbackImpl();
552 evaluateContext.evaluateSync(expression, null, callbackImpl); 594 evaluateContext.evaluateSync(expression, null, callbackImpl);
553 return callbackImpl.get(); 595 return callbackImpl.get();
554 } 596 }
555 } 597 }
OLDNEW
« no previous file with comments | « plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/ScriptManager.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698