This repository has been archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from motin/v5-init
[develop] Start of version 5 - WebExtension Experiments
- Loading branch information
Showing
67 changed files
with
10,392 additions
and
1,860 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# do not lint/format generated artifacts | ||
dist/ | ||
package-lock.json | ||
# makes sure that eslintrc.js gets linted/formatted | ||
!.eslintrc.js | ||
# don't lint/format package.json since npm install formats it differently by default | ||
package.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
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 |
---|---|---|
|
@@ -2,4 +2,3 @@ node_modules | |
*.xpi | ||
*.tgz | ||
*.*.swp | ||
dist/ |
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ RUN apt-get update -y && \ | |
apt-get install -y zip firefox xvfb nodejs xsel git ssh openbox && \ | ||
npm install -g [email protected] | ||
|
||
ENV PATH="/shield-study-utils/node_modules/.bin:$PATH" | ||
ENV PATH="/shield-study-addon-utils/node_modules/.bin:$PATH" |
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.
22 changes: 22 additions & 0 deletions
22
examples/test-addon/bin/bundle-shield-studies-addon-utils.sh
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,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
# fail on any error | ||
set -o errexit | ||
|
||
# always run from the repository root directory | ||
script_path=`dirname $0` | ||
cd "$script_path/../../../" | ||
|
||
# paths | ||
WEBEXTAPIS_PATH="webExtensionApis" | ||
ADDON_SRC_PATH="examples/test-addon/src" | ||
|
||
# bundle the study web extension experiment | ||
mkdir -p $ADDON_SRC_PATH/privileged/study | ||
cp $WEBEXTAPIS_PATH/study/api.js $ADDON_SRC_PATH/privileged/study/api.js | ||
cp $WEBEXTAPIS_PATH/study/schema.json $ADDON_SRC_PATH/privileged/study/schema.json | ||
|
||
# bundle the prefs web extension experiment | ||
mkdir -p $ADDON_SRC_PATH/privileged/prefs | ||
cp $WEBEXTAPIS_PATH/prefs/api.js $ADDON_SRC_PATH/privileged/prefs/api.js | ||
cp $WEBEXTAPIS_PATH/prefs/schema.json $ADDON_SRC_PATH/privileged/prefs/schema.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,2 @@ | ||
* | ||
!*.gitignore |
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,84 @@ | ||
/* eslint no-console:off */ | ||
/* global studySetup */ | ||
|
||
"use strict"; | ||
|
||
class Study { | ||
constructor(variation) {} | ||
|
||
// Will run only during first install attempt | ||
// Use web extension experiments to get whatever prefs, add-ons, | ||
// telemetry, anything necessary for the check | ||
static async isEligible() { | ||
//browser.prefs.get('my.favorite.pref'); | ||
return true; | ||
} | ||
|
||
// Expiration checks should be implemented in a very reliable way by | ||
// the add-on since Normandy does not handle study expiration in a reliable manner | ||
static async hasExpired() { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Fired when the extension is first installed, when the extension is updated | ||
* to a new version, and when the browser is updated to a new version. | ||
* @param details | ||
*/ | ||
function handleInstalled(details) { | ||
console.log( | ||
"The 'handleInstalled' event was fired.", | ||
details.reason, | ||
details, | ||
); | ||
} | ||
|
||
/** | ||
* Fired when a profile that has this extension installed first starts up. | ||
* This event is not fired when a private browsing/incognito profile is started. | ||
*/ | ||
async function handleStartup() { | ||
console.log("The 'handleStartup' event was fired.", arguments); | ||
} | ||
|
||
// todo: on shutdown | ||
// Run shutdown-related non-privileged code | ||
|
||
browser.runtime.onStartup.addListener(handleStartup); | ||
browser.runtime.onInstalled.addListener(handleInstalled); | ||
|
||
async function initiateStudy() { | ||
// Set dynamic study configuration flags | ||
studySetup.eligible = await Study.isEligible(); | ||
studySetup.expired = await Study.hasExpired(); | ||
// Ensure we have configured study and are supposed to run our feature | ||
await browser.study.configure(studySetup); | ||
// Run the startup study checks | ||
await browser.study.startup(); | ||
// Read the active study variation | ||
const { variation } = await browser.study.info(); | ||
// Initiate our study-specific background logic | ||
new Study(variation); | ||
} | ||
|
||
// Since this is a test-addon, we don't initiate any code directly, but wait | ||
// for events sent by tests. This allows us to control and test the execution | ||
// properly. | ||
browser.runtime.onMessage.addListener((request, sender, sendResponse) => { | ||
console.log("request", request); | ||
if (request === "test:initiateStudy") { | ||
initiateStudy(); | ||
} | ||
}); | ||
|
||
// The tests that probe the web extensions APIs directly rely on an extension | ||
// page opening up in a new window/tab. | ||
// For more information, see shield-studies-addon-utils/testUtils/executeJs.js | ||
const createData = { | ||
type: "detached_panel", | ||
url: "extension-page-for-tests/index.html", | ||
width: 500, | ||
height: 500, | ||
}; | ||
const creating = browser.windows.create(createData); |
31 changes: 31 additions & 0 deletions
31
examples/test-addon/src/extension-page-for-tests/index.html
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,31 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> | ||
<link rel="stylesheet" type="text/css" href="chrome://browser/content/extension.css"> | ||
<style> | ||
|
||
body { | ||
margin: 1em; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
|
||
<h1>Shield Study Utils Test Add-on</h1> | ||
<p>This is an extension page for shield-studies-addon-utils/test-addon</p> | ||
|
||
<p>This add-on initiates no background logic on it's own, so that the tests | ||
can test each lifecycle event in isolation.</p> | ||
|
||
<p>For manual testing, use the buttons below to run the code | ||
corresponding to each lifecycle event.</p> | ||
|
||
<p> | ||
<button id="initiateStudy-button" class="button-style">initiateStudy</button> | ||
</p> | ||
|
||
<script src="./page.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.