advanced-origins.js 4.7 KB

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