Skip to content

Commit

Permalink
[java] Refactoring DevTools classes to match CDP specification structure
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Oct 18, 2019
1 parent 6d9e681 commit 8ae7d7b
Show file tree
Hide file tree
Showing 10 changed files with 291 additions and 275 deletions.
110 changes: 0 additions & 110 deletions java/client/src/org/openqa/selenium/devtools/Console.java

This file was deleted.

2 changes: 1 addition & 1 deletion java/client/src/org/openqa/selenium/devtools/DevTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

import static java.util.concurrent.TimeUnit.MILLISECONDS;

import org.openqa.selenium.devtools.log.Log;
import org.openqa.selenium.devtools.target.Target;
import org.openqa.selenium.devtools.target.model.SessionID;
import org.openqa.selenium.devtools.target.model.TargetID;
import org.openqa.selenium.devtools.target.model.TargetInfo;
import org.openqa.selenium.remote.SessionId;

import java.io.Closeable;
import java.time.Duration;
Expand Down
156 changes: 0 additions & 156 deletions java/client/src/org/openqa/selenium/devtools/Log.java

This file was deleted.

46 changes: 46 additions & 0 deletions java/client/src/org/openqa/selenium/devtools/console/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC 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.

package org.openqa.selenium.devtools.console;

import static org.openqa.selenium.devtools.ConverterFunctions.map;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.devtools.Command;
import org.openqa.selenium.devtools.Event;
import org.openqa.selenium.devtools.console.model.ConsoleMessage;

public class Console {

private final static String DOMAIN_NAME = "Console";

public static Command<Void> enable() {
return new Command<>(DOMAIN_NAME + ".enable", ImmutableMap.of());
}

public static Command<Void> disable() {
return new Command<>(DOMAIN_NAME + ".disable", ImmutableMap.of());
}

public static Event<ConsoleMessage> messageAdded() {
return new Event<>(
DOMAIN_NAME + ".messageAdded",
map("message", ConsoleMessage.class));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.openqa.selenium.devtools.console.model;

import org.openqa.selenium.devtools.console.Console;
import org.openqa.selenium.json.JsonInput;

import java.util.Objects;
import java.util.StringJoiner;

public class ConsoleMessage {

private final String source;
private final String level;
private final String text;

ConsoleMessage(String source, String level, String text) {
this.source = Objects.requireNonNull(source);
this.level = Objects.requireNonNull(level);
this.text = Objects.requireNonNull(text);
}

public String getSource() {
return source;
}

public String getLevel() {
return level;
}

public String getText() {
return text;
}

private static ConsoleMessage fromJson(JsonInput input) {
String source = null;
String level = null;
String text = null;

input.beginObject();
while (input.hasNext()) {
switch (input.nextName()) {
case "level":
level = input.nextString();
break;

case "source":
source = input.nextString();
break;

case "text":
text = input.nextString();
break;

default:
input.skipValue();
break;
}
}
input.endObject();

return new ConsoleMessage(source, level, text);
}

@Override
public String toString() {
return new StringJoiner(", ", ConsoleMessage.class.getSimpleName() + "[", "]")
.add("level='" + level + "'")
.add("source='" + source + "'")
.add("text='" + text + "'")
.toString();
}
}
Loading

0 comments on commit 8ae7d7b

Please sign in to comment.