浏览代码

Remove test folder

simov 2 年之前
父节点
当前提交
429cb66ef7
共有 12 个文件被更改,包括 0 次插入1836 次删除
  1. 0 86
      manifest.test.json
  2. 0 75
      test/defaults-options.js
  3. 0 188
      test/defaults-popup.js
  4. 0 72
      test/index.js
  5. 0 61
      test/origin-add.js
  6. 0 328
      test/origin-csp.js
  7. 0 142
      test/origin-encoding.js
  8. 0 126
      test/origin-match.js
  9. 0 18
      test/package.json
  10. 0 606
      test/popup-options.js
  11. 0 41
      test/utils/defaults.js
  12. 0 93
      test/utils/server.js

+ 0 - 86
manifest.test.json

@@ -1,86 +0,0 @@
-{
-  "manifest_version": 2,
-  "name"            : "Markdown Viewer",
-  "version"         : "3.9",
-  "description"     : "Markdown Viewer",
-
-  "browser_action": {
-    "default_icon": {
-      "19" : "/icons/icon19.png",
-      "38" : "/icons/icon38.png"
-    },
-    "default_title": "Markdown Viewer",
-    "default_popup": "/popup/index.html"
-  },
-
-  "options_page": "/options/index.html",
-
-  "background" : {
-    "scripts": [
-      "/vendor/marked.min.js",
-      "/vendor/remark.min.js",
-
-      "/background/compilers/marked.js",
-      "/background/compilers/remark.js",
-
-      "/background/storage.js",
-      "/background/webrequest.js",
-      "/background/detect.js",
-      "/background/inject.js",
-      "/background/messages.js",
-      "/background/mathjax.js",
-      "/background/xhr.js",
-
-      "/background/index.js"
-    ],
-    "persistent": false
-  },
-
-  "web_accessible_resources": [
-    "/themes/github.css",
-    "/themes/github-dark.css",
-
-    "/themes/godspeed.css",
-    "/themes/new-modern.css",
-    "/themes/torpedo.css",
-    "/themes/vostok.css",
-
-    "/themes/ghostwriter.css",
-    "/themes/radar.css",
-    "/themes/foghorn.css",
-    "/themes/markdown.css",
-    "/themes/markedapp-byword.css",
-    "/themes/solarized-dark.css",
-    "/themes/solarized-light.css",
-
-    "/themes/screen.css",
-    "/themes/markdown5.css",
-    "/themes/markdown6.css",
-    "/themes/markdown7.css",
-    "/themes/markdown8.css",
-    "/themes/markdown9.css",
-    "/themes/markdown-alt.css"
-  ],
-
-  "icons": {
-    "16" : "/icons/icon16.png",
-    "48" : "/icons/icon48.png",
-    "128": "/icons/icon128.png"
-  },
-
-  "homepage_url": "https://chrome.google.com/webstore/detail/markdown-viewer/ckkdlimhmcjmikdlpkmbgfkaikojcbjk",
-
-  "permissions": [
-    "storage",
-    "file:///*",
-    "http://localhost:3000/*"
-  ],
-
-  "optional_permissions": [
-    "https://*/",
-    "http://*/",
-    "*://*/",
-    "webRequest",
-    "webRequestBlocking"
-  ]
-}

+ 0 - 75
test/defaults-options.js

@@ -1,75 +0,0 @@
-
-var t = require('assert')
-
-
-module.exports = ({advanced}) => {
-
-  before(async () => {
-    await advanced.bringToFront()
-  })
-
-  it('access to file URLs', async () => {
-    t.strictEqual(
-      await advanced.evaluate(() =>
-        origins.state.file
-      ),
-      true,
-      'origins.state.file should be true'
-    )
-  })
-
-  it('header detection', async () => {
-    t.strictEqual(
-      await advanced.evaluate(() =>
-        origins.state.header
-      ),
-      true,
-      'origins.state.header should be true'
-    )
-    t.strictEqual(
-      await advanced.evaluate(() =>
-        document.querySelector('.m-switch')
-      ),
-      null,
-      'header detection switch should be hidden'
-    )
-  })
-
-  it('allowed origins', async () => {
-    t.deepStrictEqual(
-      await advanced.evaluate(() =>
-        origins.state.origins
-      ),
-      {
-        'file://': {
-          match: '\\.(?:markdown|mdown|mkdn|md|mkd|mdwn|mdtxt|mdtext|text)(?:#.*|\\?.*)?$',
-          csp: false,
-          encoding: ''
-        }
-      },
-      'origins.state.origins should contain the file:// origin'
-    )
-    t.equal(
-      await advanced.evaluate(() =>
-        document.querySelectorAll('.m-origins .m-list li').length
-      ),
-      1,
-      'should contain only one origin'
-    )
-    t.equal(
-      await advanced.evaluate(() =>
-        document.querySelector('.m-origins .m-list li:nth-of-type(1) .m-title').innerText
-      ),
-      'file://',
-      'origin name should be file://'
-    )
-    t.equal(
-      await advanced.evaluate(() =>
-        document.querySelector('.m-list li:nth-of-type(1) .m-match input').value
-      ),
-      '\\.(?:markdown|mdown|mkdn|md|mkd|mdwn|mdtxt|mdtext|text)(?:#.*|\\?.*)?$',
-      'the text input should contain the default path matching regexp'
-    )
-  })
-
-}

+ 0 - 188
test/defaults-popup.js

