Package org.chromium.sdk

Examples of org.chromium.sdk.JavascriptVm$ScriptsCallback


    return breakpointManager.changeBreakpoint(this, callback, syncCallback);
  }

  @Override
  public IgnoreCountBreakpointExtension getIgnoreCountBreakpointExtension() {
    JavascriptVm javascriptVm = breakpointManager.getDebugSession().getJavascriptVm();
    return javascriptVm.getIgnoreCountBreakpointExtension();
  }
View Full Code Here


    ConnectionLogger.Factory connectionLoggerFactory = new ConnectionLogger.Factory() {
      public ConnectionLogger newConnectionLogger() {
        return new SystemOutConnectionLogger();
      }
    };
    JavascriptVm vm;
    try {
      vm = commandLineArgs.getProtocolType().connect(address, stateManager,
          connectionLoggerFactory);
    } catch (IOException e) {
      throw new SmokeException("Failed to connect", e);
    }

    Collection<Script> scripts = loadScripts(vm);

    // Finding script1.js script.
    Script scriptOne;
    lookForScript: {
      for (Script script : scripts) {
        String name = script.getName();
        if (name != null && name.endsWith(SCRIPT_ONE_NAME)) {
          scriptOne = script;
          break lookForScript;
        }
      }
      throw new SmokeException("Failed to find script " + SCRIPT_ONE_NAME);
    }

    // Getting a number of the line with the marker.
    int breakLine = findSourceMark(scriptOne, BREAKPOINT_MARK);
    if (breakLine == -1) {
      throw new SmokeException("Failed to find mark in script");
    }

    // Setting a breakpoint.
    CallbackSemaphore callbackSemaphore = new CallbackSemaphore();
    Breakpoint.Target breakpointTarget = new Breakpoint.Target.ScriptName(scriptOne.getName());
    RelayOk relayOk = vm.setBreakpoint(breakpointTarget, breakLine, 0, true, null,
        null, callbackSemaphore);
    callbackSemaphore.acquireDefault(relayOk);

    // First time just suspend on breakpoint and go on.
    {
      DebugContext context = stateManager.expectEvent(EXPECT_SUSPENDED_VISITOR);
      context.continueVm(DebugContext.StepAction.CONTINUE, 0, null);
      stateManager.expectEvent(EXPECT_RESUMED_VISITOR);
    }

    // Second time check variables and expressions.
    {
      DebugContext context = stateManager.expectEvent(EXPECT_SUSPENDED_VISITOR);

      {
        // Check cache dropping.
        JsObject root = evaluateSync(context.getGlobalEvaluateContext(),
            "(debug_value_1 = {a:2})").asObject();
        if (root == null) {
          throw new RuntimeException();
        }
        String aValue;
        aValue = root.getProperty("a").getValue().getValueString();
        if (!"2".equals(aValue)) {
          throw new SmokeException();
        }
        evaluateSync(context.getGlobalEvaluateContext(), "debug_value_1.a = 3");

        root.getRemoteValueMapping().clearCaches();

        aValue = root.getProperty("a").getValue().getValueString();
        if (!"3".equals(aValue)) {
          throw new SmokeException();
        }
      }

      {
        // Check literals.
        for (LiteralTestCase literal : TEST_LITERALS) {
          JsValue resultValue = evaluateSync(context.getGlobalEvaluateContext(),
              literal.javaScriptExpression);
          if (resultValue.getType() != literal.expectedType) {
            throw new SmokeException("Unexpected type of '" + literal.javaScriptExpression +
                "': " + resultValue.getType());
          }
          if (!literal.expectedDescription.equals(resultValue.getValueString())) {
            throw new SmokeException("Unexpected string value of '" +
                literal.javaScriptExpression + "': " + resultValue.getValueString());
          }
        }
      }

      // Do not block dispatcher thread.
      stateManager.setDefaultReceiver(IGNORE_SCRIPTS_VISITOR);

      List<? extends CallFrame> callFrames = context.getCallFrames();
      CallFrame topFrame = callFrames.get(0);

      JsScope localScope;
      findScope: {
        for (JsScope scope : topFrame.getVariableScopes()) {
          if (scope.getType() == JsScope.Type.LOCAL) {
            localScope = scope;
            break findScope;
          }
        }
        throw new SmokeException("Failed to find local scope");
      }

      JsVariable xVar = getVariable(localScope, "x");
      if (!"1".equals(xVar.getValue().getValueString())) {
        throw new SmokeException("Unexpected value of local variable");
      }
      JsVariable yVar = getVariable(localScope, "y");
      if (!"2".equals(yVar.getValue().getValueString())) {
        throw new SmokeException("Unexpected value of local variable");
      }

      for (CallFrame frame : callFrames) {
        checkExpression(frame);
      }

      context.continueVm(DebugContext.StepAction.CONTINUE, 0, null);
      stateManager.expectEvent(EXPECT_RESUMED_VISITOR);
    }

    stateManager.setDefaultReceiver(IGNORE_ALL_VISITOR);
    vm.detach();

    System.out.println("Test passed OK");
  }
