This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #2150: Add engine API to install WebExtensions
- Loading branch information
Showing
10 changed files
with
229 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
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
18 changes: 18 additions & 0 deletions
18
...ncept/engine/src/main/java/mozilla/components/concept/engine/webextension/WebExtension.kt
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,18 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.concept.engine.webextension | ||
|
||
/** | ||
* Represents a browser extension based on the WebExtension API: | ||
* https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions | ||
* | ||
* @property id the unique ID of this extension. | ||
* @property url the url pointing to a resources path for locating the extension | ||
* within the APK file e.g. resource://android/assets/extensions/my_web_ext. | ||
*/ | ||
data class WebExtension( | ||
val id: String, | ||
val url: String | ||
) |
72 changes: 72 additions & 0 deletions
72
components/concept/engine/src/test/java/mozilla/components/concept/engine/EngineTest.kt
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,72 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.concept.engine | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import mozilla.components.concept.engine.webextension.WebExtension | ||
import org.json.JSONObject | ||
import org.junit.Assert.fail | ||
import org.junit.Test | ||
import java.lang.UnsupportedOperationException | ||
|
||
class EngineTest { | ||
|
||
@Test | ||
fun `throws exception if webextensions not supported`() { | ||
val engine = object : Engine { | ||
override fun createView(context: Context, attrs: AttributeSet?): EngineView { | ||
throw NotImplementedError("Not needed for test") | ||
} | ||
|
||
override fun createSession(private: Boolean): EngineSession { | ||
throw NotImplementedError("Not needed for test") | ||
} | ||
|
||
override fun createSessionState(json: JSONObject): EngineSessionState { | ||
throw NotImplementedError("Not needed for test") | ||
} | ||
|
||
override fun name(): String { | ||
throw NotImplementedError("Not needed for test") | ||
} | ||
|
||
override fun speculativeConnect(url: String) { | ||
throw NotImplementedError("Not needed for test") | ||
} | ||
|
||
override val settings: Settings | ||
get() = throw NotImplementedError("Not needed for test") | ||
} | ||
|
||
try { | ||
engine.installWebExtension(WebExtension("my-ext", "resource://path")) | ||
fail("Expected UnsupportedOperationException") | ||
} catch (_: UnsupportedOperationException) { | ||
// expected | ||
} | ||
|
||
try { | ||
engine.installWebExtension(WebExtension("my-ext", "resource://path")) { _, _ -> } | ||
fail("Expected UnsupportedOperationException") | ||
} catch (_: UnsupportedOperationException) { | ||
// expected | ||
} | ||
|
||
try { | ||
engine.installWebExtension(WebExtension("my-ext", "resource://path"), onSuccess = { }) | ||
fail("Expected UnsupportedOperationException") | ||
} catch (_: UnsupportedOperationException) { | ||
// expected | ||
} | ||
|
||
try { | ||
engine.installWebExtension(WebExtension("my-ext", "resource://path"), onSuccess = { }) { _, _ -> } | ||
fail("Expected UnsupportedOperationException") | ||
} catch (_: UnsupportedOperationException) { | ||
// expected | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...t/engine/src/test/java/mozilla/components/concept/engine/webextension/WebExtensionTest.kt
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,23 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.concept.engine.webextension | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNotEquals | ||
import org.junit.Test | ||
|
||
class WebExtensionTest { | ||
|
||
@Test | ||
fun createWebExtension() { | ||
val ext1 = WebExtension("1", "url1") | ||
val ext2 = WebExtension("2", "url2") | ||
|
||
assertNotEquals(ext1, ext2) | ||
assertEquals(ext1, WebExtension("1", "url1")) | ||
assertEquals("1", ext1.id) | ||
assertEquals("url1", ext1.url) | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
samples/browser/src/main/assets/extensions/borderify/borderify.js
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 @@ | ||
document.body.style.border = "5px solid red"; |
11 changes: 11 additions & 0 deletions
11
samples/browser/src/main/assets/extensions/borderify/manifest.json
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,11 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "Mozilla Android Components - Borderify", | ||
"version": "1.0", | ||
"content_scripts": [ | ||
{ | ||
"matches": ["*://*.mozilla.org/*"], | ||
"js": ["borderify.js"] | ||
} | ||
] | ||
} |