@@ -1,188 +0,0 @@
-
-var t = require('assert')
-
-
-module.exports = ({popup}) => {
-
-  before(async () => {
-    await popup.bringToFront()
-  })
-
-  it('button - raw', async () => {
-    t.strictEqual(
-      await popup.evaluate(() =>
-        state.raw
-      ),
-      false,
-      'state.raw should equal false'
-    )
-    t.strictEqual(
-      await popup.evaluate(() =>
-        document.querySelector('.m-button:first-child').innerText.toLowerCase()
-      ),
-      'markdown',
-      'button text should equal markdown'
-    )
-  })
-
-  it('tabs', async () => {
-    t.equal(
-      await popup.evaluate(() =>
-        state.tab
-      ),
-      'theme',
-      'state.tab should equal theme'
-    )
-    t.deepStrictEqual(
-      await popup.evaluate(() =>
-        state.tabs
-      ),
-      await popup.evaluate(() =>
-        Array.from(document.querySelectorAll('.m-tabs a'))
-          .map((tab) => tab.innerText.trim().toLowerCase())
-      ),
-      'state.tabs should be identical to dom tabs'
-    )
-    t.strictEqual(
-      await popup.evaluate(() =>
-        localStorage.getItem('tab')
-      ),
-      null,
-      'localStorage tab key should be null'
-    )
-  })
-
-  it('tab - theme', async () => {
-    t.equal(
-      await popup.evaluate(() =>
-        state.theme
-      ),
-      'github',
-      'state.theme should equal github'
-    )
-    t.strictEqual(
-      await popup.evaluate(() =>
-        document.querySelector('.m-panel:first-child')
-          .classList.contains('is-active')
-      ),
-      true,
-      'the first tab panel should be active'
-    )
-    t.deepStrictEqual(
-      await popup.evaluate(() =>
-        state.themes
-      ),
-      await popup.evaluate(() =>
-        Array.from(document.querySelectorAll('.m-panel:first-child select option'))
-          .map((option) => option.innerText)
-      ),
-      'state.themes should be identical to dom themes'
-    )
-    t.strictEqual(
-      await popup.evaluate(() =>
-        document.querySelector('.m-panel:first-child select').selectedIndex
-      ),
-      0,
-      'dom select option should be 0'
-    )
-    t.strictEqual(
-      await popup.evaluate(() =>
-        state.themes.length
-      ),
-      20,
-      'state.themes count should be 20'
-    )
-  })
-
-  it('tab - compiler', async () => {
-    await popup.click('.m-tabs a:nth-of-type(2)')
-
-    t.equal(
-      await popup.evaluate(() =>
-        state.tab
-      ),
-      'compiler',
-      'state.tab should equal compiler'
-    )
-    t.strictEqual(
-      await popup.evaluate(() =>
-        localStorage.getItem('compiler')
-      ),
-      null,
-      'localStorage compiler key should be null'
-    )
-    t.strictEqual(
-      await popup.evaluate(() =>
-        document.querySelector('.m-panel:nth-of-type(2)')
-          .classList.contains('is-active')
-      ),
-      true,
-      'the second tab panel should be active'
-    )
-    t.deepStrictEqual(
-      await popup.evaluate(() =>
-        state.compilers
-      ),
-      await popup.evaluate(() =>
-        Array.from(document.querySelectorAll('.m-panel:nth-of-type(2) select option'))
-          .map((option) => option.innerText)
-      ),
-      'state.compilers should be identical to dom compilers'
-    )
-    t.strictEqual(
-      await popup.evaluate(() =>
-        document.querySelector('.m-panel:first-child select').selectedIndex
-      ),
-      0,
-      'dom select option should be 0'
-    )
-    t.strictEqual(
-      await popup.evaluate(() =>
-        state.compilers.length
-      ),
-      2,
-      'state.compilers length should equal 2'
-    )
-    t.deepStrictEqual(
-      await popup.evaluate(() =>
-        Object.keys(state.options)
-        .filter((key) => typeof state.options[key] === 'boolean')
-        .reduce((obj, key) => (obj[key] = state.options[key], obj), {})
-      ),
-      await popup.evaluate(() =>
-        Array.from(document.querySelectorAll('.m-panel:nth-of-type(2) label'))
-          .reduce((all, option) => (
-            all[option.querySelector('span').innerText.trim()] =
-            option.classList.contains('is-checked'), all
-          ), {})
-      ),
-      'state.options should equal dom compiler options'
-    )
-  })
-
-  it('tab - content', async () => {
-    await popup.click('.m-tabs a:nth-of-type(3)')
-
-    t.equal(
-      await popup.evaluate(() =>
-        state.tab
-      ),
-      'content',
-      'state.tab should equal content'
-    )
-    t.deepStrictEqual(
-      await popup.evaluate(() =>
-        state.content
-      ),
-      await popup.evaluate(() =>
-        Array.from(document.querySelectorAll('.m-panel:nth-of-type(3) label'))
-          .reduce((all, option) => (
-            all[option.querySelector('span').innerText.trim()] =
-            option.classList.contains('is-checked'), all
-          ), {})
-      ),
-      'state.content should equal dom content options'
-    )
-  })
-
-}

+ 0 - 72
test/index.js

@@ -1,72 +0,0 @@
-
-var path = require('path')
-var puppeteer = require('puppeteer')
-var Server = require('./utils/server')
-
-var options = {
-  headless: false,
-  slowMo: 25,
-  args: [
-    `--disable-extensions-except=${path.resolve(__dirname, '../')}`,
-    `--load-extension=${path.resolve(__dirname, '../')}`,
-  ],
-}
-
-var tests = [
-  'defaults-popup',
-  'defaults-options',
-
-  'popup-options',
-
-  'origin-add',
-  'origin-match',
-  'origin-encoding',
-  'origin-csp', // should be last - destroys popup and advanced
-]
-
-
-describe('markdown-viewer', () => {
-  var browser, server
-
-  it('test suite', async () => {
-    browser = await puppeteer.launch(options)
-
-    var extensions = await browser.newPage()
-    await extensions.goto('chrome://extensions')
-    // enable developer mode
-    await extensions.evaluate(() => {
-      document.querySelector('extensions-manager').shadowRoot
-        .querySelector('extensions-toolbar').shadowRoot
-        .querySelector('cr-toggle').click()
-    })
-    // get extension id
-    var id = await extensions.evaluate(() =>
-      Array.from(
-        document.querySelector('extensions-manager').shadowRoot
-          .querySelector('extensions-item-list').shadowRoot
-          .querySelectorAll('extensions-item')
-      )[0].id
-    )
-
-    var popup = await browser.newPage()
-    await popup.goto(`chrome-extension://${id}/popup/index.html`)
-
-    var advanced = await browser.newPage()
-    await advanced.goto(`chrome-extension://${id}/options/index.html`)
-
-    var content = await browser.newPage()
-
-    var server = await Server()
-
-    tests.forEach((file) => {
-      describe(file, () => {
-        require(`./${file}.js`)({puppeteer, browser, extensions, popup, advanced, content})
-      })
-    })
-
-    after(async () => {
-      server.close()
-      await browser.close()
-    })
-  })
-})

+ 0 - 61
test/origin-add.js

