-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Firefox endpoint for setting context and allow to be Augmented
- Loading branch information
1 parent
11194a7
commit 962db26
Showing
5 changed files
with
201 additions
and
1 deletion.
There are no files selected for viewing
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,67 @@ | ||
// 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.firefox; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.openqa.selenium.Capabilities; | ||
import org.openqa.selenium.remote.AdditionalHttpCommands; | ||
import org.openqa.selenium.remote.AugmenterProvider; | ||
import org.openqa.selenium.remote.CommandInfo; | ||
import org.openqa.selenium.remote.ExecuteMethod; | ||
import org.openqa.selenium.remote.http.HttpMethod; | ||
|
||
import java.util.Map; | ||
import java.util.function.Predicate; | ||
|
||
import static org.openqa.selenium.remote.BrowserType.FIREFOX; | ||
|
||
@AutoService({AdditionalHttpCommands.class, AugmenterProvider.class}) | ||
public class AddHasContext implements AugmenterProvider<HasContext>, AdditionalHttpCommands { | ||
|
||
public static final String CONTEXT = "context"; | ||
|
||
private static final Map<String, CommandInfo> COMMANDS = ImmutableMap.of( | ||
CONTEXT, new CommandInfo("/session/:sessionId/moz/context", HttpMethod.POST)); | ||
|
||
@Override | ||
public Map<String, CommandInfo> getAdditionalCommands() { | ||
return COMMANDS; | ||
} | ||
|
||
@Override | ||
public Predicate<Capabilities> isApplicable() { | ||
return caps -> FIREFOX.equals(caps.getBrowserName()); | ||
} | ||
|
||
@Override | ||
public Class<HasContext> getDescribedInterface() { | ||
return HasContext.class; | ||
} | ||
|
||
@Override | ||
public HasContext getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) { | ||
return new HasContext() { | ||
@Override public void setContext(FirefoxCommandContext context) { | ||
executeMethod.execute( | ||
CONTEXT, | ||
ImmutableMap.of(CONTEXT, context)); | ||
} | ||
}; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
java/src/org/openqa/selenium/firefox/FirefoxCommandContext.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,37 @@ | ||
// 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.firefox; | ||
|
||
/** | ||
* Represents the valid values for the command context used for executing Firefox driver commands. | ||
*/ | ||
public enum FirefoxCommandContext { | ||
CONTENT("content"), | ||
CHROME("chrome"); | ||
|
||
private String text; | ||
|
||
FirefoxCommandContext(String text) { | ||
this.text = text; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(text); | ||
} | ||
} |
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 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,36 @@ | ||
// 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.firefox; | ||
|
||
import org.openqa.selenium.Beta; | ||
|
||
/** | ||
* Used by classes to indicate that they can install and uninstall browser extensions on the fly. | ||
*/ | ||
@Beta | ||
public interface HasContext { | ||
|
||
/** | ||
* Context commands are operating on. | ||
* | ||
* @param context {@link FirefoxCommandContext} operating on page loaded in the browser or on browser elements hosting the page. | ||
* | ||
*/ | ||
void setContext(FirefoxCommandContext context); | ||
|
||
} |
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