| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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.internal.v8native; | 5 package org.chromium.sdk.internal.v8native; |
| 6 | 6 |
| 7 import static org.junit.Assert.*; | 7 import static org.junit.Assert.*; |
| 8 import java.util.Collection; | |
| 9 import java.util.Collections; | 8 import java.util.Collections; |
| 10 import java.util.concurrent.CountDownLatch; | 9 import java.util.concurrent.CountDownLatch; |
| 11 | 10 |
| 12 import org.chromium.sdk.CallbackSemaphore; | 11 import org.chromium.sdk.CallbackSemaphore; |
| 13 import org.chromium.sdk.JsEvaluateContext; | 12 import org.chromium.sdk.JsEvaluateContext; |
| 14 import org.chromium.sdk.JsObject; | 13 import org.chromium.sdk.JsEvaluateContext.ResultOrException; |
| 15 import org.chromium.sdk.JsValue; | 14 import org.chromium.sdk.JsValue; |
| 16 import org.chromium.sdk.JsVariable; | |
| 17 import org.chromium.sdk.RelayOk; | 15 import org.chromium.sdk.RelayOk; |
| 18 import org.chromium.sdk.internal.browserfixture.AbstractAttachedTest; | 16 import org.chromium.sdk.internal.browserfixture.AbstractAttachedTest; |
| 19 import org.chromium.sdk.internal.transport.FakeConnection; | 17 import org.chromium.sdk.internal.transport.FakeConnection; |
| 20 import org.junit.Test; | 18 import org.junit.Test; |
| 21 | 19 |
| 22 /** | 20 /** |
| 23 * A test for the DebugContextImpl class. | 21 * A test for the DebugContextImpl class. |
| 24 */ | 22 */ |
| 25 public class LoadValueTest extends AbstractAttachedTest<FakeConnection>{ | 23 public class LoadValueTest extends AbstractAttachedTest<FakeConnection>{ |
| 26 | 24 |
| 27 @Test | 25 @Test |
| 28 public void testLoadFullValue() throws Exception { | 26 public void testLoadFullValue() throws Exception { |
| 29 { | 27 { |
| 30 CountDownLatch latch = expectSuspend(); | 28 CountDownLatch latch = expectSuspend(); |
| 31 messageResponder.hitBreakpoints(Collections.<Long>emptyList()); | 29 messageResponder.hitBreakpoints(Collections.<Long>emptyList()); |
| 32 latch.await(); | 30 latch.await(); |
| 33 } | 31 } |
| 34 | 32 |
| 35 final JsVariable [] expressionResult = { null }; | 33 final JsValue [] expressionResult = { null }; |
| 36 JsEvaluateContext.EvaluateCallback evaluateCallback = new JsEvaluateContext.
EvaluateCallback() { | 34 JsEvaluateContext.EvaluateCallback evaluateCallback = new JsEvaluateContext.
EvaluateCallback() { |
| 37 public void success(JsVariable variable) { | 35 @Override |
| 38 expressionResult[0] = variable; | 36 public void success(ResultOrException result) { |
| 37 result.accept(new ResultOrException.Visitor<Void>() { |
| 38 @Override |
| 39 public Void visitResult(JsValue value) { |
| 40 expressionResult[0] = value; |
| 41 return null; |
| 42 } |
| 43 |
| 44 @Override public Void visitException(JsValue exception) { |
| 45 return null; |
| 46 } |
| 47 }); |
| 39 } | 48 } |
| 40 public void failure(String errorMessage) { | 49 @Override |
| 50 public void failure(Exception cause) { |
| 41 } | 51 } |
| 42 }; | 52 }; |
| 43 | 53 |
| 44 suspendContext.getGlobalEvaluateContext().evaluateSync("#long_value", null,
evaluateCallback); | 54 suspendContext.getGlobalEvaluateContext().evaluateSync("#long_value", null,
evaluateCallback); |
| 45 assertNotNull(expressionResult[0]); | 55 assertNotNull(expressionResult[0]); |
| 46 | 56 |
| 47 JsValue value = expressionResult[0].getValue(); | 57 JsValue value = expressionResult[0]; |
| 48 assertTrue(value.isTruncated()); | 58 assertTrue(value.isTruncated()); |
| 49 String shortValue = value.getValueString(); | 59 String shortValue = value.getValueString(); |
| 50 | 60 |
| 51 final boolean[] reloadResult = { false } ; | 61 final boolean[] reloadResult = { false } ; |
| 52 JsValue.ReloadBiggerCallback callback = new JsValue.ReloadBiggerCallback() { | 62 JsValue.ReloadBiggerCallback callback = new JsValue.ReloadBiggerCallback() { |
| 53 public void done() { | 63 public void done() { |
| 54 reloadResult[0] = true; | 64 reloadResult[0] = true; |
| 55 } | 65 } |
| 56 }; | 66 }; |
| 57 CallbackSemaphore semaphore = new CallbackSemaphore(); | 67 CallbackSemaphore semaphore = new CallbackSemaphore(); |
| 58 RelayOk relayOk = value.reloadHeavyValue(callback, semaphore); | 68 RelayOk relayOk = value.reloadHeavyValue(callback, semaphore); |
| 59 semaphore.acquireDefault(relayOk); | 69 semaphore.acquireDefault(relayOk); |
| 60 assertTrue(reloadResult[0]); | 70 assertTrue(reloadResult[0]); |
| 61 | 71 |
| 62 String reloadedValue = value.getValueString(); | 72 String reloadedValue = value.getValueString(); |
| 63 | 73 |
| 64 assertTrue(shortValue.length() < reloadedValue.length()); | 74 assertTrue(shortValue.length() < reloadedValue.length()); |
| 65 } | 75 } |
| 66 | 76 |
| 67 @Override | 77 @Override |
| 68 protected FakeConnection createConnection() { | 78 protected FakeConnection createConnection() { |
| 69 return new FakeConnection(messageResponder); | 79 return new FakeConnection(messageResponder); |
| 70 } | 80 } |
| 71 } | 81 } |
| OLD | NEW |