@@ -1,61 +0,0 @@
-
-var t = require('assert')
-var defaults = require('./utils/defaults')
-
-
-module.exports = ({popup, advanced, content}) => {
-
-  before(async () => {
-    await defaults({popup, advanced, content})
-  })
-
-  describe('defaults', () => {
-    it('localhost:3000', async () => {
-      await advanced.bringToFront()
-      await advanced.waitForTimeout(300)
-      t.equal(
-        await advanced.evaluate(() =>
-          document.querySelectorAll('.m-origins .m-list li').length
-        ),
-        2,
-        'allowed origins count should be 2'
-      )
-      t.equal(
-        await advanced.evaluate(() =>
-          document.querySelector('.m-origins .m-list li:nth-of-type(1) .m-title').innerText
-        ),
-        'http://localhost:3000',
-        'origin name should be http://localhost:3000'
-      )
-      t.strictEqual(
-        await advanced.evaluate(() =>
-          document.querySelector('.m-origins .m-list li:nth-of-type(1) .m-switch').classList.contains('is-checked')
-        ),
-        false,
-        'csp checkbox should be disabled'
-      )
-      t.equal(
-        await advanced.evaluate(() =>
-          document.querySelector('.m-origins .m-list li:nth-of-type(1) .m-encoding select').value
-        ),
-        '',
-        'encoding should be set to auto'
-      )
-      t.strictEqual(
-        await advanced.evaluate(() =>
-          document.querySelectorAll('.m-origins .m-list li:nth-of-type(1) .m-footer .m-button').length
-        ),
-        1,
-        'only one button should be visible in the origin footer'
-      )
-      t.equal(
-        await advanced.evaluate(() =>
-          document.querySelector('.m-origins .m-list li:nth-of-type(1) .m-footer .m-button').innerText.toLowerCase()
-        ),
-        'remove',
-        'remove origin button should be rendered'
-      )
-    })
-  })
-
-}

+ 0 - 328
test/origin-csp.js

@@ -1,328 +0,0 @@
-
-var t = require('assert')
-var defaults = require('./utils/defaults')
-
-
-module.exports = ({extensions, popup, advanced, content}) => {
-
-  before(async () => {
-    await defaults({popup, advanced, content})
-
-    await advanced.bringToFront()
-
-    // enable path matching
-    await advanced.evaluate(() => {
-      document.querySelector('.m-list li:nth-of-type(1) input').value = 'csp-match-path'
-      document.querySelector('.m-list li:nth-of-type(1) input').dispatchEvent(new Event('keyup'))
-    })
-    // there is debounce timeout of 750ms in the options UI
-    await advanced.waitForTimeout(800)
-  })
-
-  describe('not correct content-type + non matching path', () => {
-    before(async () => {
-      await advanced.bringToFront()
-
-      // expand origin
-      if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
-        await advanced.click('.m-list li:nth-of-type(1)')
-      }
-
-      // enable csp
-      if (!await advanced.evaluate(() => origins.state.origins['http://localhost:3000'].csp)) {
-        await advanced.click('.m-list li:nth-of-type(1) .m-switch')
-      }
-
-      // go to page serving content with strict csp
-      await content.goto('http://localhost:3000/csp-no-header-no-path')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-    })
-    it('non matching urls should be skipped', async () => {
-      t.strictEqual(
-        await content.evaluate(() => {
-          try {
-            window.localStorage
-          }
-          catch (err) {
-            return err.message.split(':')[1].trim()
-          }
-        }),
-        `The document is sandboxed and lacks the 'allow-same-origin' flag.`,
-        'localStorage should not be accessible'
-      )
-    })
-  })
-
-  describe('correct content-type + non matching path', () => {
-    before(async () => {
-      await advanced.bringToFront()
-
-      // expand origin
-      if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
-        await advanced.click('.m-list li:nth-of-type(1)')
-      }
-
-      // enable csp
-      if (!await advanced.evaluate(() => origins.state.origins['http://localhost:3000'].csp)) {
-        await advanced.click('.m-list li:nth-of-type(1) .m-switch')
-      }
-
-      // go to page serving content with strict csp
-      await content.goto('http://localhost:3000/csp-match-header')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-    })
-    it('non matching urls cannot be checked for enabled csp', async () => {
-      t.strictEqual(
-        await content.evaluate(() => {
-          try {
-            window.localStorage
-          }
-          catch (err) {
-            return err.message.split(':')[1].trim()
-          }
-        }),
-        `The document is sandboxed and lacks the 'allow-same-origin' flag.`,
-        'localStorage should not be accessible'
-      )
-    })
-  })
-
-  // TEST: localStorage is no longer available even with disabled CSP
-  describe.skip('not correct content-type + matching path', () => {
-    before(async () => {
-      await advanced.bringToFront()
-
-      // expand origin
-      if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
-        await advanced.click('.m-list li:nth-of-type(1)')
-      }
-
-      // enable csp
-      if (!await advanced.evaluate(() => origins.state.origins['http://localhost:3000'].csp)) {
-        await advanced.click('.m-list li:nth-of-type(1) .m-switch')
-      }
-
-      // go to page serving content with strict csp
-      await content.goto('http://localhost:3000/csp-match-path')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-    })
-    it('webRequest.onHeadersReceived event is enabled', async () => {
-      t.strictEqual(
-        await content.evaluate(() =>
-          window.localStorage.toString()
-        ),
-        '[object Storage]',
-        'localStorage should be accessible'
-      )
-    })
-  })
-
-  // TEST: localStorage is no longer available even with disabled CSP
-  describe.skip('disable - enable - disable', () => {
-    it('full cycle', async () => {
-      // 1. disable
-      await advanced.bringToFront()
-
-      // expand origin
-      if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
-        await advanced.click('.m-list li:nth-of-type(1)')
-      }
-
-      // disable csp
-      if (await advanced.evaluate(() => origins.state.origins['http://localhost:3000'].csp)) {
-        await advanced.click('.m-list li:nth-of-type(1) .m-switch')
-      }
-      await advanced.waitForTimeout(300)
-
-      // go to page serving content with strict csp
-      await content.goto('http://localhost:3000/csp-match-path')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() => {
-          try {
-            window.localStorage
-          }
-          catch (err) {
-            return err.message.split(':')[1].trim()
-          }
-        }),
-        `The document is sandboxed and lacks the 'allow-same-origin' flag.`,
-        'localStorage should not be accessible'
-      )
-
-      // 2. enable
-      await advanced.bringToFront()
-
-      // enable csp
-      if (!await advanced.evaluate(() => origins.state.origins['http://localhost:3000'].csp)) {
-        await advanced.click('.m-list li:nth-of-type(1) .m-switch')
-      }
-      await advanced.waitForTimeout(300)
-
-      // go to page serving content with strict csp
-      await content.goto('http://localhost:3000/csp-match-path')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          window.localStorage.toString()
-        ),
-        '[object Storage]',
-        'localStorage should be accessible'
-      )
-
-      // 3. disable
-      await advanced.bringToFront()
-
-      // disable csp
-      if (await advanced.evaluate(() => origins.state.origins['http://localhost:3000'].csp)) {
-        await advanced.click('.m-list li:nth-of-type(1) .m-switch')
-      }
-      await advanced.waitForTimeout(300)
-
-      // go to page serving content with strict csp
-      await content.goto('http://localhost:3000/csp-match-path')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() => {
-          try {
-            window.localStorage
-          }
-          catch (err) {
-            return err.message.split(':')[1].trim()
-          }
-        }),
-        `The document is sandboxed and lacks the 'allow-same-origin' flag.`,
-        'localStorage should not be accessible'
-      )
-    })
-  })
-
-  describe('persist state', () => {
-    it('enable csp', async () => {
-      await advanced.bringToFront()
-
-      // expand origin
-      if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
-        await advanced.click('.m-list li:nth-of-type(1)')
-      }
-
-      // enable csp
-      if (!await advanced.evaluate(() => origins.state.origins['http://localhost:3000'].csp)) {
-        await advanced.click('.m-list li:nth-of-type(1) .m-switch')
-      }
-      await advanced.reload()
-      await advanced.waitForTimeout(300)
-
-      // expand origin
-      await advanced.click('.m-list li:nth-of-type(1)')
-
-      t.strictEqual(
-        await advanced.evaluate(() =>
-          document.querySelector('.m-list li:nth-of-type(1) .m-switch').classList.contains('is-checked')
-        ),
-        true,
-        'csp checkbox should be enabled'
-      )
-    })
-    it('disable csp', async () => {
-      await advanced.bringToFront()
-
-      // expand origin
-      if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
-        await advanced.click('.m-list li:nth-of-type(1)')
-      }
-
-      // disable csp
-      if (await advanced.evaluate(() => origins.state.origins['http://localhost:3000'].csp)) {
-        await advanced.click('.m-list li:nth-of-type(1) .m-switch')
-      }
-      await advanced.reload()
-      await advanced.waitForTimeout(300)
-
-      // expand origin
-      await advanced.click('.m-list li:nth-of-type(1)')
-
-      t.strictEqual(
-        await advanced.evaluate(() =>
-          document.querySelector('.m-list li:nth-of-type(1) .m-switch').classList.contains('is-checked')
-        ),
-        false,
-        'csp checkbox should be disabled'
-      )
-    })
-  })
-
-  describe('enable csp + suspend the event page', () => {
-    before(async () => {
-      await advanced.bringToFront()
-
-      // expand origin
-      if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
-        await advanced.click('.m-list li:nth-of-type(1)')
-      }
-
-      // enable csp
-      if (!await advanced.evaluate(() => origins.state.origins['http://localhost:3000'].csp)) {
-        await advanced.click('.m-list li:nth-of-type(1) .m-switch')
-      }
-
-      // chrome://extensions
-      await extensions.bringToFront()
-
-      // enable developer mode
-      await extensions.evaluate(() => {
-        Array.from(
-          document.querySelector('extensions-manager').shadowRoot
-            .querySelector('extensions-item-list').shadowRoot
-            .querySelectorAll('extensions-item'))[0].shadowRoot
-            .querySelector('#enableToggle').click()
-      })
-      // disable the extension
-      await extensions.evaluate(() => {
-        Array.from(
-          document.querySelector('extensions-manager').shadowRoot
-            .querySelector('extensions-item-list').shadowRoot
-            .querySelectorAll('extensions-item'))[0].shadowRoot
-            .querySelector('#enableToggle').click()
-      })
-      await extensions.waitForTimeout(300)
-      // check
-      t.equal(
-        await extensions.evaluate(() =>
-          Array.from(
-            document.querySelector('extensions-manager').shadowRoot
-              .querySelector('extensions-item-list').shadowRoot
-              .querySelectorAll('extensions-item'))[0].shadowRoot
-              .querySelector('#inspect-views a').innerText
-        ),
-        'background page (Inactive)',
-        'background page should be inactive'
-      )
-
-      // go to page serving content with strict csp
-      await content.goto('http://localhost:3000/csp-match-path')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-    })
-    // TEST: localStorage is no longer available even with disabled CSP
-    it.skip('the tab is reloaded on event page wakeup', async () => {
-      t.strictEqual(
-        await content.evaluate(() =>
-          window.localStorage.toString()
-        ),
-        '[object Storage]',
-        'localStorage should be accessible'
-      )
-    })
-  })
-
-}