View Full Code Here

    public static RelayOk createOnRemote(final ChromiumLineBreakpoint uiBreakpoint,
        VmResourceRef vmResourceRef, final ConnectedTargetData connectedTargetData,
        final CreateOnRemoveCallback createOnRemoveCallback,
        SyncCallback syncCallback) throws CoreException {
      final JavascriptVm javascriptVm = connectedTargetData.getJavascriptVm();

      // ILineBreakpoint lines are 1-based while V8 lines are 0-based
      final int line = (uiBreakpoint.getLineNumber() - 1);
      final int column = 0;

      BreakpointCallback callback = new BreakpointCallback() {
        public void success(Breakpoint sdkBreakpoint) {
          createOnRemoveCallback.success(sdkBreakpoint);
        }
        public void failure(String errorMessage) {
          createOnRemoveCallback.failure(errorMessage);
        }
      };

      class SdkParams {
        SdkParams(Target target, int line, int column) {
          this.target = target;
          this.line = line;
          this.column = column;
        }

        final Breakpoint.Target target;
        final int line;
        final int column;
      }

      SdkParams sdkParams = vmResourceRef.accept(new VmResourceRef.Visitor<SdkParams>() {
        @Override
        public SdkParams visitRegExpBased(ScriptNamePattern scriptNamePattern) {
          // TODO: support source mapping perhaps.

          ScriptRegExpSupport scriptRegExpSupport =
              javascriptVm.getBreakpointTypeExtension().getScriptRegExpSupport();
          if (scriptRegExpSupport == null) {
            // TODO: check earlier in UI.
            throw new RuntimeException("Script RegExp is not supported by VM");
          }

          final Breakpoint.Target targetValue =
              scriptRegExpSupport.createTarget(scriptNamePattern.getJavaScriptRegExp());
          return new SdkParams(targetValue, line, column);
        }

        @Override
        public SdkParams visitResourceId(VmResourceId resourceId) {
          SourcePositionMap map = connectedTargetData.getSourcePositionMap();
          SourcePosition vmPosition =
              map.translatePosition(resourceId, line, column,TranslateDirection.USER_TO_VM);
          final int vmLine = vmPosition.getLine();
          final int vmColumn = vmPosition.getColumn();
          final Breakpoint.Target target;
          VmResourceId vmSideVmResourceId = vmPosition.getId();
          if (vmSideVmResourceId.getId() == null) {
            target = new Breakpoint.Target.ScriptName(vmSideVmResourceId.getName());
          } else {
            target = new Breakpoint.Target.ScriptId(vmSideVmResourceId.getId());
          }

          return new SdkParams(target, vmLine, vmColumn);
        }
      });

      IgnoreCountBreakpointExtension extension = javascriptVm.getIgnoreCountBreakpointExtension();
      if (extension == null) {
        if (uiBreakpoint.getEffectiveIgnoreCount() != Breakpoint.EMPTY_VALUE) {
          ChromiumDebugPlugin.log(
              new Exception("Failed to set breakpoint ignore count as it is not supported by VM"));
        }
        return javascriptVm.setBreakpoint(
            sdkParams.target,
            sdkParams.line,
            sdkParams.column,
            uiBreakpoint.isEnabled(),
            uiBreakpoint.getCondition(),
View Full Code Here

    return breakpointManager.changeBreakpoint(this, callback, syncCallback);
  }

  @Override
  public IgnoreCountBreakpointExtension getIgnoreCountBreakpointExtension() {
    JavascriptVm javascriptVm = breakpointManager.getDebugSession().getJavascriptVm();
    return javascriptVm.getIgnoreCountBreakpointExtension();
  }
View Full Code Here

    ConnectionLogger.Factory connectionLoggerFactory = new ConnectionLogger.Factory() {
      public ConnectionLogger newConnectionLogger() {
        return new SystemOutConnectionLogger();
      }
    };
    JavascriptVm vm;
    try {
      vm = commandLineArgs.getProtocolType().connect(address, stateManager,
          connectionLoggerFactory);
    } catch (IOException e) {
      throw new SmokeException("Failed to connect", e);
    }

    Collection<Script> scripts = loadScripts(vm);

    // Finding script1.js script.
    Script scriptOne;
    lookForScript: {
      for (Script script : scripts) {
        String name = script.getName();
        if (name != null && name.endsWith(SCRIPT_ONE_NAME)) {
          scriptOne = script;
          break lookForScript;
        }
      }
      throw new SmokeException("Failed to find script " + SCRIPT_ONE_NAME);
    }

    // Getting a number of the line with the marker.
    int breakLine = findSourceMark(scriptOne, BREAKPOINT_MARK);
    if (breakLine == -1) {
      throw new SmokeException("Failed to find mark in script");
    }

    // Setting a breakpoint.
    CallbackSemaphore callbackSemaphore = new CallbackSemaphore();
    Breakpoint.Target breakpointTarget = new Breakpoint.Target.ScriptName(scriptOne.getName());
    RelayOk relayOk = vm.setBreakpoint(breakpointTarget, breakLine, 0, true, null,
        null, callbackSemaphore);
    callbackSemaphore.acquireDefault(relayOk);

    // First time just suspend on breakpoint and go on.
    {
      DebugContext context = stateManager.expectEvent(EXPECT_SUSPENDED_VISITOR);
      context.continueVm(DebugContext.StepAction.CONTINUE, 0, null);
      stateManager.expectEvent(EXPECT_RESUMED_VISITOR);
    }

    // Second time check variables and expressions.
    {
      DebugContext context = stateManager.expectEvent(EXPECT_SUSPENDED_VISITOR);

      {
        // Check cache dropping.
        JsObject root = evaluateSync(context.getGlobalEvaluateContext(),
            "(debug_value_1 = {a:2})").getValue().asObject();
        if (root == null) {
          throw new RuntimeException();
        }
        String aValue;
        aValue = root.getProperty("a").getValue().getValueString();
        if (!"2".equals(aValue)) {
          throw new SmokeException();
        }
        evaluateSync(context.getGlobalEvaluateContext(), "debug_value_1.a = 3");

        root.getRemoteValueMapping().clearCaches();

        aValue = root.getProperty("a").getValue().getValueString();
        if (!"3".equals(aValue)) {
          throw new SmokeException();
        }
      }

      {
        // Check literals.
        for (LiteralTestCase literal : TEST_LITERALS) {
          JsVariable resultVar = evaluateSync(context.getGlobalEvaluateContext(),
              literal.javaScriptExpression);
          JsValue resultValue = resultVar.getValue();
          if (resultValue.getType() != literal.expectedType) {
            throw new SmokeException("Unexpected type of '" + literal.javaScriptExpression +
                "': " + resultValue.getType());
          }
          if (!literal.expectedDescription.equals(resultValue.getValueString())) {
            throw new SmokeException("Unexpected string value of '" +
                literal.javaScriptExpression + "': " + resultValue.getValueString());
          }
        }
      }

      // Do not block dispatcher thread.
      stateManager.setDefaultReceiver(IGNORE_SCRIPTS_VISITOR);

      List<? extends CallFrame> callFrames = context.getCallFrames();
      CallFrame topFrame = callFrames.get(0);

      JsScope localScope;
      findScope: {
        for (JsScope scope : topFrame.getVariableScopes()) {
          if (scope.getType() == JsScope.Type.LOCAL) {
            localScope = scope;
            break findScope;
          }
        }
        throw new SmokeException("Failed to find local scope");
      }

      JsVariable xVar = getVariable(localScope, "x");
      if (!"1".equals(xVar.getValue().getValueString())) {
        throw new SmokeException("Unexpected value of local variable");
      }
      JsVariable yVar = getVariable(localScope, "y");
      if (!"2".equals(yVar.getValue().getValueString())) {
        throw new SmokeException("Unexpected value of local variable");
      }

      for (CallFrame frame : callFrames) {
        checkExpression(frame);
      }

      context.continueVm(DebugContext.StepAction.CONTINUE, 0, null);
      stateManager.expectEvent(EXPECT_RESUMED_VISITOR);
    }

    stateManager.setDefaultReceiver(IGNORE_ALL_VISITOR);
    vm.detach();

    System.out.println("Test passed OK");
  }
View Full Code Here

TOP

Related Classes of org.chromium.sdk.JavascriptVm$ScriptsCallback

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.