origin-match.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. var t = require('assert')
  2. var defaults = require('./utils/defaults')
  3. module.exports = ({popup, advanced, content}) => {
  4. before(async () => {
  5. await defaults({popup, advanced, content})
  6. })
  7. describe('correct content-type + disabled header detection + disabled path matching', () => {
  8. before(async () => {
  9. await advanced.bringToFront()
  10. // disable header detection
  11. if (await advanced.evaluate(() => origins.state.header)) {
  12. await advanced.click('.m-switch')
  13. }
  14. // disable path matching
  15. await advanced.evaluate(() => {
  16. document.querySelector('.m-list li:nth-of-type(1) input').value = ''
  17. document.querySelector('.m-list li:nth-of-type(1) input').dispatchEvent(new Event('keyup'))
  18. })
  19. // there is debounce timeout of 750ms in the options UI
  20. await advanced.waitFor(800)
  21. })
  22. it('text/markdown', async () => {
  23. // go to page serving markdown as text/markdown
  24. await content.goto('http://localhost:3000/correct-content-type')
  25. await content.bringToFront()
  26. await content.waitFor(300)
  27. t.equal(
  28. await content.evaluate(() =>
  29. document.querySelector('pre').innerText
  30. ),
  31. '**bold**',
  32. 'markdown should not be rendered'
  33. )
  34. })
  35. })
  36. describe('correct content-type + enabled header detection + disabled path matching', () => {
  37. before(async () => {
  38. await advanced.bringToFront()
  39. // enable header detection
  40. if (!await advanced.evaluate(() => origins.state.header)) {
  41. await advanced.click('.m-switch')
  42. }
  43. // disable path matching
  44. await advanced.evaluate(() => {
  45. document.querySelector('.m-list li:nth-of-type(1) input').value = ''
  46. document.querySelector('.m-list li:nth-of-type(1) input').dispatchEvent(new Event('keyup'))
  47. })
  48. // there is debounce timeout of 750ms in the options UI
  49. await advanced.waitFor(800)
  50. })
  51. it('text/markdown', async () => {
  52. // go to page serving markdown as text/markdown
  53. await content.goto('http://localhost:3000/correct-content-type')
  54. await content.bringToFront()
  55. await content.waitFor(300)
  56. t.equal(
  57. await content.evaluate(() =>
  58. document.querySelector('#_html p strong').innerText
  59. ),
  60. 'bold',
  61. 'markdown should be rendered'
  62. )
  63. })
  64. it('text/x-markdown', async () => {
  65. // go to page serving markdown as text/x-markdown
  66. await content.goto('http://localhost:3000/correct-content-type-variation')
  67. await content.bringToFront()
  68. await content.waitFor(300)
  69. t.equal(
  70. await content.evaluate(() =>
  71. document.querySelector('#_html p strong').innerText
  72. ),
  73. 'bold',
  74. 'markdown should be rendered'
  75. )
  76. })
  77. })
  78. describe('wrong content-type + enabled header detection + enabled path matching', () => {
  79. before(async () => {
  80. await advanced.bringToFront()
  81. // enable header detection
  82. if (!await advanced.evaluate(() => origins.state.header)) {
  83. await advanced.click('.m-switch')
  84. }
  85. // enable path matching
  86. await advanced.evaluate(() => {
  87. document.querySelector('.m-list li:nth-of-type(1) input').value = 'wrong-content-type'
  88. document.querySelector('.m-list li:nth-of-type(1) input').dispatchEvent(new Event('keyup'))
  89. })
  90. // there is debounce timeout of 750ms in the options UI
  91. await advanced.waitFor(800)
  92. })
  93. it('text/plain', async () => {
  94. // go to page serving markdown as text/plain
  95. await content.goto('http://localhost:3000/wrong-content-type')
  96. await content.bringToFront()
  97. await content.waitFor(300)
  98. t.equal(
  99. await content.evaluate(() =>
  100. document.querySelector('#_html p strong').innerText
  101. ),
  102. 'bold',
  103. 'markdown should be rendered'
  104. )
  105. })
  106. })
  107. }