+ 0 - 142
test/origin-encoding.js

@@ -1,142 +0,0 @@
-
-var t = require('assert')
-var defaults = require('./utils/defaults')
-
-
-module.exports = ({popup, advanced, content}) => {
-
-  before(async () => {
-    await defaults({popup, advanced, content})
-
-    // enable path matching
-    await advanced.evaluate(() => {
-      document.querySelector('.m-list li:nth-of-type(1) input').value = 'encoding-.*'
-      document.querySelector('.m-list li:nth-of-type(1) input').dispatchEvent(new Event('keyup'))
-    })
-    // there is debounce timeout of 750ms in the options UI
-    await advanced.waitForTimeout(800)
-  })
-
-  describe('no content-type header set', () => {
-    before(async () => {
-      // set wrong encoding
-      await advanced.select('.m-list li:nth-of-type(1) .m-encoding select', 'Shift_JIS')
-
-      // go to page serving Big5 encoded string
-      // with no content-type header set
-      await content.goto('http://localhost:3000/encoding-no-content-type')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-    })
-    it('do not override if content-type header is missing', async () => {
-      t.equal(
-        await content.evaluate(() => document.charset),
-        'Big5',
-        'chrome detects the correct encoding automatically'
-      )
-      t.equal(
-        await content.evaluate(() => document.querySelector('#_html p').innerText),
-        '你好',
-        'text should be decoded correctly'
-      )
-    })
-  })
-
-  describe('no charset in content-type header', () => {
-    before(async () => {
-      // set wrong encoding
-      await advanced.select('.m-list li:nth-of-type(1) .m-encoding select', 'Shift_JIS')
-
-      // go to page serving Big5 encoded string
-      // with no charset set in the content-type header
-      await content.goto('http://localhost:3000/encoding-no-charset')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-    })
-    it('do not override if charset is missing in content-type header', async () => {
-      t.equal(
-        await content.evaluate(() => document.charset),
-        'Big5',
-        'chrome detects the correct encoding automatically'
-      )
-      t.equal(
-        await content.evaluate(() => document.querySelector('#_html p').innerText),
-        '你好',
-        'text should be decoded correctly'
-      )
-    })
-  })
-
-  describe('wrong charset in content-type header', () => {
-    before(async () => {
-      // detect encoding automatically
-      await advanced.select('.m-list li:nth-of-type(1) .m-encoding select', '')
-
-      // go to page serving windows-1251 encoded string
-      // with UTF-8 charset set in content-type header
-      await content.goto('http://localhost:3000/encoding-wrong-charset')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-    })
-    it('when encoding override is disabled', async () => {
-      t.equal(
-        await content.evaluate(() => document.charset),
-        'UTF-8',
-        'chrome picks the wrong encoding from the content-type charset'
-      )
-      t.equal(
-        await content.evaluate(() => document.querySelector('#_html p').innerText),
-        '�������',
-        'text should be decoded incorrectly'
-      )
-    })
-  })
-
-  // TEST: overriding content-type no longer works
-  describe.skip('override charset set in content-type header', () => {
-    before(async () => {
-      await advanced.bringToFront()
-
-      // override encoding
-      await advanced.select('.m-list li:nth-of-type(1) .m-encoding select', 'Windows-1251')
-
-      // go to page serving windows-1251 encoded string
-      // with UTF-8 charset set in content-type header
-      await content.goto('http://localhost:3000/encoding-wrong-charset')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-    })
-    it('use encoding set for the origin', async () => {
-      t.equal(
-        await content.evaluate(() => document.charset),
-        'windows-1251',
-        'the content-type charset should be overridden'
-      )
-      t.equal(
-        await content.evaluate(() => document.querySelector('#_html p').innerText),
-        'здрасти',
-        'text should be decoded correctly'
-      )
-    })
-  })
-
-  describe('persist state', () => {
-    before(async () => {
-      await advanced.bringToFront()
-      await advanced.reload()
-      await advanced.waitForTimeout(300)
-      // expand origin
-      await advanced.click('.m-list li:nth-of-type(1)')
-    })
-    it('reload', async () => {
-      t.equal(
-        await advanced.evaluate(() =>
-          document.querySelector('.m-list li:nth-of-type(1) .m-encoding select').value
-        ),
-        'Windows-1251',
-        'should persist the selected encoding'
-      )
-    })
-  })
-
-}

