forked from SeleniumHQ/selenium
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[java] Refactoring DevTools classes to match CDP specification structure
- Loading branch information
Showing
10 changed files
with
291 additions
and
275 deletions.
There are no files selected for viewing
110 changes: 0 additions & 110 deletions
110
java/client/src/org/openqa/selenium/devtools/Console.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
java/client/src/org/openqa/selenium/devtools/console/Console.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
java/client/src/org/openqa/selenium/devtools/console/model/ConsoleMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.