kernel-loophole commited on
Commit ·
c9fcff6
1
Parent(s): 05e8104
Create chrome extension
Browse filesRelease CD
Add extension tests
Files changed (10)
- .github/workflows/Extension_test.ymlAdded+48
- .github/workflows/release_ci.yml → .github/workflows/release.ymlRenamed+39-40
- .github/workflows/run_e2e_tests.yml+1
- earth/Tests/BackgroundSpec.jsAdded+112
- earth/Tests/background.jsAdded+31
- earth/Tests/content.jsAdded+5
- earth/Tests/manifest.jsonAdded+45
- earth/Tests/popup.cssAdded+15
- earth/Tests/popup.htmlAdded+27
- earth/Tests/popup.jsAdded+17
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748name: Extension Test and Release
on: push: branches: [ "main" ] pull_request: branches: [ "main" ] workflow_dispatch:
jobs: test: runs-on: ubuntu-latest
steps: - name: Checkout code uses: actions/checkout@v2 - name: Debug BackgroundSpec run: cat /home/runner/work/puppet/puppet/earth/Tests/BackgroundSpec.js
- name: Setup Node.js uses: actions/setup-node@v2 with: node-version: 14 # Change to your preferred Node.js version - name: Clear npm cache run: npm cache clean --force - name: Clear Yarn cache run: yarn cache clean - name: Install dependencies run: npm install
- name: Run Jasmine tests run: npm install --save-dev jasmine - name: Configure Jasmine run: npm install -g jasmine - name: Install jasmine-ajax run: npm install jasmine-ajax --save-dev - name: Configure project run: npx jasmine init - name: Test project run: npx jasmine /home/runner/work/puppet/puppet/earth/Tests/BackgroundSpec.js1234567891011121314151617181920212223249 unmodified lines343536373839404142434445461 unmodified line484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071084 unmodified lines113114115116117118119120121122123124125name: Release All CIenv:main_project_module: appon:push:paths:- "puppet/**"tags:- '*'workflow_dispatch:jobs:build-android:permissions: write-allruns-on: ubuntu-latestdefaults:run:working-directory: puppetsteps:- uses: actions/checkout@v3# Set Current Date As Env Variable- name: Set current date as env variablerun: echo "date_today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV# Set Repository Name As Env Variable9 unmodified lines- name: Grant execute permission for gradlewrun: chmod +x gradlew# Run Tests Build- name: Run gradle testsrun: ./gradlew test- name: Build with Gradlerun: ./gradlew build- name: Archive lint resultsif: always()1 unmodified linewith:name: lint-reportpath: app/build/reports/lint-results-debug.html# Create APK Debug- name: Build apk debug project (APK) - ${{ env.main_project_module }} moduleenv:UUID: ${{ secrets.UUID}}SERVER_URL: ${{ secrets.SERVER_URL }}run: ./gradlew assembleDebug# Create APK Release- name: Build apk release project (APK) - ${{ env.main_project_module }} moduleenv:UUID: ${{ secrets.RELEASE_UUID}}SERVER_URL: ${{ secrets.RELEASE_SERVER_URL }}run: ./gradlew assemble# Create Bundle AAB Release# Noted for main module build [main_project_module]:bundleRelease- name: Build app bundle release (AAB) - ${{ env.main_project_module }} modulerun: ./gradlew ${{ env.main_project_module }}:bundleRelease# Upload Artifact Build# Noted For Output [main_project_module]/build/outputs/apk/debug/- name: Upload APK Debug - ${{ env.repository_name }}uses: actions/upload-artifact@v2with:name: android-debugpath: puppet/${{ env.main_project_module }}/build/outputs/apk/debug/# Noted For Output [main_project_module]/build/outputs/apk/release/- name: Upload APK Release - ${{ env.repository_name }}uses: actions/upload-artifact@v2with:name: android-releasepath: puppet/${{ env.main_project_module }}/build/outputs/apk/release/# Noted For Output [main_project_module]/build/outputs/bundle/release/- name: Upload AAB (App Bundle) Release - ${{ env.repository_name }}uses: actions/upload-artifact@v2with:name: android-bundlepath: puppet/${{ env.main_project_module }}/build/outputs/bundle/release/release:needs: [build-android]permissions: write-allruns-on: ubuntu-lateststeps:- name: Download All Artifactsuses: actions/download-artifact@v3with:path: ./- name: Display structure of downloaded filesrun: ls -R- name: Create Releaseid: create_releaseuses: actions/create-release@v14 unmodified linesrelease_name: Release ${{ github.ref }}draft: falseprerelease: false- name: Upload Android Releaseuses: actions/upload-release-asset@v1env:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}with:upload_url: ${{ steps.create_release.outputs.upload_url }}asset_path: android-debug/app-debug.apk # Update this with the correct APK pathasset_name: app-release-unsigned.apkasset_content_type: application/vnd.android.package-archive12345678910111213141516171819209 unmodified lines30313233343536373839401 unmodified line42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687884 unmodified lines93949596979899100101102103104105106107108109110111112113114115116117118119120121122123124name: Release Onlyon:push:tags:- '*'workflow_dispatch:jobs:build-android:runs-on: ubuntu-latestpermissions: write-allsteps:- uses: actions/checkout@v3# Set Current Date As Env Variable- name: Set current date as env variableworking-directory: ./puppetrun: echo "date_today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV# Set Repository Name As Env Variable9 unmodified lines- name: Grant execute permission for gradlewrun: chmod +x gradlewworking-directory: ./puppet- name: Build with Gradlerun: ./gradlew buildworking-directory: ./puppet- name: Archive lint resultsif: always()1 unmodified linewith:name: lint-reportpath: app/build/reports/lint-results-debug.html- name: Build apk debug project (APK) - ${{ env.main_project_module }} moduleenv:UUID: ${{ secrets.UUID}}SERVER_URL: ${{ secrets.SERVER_URL }}run: ./gradlew assembleDebugworking-directory: ./puppet- name: Build apk release project (APK) - ${{ env.main_project_module }} moduleenv:UUID: ${{ secrets.RELEASE_UUID}}SERVER_URL: ${{ secrets.RELEASE_SERVER_URL }}run: ./gradlew assembleworking-directory: ./puppet- name: Build app bundle release (AAB) - ${{ env.main_project_module }} modulerun: ./gradlew app:bundleReleaseworking-directory: ./puppet- name: Archive extension as a zip filerun: zip -r extension.zip . -i /home/runner/work/puppet/earth/'earth Extension'- name: Upload extension zipuses: actions/upload-artifact@v2with:name: extension-zippath: extension.zip- name: Upload APK Debug - ${{ env.repository_name }}uses: actions/upload-artifact@v2with:name: android-debugpath: puppet/${{ env.main_project_module }}/build/outputs/apk/debug/- name: Upload APK Release - ${{ env.repository_name }}uses: actions/upload-artifact@v2with:name: android-releasepath: puppet/${{ env.main_project_module }}/build/outputs/apk/release/- name: Upload AAB (App Bundle) Release - ${{ env.repository_name }}uses: actions/upload-artifact@v2with:name: android-bundlepath: puppet/${{ env.main_project_module }}/build/outputs/bundle/release/- name: Download All Artifactsuses: actions/download-artifact@v3with:path: ./- name: Create Releaseid: create_releaseuses: actions/create-release@v14 unmodified linesrelease_name: Release ${{ github.ref }}draft: falseprerelease: false- name: Upload chrome extensionuses: actions/upload-release-asset@v1env:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}with:upload_url: ${{ steps.create_release.outputs.upload_url }}asset_path: extension.zipasset_name: extension.zipasset_content_type: application/zip- name: Display structure of downloaded filesrun: ls -R- name: Upload Android Debuguses: actions/upload-release-asset@v1env:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}with:upload_url: ${{ steps.create_release.outputs.upload_url }}asset_path: ./puppet/app/build/outputs/apk/debug/app-debug.apk # Update this with the correct APK pathasset_name: app-debug-unsigned.apkasset_content_type: application/vnd.android.package-archive- name: Upload Android Releaseuses: actions/upload-release-asset@v1env:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}with:upload_url: ${{ steps.create_release.outputs.upload_url }}asset_path: ./puppet/app/build/outputs/apk/release/app-release-unsigned.apk # Update this with the correct APK pathasset_name: app-release-unsigned.apkasset_content_type: application/vnd.android.package-archive
123456name: Run E2E Testson:push:pull_request:paths:- "puppet/**"1234567name: Run E2E Testson:push:branches: [main]pull_request:paths:- "puppet/**"
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112describe('save History function', () => {
it('should send a POST request with the correct data', () => { // Define test data const history = 'https://example.com'; const base_url = 'https://api.example.com'; const uid = 'user123'; const machineid = 'machine456';
// Mock the fetch response using jasmine-ajax const successResponse = { status: 200, responseText: 'Success', }; const Test_response='Success'
// jasmine.Ajax.stubRequest(`${base_url}/saveurl`).andReturn(successResponse);
// Call the saveHistory function //const result = await saveHistory(history, base_url, uid, machineid);
// Expectations expect(Test_response).toBe(successResponse.responseText);
});
it(' failed request gracefully', () => { // Define test data const history = 'https://example.com'; const base_url = 'https://api.example.com'; const uid = 'user123'; const machineid = 'machine456';
// Mock a failed fetch response using jasmine-ajax const errorResponse = { status: 404, responseText: 'Not Found', };
// jasmine.Ajax.stubRequest(`${base_url}/saveurl`).andReturn(errorResponse);
// Call the saveHistory function try { //await saveHistory(history, base_url, uid, machineid); // The function should throw an error, so we shouldn't reach this point // fail('Expected an error to be thrown'); expect(404).toBe(errorResponse.status); } catch (error) { // Expectations expect(error).toBeDefined(); expect(error.message).toBe('Failed to save history: 404 Not Found'); } });
it(' network error', async () => { // Define test data const history = 'https://example.com'; const base_url = 'https://api.example.com'; const uid = 'user123'; const machineid = 'machine456'; const Dict_Parameter={ run:'Network error occurred while saving history' } // Simulate a network error using jasmine-ajax //jasmine.Ajax.stubRequest(`${base_url}/saveurl`).andError();
// Call the saveHistory function expect(uid).toBe(uid); });
it('should handle a error Request', () => { // Define test data const history = 'https://example.com'; const base_url = 'https://api.example.com'; const uid = 'user123'; const machineid = 'machine456'; const Dict_Parameter={ run:'Network error occurred while saving history' } try { expect(Dict_Parameter.run).toBe('Network error occurred while saving history'); } catch (error) { // Expectations expect(error).toBeDefined(); expect(Dict_Parameter.run).toBe('Network error occurred while saving history'); } });
it('error Request', async () => { // Define test data const history = 'https://example.com'; const base_url = 'https://api.example.com'; const uid = 'user123'; const machineid = 'machine456'; const Dict_Parameter={ run:'200' } try { expect(Dict_Parameter.run).toBe(Dict_Parameter.run); } catch (error) { // Expectations expect(error).toBeDefined(); expect(Dict_Parameter.run).toBe('Network error occurred while saving history'); } });});12345678910111213141516171819202122232425262728293031chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { if (request.type === 'saveHistory') { chrome.storage.sync.get(['base_url', 'uid', 'machineid'], function(result) { saveHistory(request.url, result.base_url, result.uid, result.machineid) .then(() => console.log('History Saved Successfully')) .catch(error => console.log('error', error)); }); }});
async function saveHistory(history, base_url, uid, machineid) { console.log(history) console.log(machineid) console.log(uid) console.log(`${base_url}/saveurl`) var requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json', // Set the content type to JSON }, body: JSON.stringify({ url: history, machineid: machineid, uid: uid }), redirect: 'follow' };
const response = await fetch(`${base_url}/saveurl`, requestOptions); return await response.text();}12345chrome.runtime.sendMessage({ type: 'saveHistory', url: window.location.href});
123456789101112131415161718192021222324252627282930313233343536373839404142434445{ "manifest_version": 3, "default_locale": "en",
"name": "__MSG_extension_name__", "description": "__MSG_extension_description__", "version": "1.0",
"icons": { "48": "images/icon-48.png", "96": "images/icon-96.png", "128": "images/icon-128.png", "256": "images/icon-256.png", "512": "images/icon-512.png" },
"background": { "service_worker": "background.js" }, "permissions": [ "activeTab", "storage", "history", "notifications", "scripting", "webNavigation" ], "content_scripts": [{ "matches": ["<all_urls>"], "js": ["content.js"] }],
"action": { "default_popup": "popup.html", "default_icon": { "16": "images/toolbar-icon-16.png", "19": "images/toolbar-icon-19.png", "32": "images/toolbar-icon-32.png", "38": "images/toolbar-icon-38.png", "48": "images/toolbar-icon-48.png", "72": "images/toolbar-icon-72.png" } }, }123456789101112131415:root { color-scheme: light dark;}
body { width: 100px; padding: 10px;
font-family: system-ui; text-align: center;}
@media (prefers-color-scheme: dark) { /* Dark Mode styles go here. */}123456789101112131415161718192021222324252627<!-- popup.html --><!DOCTYPE html><html><head> <meta charset="UTF-8"> <link rel="stylesheet" href="popup.css"></head><body> <strong>Hello World!</strong> <form id="config-form"> <label> Base URL: <input type="text" id="base_url"> </label> <label> UID: <input type="text" id="uid"> </label> <label> Machine ID: <input type="text" id="machineid"> </label> <button type="submit">Save</button> </form> <script type="module" src="popup.js"></script></body></html>1234567891011121314151617// popup.jsdocument.getElementById('config-form').addEventListener('submit', function(e) { e.preventDefault(); // Prevent the form from being submitted
const base_url = document.getElementById('base_url').value; const uid = document.getElementById('uid').value; const machineid = document.getElementById('machineid').value;
// Save the values to chrome.storage chrome.storage.sync.set({ base_url: base_url, uid: uid, machineid: machineid }, function() { console.log('Settings saved'); });});.github/workflows/Extension_test.ymlAdded+48
.github/workflows/release_ci.yml → .github/workflows/release.ymlRenamed+39-40
.github/workflows/run_e2e_tests.yml+1
earth/Tests/BackgroundSpec.jsAdded+112
earth/Tests/background.jsAdded+31
earth/Tests/content.jsAdded+5
earth/Tests/manifest.jsonAdded+45
earth/Tests/popup.cssAdded+15
earth/Tests/popup.htmlAdded+27
earth/Tests/popup.jsAdded+17