+ 0 - 126
test/origin-match.js

@@ -1,126 +0,0 @@
-
-var t = require('assert')
-var defaults = require('./utils/defaults')
-
-
-module.exports = ({popup, advanced, content}) => {
-
-  before(async () => {
-    await defaults({popup, advanced, content})
-  })
-
-  describe('correct content-type + disabled header detection + disabled path matching', () => {
-    before(async () => {
-      await advanced.bringToFront()
-
-      // disable header detection
-      if (await advanced.evaluate(() => origins.state.header)) {
-        await advanced.click('.m-switch')
-      }
-
-      // disable path matching
-      await advanced.evaluate(() => {
-        document.querySelector('.m-list li:nth-of-type(1) input').value = ''
-        document.querySelector('.m-list li:nth-of-type(1) input').dispatchEvent(new Event('keyup'))
-      })
-      // there is debounce timeout of 750ms in the options UI
-      await advanced.waitForTimeout(800)
-    })
-    it('text/markdown', async () => {
-      // go to page serving markdown as text/markdown
-      await content.goto('http://localhost:3000/correct-content-type')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('pre').innerText
-        ),
-        '**bold**',
-        'markdown should not be rendered'
-      )
-    })
-  })
-
-  describe('correct content-type + enabled header detection + disabled path matching', () => {
-    before(async () => {
-      await advanced.bringToFront()
-
-      // enable header detection
-      if (!await advanced.evaluate(() => origins.state.header)) {
-        await advanced.click('.m-switch')
-      }
-
-      // disable path matching
-      await advanced.evaluate(() => {
-        document.querySelector('.m-list li:nth-of-type(1) input').value = ''
-        document.querySelector('.m-list li:nth-of-type(1) input').dispatchEvent(new Event('keyup'))
-      })
-      // there is debounce timeout of 750ms in the options UI
-      await advanced.waitForTimeout(800)
-    })
-    it('text/markdown', async () => {
-      // go to page serving markdown as text/markdown
-      await content.goto('http://localhost:3000/correct-content-type')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p strong').innerText
-        ),
-        'bold',
-        'markdown should be rendered'
-      )
-    })
-    it('text/x-markdown', async () => {
-      // go to page serving markdown as text/x-markdown
-      await content.goto('http://localhost:3000/correct-content-type-variation')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p strong').innerText
-        ),
-        'bold',
-        'markdown should be rendered'
-      )
-    })
-  })
-
-  describe('wrong content-type + enabled header detection + enabled path matching', () => {
-    before(async () => {
-      await advanced.bringToFront()
-
-      // enable header detection
-      if (!await advanced.evaluate(() => origins.state.header)) {
-        await advanced.click('.m-switch')
-      }
-
-      // enable path matching
-      await advanced.evaluate(() => {
-        document.querySelector('.m-list li:nth-of-type(1) input').value = 'wrong-content-type'
-        document.querySelector('.m-list li:nth-of-type(1) input').dispatchEvent(new Event('keyup'))
-      })
-      // there is debounce timeout of 750ms in the options UI
-      await advanced.waitForTimeout(800)
-    })
-
-    it('text/plain', async () => {
-      // go to page serving markdown as text/plain
-      await content.goto('http://localhost:3000/wrong-content-type')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p strong').innerText
-        ),
-        'bold',
-        'markdown should be rendered'
-      )
-    })
-  })
-
-}

+ 0 - 18
test/package.json

@@ -1,18 +0,0 @@
-{
-  "name": "markdown-viewer",
-  "version": "0.0.0",
-  "description": "Markdown Viewer / Browser Extension",
-  "private": true,
-  "devDependencies": {
-    "iconv-lite": "^0.4.24",
-    "mocha": "^7.2.0",
-    "puppeteer": "5.4.1",
-  },
-  "scripts": {
-    "test": "mocha --timeout 100000000 --slow 400",
-    "debug": "mocha --inspect-brk --timeout 100000000"
-  },
-  "engines": {
-    "node": ">=14.0.0"
-  }
-}

+ 0 - 606
test/popup-options.js

