origin-match.js 4.7 KB

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