advanced-origins.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. var t = require('assert')
  2. module.exports = ({browser, advanced, content}) => {
  3. before(async () => {
  4. // add origin
  5. await advanced.bringToFront()
  6. await advanced.select('.m-select', 'http')
  7. await advanced.type('[type=text]', 'localhost:3000')
  8. await advanced.click('button')
  9. // TODO: wait for https://github.com/GoogleChrome/puppeteer/pull/2289
  10. // await advanced.waitFor(() => document.querySelectorAll('.m-list li').length === 2)
  11. await advanced.waitFor(200)
  12. })
  13. describe('add origin', () => {
  14. it('localhost:3000', async () => {
  15. t.equal(
  16. await advanced.evaluate(() =>
  17. document.querySelectorAll('.m-list li').length
  18. ),
  19. 2,
  20. 'allowed origins count should be 2'
  21. )
  22. t.equal(
  23. await advanced.evaluate(() =>
  24. document.querySelector('.m-list li:nth-of-type(2) .m-origin').innerText
  25. ),
  26. 'http://localhost:3000',
  27. 'origin name should be http://localhost:3000'
  28. )
  29. })
  30. })
  31. describe('disabled header detection + disabled path matching', () => {
  32. before(async () => {
  33. await advanced.bringToFront()
  34. // disable header detection
  35. if (await advanced.evaluate(() => state.header)) {
  36. await advanced.click('.m-switch')
  37. }
  38. // expand origin
  39. if (!await advanced.evaluate(() =>
  40. document.querySelector('.m-list li:nth-of-type(2)')
  41. .classList.contains('m-exapanded')))
  42. {
  43. await advanced.click('.m-list li:nth-of-type(2)')
  44. }
  45. // disable path matching
  46. await advanced.evaluate(() => {
  47. document.querySelector('.m-list li:nth-of-type(2) input')
  48. .value = ''
  49. document.querySelector('.m-list li:nth-of-type(2) input')
  50. .dispatchEvent(new Event('keyup'))
  51. })
  52. // there is debounce timeout of 750ms in the options UI
  53. await advanced.waitFor(800)
  54. })
  55. it('text/markdown', async () => {
  56. // go to page serving markdown as text/markdown
  57. await content.goto('http://localhost:3000/correct-content-type')
  58. await content.bringToFront()
  59. await content.waitFor('pre')
  60. t.equal(
  61. await content.evaluate(() =>
  62. document.querySelector('pre').innerText
  63. ),
  64. '**bold**',
  65. 'markdown should not be rendered'
  66. )
  67. })
  68. })
  69. describe('enabled header detection + disabled path matching', () => {
  70. before(async () => {
  71. await advanced.bringToFront()
  72. // enable header detection
  73. if (!await advanced.evaluate(() => state.header)) {
  74. await advanced.click('.m-switch')
  75. }
  76. // expand origin
  77. if (!await advanced.evaluate(() =>
  78. document.querySelector('.m-list li:nth-of-type(2)')
  79. .classList.contains('m-exapanded')))
  80. {
  81. await advanced.click('.m-list li:nth-of-type(2)')
  82. }
  83. // disable path matching
  84. await advanced.evaluate(() => {
  85. document.querySelector('.m-list li:nth-of-type(2) input')
  86. .value = ''
  87. document.querySelector('.m-list li:nth-of-type(2) input')
  88. .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/markdown', async () => {
  94. // go to page serving markdown as text/markdown
  95. await content.goto('http://localhost:3000/correct-content-type')
  96. await content.bringToFront()
  97. await content.waitFor('#_html')
  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. it('text/x-markdown', async () => {
  107. // go to page serving markdown as text/x-markdown
  108. await content.goto('http://localhost:3000/correct-content-type-variation')
  109. await content.bringToFront()
  110. await content.waitFor('#_html')
  111. t.equal(
  112. await content.evaluate(() =>
  113. document.querySelector('#_html p strong').innerText
  114. ),
  115. 'bold',
  116. 'markdown should be rendered'
  117. )
  118. })
  119. })
  120. describe('enabled header detection + enabled path matching', () => {
  121. before(async () => {
  122. await advanced.bringToFront()
  123. // enable header detection
  124. if (!await advanced.evaluate(() => state.header)) {
  125. await advanced.click('.m-switch')
  126. }
  127. // expand origin
  128. if (!await advanced.evaluate(() =>
  129. document.querySelector('.m-list li:nth-of-type(2)')
  130. .classList.contains('m-exapanded')))
  131. {
  132. await advanced.click('.m-list li:nth-of-type(2)')
  133. }
  134. // enable path matching
  135. await advanced.evaluate(() => {
  136. document.querySelector('.m-list li:nth-of-type(2) input')
  137. .value = 'wrong-content-type'
  138. document.querySelector('.m-list li:nth-of-type(2) input')
  139. .dispatchEvent(new Event('keyup'))
  140. })
  141. // there is debounce timeout of 750ms in the options UI
  142. await advanced.waitFor(800)
  143. })
  144. it('text/plain', async () => {
  145. // go to page serving markdown as text/plain
  146. await content.goto('http://localhost:3000/wrong-content-type')
  147. await content.bringToFront()
  148. await content.waitFor('#_html')
  149. t.equal(
  150. await content.evaluate(() =>
  151. document.querySelector('#_html p strong').innerText
  152. ),
  153. 'bold',
  154. 'markdown should be rendered'
  155. )
  156. })
  157. })
  158. }