@@ -1,606 +0,0 @@
-
-var t = require('assert')
-var defaults = require('./utils/defaults')
-
-
-module.exports = ({popup, advanced, content}) => {
-
-  before(async () => {
-    await defaults({popup, advanced, content})
-  })
-
-  describe('button - raw/markdown', () => {
-    before(async () => {
-      // popup
-      await popup.bringToFront()
-      // defaults button
-      await popup.click('button:nth-of-type(2)')
-    })
-
-    it('render markdown as html', async () => {
-      // go to page serving markdown as text/markdown
-      await content.goto('http://localhost:3000/correct-content-type')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p strong').innerText
-        ),
-        'bold',
-        'markdown should be rendered'
-      )
-
-      // popup
-      await popup.bringToFront()
-
-      t.strictEqual(
-        await popup.evaluate(() =>
-          state.raw
-        ),
-        false,
-        'state.raw should equal false'
-      )
-      t.equal(
-        await popup.evaluate(() =>
-          document.querySelector('.m-button:first-child').innerText.toLowerCase()
-        ),
-        'markdown',
-        'button text should equal markdown'
-      )
-    })
-
-    it('display raw markdown', async () => {
-      // raw button
-      await popup.bringToFront()
-      await popup.click('button:nth-of-type(1)')
-      // content auto reloads, but there is no way to have both tabs active
-      await content.bringToFront()
-      await content.reload()
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_markdown').innerText
-        ),
-        '**bold**',
-        'markdown should not be rendered'
-      )
-
-      // popup
-      await popup.bringToFront()
-
-      t.strictEqual(
-        await popup.evaluate(() =>
-          state.raw
-        ),
-        true,
-        'state.raw should equal true'
-      )
-      t.equal(
-        await popup.evaluate(() =>
-          document.querySelector('.m-button:first-child').innerText.toLowerCase()
-        ),
-        'html',
-        'button text should equal html'
-      )
-    })
-  })
-
-  describe('set theme', () => {
-    before(async () => {
-      // popup
-      await popup.bringToFront()
-      // defaults button
-      await popup.click('button:nth-of-type(2)')
-      // theme tab
-      await popup.click('.m-tabs a:nth-of-type(1)')
-    })
-
-    it('github theme should be set by default', async () => {
-      // go to page serving markdown as text/markdown
-      await content.goto('http://localhost:3000/correct-content-type')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          /github\.css$/.test(
-            document.querySelector('#_theme').getAttribute('href')
-          )
-        ),
-        true,
-        'github theme styles should be included'
-      )
-    })
-
-    it('set github-dark theme', async () => {
-      // select github-dark theme
-      await popup.bringToFront()
-      await popup.select('.m-panel:nth-of-type(1) select', 'github-dark')
-      // content auto reloads, but there is no way to have both tabs active
-      await content.bringToFront()
-      await content.reload()
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          /github-dark\.css$/.test(
-            document.querySelector('#_theme').getAttribute('href')
-          )
-        ),
-        true,
-        'github-dark theme styles should be included'
-      )
-    })
-
-    it('popup should preserve state', async () => {
-      // reload popup
-      await popup.bringToFront()
-      await popup.reload()
-      await popup.waitForTimeout(300)
-
-      t.equal(
-        await popup.evaluate(() =>
-          state.theme
-        ),
-        'github-dark',
-        'state.theme should equal github-dark'
-      )
-      t.equal(
-        await popup.evaluate(() =>
-          document.querySelectorAll('.m-panel:nth-of-type(1) select option')[
-            document.querySelector('.m-panel:nth-of-type(1) select').selectedIndex
-          ].innerText
-        ),
-        'github-dark',
-        'dom select option should be github-dark'
-      )
-    })
-  })
-
-  describe('set compiler options - marked', () => {
-    before(async () => {
-      // popup
-      await popup.bringToFront()
-      // defaults button
-      await popup.click('button:nth-of-type(2)')
-      // compiler tab
-      await popup.click('.m-tabs a:nth-of-type(2)')
-    })
-
-    it('gfm is enabled by default', async () => {
-      // go to page serving markdown as text/markdown
-      await content.goto('http://localhost:3000/compiler-options-marked')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p del').innerText
-        ),
-        'strikethrough',
-        'gfm should be rendered'
-      )
-    })
-
-    it('gfm is disabled', async () => {
-      // disable gfm
-      await popup.bringToFront()
-      // gfm switch
-      await popup.click('.m-panel:nth-of-type(2) .m-switch:nth-of-type(2)')
-      // content auto reloads, but there is no way to have both tabs active
-      await content.bringToFront()
-      await content.reload()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p').innerText
-        ),
-        '~~strikethrough~~',
-        'gfm should not be rendered'
-      )
-    })
-
-    it('popup should preserve state', async () => {
-      // reload popup
-      await popup.bringToFront()
-      await popup.reload()
-      await popup.waitForTimeout(300)
-
-      t.equal(
-        await popup.evaluate(() =>
-          document.querySelectorAll('.m-panel:nth-of-type(2) .m-select option')[
-            document.querySelector('.m-panel:nth-of-type(2) .m-select').selectedIndex
-          ].innerText
-        ),
-        'marked',
-        'dom select option should be marked'
-      )
-      t.strictEqual(
-        await popup.evaluate(() =>
-          state.options.gfm
-        ),
-        false,
-        'state.options.gfm should be false'
-      )
-      t.strictEqual(
-        await popup.evaluate(() =>
-          document.querySelector('.m-panel:nth-of-type(2) .m-switch:nth-of-type(2)').classList.contains('is-checked')
-        ),
-        false,
-        'dom gfm checkbox should be disabled'
-      )
-    })
-  })
-
-  describe('set compiler options - remark', () => {
-    before(async () => {
-      // popup
-      await popup.bringToFront()
-      // defaults button
-      await popup.click('button:nth-of-type(2)')
-      // compiler tab
-      await popup.click('.m-tabs a:nth-of-type(2)')
-    })
-
-    it('marked should render gfm task lists by default', async () => {
-      // go to page serving markdown as text/markdown
-      await content.goto('http://localhost:3000/compiler-options-remark')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html ul li').getAttribute('class')
-        ),
-        null,
-        'no class on dom li'
-      )
-      t.strictEqual(
-        await content.evaluate(() =>
-          document.querySelector('#_html ul li [type=checkbox]').hasAttribute('disabled')
-        ),
-        true,
-        'dom li should contain checkbox in it'
-      )
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html ul li').innerText
-        ),
-        ' task',
-        'dom li should contain the task text'
-      )
-    })
-
-    it('remark should render gfm task lists by default', async () => {
-      // select remark compiler
-      await popup.bringToFront()
-      await popup.select('.m-panel:nth-of-type(2) select', 'remark')
-      // content auto reloads, but there is no way to have both tabs active
-      await content.bringToFront()
-      await content.reload()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html ul li').getAttribute('class')
-        ),
-        'task-list-item',
-        'dom li should have a class set'
-      )
-      t.strictEqual(
-        await content.evaluate(() =>
-          document.querySelector('#_html ul li [type=checkbox]').hasAttribute('disabled')
-        ),
-        true,
-        'dom li should contain checkbox in it'
-      )
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html ul li').innerText
-        ),
-        ' task',
-        'dom li should contain the task text'
-      )
-    })
-
-    it('remark disable gfm', async () => {
-      // redraw popup
-      await popup.bringToFront()
-      await popup.reload()
-      await popup.waitForTimeout(300)
-
-      // disable gfm - gfm switch
-      await popup.click('.m-panel:nth-of-type(2) .m-switch[title~=GFM]')
-      // content auto reloads, but there is no way to have both tabs active
-      await content.bringToFront()
-      await content.reload()
-      await content.waitForTimeout(300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html ul li').innerText
-        ),
-        '[ ] task',
-        'gfm task lists should not be rendered'
-      )
-    })
-
-    it('popup should preserve state', async () => {
-      // reload popup
-      await popup.bringToFront()
-      await popup.reload()
-      await popup.waitForTimeout(300)
-
-      t.equal(
-        await popup.evaluate(() =>
-          document.querySelectorAll('.m-panel:nth-of-type(2) .m-select option')[
-            document.querySelector('.m-panel:nth-of-type(2) .m-select').selectedIndex
-          ].innerText
-        ),
-        'remark',
-        'dom select option should be remark'
-      )
-      t.strictEqual(
-        await popup.evaluate(() =>
-          state.options.gfm
-        ),
-        false,
-        'state.options.gfm should be false'
-      )
-      t.strictEqual(
-        await popup.evaluate(() =>
-          document.querySelector('.m-panel:nth-of-type(2) .m-switch[title~=GFM]').classList.contains('is-checked')
-        ),
-        false,
-        'dom gfm checkbox should be disabled'
-      )
-    })
-  })
-
-  describe('set content options - toc', () => {
-    before(async () => {
-      // popup
-      await popup.bringToFront()
-      // defaults button
-      await popup.click('button:nth-of-type(2)')
-      // content tab
-      await popup.click('.m-tabs a:nth-of-type(3)')
-    })
-
-    it('toc is disabled by default', async () => {
-      // go to page serving markdown as text/markdown
-      await content.goto('http://localhost:3000/content-options-toc')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          document.querySelector('#_toc')
-        ),
-        null,
-        'toc should be disabled'
-      )
-    })
-
-    it('enable toc', async () => {
-      // enable toc
-      await popup.bringToFront()
-      // toc switch
-      await popup.click('.m-panel:nth-of-type(3) .m-switch:nth-of-type(3)')
-      // content auto reloads, but there is no way to have both tabs active
-      await content.bringToFront()
-      await content.reload()
-      await content.waitForTimeout(300)
-
-      t.deepStrictEqual(
-        await content.evaluate(() =>
-          Array.from(document.querySelectorAll('#_toc ._ul a'))
-            .map((a) => ({href: a.getAttribute('href'), text: a.innerText}))
-        ),
-        [
-          {href: '#h1', text: 'h1'},
-          {href: '#h2', text: 'h2'},
-          {href: '#h3', text: 'h3'},
-        ],
-        'toc should be rendered'
-      )
-    })
-  })
-
-  describe('set content options - scroll', () => {
-    before(async () => {
-      // popup
-      await popup.bringToFront()
-      // defaults button
-      await popup.click('button:nth-of-type(2)')
-      // content tab
-      await popup.click('.m-tabs a:nth-of-type(3)')
-    })
-
-    it('preserve scroll position by default', async () => {
-      // go to page serving markdown as text/markdown
-      await content.goto('http://localhost:3000/content-options-scroll')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      // scroll down 200px
-      await content.evaluate(() =>
-        document.querySelector('html').scrollTop = 200
-      )
-      await content.waitForTimeout(300)
-
-      // reload page
-      await content.reload()
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          document.querySelector('html').scrollTop,
-        ),
-        200,
-        'scrollTop should be 200px'
-      )
-    })
-
-    it('scroll to top', async () => {
-      // disable scroll option
-      await popup.bringToFront()
-      // scroll switch
-      await popup.click('.m-panel:nth-of-type(3) .m-switch:nth-of-type(2)')
-      // content auto reloads, but there is no way to have both tabs active
-      await content.bringToFront()
-      await content.reload()
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          document.querySelector('html').scrollTop,
-        ),
-        0,
-        'scrollTop should be 0px'
-      )
-
-      // scroll down 200px
-      await content.evaluate(() =>
-        document.querySelector('html').scrollTop = 200
-      )
-      await content.waitForTimeout(300)
-
-      // reload page
-      await content.reload()
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          document.querySelector('html').scrollTop,
-        ),
-        0,
-        'scrollTop should be 0px'
-      )
-    })
-
-    it('scroll to anchor', async () => {
-      // click on header link
-      await content.click('h2 a')
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          document.querySelector('html').scrollTop + 1
-        ),
-        await content.evaluate(() =>
-          document.querySelector('h2').offsetTop
-        ),
-        'page should be scrolled to the anchor'
-      )
-
-      // scroll down 200px
-      await content.evaluate(() =>
-        document.querySelector('html').scrollTop += 200
-      )
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          document.querySelector('html').scrollTop + 1
-        ),
-        await content.evaluate(() =>
-          document.querySelector('h2').offsetTop + 200
-        ),
-        'page should be scrolled below the anchor'
-      )
-
-      // reload page
-      await content.reload()
-      await content.waitForTimeout(300)
-
-      t.strictEqual(
-        await content.evaluate(() =>
-          document.querySelector('html').scrollTop
-        ),
-        await content.evaluate(() =>
-          document.querySelector('h2').offsetTop
-        ),
-        'page should be scrolled back to the anchor'
-      )
-    })
-  })
-
-  describe('set content options - autoreload', () => {
-    before(async () => {
-      // popup
-      await popup.bringToFront()
-      // defaults button
-      await popup.click('button:nth-of-type(2)')
-      // content tab
-      await popup.click('.m-tabs a:nth-of-type(3)')
-
-      await content.goto('about:blank')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      // go to test page
-      await content.goto('http://localhost:3000/popup-autoreload')
-      await content.bringToFront()
-      await content.waitForTimeout(300)
-
-      // enable autoreload
-      await popup.bringToFront()
-      // autoreload switch
-      await popup.click('.m-panel:nth-of-type(3) .m-switch:nth-of-type(5)')
-      // content auto reloads, but there is no way to have both tabs active
-      await content.bringToFront()
-      await content.reload()
-      await content.waitForTimeout(300)
-
-      // TODO: wait for https://github.com/GoogleChrome/puppeteer/pull/2812
-      // update autoreload interval
-      // await content.evaluate(() => state.ms = 250)
-    })
-
-    it('test ajax autoreload with non UTF-8 encoding and inactive tab', async () => {
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p').innerText.trim()
-        ),
-        '你好',
-        'first request'
-      )
-      // the initial interval is 1000
-      await content.waitForTimeout(1300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p').innerText.trim()
-        ),
-        '你好',
-        'second request - xhr body is UTF-8 - should not trigger reload'
-      )
-      // the initial interval is 1000
-      await content.waitForTimeout(1300)
-
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p').innerText.trim()
-        ),
-        '你好你好',
-        'third request - actual change'
-      )
-
-      // popup
-      await popup.bringToFront()
-      // the initial interval is 1000
-      await content.waitForTimeout(1300)
-      await content.bringToFront()
-      t.equal(
-        await content.evaluate(() =>
-          document.querySelector('#_html p').innerText.trim()
-        ),
-        '你好你好你好',
-        'fourth request - should reload inactive tab'
-      )
-    })
-  })
-
-}

