Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WebExtensionsとテスト

Shin'ya Ueoka
October 30, 2018

 WebExtensionsとテスト

Tokyo WebExtensions Meetup #3の発表資料です
https://mozilla.doorkeeper.jp/events/81371

Shin'ya Ueoka

October 30, 2018
Tweet

More Decks by Shin'ya Ueoka

Other Decks in Technology

Transcript

  1. 利用例 15 describe('#myInjectElements', () => { beforeEach(() => { //

    render HTML from a static file document.body.innerHTML = __html__['testcase1.html']; }); it('injects three elements', () => { myInjectElements(window); let es = window.document.querySelector(".injected") expect(es).to.have.lengthOf(3); }); });
  2. 利用例 17 const browserFake = require('webextensions-api-fake'); describe("#myLastCreatedTab", () => {

    beforeEach(() => { // set fake browser to global variable global.browser = browserFake(); }); it('should get last created tab', async() => { const created = await browser.tabs.create({}); const tab = await myLastCreatedTab(); expect(tab.id).to.equal(created.id); }); });
  3. ambassadorアドオン (2/2) 別タブの結果の観測もメッセージ経由 25 Background Script browser.runtime.sendMessage() browser.tabs.sendMessage() tab1 Content

    Script Page Script tab2 Content Script Page Script window.postMessage() getScroll(tab2) document .documentElement .scrollTop {x:10, y:20} {x:10, y:20} {x:10, y:20}
  4. E2Eテストのテストケース例 ambassadorアドオンとの通信は適当にラップ ES7 async/awaitでユーザーの操作を手続き的に記述 27 it('deletes tab by d', async

    () => { let tab = await tabs.create(targetWindow.id, CLIENT_URL); let before = await windows.get(targetWindow.id); await keys.press(tab.id, 'd'); let actual = await windows.get(targetWindow.id); expect(actual.tabs).to.have.lengthOf(before.tabs.length - 1); });