advanced-origins.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. var t = require('assert')
  2. module.exports = ({browser, advanced}) => {
  3. describe('add origin', () => {
  4. before(async () => {
  5. // add
  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. it('localhost:3000', async () => {
  12. t.equal(
  13. await advanced.evaluate(() =>
  14. document.querySelectorAll('.m-list li').length
  15. ),
  16. 2,
  17. 'allowed origins count should be 2'
  18. )
  19. t.equal(
  20. await advanced.evaluate(() =>
  21. document.querySelector('.m-list li:nth-of-type(2) span:nth-of-type(1)').innerText
  22. ),
  23. 'http',
  24. 'protocol should be http'
  25. )
  26. t.equal(
  27. await advanced.evaluate(() =>
  28. document.querySelector('.m-list li:nth-of-type(2) span:nth-of-type(2)').innerText
  29. ),
  30. 'localhost:3000',
  31. 'hostname should be localhost:3000'
  32. )
  33. })
  34. })
  35. describe('disabled header detection + disabled path matching', () => {
  36. var content
  37. before(async () => {
  38. // add origin
  39. await advanced.select('.m-select', 'http')
  40. await advanced.type('[type=text]', 'localhost:3000')
  41. await advanced.click('button')
  42. await advanced.waitFor(() => document.querySelectorAll('.m-list li').length === 2)
  43. // disable header detection
  44. if (await advanced.evaluate(() => state.header)) {
  45. await advanced.click('.m-switch')
  46. }
  47. // disable path matching
  48. await advanced.evaluate(() => {
  49. document.querySelector('.m-list li:nth-of-type(2) input').value = ''
  50. document.querySelector('.m-list li:nth-of-type(2) input')
  51. .dispatchEvent(new Event('keyup', {bubbles: true}))
  52. })
  53. // go to page serving markdown as text/markdown
  54. content = await browser.newPage()
  55. await content.goto('http://localhost:3000/correct-content-type')
  56. await content.bringToFront()
  57. await content.waitFor('pre')
  58. })
  59. it('text/markdown', async () => {
  60. t.equal(
  61. await content.evaluate(() =>
  62. document.querySelector('pre').innerText
  63. ),
  64. '**bold**',
  65. 'markdown should not be rendered'
  66. )
  67. })
  68. after(async () => {
  69. await content.close()
  70. })
  71. })
  72. describe('enabled header detection + disabled path matching', () => {
  73. var content
  74. before(async () => {
  75. // add origin
  76. await advanced.bringToFront()
  77. await advanced.select('.m-select', 'http')
  78. await advanced.type('[type=text]', 'localhost:3000')
  79. await advanced.click('button')
  80. await advanced.waitFor(() => document.querySelectorAll('.m-list li').length === 2)
  81. // enable header detection
  82. if (!await advanced.evaluate(() => state.header)) {
  83. await advanced.click('.m-switch')
  84. }
  85. // disable path matching
  86. await advanced.evaluate(() => {
  87. document.querySelector('.m-list li:nth-of-type(2) input').value = ''
  88. document.querySelector('.m-list li:nth-of-type(2) input')
  89. .dispatchEvent(new Event('keyup', {bubbles: true}))
  90. })
  91. // open up new page
  92. content = await browser.newPage()
  93. await content.bringToFront()
  94. })
  95. it('text/markdown', async () => {
  96. // go to page serving markdown as text/markdown
  97. await content.goto('http://localhost:3000/correct-content-type')
  98. await content.waitFor('#_html')
  99. t.equal(
  100. await content.evaluate(() =>
  101. document.querySelector('#_html p strong').innerText
  102. ),
  103. 'bold',
  104. 'markdown should be rendered'
  105. )
  106. })
  107. it('text/x-markdown', async () => {
  108. // go to page serving markdown as text/x-markdown
  109. await content.goto('http://localhost:3000/correct-content-type-variation')
  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. after(async () => {
  120. await content.close()
  121. })
  122. })
  123. describe('enabled header detection + enabled path matching', () => {
  124. var content
  125. before(async () => {
  126. // add origin
  127. await advanced.select('.m-select', 'http')
  128. await advanced.type('[type=text]', 'localhost:3000')
  129. await advanced.click('button')
  130. await advanced.waitFor(() => document.querySelectorAll('.m-list li').length === 2)
  131. // enable header detection
  132. if (!await advanced.evaluate(() => state.header)) {
  133. await advanced.click('.m-switch')
  134. }
  135. // enable path matching
  136. await advanced.evaluate(() => {
  137. document.querySelector('.m-list li:nth-of-type(2) input').value = 'wrong-content-type'
  138. document.querySelector('.m-list li:nth-of-type(2) input')
  139. .dispatchEvent(new Event('keyup', {bubbles: true}))
  140. })
  141. // TODO: figure out why is this needed
  142. await advanced.waitFor(600)
  143. // open up new page
  144. content = await browser.newPage()
  145. await content.bringToFront()
  146. })
  147. it('text/plain', async () => {
  148. // go to page serving markdown as text/plain
  149. await content.goto('http://localhost:3000/wrong-content-type')
  150. await content.waitFor('#_html')
  151. t.equal(
  152. await content.evaluate(() =>
  153. document.querySelector('#_html p strong').innerText
  154. ),
  155. 'bold',
  156. 'markdown should be rendered'
  157. )
  158. })
  159. after(async () => {
  160. await content.close()
  161. })
  162. })
  163. }