+ 0 - 41
test/utils/defaults.js

@@ -1,41 +0,0 @@
-
-module.exports = async ({popup, advanced, content}) => {
-  // popup
-  await popup.bringToFront()
-  // defaults button
-  await popup.click('button:nth-of-type(2)')
-  await popup.waitForTimeout(300)
-
-  // advanced
-  await advanced.bringToFront()
-
-  // enable header detection
-  if (!await advanced.evaluate(() => origins.state.header)) {
-    await advanced.click('.m-switch')
-  }
-
-  // remove origin
-  if (await advanced.evaluate(() => Object.keys(origins.state.origins).length > 1)) {
-    // expand origin
-    if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
-      await advanced.click('.m-list li:nth-of-type(1)')
-    }
-    await advanced.click('.m-list li:nth-of-type(1) .m-footer .m-button')
-  }
-
-  // add origin
-  await advanced.select('.m-select', 'http')
-  await advanced.type('[type=text]', 'localhost:3000')
-  await advanced.click('button')
-  await advanced.waitForTimeout(300)
-
-  // expand origin
-  if (!await advanced.evaluate(() => document.querySelector('.m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
-    await advanced.click('.m-list li:nth-of-type(1)')
-  }
-
-  // content
-  await content.bringToFront()
-  await content.goto('about:blank')
-  await content.waitForTimeout(300)
-}

+ 0 - 93
test/utils/server.js

@@ -1,93 +0,0 @@
-
-var http = require('http')
-var iconv = require('iconv-lite')
-
-
-module.exports = () => new Promise((resolve, reject) => {
-  var autoreload = {index: 0, content: '你好'}
-  server = http.createServer()
-
-  server.on('request', (req, res) => {
-    // content-type
-    if (/wrong-content-type/.test(req.url)) {
-      res.setHeader('Content-Type', 'text/plain')
-      res.end('**bold**')
-    }
-    else if (/correct-content-type/.test(req.url)) {
-      res.setHeader('Content-Type', 'text/markdown')
-      res.end('**bold**')
-    }
-    else if (/correct-content-type-variation/.test(req.url)) {
-      res.setHeader('Content-Type', 'text/x-markdown')
-      res.end('**bold**')
-    }
-    // popup options
-    else if (/compiler-options-marked/.test(req.url)) {
-      res.setHeader('Content-Type', 'text/x-markdown')
-      res.end('~~strikethrough~~')
-    }
-    else if (/compiler-options-remark/.test(req.url)) {
-      res.setHeader('Content-Type', 'text/x-markdown')
-      res.end('- [ ] task')
-    }
-    else if (/content-options-toc/.test(req.url)) {
-      res.setHeader('Content-Type', 'text/markdown')
-      res.end('# h1\n# h2\n# h3')
-    }
-    else if (/content-options-scroll/.test(req.url)) {
-      res.setHeader('Content-Type', 'text/markdown')
-      res.end([
-        '# h1',
-        Array(500).fill('lorem ipsum').join(' '),
-        '## h2',
-        Array(500).fill('lorem ipsum').join(' '),
-        '### h3',
-        Array(500).fill('lorem ipsum').join(' '),
-      ].join('\n\n'))
-    }
-    else if (/popup-autoreload/.test(req.url)) {
-      if (/preventCache/.test(req.url)) {
-        autoreload.index++
-      }
-      if (autoreload.index === 3) {
-        autoreload.content = '你好你好'
-      }
-      else if (autoreload.index === 5) {
-        autoreload.content = '你好你好你好'
-      }
-      res.setHeader('Content-Type', 'text/markdown')
-      res.end(iconv.encode(autoreload.content, 'big5'))
-    }
-    // csp
-    else if (/csp-match-header/.test(req.url)) {
-      res.setHeader('Content-Security-Policy',
-        `default-src 'none'; style-src 'unsafe-inline'; sandbox`)
-      res.setHeader('Content-Type', 'text/markdown')
-      res.end('# h1')
-    }
-    else if (/csp-match-path/.test(req.url)) {
-      res.setHeader('Content-Security-Policy',
-        `default-src 'none'; style-src 'unsafe-inline'; sandbox`)
-      res.end('# h1')
-    }
-    else if (/csp-no-header-no-path/.test(req.url)) {
-      res.setHeader('Content-Security-Policy',
-        `default-src 'none'; style-src 'unsafe-inline'; sandbox`)
-      res.end('# h1')
-    }
-    // encoding
-    else if (/encoding-no-content-type/.test(req.url)) {
-      res.end(iconv.encode('你好', 'big5'))
-    }
-    else if (/encoding-no-charset/.test(req.url)) {
-      res.setHeader('Content-Type', 'text/markdown')
-      res.end(iconv.encode('你好', 'big5'))
-    }
-    else if (/encoding-wrong-charset/.test(req.url)) {
-      res.setHeader('Content-Type', 'text/markdown; charset=UTF-8')
-      res.end(iconv.encode('здрасти', 'win1251'))
-    }
-  })
-
-  server.listen(3000, () => resolve(server))
-})