selenium-webdriver 3.5.0 → 4.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/CHANGES.md +246 -0
  2. package/LICENSE +1 -1
  3. package/NOTICE +1 -1
  4. package/README.md +40 -40
  5. package/chrome.js +118 -134
  6. package/edge.js +43 -117
  7. package/example/chrome_android.js +8 -9
  8. package/example/chrome_mobile_emulation.js +8 -9
  9. package/example/firefox_channels.js +23 -19
  10. package/example/google_search.js +3 -3
  11. package/example/google_search_test.js +38 -27
  12. package/example/{chrome_headless.js → headless.js} +15 -7
  13. package/example/logging.js +40 -7
  14. package/firefox.js +789 -0
  15. package/http/index.js +62 -9
  16. package/http/util.js +11 -6
  17. package/ie.js +83 -97
  18. package/index.js +198 -114
  19. package/io/exec.js +29 -15
  20. package/io/index.js +1 -1
  21. package/io/zip.js +1 -1
  22. package/lib/actions.js +68 -63
  23. package/lib/atoms/get-attribute.js +86 -0
  24. package/lib/atoms/is-displayed.js +76 -76
  25. package/lib/by.js +7 -4
  26. package/lib/capabilities.js +310 -210
  27. package/lib/command.js +27 -51
  28. package/lib/error.js +100 -41
  29. package/lib/http.js +161 -120
  30. package/lib/input.js +1044 -8
  31. package/lib/logging.js +1 -5
  32. package/lib/promise.js +222 -3331
  33. package/lib/proxy.js +134 -39
  34. package/lib/session.js +2 -2
  35. package/lib/symbols.js +0 -0
  36. package/lib/until.js +1 -1
  37. package/lib/webdriver.js +717 -953
  38. package/net/index.js +21 -25
  39. package/net/portprober.js +51 -68
  40. package/package.json +17 -12
  41. package/proxy.js +0 -0
  42. package/remote/index.js +63 -44
  43. package/safari.js +41 -128
  44. package/testing/index.js +386 -315
  45. package/.npmignore +0 -2
  46. package/example/async_await_test.js +0 -68
  47. package/example/google_search_generator.js +0 -50
  48. package/example/parallel_flows.js +0 -54
  49. package/firefox/binary.js +0 -344
  50. package/firefox/extension.js +0 -224
  51. package/firefox/index.js +0 -626
  52. package/firefox/profile.js +0 -394
  53. package/lib/README +0 -5
  54. package/lib/atoms/getAttribute.js +0 -9
  55. package/lib/devmode.js +0 -34
  56. package/lib/events.js +0 -210
  57. package/lib/firefox/webdriver.json +0 -70
  58. package/lib/test/build.js +0 -151
  59. package/lib/test/data/ClickTest_testClicksASurroundingStrongTag.html +0 -11
  60. package/lib/test/data/Page.aspx +0 -17
  61. package/lib/test/data/Page.aspx.cs +0 -22
  62. package/lib/test/data/Redirect.aspx +0 -11
  63. package/lib/test/data/Redirect.aspx.cs +0 -9
  64. package/lib/test/data/Settings.StyleCop +0 -759
  65. package/lib/test/data/Web.Config +0 -59
  66. package/lib/test/data/actualXhtmlPage.xhtml +0 -14
  67. package/lib/test/data/ajaxy_page.html +0 -81
  68. package/lib/test/data/alerts.html +0 -85
  69. package/lib/test/data/banner.gif +0 -0
  70. package/lib/test/data/beach.jpg +0 -0
  71. package/lib/test/data/blank.html +0 -1
  72. package/lib/test/data/bodyTypingTest.html +0 -41
  73. package/lib/test/data/booleanAttributes.html +0 -19
  74. package/lib/test/data/child/childPage.html +0 -8
  75. package/lib/test/data/child/grandchild/grandchildPage.html +0 -8
  76. package/lib/test/data/clickEventPage.html +0 -26
  77. package/lib/test/data/click_frames.html +0 -10
  78. package/lib/test/data/click_jacker.html +0 -38
  79. package/lib/test/data/click_out_of_bounds.html +0 -23
  80. package/lib/test/data/click_out_of_bounds_overflow.html +0 -85
  81. package/lib/test/data/click_rtl.html +0 -19
  82. package/lib/test/data/click_source.html +0 -18
  83. package/lib/test/data/click_tests/click_iframe.html +0 -6
  84. package/lib/test/data/click_tests/click_in_iframe.html +0 -8
  85. package/lib/test/data/click_tests/disabled_element.html +0 -12
  86. package/lib/test/data/click_tests/disappearing_element.html +0 -62
  87. package/lib/test/data/click_tests/google_map.html +0 -15
  88. package/lib/test/data/click_tests/google_map.png +0 -0
  89. package/lib/test/data/click_tests/html5_submit_buttons.html +0 -16
  90. package/lib/test/data/click_tests/issue5237.html +0 -9
  91. package/lib/test/data/click_tests/issue5237_frame.html +0 -1
  92. package/lib/test/data/click_tests/issue5237_target.html +0 -10
  93. package/lib/test/data/click_tests/link_that_wraps.html +0 -11
  94. package/lib/test/data/click_tests/mapped_page1.html +0 -9
  95. package/lib/test/data/click_tests/mapped_page2.html +0 -9
  96. package/lib/test/data/click_tests/mapped_page3.html +0 -9
  97. package/lib/test/data/click_tests/overlapping_elements.html +0 -70
  98. package/lib/test/data/click_tests/partially_overlapping_elements.html +0 -124
  99. package/lib/test/data/click_tests/span_that_wraps.html +0 -11
  100. package/lib/test/data/click_tests/submitted_page.html +0 -9
  101. package/lib/test/data/click_tests/wrapped_overlapping_elements.html +0 -13
  102. package/lib/test/data/click_too_big.html +0 -10
  103. package/lib/test/data/click_too_big_in_frame.html +0 -11
  104. package/lib/test/data/clicks.html +0 -35
  105. package/lib/test/data/closeable_window.html +0 -8
  106. package/lib/test/data/cn-test.html +0 -156
  107. package/lib/test/data/colorPage.html +0 -20
  108. package/lib/test/data/cookies.html +0 -30
  109. package/lib/test/data/coordinates_tests/element_in_frame.html +0 -9
  110. package/lib/test/data/coordinates_tests/element_in_nested_frame.html +0 -9
  111. package/lib/test/data/coordinates_tests/page_with_element_out_of_view.html +0 -11
  112. package/lib/test/data/coordinates_tests/page_with_empty_element.html +0 -10
  113. package/lib/test/data/coordinates_tests/page_with_fixed_element.html +0 -12
  114. package/lib/test/data/coordinates_tests/page_with_hidden_element.html +0 -10
  115. package/lib/test/data/coordinates_tests/page_with_invisible_element.html +0 -10
  116. package/lib/test/data/coordinates_tests/page_with_transparent_element.html +0 -10
  117. package/lib/test/data/coordinates_tests/simple_page.html +0 -10
  118. package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  119. package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  120. package/lib/test/data/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  121. package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  122. package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  123. package/lib/test/data/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  124. package/lib/test/data/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  125. package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  126. package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  127. package/lib/test/data/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  128. package/lib/test/data/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  129. package/lib/test/data/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  130. package/lib/test/data/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  131. package/lib/test/data/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  132. package/lib/test/data/css/ui-lightness/jquery-ui-1.8.10.custom.css +0 -573
  133. package/lib/test/data/cssTransform.html +0 -61
  134. package/lib/test/data/cssTransform2.html +0 -20
  135. package/lib/test/data/document_write_in_onload.html +0 -13
  136. package/lib/test/data/dragAndDropInsideScrolledDiv.html +0 -67
  137. package/lib/test/data/dragAndDropTest.html +0 -102
  138. package/lib/test/data/dragDropOverflow.html +0 -104
  139. package/lib/test/data/draggableLists.html +0 -67
  140. package/lib/test/data/droppableItems.html +0 -65
  141. package/lib/test/data/dynamic.html +0 -39
  142. package/lib/test/data/dynamicallyModifiedPage.html +0 -42
  143. package/lib/test/data/errors.html +0 -15
  144. package/lib/test/data/firefox/jetpack-sample.xpi +0 -0
  145. package/lib/test/data/firefox/sample.xpi +0 -0
  146. package/lib/test/data/firefox/webextension.xpi +0 -0
  147. package/lib/test/data/fixedFooterNoScroll.html +0 -13
  148. package/lib/test/data/fixedFooterNoScrollQuirksMode.html +0 -12
  149. package/lib/test/data/formPage.html +0 -175
  150. package/lib/test/data/formSelectionPage.html +0 -46
  151. package/lib/test/data/form_handling_js_submit.html +0 -30
  152. package/lib/test/data/framePage3.html +0 -7
  153. package/lib/test/data/frameScrollChild.html +0 -26
  154. package/lib/test/data/frameScrollPage.html +0 -14
  155. package/lib/test/data/frameScrollParent.html +0 -11
  156. package/lib/test/data/frameWithAnimals.html +0 -11
  157. package/lib/test/data/frame_switching_tests/bug4876.html +0 -9
  158. package/lib/test/data/frame_switching_tests/bug4876_iframe.html +0 -9
  159. package/lib/test/data/frame_switching_tests/deletingFrame.html +0 -29
  160. package/lib/test/data/frame_switching_tests/deletingFrame_iframe.html +0 -8
  161. package/lib/test/data/frame_switching_tests/deletingFrame_iframe2.html +0 -7
  162. package/lib/test/data/frameset.html +0 -14
  163. package/lib/test/data/framesetPage2.html +0 -7
  164. package/lib/test/data/framesetPage3.html +0 -4
  165. package/lib/test/data/globalscope.html +0 -15
  166. package/lib/test/data/hidden.html +0 -5
  167. package/lib/test/data/hidden_partially.html +0 -45
  168. package/lib/test/data/html5/blue.jpg +0 -0
  169. package/lib/test/data/html5/database.js +0 -84
  170. package/lib/test/data/html5/geolocation.js +0 -18
  171. package/lib/test/data/html5/green.jpg +0 -0
  172. package/lib/test/data/html5/red.jpg +0 -0
  173. package/lib/test/data/html5/status.html +0 -1
  174. package/lib/test/data/html5/test.appcache +0 -11
  175. package/lib/test/data/html5/yellow.jpg +0 -0
  176. package/lib/test/data/html5Page.html +0 -32
  177. package/lib/test/data/icon.gif +0 -0
  178. package/lib/test/data/idElements.html +0 -2
  179. package/lib/test/data/iframeAtBottom.html +0 -15
  180. package/lib/test/data/iframeWithAlert.html +0 -1
  181. package/lib/test/data/iframeWithIframe.html +0 -1
  182. package/lib/test/data/iframes.html +0 -11
  183. package/lib/test/data/injectableContent.html +0 -22
  184. package/lib/test/data/javascriptEnhancedForm.html +0 -30
  185. package/lib/test/data/javascriptPage.html +0 -285
  186. package/lib/test/data/jquery-1.3.2.js +0 -4376
  187. package/lib/test/data/js/jquery-1.4.4.min.js +0 -167
  188. package/lib/test/data/js/jquery-ui-1.8.10.custom.min.js +0 -782
  189. package/lib/test/data/js/skins/lightgray/content.inline.min.css +0 -1
  190. package/lib/test/data/js/skins/lightgray/content.min.css +0 -1
  191. package/lib/test/data/js/skins/lightgray/fonts/readme.md +0 -1
  192. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.dev.svg +0 -175
  193. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.eot +0 -0
  194. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.svg +0 -62
  195. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.ttf +0 -0
  196. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.woff +0 -0
  197. package/lib/test/data/js/skins/lightgray/fonts/tinymce.dev.svg +0 -153
  198. package/lib/test/data/js/skins/lightgray/fonts/tinymce.eot +0 -0
  199. package/lib/test/data/js/skins/lightgray/fonts/tinymce.svg +0 -63
  200. package/lib/test/data/js/skins/lightgray/fonts/tinymce.ttf +0 -0
  201. package/lib/test/data/js/skins/lightgray/fonts/tinymce.woff +0 -0
  202. package/lib/test/data/js/skins/lightgray/img/anchor.gif +0 -0
  203. package/lib/test/data/js/skins/lightgray/img/loader.gif +0 -0
  204. package/lib/test/data/js/skins/lightgray/img/object.gif +0 -0
  205. package/lib/test/data/js/skins/lightgray/img/trans.gif +0 -0
  206. package/lib/test/data/js/skins/lightgray/skin.ie7.min.css +0 -1
  207. package/lib/test/data/js/skins/lightgray/skin.min.css +0 -1
  208. package/lib/test/data/js/themes/modern/theme.min.js +0 -1
  209. package/lib/test/data/js/tinymce.min.js +0 -10
  210. package/lib/test/data/key_logger.html +0 -34
  211. package/lib/test/data/key_tests/remove_on_keypress.html +0 -36
  212. package/lib/test/data/keyboard_shortcut.html +0 -36
  213. package/lib/test/data/linked_image.html +0 -16
  214. package/lib/test/data/locators_tests/boolean_attribute_selected.html +0 -13
  215. package/lib/test/data/locators_tests/boolean_attribute_selected_html4.html +0 -13
  216. package/lib/test/data/longContentPage.html +0 -55
  217. package/lib/test/data/macbeth.html +0 -5255
  218. package/lib/test/data/map.png +0 -0
  219. package/lib/test/data/map_visibility.html +0 -8
  220. package/lib/test/data/markerTransparent.png +0 -0
  221. package/lib/test/data/messages.html +0 -15
  222. package/lib/test/data/meta-redirect.html +0 -11
  223. package/lib/test/data/missedJsReference.html +0 -11
  224. package/lib/test/data/modal_dialogs/modal_1.html +0 -21
  225. package/lib/test/data/modal_dialogs/modal_2.html +0 -21
  226. package/lib/test/data/modal_dialogs/modal_3.html +0 -15
  227. package/lib/test/data/modal_dialogs/modalindex.html +0 -21
  228. package/lib/test/data/mouseOver.html +0 -17
  229. package/lib/test/data/mousePositionTracker.html +0 -33
  230. package/lib/test/data/nestedElements.html +0 -164
  231. package/lib/test/data/overflow/x_auto_y_auto.html +0 -30
  232. package/lib/test/data/overflow/x_auto_y_hidden.html +0 -30
  233. package/lib/test/data/overflow/x_auto_y_scroll.html +0 -30
  234. package/lib/test/data/overflow/x_hidden_y_auto.html +0 -30
  235. package/lib/test/data/overflow/x_hidden_y_hidden.html +0 -30
  236. package/lib/test/data/overflow/x_hidden_y_scroll.html +0 -30
  237. package/lib/test/data/overflow/x_scroll_y_auto.html +0 -30
  238. package/lib/test/data/overflow/x_scroll_y_hidden.html +0 -30
  239. package/lib/test/data/overflow/x_scroll_y_scroll.html +0 -30
  240. package/lib/test/data/overflow-body.html +0 -15
  241. package/lib/test/data/pageWithOnBeforeUnloadMessage.html +0 -20
  242. package/lib/test/data/pageWithOnLoad.html +0 -6
  243. package/lib/test/data/pageWithOnUnload.html +0 -6
  244. package/lib/test/data/page_with_link_to_slow_loading_page.html +0 -6
  245. package/lib/test/data/plain.txt +0 -1
  246. package/lib/test/data/proxy/page1.html +0 -20
  247. package/lib/test/data/proxy/page2.html +0 -24
  248. package/lib/test/data/proxy/page3.html +0 -5
  249. package/lib/test/data/readOnlyPage.html +0 -24
  250. package/lib/test/data/rectangles.html +0 -40
  251. package/lib/test/data/resultPage.html +0 -25
  252. package/lib/test/data/rich_text.html +0 -161
  253. package/lib/test/data/safari/frames_benchmark.html +0 -31
  254. package/lib/test/data/screen/screen.css +0 -19
  255. package/lib/test/data/screen/screen.html +0 -72
  256. package/lib/test/data/screen/screen.js +0 -7
  257. package/lib/test/data/screen/screen_frame1.html +0 -72
  258. package/lib/test/data/screen/screen_frame2.html +0 -72
  259. package/lib/test/data/screen/screen_frames.html +0 -11
  260. package/lib/test/data/screen/screen_iframes.html +0 -12
  261. package/lib/test/data/screen/screen_too_long.html +0 -68
  262. package/lib/test/data/screen/screen_x_long.html +0 -72
  263. package/lib/test/data/screen/screen_x_too_long.html +0 -72
  264. package/lib/test/data/screen/screen_y_long.html +0 -72
  265. package/lib/test/data/screen/screen_y_too_long.html +0 -72
  266. package/lib/test/data/scroll.html +0 -27
  267. package/lib/test/data/scroll2.html +0 -21
  268. package/lib/test/data/scroll3.html +0 -8
  269. package/lib/test/data/scroll4.html +0 -7
  270. package/lib/test/data/scroll5.html +0 -18
  271. package/lib/test/data/scrolling_tests/frame_with_height_above_200.html +0 -26
  272. package/lib/test/data/scrolling_tests/frame_with_height_above_2000.html +0 -26
  273. package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame.html +0 -11
  274. package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html +0 -12
  275. package/lib/test/data/scrolling_tests/frame_with_small_height.html +0 -10
  276. package/lib/test/data/scrolling_tests/page_with_double_overflow_auto.html +0 -19
  277. package/lib/test/data/scrolling_tests/page_with_frame_out_of_view.html +0 -12
  278. package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames.html +0 -11
  279. package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames_out_of_view.html +0 -12
  280. package/lib/test/data/scrolling_tests/page_with_non_scrolling_frame.html +0 -11
  281. package/lib/test/data/scrolling_tests/page_with_scrolling_frame.html +0 -11
  282. package/lib/test/data/scrolling_tests/page_with_scrolling_frame_out_of_view.html +0 -12
  283. package/lib/test/data/scrolling_tests/page_with_tall_frame.html +0 -11
  284. package/lib/test/data/scrolling_tests/page_with_y_overflow_auto.html +0 -14
  285. package/lib/test/data/scrolling_tests/target_page.html +0 -9
  286. package/lib/test/data/selectPage.html +0 -58
  287. package/lib/test/data/selectableItems.html +0 -65
  288. package/lib/test/data/sessionCookie.html +0 -21
  289. package/lib/test/data/sessionCookieDest.html +0 -34
  290. package/lib/test/data/simple.xml +0 -5
  291. package/lib/test/data/simpleTest.html +0 -98
  292. package/lib/test/data/single_text_input.html +0 -12
  293. package/lib/test/data/slowLoadingAlert.html +0 -10
  294. package/lib/test/data/slowLoadingResourcePage.html +0 -12
  295. package/lib/test/data/slow_loading_iframes.html +0 -14
  296. package/lib/test/data/styledPage.html +0 -28
  297. package/lib/test/data/svgPiechart.xhtml +0 -81
  298. package/lib/test/data/svgTest.svg +0 -4
  299. package/lib/test/data/tables.html +0 -36
  300. package/lib/test/data/tinymce.html +0 -10
  301. package/lib/test/data/transformable.xml +0 -11
  302. package/lib/test/data/transformable.xsl +0 -37
  303. package/lib/test/data/transparentUpload.html +0 -70
  304. package/lib/test/data/underscore.html +0 -9
  305. package/lib/test/data/unicode_ltr.html +0 -8
  306. package/lib/test/data/upload.html +0 -45
  307. package/lib/test/data/userDefinedProperty.html +0 -8
  308. package/lib/test/data/veryLargeCanvas.html +0 -81
  309. package/lib/test/data/visibility-css.html +0 -21
  310. package/lib/test/data/win32frameset.html +0 -8
  311. package/lib/test/data/window_switching_tests/page_with_frame.html +0 -12
  312. package/lib/test/data/window_switching_tests/simple_page.html +0 -9
  313. package/lib/test/data/xhtmlFormPage.xhtml +0 -17
  314. package/lib/test/data/xhtmlTest.html +0 -76
  315. package/lib/test/fileserver.js +0 -321
  316. package/lib/test/httpserver.js +0 -120
  317. package/lib/test/index.js +0 -270
  318. package/lib/test/promise.js +0 -79
  319. package/lib/test/resources.js +0 -44
  320. package/opera.js +0 -405
  321. package/phantomjs.js +0 -282
  322. package/test/actions_test.js +0 -52
  323. package/test/chrome/options_test.js +0 -227
  324. package/test/chrome/service_test.js +0 -45
  325. package/test/cookie_test.js +0 -214
  326. package/test/element_finding_test.js +0 -426
  327. package/test/execute_script_test.js +0 -350
  328. package/test/fingerprint_test.js +0 -62
  329. package/test/firefox/extension_test.js +0 -120
  330. package/test/firefox/firefox_test.js +0 -261
  331. package/test/firefox/profile_test.js +0 -140
  332. package/test/http/http_test.js +0 -223
  333. package/test/http/util_test.js +0 -178
  334. package/test/io/io_test.js +0 -360
  335. package/test/io/zip_test.js +0 -128
  336. package/test/lib/by_test.js +0 -160
  337. package/test/lib/capabilities_test.js +0 -111
  338. package/test/lib/error_test.js +0 -305
  339. package/test/lib/events_test.js +0 -177
  340. package/test/lib/http_test.js +0 -696
  341. package/test/lib/logging_test.js +0 -272
  342. package/test/lib/promise_aplus_test.js +0 -78
  343. package/test/lib/promise_error_test.js +0 -884
  344. package/test/lib/promise_flow_test.js +0 -2288
  345. package/test/lib/promise_generator_test.js +0 -310
  346. package/test/lib/promise_test.js +0 -1109
  347. package/test/lib/testutil.js +0 -90
  348. package/test/lib/until_test.js +0 -478
  349. package/test/lib/webdriver_test.js +0 -2311
  350. package/test/logging_test.js +0 -167
  351. package/test/net/index_test.js +0 -60
  352. package/test/net/portprober_test.js +0 -128
  353. package/test/page_loading_test.js +0 -166
  354. package/test/phantomjs/execute_phantomjs_test.js +0 -59
  355. package/test/proxy_test.js +0 -180
  356. package/test/rect_test.js +0 -60
  357. package/test/remote_test.js +0 -117
  358. package/test/safari_test.js +0 -108
  359. package/test/session_test.js +0 -99
  360. package/test/stale_element_test.js +0 -63
  361. package/test/tag_name_test.js +0 -36
  362. package/test/testing/assert_test.js +0 -373
  363. package/test/testing/index_test.js +0 -224
  364. package/test/upload_test.js +0 -86
  365. package/test/window_test.js +0 -161
  366. package/testing/assert.js +0 -378
@@ -1,2288 +0,0 @@
1
- // Licensed to the Software Freedom Conservancy (SFC) under one
2
- // or more contributor license agreements. See the NOTICE file
3
- // distributed with this work for additional information
4
- // regarding copyright ownership. The SFC licenses this file
5
- // to you under the Apache License, Version 2.0 (the
6
- // "License"); you may not use this file except in compliance
7
- // with the License. You may obtain a copy of the License at
8
- //
9
- // http://www.apache.org/licenses/LICENSE-2.0
10
- //
11
- // Unless required by applicable law or agreed to in writing,
12
- // software distributed under the License is distributed on an
13
- // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- // KIND, either express or implied. See the License for the
15
- // specific language governing permissions and limitations
16
- // under the License.
17
-
18
- 'use strict';
19
-
20
- const assert = require('assert');
21
- const fail = assert.fail;
22
- const sinon = require('sinon');
23
-
24
- const testutil = require('./testutil');
25
- const {TimeoutError} = require('../../lib/error');
26
- const promise = require('../../lib/promise');
27
- const {enablePromiseManager} = require('../../lib/test/promise');
28
-
29
- const NativePromise = Promise;
30
-
31
- // Aliases for readability.
32
- const StubError = testutil.StubError;
33
- const assertIsStubError = testutil.assertIsStubError;
34
- const callbackPair = testutil.callbackPair;
35
- const throwStubError = testutil.throwStubError;
36
-
37
- describe('promise control flow', function() {
38
- enablePromiseManager(() => {
39
- let flow, flowHistory, messages, uncaughtExceptions;
40
-
41
- beforeEach(function setUp() {
42
- promise.LONG_STACK_TRACES = false;
43
- flow = new promise.ControlFlow();
44
- promise.setDefaultFlow(flow);
45
- messages = [];
46
- flowHistory = [];
47
-
48
- uncaughtExceptions = [];
49
- flow.on(promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION,
50
- onUncaughtException);
51
- });
52
-
53
- afterEach(function tearDown() {
54
- flow.removeAllListeners(
55
- promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION);
56
- assert.deepEqual([], uncaughtExceptions,
57
- 'There were uncaught exceptions');
58
- flow.reset();
59
- promise.LONG_STACK_TRACES = false;
60
- });
61
-
62
- function onUncaughtException(e) {
63
- uncaughtExceptions.push(e);
64
- }
65
-
66
- function defer() {
67
- let d = {};
68
- let promise = new Promise((resolve, reject) => {
69
- Object.assign(d, {resolve, reject});
70
- });
71
- d.promise = promise;
72
- return d;
73
- }
74
-
75
- function waitForAbort(opt_flow) {
76
- var theFlow = opt_flow || flow;
77
- theFlow.removeAllListeners(
78
- promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION);
79
- return new NativePromise(function(fulfill, reject) {
80
- theFlow.once(promise.ControlFlow.EventType.IDLE, function() {
81
- reject(Error('expected flow to report an unhandled error'));
82
- });
83
- theFlow.once(
84
- promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION,
85
- fulfill);
86
- });
87
- }
88
-
89
- function waitForIdle(opt_flow) {
90
- var theFlow = opt_flow || flow;
91
- return new NativePromise(function(fulfill, reject) {
92
- theFlow.once(promise.ControlFlow.EventType.IDLE, fulfill);
93
- theFlow.once(
94
- promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION, reject);
95
- });
96
- }
97
-
98
- function timeout(ms) {
99
- return new NativePromise(function(fulfill) {
100
- setTimeout(fulfill, ms);
101
- });
102
- }
103
-
104
-
105
- function schedule(msg, opt_return) {
106
- return scheduleAction(msg, function() {
107
- return opt_return;
108
- });
109
- }
110
-
111
- /**
112
- * @param {string} value The value to push.
113
- * @param {promise.Promise=} opt_taskPromise Promise to return from
114
- * the task.
115
- * @return {!promise.Promise} The result.
116
- */
117
- function schedulePush(value, opt_taskPromise) {
118
- return scheduleAction(value, function() {
119
- messages.push(value);
120
- return opt_taskPromise;
121
- });
122
- }
123
-
124
- /**
125
- * @param {string} msg Debug message.
126
- * @param {!Function} actionFn The function.
127
- * @return {!promise.Promise} The function result.
128
- */
129
- function scheduleAction(msg, actionFn) {
130
- return promise.controlFlow().execute(function() {
131
- flowHistory.push(msg);
132
- return actionFn();
133
- }, msg);
134
- }
135
-
136
- /**
137
- * @param {!Function} condition The condition function.
138
- * @param {number=} opt_timeout The timeout.
139
- * @param {string=} opt_message Optional message.
140
- * @return {!promise.Promise} The wait result.
141
- */
142
- function scheduleWait(condition, opt_timeout, opt_message) {
143
- var msg = opt_message || '';
144
- // It's not possible to hook into when the wait itself is scheduled, so
145
- // we record each iteration of the wait loop.
146
- var count = 0;
147
- return promise.controlFlow().wait(function() {
148
- flowHistory.push((count++) + ': ' + msg);
149
- return condition();
150
- }, opt_timeout, msg);
151
- }
152
-
153
- function asyncRun(fn, opt_self) {
154
- NativePromise.resolve().then(() => fn.call(opt_self));
155
- }
156
-
157
- function assertFlowHistory(var_args) {
158
- var expected = Array.prototype.slice.call(arguments, 0);
159
- assert.deepEqual(expected, flowHistory);
160
- }
161
-
162
- function assertMessages(var_args) {
163
- var expected = Array.prototype.slice.call(arguments, 0);
164
- assert.deepEqual(expected, messages);
165
- }
166
-
167
- function assertingMessages(var_args) {
168
- var args = Array.prototype.slice.call(arguments, 0);
169
- return () => assertMessages.apply(null, args);
170
- }
171
-
172
- function assertFlowIs(flow) {
173
- assert.equal(flow, promise.controlFlow());
174
- }
175
-
176
- describe('testScheduling', function() {
177
- it('aSimpleFunction', function() {
178
- schedule('go');
179
- return waitForIdle().then(function() {
180
- assertFlowHistory('go');
181
- });
182
- });
183
-
184
- it('aSimpleFunctionWithANonPromiseReturnValue', function() {
185
- schedule('go', 123).then(function(value) {
186
- assert.equal(123, value);
187
- });
188
- return waitForIdle().then(function() {
189
- assertFlowHistory('go');
190
- });
191
- });
192
-
193
- it('aSimpleSequence', function() {
194
- schedule('a');
195
- schedule('b');
196
- schedule('c');
197
- return waitForIdle().then(function() {
198
- assertFlowHistory('a', 'b', 'c');
199
- });
200
- });
201
-
202
- it('invokesCallbacksWhenTaskIsDone', function() {
203
- var d = new promise.Deferred();
204
- var called = false;
205
- var done = schedule('a', d.promise).then(function(value) {
206
- called = true;
207
- assert.equal(123, value);
208
- });
209
- return timeout(5).then(function() {
210
- assert.ok(!called);
211
- d.fulfill(123);
212
- return done;
213
- }).
214
- then(function() {
215
- assertFlowHistory('a');
216
- });
217
- });
218
-
219
- it('blocksUntilPromiseReturnedByTaskIsResolved', function() {
220
- var done = promise.defer();
221
- schedulePush('a', done.promise);
222
- schedulePush('b');
223
- setTimeout(function() {
224
- done.fulfill();
225
- messages.push('c');
226
- }, 25);
227
- return waitForIdle().then(assertingMessages('a', 'c', 'b'));
228
- });
229
-
230
- it('waitsForReturnedPromisesToResolve', function() {
231
- var d1 = new promise.Deferred();
232
- var d2 = new promise.Deferred();
233
-
234
- var callback = sinon.spy();
235
- schedule('a', d1.promise).then(callback);
236
-
237
- return timeout(5).then(function() {
238
- assert(!callback.called);
239
- d1.fulfill(d2.promise);
240
- return timeout(5);
241
- }).then(function() {
242
- assert(!callback.called);
243
- d2.fulfill('fluffy bunny');
244
- return waitForIdle();
245
- }).then(function() {
246
- assert(callback.called);
247
- assert.equal('fluffy bunny', callback.getCall(0).args[0]);
248
- assertFlowHistory('a');
249
- });
250
- });
251
-
252
- it('executesTasksInAFutureTurnAfterTheyAreScheduled', function() {
253
- var count = 0;
254
- function incr() { count++; }
255
-
256
- scheduleAction('', incr);
257
- assert.equal(0, count);
258
- return waitForIdle().then(function() {
259
- assert.equal(1, count);
260
- });
261
- });
262
-
263
- it('executesOneTaskPerTurnOfTheEventLoop', function() {
264
- var order = [];
265
- function go() {
266
- order.push(order.length / 2);
267
- asyncRun(function() {
268
- order.push('-');
269
- });
270
- }
271
-
272
- scheduleAction('', go);
273
- scheduleAction('', go);
274
- return waitForIdle().then(function() {
275
- assert.deepEqual([0, '-', 1, '-'], order);
276
- })
277
- });
278
-
279
- it('firstScheduledTaskIsWithinACallback', function() {
280
- promise.fulfilled().then(function() {
281
- schedule('a');
282
- schedule('b');
283
- schedule('c');
284
- }).then(function() {
285
- assertFlowHistory('a', 'b', 'c');
286
- });
287
- return waitForIdle();
288
- });
289
-
290
- it('newTasksAddedWhileWaitingOnTaskReturnedPromise1', function() {
291
- scheduleAction('a', function() {
292
- var d = promise.defer();
293
- setTimeout(function() {
294
- schedule('c');
295
- d.fulfill();
296
- }, 10);
297
- return d.promise;
298
- });
299
- schedule('b');
300
- return waitForIdle().then(function() {
301
- assertFlowHistory('a', 'b', 'c');
302
- });
303
- });
304
-
305
- it('newTasksAddedWhileWaitingOnTaskReturnedPromise2', function() {
306
- scheduleAction('a', function() {
307
- var d = promise.defer();
308
- setTimeout(function() {
309
- schedule('c');
310
- asyncRun(d.fulfill);
311
- }, 10);
312
- return d.promise;
313
- });
314
- schedule('b');
315
- return waitForIdle().then(function() {
316
- assertFlowHistory('a', 'c', 'b');
317
- });
318
- });
319
- });
320
-
321
- describe('testFraming', function() {
322
- it('callbacksRunInANewFrame', function() {
323
- schedule('a').then(function() {
324
- schedule('c');
325
- });
326
- schedule('b');
327
- return waitForIdle().then(function() {
328
- assertFlowHistory('a', 'c', 'b');
329
- });
330
- });
331
-
332
- it('lotsOfNesting', function() {
333
- schedule('a').then(function() {
334
- schedule('c').then(function() {
335
- schedule('e').then(function() {
336
- schedule('g');
337
- });
338
- schedule('f');
339
- });
340
- schedule('d');
341
- });
342
- schedule('b');
343
-
344
- return waitForIdle().then(function() {
345
- assertFlowHistory('a', 'c', 'e', 'g', 'f', 'd', 'b');
346
- });
347
- });
348
-
349
- it('callbackReturnsPromiseThatDependsOnATask_1', function() {
350
- schedule('a').then(function() {
351
- schedule('b');
352
- return promise.delayed(5).then(function() {
353
- return schedule('c');
354
- });
355
- });
356
- schedule('d');
357
-
358
- return waitForIdle().then(function() {
359
- assertFlowHistory('a', 'b', 'c', 'd');
360
- });
361
- });
362
-
363
- it('callbackReturnsPromiseThatDependsOnATask_2', function() {
364
- schedule('a').then(function() {
365
- schedule('b');
366
- return promise.delayed(5).
367
- then(function() { return promise.delayed(5) }).
368
- then(function() { return promise.delayed(5) }).
369
- then(function() { return promise.delayed(5) }).
370
- then(function() { return schedule('c'); });
371
- });
372
- schedule('d');
373
-
374
- return waitForIdle().then(function() {
375
- assertFlowHistory('a', 'b', 'c', 'd');
376
- });
377
- });
378
-
379
- it('eachCallbackWaitsForAllScheduledTasksToComplete', function() {
380
- schedule('a').
381
- then(function() {
382
- schedule('b');
383
- schedule('c');
384
- }).
385
- then(function() {
386
- schedule('d');
387
- });
388
- schedule('e');
389
-
390
- return waitForIdle().then(function() {
391
- assertFlowHistory('a', 'b', 'c', 'd', 'e');
392
- });
393
- });
394
-
395
- it('eachCallbackWaitsForReturnTasksToComplete', function() {
396
- schedule('a').
397
- then(function() {
398
- schedule('b');
399
- return schedule('c');
400
- }).
401
- then(function() {
402
- schedule('d');
403
- });
404
- schedule('e');
405
-
406
- return waitForIdle().then(function() {
407
- assertFlowHistory('a', 'b', 'c', 'd', 'e');
408
- });
409
- });
410
-
411
- it('callbacksOnAResolvedPromiseInsertIntoTheCurrentFlow', function() {
412
- promise.fulfilled().then(function() {
413
- schedule('b');
414
- });
415
- schedule('a');
416
-
417
- return waitForIdle().then(function() {
418
- assertFlowHistory('b', 'a');
419
- });
420
- });
421
-
422
- it('callbacksInterruptTheFlowWhenPromiseIsResolved', function() {
423
- schedule('a').then(function() {
424
- schedule('c');
425
- });
426
- schedule('b');
427
-
428
- return waitForIdle().then(function() {
429
- assertFlowHistory('a', 'c', 'b');
430
- });
431
- });
432
-
433
- it('allCallbacksInAFrameAreScheduledWhenPromiseIsResolved', function() {
434
- var a = schedule('a');
435
- a.then(function() { schedule('b'); });
436
- schedule('c');
437
- a.then(function() { schedule('d'); });
438
- schedule('e');
439
-
440
- return waitForIdle().then(function() {
441
- assertFlowHistory('a', 'b', 'c', 'd', 'e');
442
- });
443
- });
444
-
445
- it('tasksScheduledInInActiveFrameDoNotGetPrecedence', function() {
446
- var d = promise.fulfilled();
447
- schedule('a');
448
- schedule('b');
449
- d.then(function() { schedule('c'); });
450
-
451
- return waitForIdle().then(function() {
452
- assertFlowHistory('a', 'b', 'c');
453
- });
454
- });
455
-
456
- it('tasksScheduledInAFrameGetPrecedence_1', function() {
457
- var a = schedule('a');
458
- schedule('b').then(function() {
459
- a.then(function() {
460
- schedule('c');
461
- schedule('d');
462
- });
463
- var e = schedule('e');
464
- a.then(function() {
465
- schedule('f');
466
- e.then(function() {
467
- schedule('g');
468
- });
469
- schedule('h');
470
- });
471
- schedule('i');
472
- });
473
- schedule('j');
474
-
475
- return waitForIdle().then(function() {
476
- assertFlowHistory('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');
477
- });
478
- });
479
- });
480
-
481
- describe('testErrorHandling', function() {
482
- it('thrownErrorsArePassedToTaskErrback', function() {
483
- scheduleAction('function that throws', throwStubError).
484
- then(fail, assertIsStubError);
485
- return waitForIdle();
486
- });
487
-
488
- it('thrownErrorsPropagateThroughPromiseChain', function() {
489
- scheduleAction('function that throws', throwStubError).
490
- then(fail).
491
- then(fail, assertIsStubError);
492
- return waitForIdle();
493
- });
494
-
495
- it('catchesErrorsFromFailedTasksInAFrame', function() {
496
- schedule('a').then(function() {
497
- schedule('b');
498
- scheduleAction('function that throws', throwStubError);
499
- }).
500
- then(fail, assertIsStubError);
501
- return waitForIdle();
502
- });
503
-
504
- it('abortsIfOnlyTaskReturnsAnUnhandledRejection', function() {
505
- scheduleAction('function that returns rejected promise', function() {
506
- return promise.rejected(new StubError);
507
- });
508
- return waitForAbort().then(assertIsStubError);
509
- });
510
-
511
- it('abortsIfThereIsAnUnhandledRejection', function() {
512
- promise.rejected(new StubError);
513
- schedule('this should not run');
514
- return waitForAbort().
515
- then(assertIsStubError).
516
- then(function() {
517
- assertFlowHistory(/* none */);
518
- });
519
- });
520
-
521
- it('abortsSequenceIfATaskFails', function() {
522
- schedule('a');
523
- schedule('b');
524
- scheduleAction('c', throwStubError);
525
- schedule('d'); // Should never execute.
526
-
527
- return waitForAbort().
528
- then(assertIsStubError).
529
- then(function() {
530
- assertFlowHistory('a', 'b', 'c');
531
- });
532
- });
533
-
534
- it('abortsFromUnhandledFramedTaskFailures_1', function() {
535
- schedule('outer task').then(function() {
536
- scheduleAction('inner task', throwStubError);
537
- });
538
- schedule('this should not run');
539
- return waitForAbort().
540
- then(assertIsStubError).
541
- then(function() {
542
- assertFlowHistory('outer task', 'inner task');
543
- });
544
- });
545
-
546
- it('abortsFromUnhandledFramedTaskFailures_2', function() {
547
- schedule('a').then(function() {
548
- schedule('b').then(function() {
549
- scheduleAction('c', throwStubError);
550
- // This should not execute.
551
- schedule('d');
552
- });
553
- });
554
-
555
- return waitForAbort().
556
- then(assertIsStubError).
557
- then(function() {
558
- assertFlowHistory('a', 'b', 'c');
559
- });
560
- });
561
-
562
- it('abortsWhenErrorBubblesUpFromFullyResolvingAnObject', function() {
563
- var callback = sinon.spy();
564
-
565
- scheduleAction('', function() {
566
- var obj = {'foo': promise.rejected(new StubError)};
567
- return promise.fullyResolved(obj).then(callback);
568
- });
569
-
570
- return waitForAbort().
571
- then(assertIsStubError).
572
- then(() => assert(!callback.called));
573
- });
574
-
575
- it('abortsWhenErrorBubblesUpFromFullyResolvingAnObject_withCallback', function() {
576
- var callback1 = sinon.spy();
577
- var callback2 = sinon.spy();
578
-
579
- scheduleAction('', function() {
580
- var obj = {'foo': promise.rejected(new StubError)};
581
- return promise.fullyResolved(obj).then(callback1);
582
- }).then(callback2);
583
-
584
- return waitForAbort().
585
- then(assertIsStubError).
586
- then(() => assert(!callback1.called)).
587
- then(() => assert(!callback2.called));
588
- });
589
-
590
- it('canCatchErrorsFromNestedTasks', function() {
591
- var errback = sinon.spy();
592
- schedule('a').
593
- then(function() {
594
- return scheduleAction('b', throwStubError);
595
- }).
596
- catch(errback);
597
- return waitForIdle().then(function() {
598
- assert(errback.called);
599
- assertIsStubError(errback.getCall(0).args[0]);
600
- });
601
- });
602
-
603
- it('nestedCommandFailuresCanBeCaughtAndSuppressed', function() {
604
- var errback = sinon.spy();
605
- schedule('a').then(function() {
606
- return schedule('b').then(function() {
607
- return schedule('c').then(function() {
608
- throw new StubError;
609
- });
610
- });
611
- }).catch(errback);
612
- schedule('d');
613
- return waitForIdle().
614
- then(function() {
615
- assert(errback.called);
616
- assertIsStubError(errback.getCall(0).args[0]);
617
- assertFlowHistory('a', 'b', 'c', 'd');
618
- });
619
- });
620
-
621
- it('aTaskWithAnUnhandledPromiseRejection', function() {
622
- schedule('a');
623
- scheduleAction('sub-tasks', function() {
624
- promise.rejected(new StubError);
625
- });
626
- schedule('should never run');
627
-
628
- return waitForAbort().
629
- then(assertIsStubError).
630
- then(function() {
631
- assertFlowHistory('a', 'sub-tasks');
632
- });
633
- });
634
-
635
- it('aTaskThatReutrnsARejectedPromise', function() {
636
- schedule('a');
637
- scheduleAction('sub-tasks', function() {
638
- return promise.rejected(new StubError);
639
- });
640
- schedule('should never run');
641
-
642
- return waitForAbort().
643
- then(assertIsStubError).
644
- then(function() {
645
- assertFlowHistory('a', 'sub-tasks');
646
- });
647
- });
648
-
649
- it('discardsSubtasksIfTaskThrows', function() {
650
- var pair = callbackPair(null, assertIsStubError);
651
- scheduleAction('a', function() {
652
- schedule('b');
653
- schedule('c');
654
- throwStubError();
655
- }).then(pair.callback, pair.errback);
656
- schedule('d');
657
-
658
- return waitForIdle().
659
- then(pair.assertErrback).
660
- then(function() {
661
- assertFlowHistory('a', 'd');
662
- });
663
- });
664
-
665
- it('discardsRemainingSubtasksIfASubtaskFails', function() {
666
- var pair = callbackPair(null, assertIsStubError);
667
- scheduleAction('a', function() {
668
- schedule('b');
669
- scheduleAction('c', throwStubError);
670
- schedule('d');
671
- }).then(pair.callback, pair.errback);
672
- schedule('e');
673
-
674
- return waitForIdle().
675
- then(pair.assertErrback).
676
- then(function() {
677
- assertFlowHistory('a', 'b', 'c', 'e');
678
- });
679
- });
680
- });
681
-
682
- describe('testTryModelingFinally', function() {
683
- it('happyPath', function() {
684
- /* Model:
685
- try {
686
- doFoo();
687
- doBar();
688
- } finally {
689
- doBaz();
690
- }
691
- */
692
- schedulePush('foo').
693
- then(() => schedulePush('bar')).
694
- finally(() => schedulePush('baz'));
695
- return waitForIdle().then(assertingMessages('foo', 'bar', 'baz'));
696
- });
697
-
698
- it('firstTryFails', function() {
699
- /* Model:
700
- try {
701
- doFoo();
702
- doBar();
703
- } finally {
704
- doBaz();
705
- }
706
- */
707
-
708
- scheduleAction('doFoo and throw', function() {
709
- messages.push('foo');
710
- throw new StubError;
711
- }).
712
- then(function() { schedulePush('bar'); }).
713
- finally(function() { schedulePush('baz'); });
714
-
715
- return waitForAbort().
716
- then(assertIsStubError).
717
- then(assertingMessages('foo', 'baz'));
718
- });
719
-
720
- it('secondTryFails', function() {
721
- /* Model:
722
- try {
723
- doFoo();
724
- doBar();
725
- } finally {
726
- doBaz();
727
- }
728
- */
729
-
730
- schedulePush('foo').
731
- then(function() {
732
- return scheduleAction('doBar and throw', function() {
733
- messages.push('bar');
734
- throw new StubError;
735
- });
736
- }).
737
- finally(function() {
738
- return schedulePush('baz');
739
- });
740
- return waitForAbort().
741
- then(assertIsStubError).
742
- then(assertingMessages('foo', 'bar', 'baz'));
743
- });
744
- });
745
-
746
- describe('testTaskCallbacksInterruptFlow', function() {
747
- it('(base case)', function() {
748
- schedule('a').then(function() {
749
- schedule('b');
750
- });
751
- schedule('c');
752
- return waitForIdle().then(function() {
753
- assertFlowHistory('a', 'b', 'c');
754
- });
755
- });
756
-
757
- it('taskDependsOnImmediatelyFulfilledPromise', function() {
758
- scheduleAction('a', function() {
759
- return promise.fulfilled();
760
- }).then(function() {
761
- schedule('b');
762
- });
763
- schedule('c');
764
- return waitForIdle().then(function() {
765
- assertFlowHistory('a', 'b', 'c');
766
- });
767
- });
768
-
769
- it('taskDependsOnPreviouslyFulfilledPromise', function() {
770
- var aPromise = promise.fulfilled(123);
771
- scheduleAction('a', function() {
772
- return aPromise;
773
- }).then(function(value) {
774
- assert.equal(123, value);
775
- schedule('b');
776
- });
777
- schedule('c');
778
- return waitForIdle().then(function() {
779
- assertFlowHistory('a', 'b', 'c');
780
- });
781
- });
782
-
783
- it('taskDependsOnAsyncPromise', function() {
784
- scheduleAction('a', function() {
785
- return promise.delayed(25);
786
- }).then(function() {
787
- schedule('b');
788
- });
789
- schedule('c');
790
- return waitForIdle().then(function() {
791
- assertFlowHistory('a', 'b', 'c');
792
- });
793
- });
794
-
795
- it('promiseChainedToTaskInterruptFlow', function() {
796
- schedule('a').then(function() {
797
- return promise.fulfilled();
798
- }).then(function() {
799
- return promise.fulfilled();
800
- }).then(function() {
801
- schedule('b');
802
- });
803
- schedule('c');
804
- return waitForIdle().then(function() {
805
- assertFlowHistory('a', 'b', 'c');
806
- });
807
- });
808
-
809
- it('nestedTaskCallbacksInterruptFlowWhenResolved', function() {
810
- schedule('a').then(function() {
811
- schedule('b').then(function() {
812
- schedule('c');
813
- });
814
- });
815
- schedule('d');
816
- return waitForIdle().then(function() {
817
- assertFlowHistory('a', 'b', 'c', 'd');
818
- });
819
- });
820
- });
821
-
822
- describe('testDelayedNesting', function() {
823
-
824
- it('1', function() {
825
- var a = schedule('a');
826
- schedule('b').then(function() {
827
- a.then(function() { schedule('c'); });
828
- schedule('d');
829
- });
830
- schedule('e');
831
-
832
- return waitForIdle().then(function() {
833
- assertFlowHistory('a', 'b', 'c', 'd', 'e');
834
- });
835
- });
836
-
837
- it('2', function() {
838
- var a = schedule('a');
839
- schedule('b').then(function() {
840
- a.then(function() { schedule('c'); });
841
- schedule('d');
842
- a.then(function() { schedule('e'); });
843
- });
844
- schedule('f');
845
-
846
- return waitForIdle().then(function() {
847
- assertFlowHistory('a', 'b', 'c', 'd', 'e', 'f');
848
- });
849
- });
850
-
851
- it('3', function() {
852
- var a = schedule('a');
853
- schedule('b').then(function() {
854
- a.then(function() { schedule('c'); });
855
- a.then(function() { schedule('d'); });
856
- });
857
- schedule('e');
858
-
859
- return waitForIdle().then(function() {
860
- assertFlowHistory('a', 'b', 'c', 'd', 'e');
861
- });
862
- });
863
-
864
- it('4', function() {
865
- var a = schedule('a');
866
- schedule('b').then(function() {
867
- a.then(function() { schedule('c'); }).then(function() {
868
- schedule('d');
869
- });
870
- a.then(function() { schedule('e'); });
871
- });
872
- schedule('f');
873
-
874
- return waitForIdle().then(function() {
875
- assertFlowHistory('a', 'b', 'c', 'd', 'e', 'f');
876
- });
877
- });
878
-
879
- it('5', function() {
880
- var a = schedule('a');
881
- schedule('b').then(function() {
882
- var c;
883
- a.then(function() { c = schedule('c'); }).then(function() {
884
- schedule('d');
885
- a.then(function() { schedule('e'); });
886
- c.then(function() { schedule('f'); });
887
- schedule('g');
888
- });
889
- a.then(function() { schedule('h'); });
890
- });
891
- schedule('i');
892
-
893
- return waitForIdle().then(function() {
894
- assertFlowHistory('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');
895
- });
896
- });
897
- });
898
-
899
- describe('testWaiting', function() {
900
- it('onAConditionThatIsAlwaysTrue', function() {
901
- scheduleWait(function() { return true;}, 0, 'waiting on true');
902
- return waitForIdle().then(function() {
903
- assertFlowHistory('0: waiting on true');
904
- });
905
- });
906
-
907
- it('aSimpleCountingCondition', function() {
908
- var count = 0;
909
- scheduleWait(function() {
910
- return ++count == 3;
911
- }, 100, 'counting to 3');
912
-
913
- return waitForIdle().then(function() {
914
- assert.equal(3, count);
915
- });
916
- });
917
-
918
- it('aConditionThatReturnsAPromise', function() {
919
- var d = new promise.Deferred();
920
- var count = 0;
921
-
922
- scheduleWait(function() {
923
- count += 1;
924
- return d.promise;
925
- }, 0, 'waiting for promise');
926
-
927
- return timeout(50).then(function() {
928
- assert.equal(1, count);
929
- d.fulfill(123);
930
- return waitForIdle();
931
- });
932
- });
933
-
934
- it('aConditionThatReturnsAPromise_2', function() {
935
- var count = 0;
936
- scheduleWait(function() {
937
- return promise.fulfilled(++count == 3);
938
- }, 100, 'waiting for promise');
939
-
940
- return waitForIdle().then(function() {
941
- assert.equal(3, count);
942
- });
943
- });
944
-
945
- it('aConditionThatReturnsATaskResult', function() {
946
- var count = 0;
947
- scheduleWait(function() {
948
- return scheduleAction('increment count', function() {
949
- return ++count == 3;
950
- });
951
- }, 100, 'counting to 3');
952
- schedule('post wait');
953
-
954
- return waitForIdle().then(function() {
955
- assert.equal(3, count);
956
- assertFlowHistory(
957
- '0: counting to 3', 'increment count',
958
- '1: counting to 3', 'increment count',
959
- '2: counting to 3', 'increment count',
960
- 'post wait');
961
- });
962
- });
963
-
964
- it('conditionContainsASubtask', function() {
965
- var count = 0;
966
- scheduleWait(function() {
967
- schedule('sub task');
968
- return ++count == 3;
969
- }, 100, 'counting to 3');
970
- schedule('post wait');
971
-
972
- return waitForIdle().then(function() {
973
- assert.equal(3, count);
974
- assertFlowHistory(
975
- '0: counting to 3', 'sub task',
976
- '1: counting to 3', 'sub task',
977
- '2: counting to 3', 'sub task',
978
- 'post wait');
979
- });
980
- });
981
-
982
- it('cancelsWaitIfScheduledTaskFails', function() {
983
- var pair = callbackPair(null, assertIsStubError);
984
- scheduleWait(function() {
985
- scheduleAction('boom', throwStubError);
986
- schedule('this should not run');
987
- return true;
988
- }, 100, 'waiting to go boom').then(pair.callback, pair.errback);
989
- schedule('post wait');
990
-
991
- return waitForIdle().
992
- then(pair.assertErrback).
993
- then(function() {
994
- assertFlowHistory(
995
- '0: waiting to go boom', 'boom',
996
- 'post wait');
997
- });
998
- });
999
-
1000
- it('failsIfConditionThrows', function() {
1001
- var callbacks = callbackPair(null, assertIsStubError);
1002
- scheduleWait(throwStubError, 0, 'goes boom').
1003
- then(callbacks.callback, callbacks.errback);
1004
- schedule('post wait');
1005
-
1006
- return waitForIdle().
1007
- then(callbacks.assertErrback).
1008
- then(function() {
1009
- assertFlowHistory('0: goes boom', 'post wait');
1010
- });
1011
- });
1012
-
1013
- it('failsIfConditionReturnsARejectedPromise', function() {
1014
- var callbacks = callbackPair(null, assertIsStubError);
1015
- scheduleWait(function() {
1016
- return promise.rejected(new StubError);
1017
- }, 0, 'goes boom').then(callbacks.callback, callbacks.errback);
1018
- schedule('post wait');
1019
-
1020
- return waitForIdle().
1021
- then(callbacks.assertErrback).
1022
- then(function() {
1023
- assertFlowHistory('0: goes boom', 'post wait');
1024
- });
1025
- });
1026
-
1027
- it('failsIfConditionHasUnhandledRejection', function() {
1028
- var callbacks = callbackPair(null, assertIsStubError);
1029
- scheduleWait(function() {
1030
- promise.controlFlow().execute(throwStubError);
1031
- }, 0, 'goes boom').then(callbacks.callback, callbacks.errback);
1032
- schedule('post wait');
1033
-
1034
- return waitForIdle().
1035
- then(callbacks.assertErrback).
1036
- then(function() {
1037
- assertFlowHistory('0: goes boom', 'post wait');
1038
- });
1039
- });
1040
-
1041
- it('failsIfConditionHasAFailedSubtask', function() {
1042
- var callbacks = callbackPair(null, assertIsStubError);
1043
- var count = 0;
1044
- scheduleWait(function() {
1045
- scheduleAction('maybe throw', function() {
1046
- if (++count == 2) {
1047
- throw new StubError;
1048
- }
1049
- });
1050
- }, 100, 'waiting').then(callbacks.callback, callbacks.errback);
1051
- schedule('post wait');
1052
-
1053
- return waitForIdle().then(function() {
1054
- assert.equal(2, count);
1055
- assertFlowHistory(
1056
- '0: waiting', 'maybe throw',
1057
- '1: waiting', 'maybe throw',
1058
- 'post wait');
1059
- });
1060
- });
1061
-
1062
- it('pollingLoopWaitsForAllScheduledTasksInCondition', function() {
1063
- var count = 0;
1064
- scheduleWait(function() {
1065
- scheduleAction('increment count', function() { ++count; });
1066
- return count >= 3;
1067
- }, 100, 'counting to 3');
1068
- schedule('post wait');
1069
-
1070
- return waitForIdle().then(function() {
1071
- assert.equal(4, count);
1072
- assertFlowHistory(
1073
- '0: counting to 3', 'increment count',
1074
- '1: counting to 3', 'increment count',
1075
- '2: counting to 3', 'increment count',
1076
- '3: counting to 3', 'increment count',
1077
- 'post wait');
1078
- });
1079
- });
1080
-
1081
- it('waitsForeverOnAZeroTimeout', function() {
1082
- var done = false;
1083
- setTimeout(function() {
1084
- done = true;
1085
- }, 150);
1086
- var waitResult = scheduleWait(function() {
1087
- return done;
1088
- }, 0);
1089
-
1090
- return timeout(75).then(function() {
1091
- assert.ok(!done);
1092
- return timeout(100);
1093
- }).then(function() {
1094
- assert.ok(done);
1095
- return waitResult;
1096
- });
1097
- });
1098
-
1099
- it('waitsForeverIfTimeoutOmitted', function() {
1100
- var done = false;
1101
- setTimeout(function() {
1102
- done = true;
1103
- }, 150);
1104
- var waitResult = scheduleWait(function() {
1105
- return done;
1106
- });
1107
-
1108
- return timeout(75).then(function() {
1109
- assert.ok(!done);
1110
- return timeout(100);
1111
- }).then(function() {
1112
- assert.ok(done);
1113
- return waitResult;
1114
- });
1115
- });
1116
-
1117
- it('timesOut_nonZeroTimeout', function() {
1118
- var count = 0;
1119
- scheduleWait(function() {
1120
- count += 1;
1121
- var ms = count === 2 ? 65 : 5;
1122
- return promise.delayed(ms).then(function() {
1123
- return false;
1124
- });
1125
- }, 60, 'counting to 3');
1126
- return waitForAbort().then(function(e) {
1127
- switch (count) {
1128
- case 1:
1129
- assertFlowHistory('0: counting to 3');
1130
- break;
1131
- case 2:
1132
- assertFlowHistory('0: counting to 3', '1: counting to 3');
1133
- break;
1134
- default:
1135
- fail('unexpected polling count: ' + count);
1136
- }
1137
- assert.ok(e instanceof TimeoutError, 'Unexpected error: ' + e);
1138
- assert.ok(
1139
- /^counting to 3\nWait timed out after \d+ms$/.test(e.message));
1140
- });
1141
- });
1142
-
1143
- it('shouldFailIfConditionReturnsARejectedPromise', function() {
1144
- scheduleWait(function() {
1145
- return promise.rejected(new StubError);
1146
- }, 100, 'returns rejected promise on first pass');
1147
- return waitForAbort().then(assertIsStubError);
1148
- });
1149
-
1150
- it('scheduleWithIntermittentWaits', function() {
1151
- schedule('a');
1152
- scheduleWait(function() { return true; }, 0, 'wait 1');
1153
- schedule('b');
1154
- scheduleWait(function() { return true; }, 0, 'wait 2');
1155
- schedule('c');
1156
- scheduleWait(function() { return true; }, 0, 'wait 3');
1157
-
1158
- return waitForIdle().then(function() {
1159
- assertFlowHistory('a', '0: wait 1', 'b', '0: wait 2', 'c', '0: wait 3');
1160
- });
1161
- });
1162
-
1163
- it('scheduleWithIntermittentAndNestedWaits', function() {
1164
- schedule('a');
1165
- scheduleWait(function() { return true; }, 0, 'wait 1').
1166
- then(function() {
1167
- schedule('d');
1168
- scheduleWait(function() { return true; }, 0, 'wait 2');
1169
- schedule('e');
1170
- });
1171
- schedule('b');
1172
- scheduleWait(function() { return true; }, 0, 'wait 3');
1173
- schedule('c');
1174
- scheduleWait(function() { return true; }, 0, 'wait 4');
1175
-
1176
- return waitForIdle().then(function() {
1177
- assertFlowHistory(
1178
- 'a', '0: wait 1', 'd', '0: wait 2', 'e', 'b', '0: wait 3', 'c',
1179
- '0: wait 4');
1180
- });
1181
- });
1182
-
1183
- it('requiresConditionToBeAPromiseOrFunction', function() {
1184
- assert.throws(function() {
1185
- flow.wait(1234, 0);
1186
- });
1187
- flow.wait(function() { return true;}, 0);
1188
- flow.wait(promise.fulfilled(), 0);
1189
- return waitForIdle();
1190
- });
1191
-
1192
- it('promiseThatDoesNotResolveBeforeTimeout', function() {
1193
- var d = promise.defer();
1194
- flow.wait(d.promise, 5).then(fail, function(e) {
1195
- assert.ok(e instanceof TimeoutError, 'Unexpected error: ' + e);
1196
- assert.ok(
1197
- /Timed out waiting for promise to resolve after \d+ms/
1198
- .test(e.message),
1199
- 'unexpected error message: ' + e.message);
1200
- });
1201
- return waitForIdle();
1202
- });
1203
-
1204
- it('unboundedWaitOnPromiseResolution', function() {
1205
- var messages = [];
1206
- var d = promise.defer();
1207
- var waitResult = flow.wait(d.promise).then(function(value) {
1208
- messages.push('b');
1209
- assert.equal(1234, value);
1210
- });
1211
- setTimeout(function() {
1212
- messages.push('a');
1213
- }, 5);
1214
-
1215
- timeout(10).then(function() {
1216
- assert.deepEqual(['a'], messages);
1217
- d.fulfill(1234);
1218
- return waitResult;
1219
- }).then(function() {
1220
- assert.deepEqual(['a', 'b'], messages);
1221
- });
1222
-
1223
- return waitForIdle();
1224
- });
1225
- });
1226
-
1227
- describe('testSubtasks', function() {
1228
- it('(base case)', function() {
1229
- schedule('a');
1230
- scheduleAction('sub-tasks', function() {
1231
- schedule('c');
1232
- schedule('d');
1233
- });
1234
- schedule('b');
1235
-
1236
- return waitForIdle().then(function() {
1237
- assertFlowHistory('a', 'sub-tasks', 'c', 'd', 'b');
1238
- });
1239
- });
1240
-
1241
- it('nesting', function() {
1242
- schedule('a');
1243
- scheduleAction('sub-tasks', function() {
1244
- schedule('b');
1245
- scheduleAction('sub-sub-tasks', function() {
1246
- schedule('c');
1247
- schedule('d');
1248
- });
1249
- schedule('e');
1250
- });
1251
- schedule('f');
1252
-
1253
- return waitForIdle().then(function() {
1254
- assertFlowHistory(
1255
- 'a', 'sub-tasks', 'b', 'sub-sub-tasks', 'c', 'd', 'e', 'f');
1256
- });
1257
- });
1258
-
1259
- it('taskReturnsSubTaskResult_1', function() {
1260
- schedule('a');
1261
- scheduleAction('sub-tasks', function() {
1262
- return schedule('c');
1263
- });
1264
- schedule('b');
1265
-
1266
- return waitForIdle().then(function() {
1267
- assertFlowHistory('a', 'sub-tasks', 'c', 'b');
1268
- });
1269
- });
1270
-
1271
- it('taskReturnsSubTaskResult_2', function() {
1272
- let pair = callbackPair((value) => assert.equal(123, value));
1273
- schedule('a');
1274
- schedule('sub-tasks', promise.fulfilled(123)).then(pair.callback);
1275
- schedule('b');
1276
-
1277
- return waitForIdle().then(function() {
1278
- assertFlowHistory('a', 'sub-tasks','b');
1279
- pair.assertCallback();
1280
- });
1281
- });
1282
-
1283
- it('taskReturnsPromiseThatDependsOnSubtask_1', function() {
1284
- scheduleAction('a', function() {
1285
- return promise.delayed(10).then(function() {
1286
- schedule('b');
1287
- });
1288
- });
1289
- schedule('c');
1290
- return waitForIdle().then(function() {
1291
- assertFlowHistory('a', 'b', 'c');
1292
- });
1293
- });
1294
-
1295
- it('taskReturnsPromiseThatDependsOnSubtask_2', function() {
1296
- scheduleAction('a', function() {
1297
- return promise.fulfilled().then(function() {
1298
- schedule('b');
1299
- });
1300
- });
1301
- schedule('c');
1302
- return waitForIdle().then(function() {
1303
- assertFlowHistory('a', 'b', 'c');
1304
- });
1305
- });
1306
-
1307
- it('taskReturnsPromiseThatDependsOnSubtask_3', function() {
1308
- scheduleAction('a', function() {
1309
- return promise.delayed(10).then(function() {
1310
- return schedule('b');
1311
- });
1312
- });
1313
- schedule('c');
1314
- return waitForIdle().then(function() {
1315
- assertFlowHistory('a', 'b', 'c');
1316
- });
1317
- });
1318
-
1319
- it('taskReturnsPromiseThatDependsOnSubtask_4', function() {
1320
- scheduleAction('a', function() {
1321
- return promise.delayed(5).then(function() {
1322
- return promise.delayed(5).then(function() {
1323
- return schedule('b');
1324
- });
1325
- });
1326
- });
1327
- schedule('c');
1328
- return waitForIdle().then(function() {
1329
- assertFlowHistory('a', 'b', 'c');
1330
- });
1331
- });
1332
-
1333
- it('taskReturnsPromiseThatDependsOnSubtask_5', function() {
1334
- scheduleAction('a', function() {
1335
- return promise.delayed(5).then(function() {
1336
- return promise.delayed(5).then(function() {
1337
- return promise.delayed(5).then(function() {
1338
- return promise.delayed(5).then(function() {
1339
- return schedule('b');
1340
- });
1341
- });
1342
- });
1343
- });
1344
- });
1345
- schedule('c');
1346
- return waitForIdle().then(function() {
1347
- assertFlowHistory('a', 'b', 'c');
1348
- });
1349
- });
1350
-
1351
- it('taskReturnsPromiseThatDependsOnSubtask_6', function() {
1352
- scheduleAction('a', function() {
1353
- return promise.delayed(5).
1354
- then(function() { return promise.delayed(5) }).
1355
- then(function() { return promise.delayed(5) }).
1356
- then(function() { return promise.delayed(5) }).
1357
- then(function() { return schedule('b'); });
1358
- });
1359
- schedule('c');
1360
- return waitForIdle().then(function() {
1361
- assertFlowHistory('a', 'b', 'c');
1362
- });
1363
- });
1364
-
1365
- it('subTaskFails_1', function() {
1366
- schedule('a');
1367
- scheduleAction('sub-tasks', function() {
1368
- scheduleAction('sub-task that fails', throwStubError);
1369
- });
1370
- schedule('should never execute');
1371
-
1372
- return waitForAbort().
1373
- then(assertIsStubError).
1374
- then(function() {
1375
- assertFlowHistory('a', 'sub-tasks', 'sub-task that fails');
1376
- });
1377
- });
1378
-
1379
- it('subTaskFails_2', function() {
1380
- schedule('a');
1381
- scheduleAction('sub-tasks', function() {
1382
- return promise.rejected(new StubError);
1383
- });
1384
- schedule('should never execute');
1385
-
1386
- return waitForAbort().
1387
- then(assertIsStubError).
1388
- then(function() {
1389
- assertFlowHistory('a', 'sub-tasks');
1390
- });
1391
- });
1392
-
1393
- it('subTaskFails_3', function() {
1394
- var callbacks = callbackPair(null, assertIsStubError);
1395
-
1396
- schedule('a');
1397
- scheduleAction('sub-tasks', function() {
1398
- return promise.rejected(new StubError);
1399
- }).then(callbacks.callback, callbacks.errback);
1400
- schedule('b');
1401
-
1402
- return waitForIdle().
1403
- then(function() {
1404
- assertFlowHistory('a', 'sub-tasks', 'b');
1405
- callbacks.assertErrback();
1406
- });
1407
- });
1408
- });
1409
-
1410
- describe('testEventLoopWaitsOnPendingPromiseRejections', function() {
1411
- it('oneRejection', function() {
1412
- var d = new promise.Deferred;
1413
- scheduleAction('one', function() {
1414
- return d.promise;
1415
- });
1416
- scheduleAction('two', function() {});
1417
-
1418
- return timeout(50).then(function() {
1419
- assertFlowHistory('one');
1420
- d.reject(new StubError);
1421
- return waitForAbort();
1422
- }).
1423
- then(assertIsStubError).
1424
- then(function() {
1425
- assertFlowHistory('one');
1426
- });
1427
- });
1428
-
1429
- it('multipleRejections', function() {
1430
- var once = Error('once');
1431
- var twice = Error('twice');
1432
-
1433
- scheduleAction('one', function() {
1434
- promise.rejected(once);
1435
- promise.rejected(twice);
1436
- });
1437
- var twoResult = scheduleAction('two', function() {});
1438
-
1439
- flow.removeAllListeners(
1440
- promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION);
1441
- return new NativePromise(function(fulfill, reject) {
1442
- setTimeout(function() {
1443
- reject(Error('Should have reported the two errors by now'));
1444
- }, 50);
1445
- flow.on(
1446
- promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION,
1447
- fulfill);
1448
- }).then(function(e) {
1449
- assert.ok(e instanceof promise.MultipleUnhandledRejectionError,
1450
- 'Not a MultipleUnhandledRejectionError');
1451
- let errors = Array.from(e.errors);
1452
- assert.deepEqual([once, twice], errors);
1453
- assertFlowHistory('one');
1454
- });
1455
- });
1456
- });
1457
-
1458
- describe('testCancelsPromiseReturnedByCallbackIfFrameFails', function() {
1459
- it('promiseCallback', function() {
1460
- var chainPair = callbackPair(null, assertIsStubError);
1461
- var deferredPair = callbackPair(null, function(e) {
1462
- assert.equal('CancellationError: StubError', e.toString(),
1463
- 'callback result should be cancelled');
1464
- });
1465
-
1466
- var d = new promise.Deferred();
1467
- d.promise.then(deferredPair.callback, deferredPair.errback);
1468
-
1469
- promise.fulfilled().
1470
- then(function() {
1471
- scheduleAction('boom', throwStubError);
1472
- schedule('this should not run');
1473
- return d.promise;
1474
- }).
1475
- then(chainPair.callback, chainPair.errback);
1476
-
1477
- return waitForIdle().then(function() {
1478
- assertFlowHistory('boom');
1479
- chainPair.assertErrback('chain errback not invoked');
1480
- deferredPair.assertErrback('deferred errback not invoked');
1481
- });
1482
- });
1483
-
1484
- it('taskCallback', function() {
1485
- var chainPair = callbackPair(null, assertIsStubError);
1486
- var deferredPair = callbackPair(null, function(e) {
1487
- assert.equal('CancellationError: StubError', e.toString(),
1488
- 'callback result should be cancelled');
1489
- });
1490
-
1491
- var d = new promise.Deferred();
1492
- d.promise.then(deferredPair.callback, deferredPair.errback);
1493
-
1494
- schedule('a').
1495
- then(function() {
1496
- scheduleAction('boom', throwStubError);
1497
- schedule('this should not run');
1498
- return d.promise;
1499
- }).
1500
- then(chainPair.callback, chainPair.errback);
1501
-
1502
- return waitForIdle().then(function() {
1503
- assertFlowHistory('a', 'boom');
1504
- chainPair.assertErrback('chain errback not invoked');
1505
- deferredPair.assertErrback('deferred errback not invoked');
1506
- });
1507
- });
1508
- });
1509
-
1510
- it('testMaintainsOrderInCallbacksWhenATaskReturnsAPromise', function() {
1511
- schedule('__start__', promise.fulfilled()).
1512
- then(function() {
1513
- messages.push('a');
1514
- schedulePush('b');
1515
- messages.push('c');
1516
- }).
1517
- then(function() {
1518
- messages.push('d');
1519
- });
1520
- schedulePush('e');
1521
-
1522
- return waitForIdle().then(function() {
1523
- assertFlowHistory('__start__', 'b', 'e');
1524
- assertMessages('a', 'c', 'b', 'd', 'e');
1525
- });
1526
- });
1527
-
1528
- it('testOwningFlowIsActivatedForExecutingTasks', function() {
1529
- var defaultFlow = promise.controlFlow();
1530
- var order = [];
1531
-
1532
- promise.createFlow(function(flow) {
1533
- assertFlowIs(flow);
1534
- order.push(0);
1535
-
1536
- defaultFlow.execute(function() {
1537
- assertFlowIs(defaultFlow);
1538
- order.push(1);
1539
- });
1540
- });
1541
-
1542
- return waitForIdle().then(function() {
1543
- assertFlowIs(defaultFlow);
1544
- assert.deepEqual([0, 1], order);
1545
- });
1546
- });
1547
-
1548
- it('testCreateFlowReturnsPromisePairedWithCreatedFlow', function() {
1549
- return new NativePromise(function(fulfill, reject) {
1550
- var newFlow;
1551
- promise.createFlow(function(flow) {
1552
- newFlow = flow;
1553
- assertFlowIs(newFlow);
1554
- }).then(function() {
1555
- assertFlowIs(newFlow);
1556
- waitForIdle(newFlow).then(fulfill, reject);
1557
- });
1558
- });
1559
- });
1560
-
1561
- it('testDeferredFactoriesCreateForActiveFlow_defaultFlow', function() {
1562
- var e = Error();
1563
- var defaultFlow = promise.controlFlow();
1564
- promise.fulfilled().then(function() {
1565
- assertFlowIs(defaultFlow);
1566
- });
1567
- promise.rejected(e).then(null, function(err) {
1568
- assert.equal(e, err);
1569
- assertFlowIs(defaultFlow);
1570
- });
1571
- promise.defer().promise.then(function() {
1572
- assertFlowIs(defaultFlow);
1573
- });
1574
-
1575
- return waitForIdle();
1576
- });
1577
-
1578
- it('testDeferredFactoriesCreateForActiveFlow_newFlow', function() {
1579
- var e = Error();
1580
- var newFlow = new promise.ControlFlow;
1581
- newFlow.execute(function() {
1582
- promise.fulfilled().then(function() {
1583
- assertFlowIs(newFlow);
1584
- });
1585
-
1586
- promise.rejected(e).then(null, function(err) {
1587
- assert.equal(e, err);
1588
- assertFlowIs(newFlow);
1589
- });
1590
-
1591
- let d = promise.defer();
1592
- d.promise.then(function() {
1593
- assertFlowIs(newFlow);
1594
- });
1595
- d.fulfill();
1596
- }).then(function() {
1597
- assertFlowIs(newFlow);
1598
- });
1599
-
1600
- return waitForIdle(newFlow);
1601
- });
1602
-
1603
- it('testFlowsSynchronizeWithThemselvesNotEachOther', function() {
1604
- var defaultFlow = promise.controlFlow();
1605
- schedulePush('a', 'a');
1606
- promise.controlFlow().timeout(500);
1607
- schedulePush('b', 'b');
1608
-
1609
- promise.createFlow(function(flow2) {
1610
- assertFlowIs(flow2);
1611
- schedulePush('c', 'c');
1612
- schedulePush('d', 'd');
1613
- });
1614
-
1615
- return waitForIdle().then(function() {
1616
- assertMessages('a', 'c', 'd', 'b');
1617
- });
1618
- });
1619
-
1620
- it('testUnhandledErrorsAreReportedToTheOwningFlow', function() {
1621
- var error1 = Error('e1');
1622
- var error2 = Error('e2');
1623
-
1624
- var defaultFlow = promise.controlFlow();
1625
- defaultFlow.removeAllListeners('uncaughtException');
1626
-
1627
- var flow1Error = defer();
1628
- flow1Error.promise.then(function(value) {
1629
- assert.equal(error2, value);
1630
- });
1631
-
1632
- var flow2Error = defer();
1633
- flow2Error.promise.then(function(value) {
1634
- assert.equal(error1, value);
1635
- });
1636
-
1637
- promise.createFlow(function(flow) {
1638
- flow.once('uncaughtException', flow2Error.resolve);
1639
- promise.rejected(error1);
1640
-
1641
- defaultFlow.once('uncaughtException', flow1Error.resolve);
1642
- defaultFlow.execute(function() {
1643
- promise.rejected(error2);
1644
- });
1645
- });
1646
-
1647
- return NativePromise.all([flow1Error.promise, flow2Error.promise]);
1648
- });
1649
-
1650
- it('testCanSynchronizeFlowsByReturningPromiseFromOneToAnother', function() {
1651
- var flow1 = new promise.ControlFlow;
1652
- var flow1Done = defer();
1653
- flow1.once('idle', flow1Done.resolve);
1654
- flow1.once('uncaughtException', flow1Done.reject);
1655
-
1656
- var flow2 = new promise.ControlFlow;
1657
- var flow2Done = defer();
1658
- flow2.once('idle', flow2Done.resolve);
1659
- flow2.once('uncaughtException', flow2Done.reject);
1660
-
1661
- flow1.execute(function() {
1662
- schedulePush('a', 'a');
1663
- return promise.delayed(25);
1664
- }, 'start flow 1');
1665
-
1666
- flow2.execute(function() {
1667
- schedulePush('b', 'b');
1668
- schedulePush('c', 'c');
1669
- flow2.execute(function() {
1670
- return flow1.execute(function() {
1671
- schedulePush('d', 'd');
1672
- }, 'flow 1 task');
1673
- }, 'inject flow1 result into flow2');
1674
- schedulePush('e', 'e');
1675
- }, 'start flow 2');
1676
-
1677
- return NativePromise.all([flow1Done.promise, flow2Done.promise]).
1678
- then(function() {
1679
- assertMessages('a', 'b', 'c', 'd', 'e');
1680
- });
1681
- });
1682
-
1683
- it('testFramesWaitToCompleteForPendingRejections', function() {
1684
- return new NativePromise(function(fulfill, reject) {
1685
-
1686
- promise.controlFlow().execute(function() {
1687
- promise.rejected(new StubError);
1688
- }).then(fulfill, reject);
1689
-
1690
- }).
1691
- then(() => fail('expected to fail'), assertIsStubError);
1692
- });
1693
-
1694
- it('testSynchronizeErrorsPropagateToOuterFlow', function() {
1695
- var outerFlow = new promise.ControlFlow;
1696
- var innerFlow = new promise.ControlFlow;
1697
-
1698
- var block = defer();
1699
- innerFlow.execute(function() {
1700
- return block.promise;
1701
- }, 'block inner flow');
1702
-
1703
- outerFlow.execute(function() {
1704
- block.resolve();
1705
- return innerFlow.execute(function() {
1706
- promise.rejected(new StubError);
1707
- }, 'trigger unhandled rejection error');
1708
- }, 'run test');
1709
-
1710
- return NativePromise.all([
1711
- waitForIdle(innerFlow),
1712
- waitForAbort(outerFlow).then(assertIsStubError)
1713
- ]);
1714
- });
1715
-
1716
- it('testFailsIfErrbackThrows', function() {
1717
- promise.rejected('').then(null, throwStubError);
1718
- return waitForAbort().then(assertIsStubError);
1719
- });
1720
-
1721
- it('testFailsIfCallbackReturnsRejectedPromise', function() {
1722
- promise.fulfilled().then(function() {
1723
- return promise.rejected(new StubError);
1724
- });
1725
- return waitForAbort().then(assertIsStubError);
1726
- });
1727
-
1728
- it('testAbortsFrameIfTaskFails', function() {
1729
- promise.fulfilled().then(function() {
1730
- promise.controlFlow().execute(throwStubError);
1731
- });
1732
- return waitForAbort().then(assertIsStubError);
1733
- });
1734
-
1735
- it('testAbortsFramePromisedChainedFromTaskIsNotHandled', function() {
1736
- promise.fulfilled().then(function() {
1737
- promise.controlFlow().execute(function() {}).
1738
- then(throwStubError);
1739
- });
1740
- return waitForAbort().then(assertIsStubError);
1741
- });
1742
-
1743
- it('testTrapsChainedUnhandledRejectionsWithinAFrame', function() {
1744
- var pair = callbackPair(null, assertIsStubError);
1745
- promise.fulfilled().then(function() {
1746
- promise.controlFlow().execute(function() {}).
1747
- then(throwStubError);
1748
- }).then(pair.callback, pair.errback);
1749
-
1750
- return waitForIdle().then(pair.assertErrback);
1751
- });
1752
-
1753
- it('testCancelsRemainingTasksIfFrameThrowsDuringScheduling', function() {
1754
- var task1, task2;
1755
- var pair = callbackPair(null, assertIsStubError);
1756
- var flow = promise.controlFlow();
1757
- flow.execute(function() {
1758
- task1 = flow.execute(function() {});
1759
- task2 = flow.execute(function() {});
1760
- throw new StubError;
1761
- }).then(pair.callback, pair.errback);
1762
-
1763
- return waitForIdle().
1764
- then(pair.assertErrback).
1765
- then(function() {
1766
- pair = callbackPair();
1767
- return task1.then(pair.callback, pair.errback);
1768
- }).
1769
- then(function() {
1770
- pair.assertErrback();
1771
- pair = callbackPair();
1772
- return task2.then(pair.callback, pair.errback);
1773
- }).
1774
- then(function() {
1775
- pair.assertErrback();
1776
- });
1777
- });
1778
-
1779
- it('testCancelsRemainingTasksInFrameIfATaskFails', function() {
1780
- var task;
1781
- var pair = callbackPair(null, assertIsStubError);
1782
- var flow = promise.controlFlow();
1783
- flow.execute(function() {
1784
- flow.execute(throwStubError);
1785
- task = flow.execute(function() {});
1786
- }).then(pair.callback, pair.errback);
1787
-
1788
- return waitForIdle().then(pair.assertErrback).then(function() {
1789
- pair = callbackPair();
1790
- task.then(pair.callback, pair.errback);
1791
- }).then(function() {
1792
- pair.assertErrback();
1793
- });
1794
- });
1795
-
1796
- it('testDoesNotModifyRejectionErrorIfPromiseNotInsideAFlow', function() {
1797
- var error = Error('original message');
1798
- var originalStack = error.stack;
1799
- var originalStr = error.toString();
1800
-
1801
- var pair = callbackPair(null, function(e) {
1802
- assert.equal(error, e);
1803
- assert.equal('original message', e.message);
1804
- assert.equal(originalStack, e.stack);
1805
- assert.equal(originalStr, e.toString());
1806
- });
1807
-
1808
- promise.rejected(error).then(pair.callback, pair.errback);
1809
- return waitForIdle().then(pair.assertErrback);
1810
- });
1811
-
1812
- /** See https://github.com/SeleniumHQ/selenium/issues/444 */
1813
- it('testMaintainsOrderWithPromiseChainsCreatedWithinAForeach_1', function() {
1814
- var messages = [];
1815
- flow.execute(function() {
1816
- return promise.fulfilled(['a', 'b', 'c', 'd']);
1817
- }, 'start').then(function(steps) {
1818
- steps.forEach(function(step) {
1819
- promise.fulfilled(step)
1820
- .then(function() {
1821
- messages.push(step + '.1');
1822
- }).then(function() {
1823
- messages.push(step + '.2');
1824
- });
1825
- })
1826
- });
1827
- return waitForIdle().then(function() {
1828
- assert.deepEqual(
1829
- ['a.1', 'a.2', 'b.1', 'b.2', 'c.1', 'c.2', 'd.1', 'd.2'],
1830
- messages);
1831
- });
1832
- });
1833
-
1834
- /** See https://github.com/SeleniumHQ/selenium/issues/444 */
1835
- it('testMaintainsOrderWithPromiseChainsCreatedWithinAForeach_2', function() {
1836
- var messages = [];
1837
- flow.execute(function() {
1838
- return promise.fulfilled(['a', 'b', 'c', 'd']);
1839
- }, 'start').then(function(steps) {
1840
- steps.forEach(function(step) {
1841
- promise.fulfilled(step)
1842
- .then(function() {
1843
- messages.push(step + '.1');
1844
- }).then(function() {
1845
- flow.execute(function() {}, step + '.2').then(function() {
1846
- messages.push(step + '.2');
1847
- });
1848
- });
1849
- })
1850
- });
1851
- return waitForIdle().then(function() {
1852
- assert.deepEqual(
1853
- ['a.1', 'a.2', 'b.1', 'b.2', 'c.1', 'c.2', 'd.1', 'd.2'],
1854
- messages);
1855
- });
1856
- });
1857
-
1858
- /** See https://github.com/SeleniumHQ/selenium/issues/444 */
1859
- it('testMaintainsOrderWithPromiseChainsCreatedWithinAForeach_3', function() {
1860
- var messages = [];
1861
- flow.execute(function() {
1862
- return promise.fulfilled(['a', 'b', 'c', 'd']);
1863
- }, 'start').then(function(steps) {
1864
- steps.forEach(function(step) {
1865
- promise.fulfilled(step)
1866
- .then(function(){})
1867
- .then(function() {
1868
- messages.push(step + '.1');
1869
- return flow.execute(function() {}, step + '.1');
1870
- }).then(function() {
1871
- flow.execute(function() {}, step + '.2').then(function(text) {
1872
- messages.push(step + '.2');
1873
- });
1874
- });
1875
- })
1876
- });
1877
- return waitForIdle().then(function() {
1878
- assert.deepEqual(
1879
- ['a.1', 'a.2', 'b.1', 'b.2', 'c.1', 'c.2', 'd.1', 'd.2'],
1880
- messages);
1881
- });
1882
- });
1883
-
1884
- /** See https://github.com/SeleniumHQ/selenium/issues/363 */
1885
- it('testTasksScheduledInASeparateTurnOfTheEventLoopGetASeparateTaskQueue_2', function() {
1886
- scheduleAction('a', () => promise.delayed(10));
1887
- schedule('b');
1888
- setTimeout(() => schedule('c'), 0);
1889
-
1890
- return waitForIdle().then(function() {
1891
- assertFlowHistory('a', 'c', 'b');
1892
- });
1893
- });
1894
-
1895
- /** See https://github.com/SeleniumHQ/selenium/issues/363 */
1896
- it('testTasksScheduledInASeparateTurnOfTheEventLoopGetASeparateTaskQueue_2', function() {
1897
- scheduleAction('a', () => promise.delayed(10));
1898
- schedule('b');
1899
- schedule('c');
1900
- setTimeout(function() {
1901
- schedule('d');
1902
- scheduleAction('e', () => promise.delayed(10));
1903
- schedule('f');
1904
- }, 0);
1905
-
1906
- return waitForIdle().then(function() {
1907
- assertFlowHistory('a', 'd', 'e', 'b', 'c', 'f');
1908
- });
1909
- });
1910
-
1911
- /** See https://github.com/SeleniumHQ/selenium/issues/363 */
1912
- it('testCanSynchronizeTasksFromAdjacentTaskQueues', function() {
1913
- var task1 = scheduleAction('a', () => promise.delayed(10));
1914
- schedule('b');
1915
- setTimeout(function() {
1916
- scheduleAction('c', () => task1);
1917
- schedule('d');
1918
- }, 0);
1919
-
1920
- return waitForIdle().then(function() {
1921
- assertFlowHistory('a', 'c', 'd', 'b');
1922
- });
1923
- });
1924
-
1925
- describe('testCancellingAScheduledTask', function() {
1926
- it('1', function() {
1927
- var called = false;
1928
- var task1 = scheduleAction('a', () => called = true);
1929
- task1.cancel('no soup for you');
1930
-
1931
- return waitForIdle().then(function() {
1932
- assert.ok(!called);
1933
- assertFlowHistory();
1934
- return task1.catch(function(e) {
1935
- assert.ok(e instanceof promise.CancellationError);
1936
- assert.equal('no soup for you', e.message);
1937
- });
1938
- });
1939
- });
1940
-
1941
- it('2', function() {
1942
- schedule('a');
1943
- var called = false;
1944
- var task2 = scheduleAction('b', () => called = true);
1945
- schedule('c');
1946
-
1947
- task2.cancel('no soup for you');
1948
-
1949
- return waitForIdle().then(function() {
1950
- assert.ok(!called);
1951
- assertFlowHistory('a', 'c');
1952
- return task2.catch(function(e) {
1953
- assert.ok(e instanceof promise.CancellationError);
1954
- assert.equal('no soup for you', e.message);
1955
- });
1956
- });
1957
- });
1958
-
1959
- it('3', function() {
1960
- var called = false;
1961
- var task = scheduleAction('a', () => called = true);
1962
- task.cancel(new StubError);
1963
-
1964
- return waitForIdle().then(function() {
1965
- assert.ok(!called);
1966
- assertFlowHistory();
1967
- return task.catch(function(e) {
1968
- assert.ok(e instanceof promise.CancellationError);
1969
- });
1970
- });
1971
- });
1972
-
1973
- it('4', function() {
1974
- var seen = [];
1975
- var task = scheduleAction('a', () => seen.push(1))
1976
- .then(() => seen.push(2))
1977
- .then(() => seen.push(3))
1978
- .then(() => seen.push(4))
1979
- .then(() => seen.push(5));
1980
- task.cancel(new StubError);
1981
-
1982
- return waitForIdle().then(function() {
1983
- assert.deepEqual([], seen);
1984
- assertFlowHistory();
1985
- return task.catch(function(e) {
1986
- assert.ok(e instanceof promise.CancellationError);
1987
- });
1988
- });
1989
- });
1990
-
1991
- it('fromWithinAnExecutingTask', function() {
1992
- var called = false;
1993
- var task;
1994
- scheduleAction('a', function() {
1995
- task.cancel('no soup for you');
1996
- });
1997
- task = scheduleAction('b', () => called = true);
1998
- schedule('c');
1999
-
2000
- return waitForIdle().then(function() {
2001
- assert.ok(!called);
2002
- assertFlowHistory('a', 'c');
2003
- return task.catch(function(e) {
2004
- assert.ok(e instanceof promise.CancellationError);
2005
- assert.equal('no soup for you', e.message);
2006
- });
2007
- });
2008
- });
2009
- });
2010
-
2011
- it('testCancellingAPendingTask', function() {
2012
- var order = [];
2013
- var unresolved = promise.defer();
2014
-
2015
- var innerTask;
2016
- var outerTask = scheduleAction('a', function() {
2017
- order.push(1);
2018
-
2019
- // Schedule a task that will never finish.
2020
- innerTask = scheduleAction('a.1', function() {
2021
- return unresolved.promise;
2022
- });
2023
-
2024
- // Since the outerTask is cancelled below, innerTask should be cancelled
2025
- // with a DiscardedTaskError, which means its callbacks are silently
2026
- // dropped - so this should never execute.
2027
- innerTask.catch(function(e) {
2028
- order.push(2);
2029
- });
2030
- });
2031
- schedule('b');
2032
-
2033
- outerTask.catch(function(e) {
2034
- order.push(3);
2035
- assert.ok(e instanceof promise.CancellationError);
2036
- assert.equal('no soup for you', e.message);
2037
- });
2038
-
2039
- unresolved.promise.catch(function(e) {
2040
- order.push(4);
2041
- assert.ok(e instanceof promise.CancellationError);
2042
- });
2043
-
2044
- return timeout(10).then(function() {
2045
- assert.deepEqual([1], order);
2046
-
2047
- outerTask.cancel('no soup for you');
2048
- return waitForIdle();
2049
- }).then(function() {
2050
- assertFlowHistory('a', 'a.1', 'b');
2051
- assert.deepEqual([1, 3, 4], order);
2052
- });
2053
- });
2054
-
2055
- it('testCancellingAPendingPromiseCallback', function() {
2056
- var called = false;
2057
-
2058
- var root = promise.fulfilled();
2059
- root.then(function() {
2060
- cb2.cancel('no soup for you');
2061
- });
2062
-
2063
- var cb2 = root.then(fail, fail); // These callbacks should never be called.
2064
- cb2.then(fail, function(e) {
2065
- called = true;
2066
- assert.ok(e instanceof promise.CancellationError);
2067
- assert.equal('no soup for you', e.message);
2068
- });
2069
-
2070
- return waitForIdle().then(function() {
2071
- assert.ok(called);
2072
- });
2073
- });
2074
-
2075
- describe('testResetFlow', function() {
2076
- it('1', function() {
2077
- var called = 0;
2078
- var task = flow.execute(() => called++);
2079
- task.finally(() => called++);
2080
-
2081
- return new Promise(function(fulfill) {
2082
- flow.once('reset', fulfill);
2083
- flow.reset();
2084
-
2085
- }).then(function() {
2086
- assert.equal(0, called);
2087
- return task;
2088
-
2089
- }).then(fail, function(e) {
2090
- assert.ok(e instanceof promise.CancellationError);
2091
- assert.equal('ControlFlow was reset', e.message);
2092
- });
2093
- });
2094
-
2095
- it('2', function() {
2096
- var called = 0;
2097
- var task1 = flow.execute(() => called++);
2098
- task1.finally(() => called++);
2099
-
2100
- var task2 = flow.execute(() => called++);
2101
- task2.finally(() => called++);
2102
-
2103
- var task3 = flow.execute(() => called++);
2104
- task3.finally(() => called++);
2105
-
2106
- return new Promise(function(fulfill) {
2107
- flow.once('reset', fulfill);
2108
- flow.reset();
2109
-
2110
- }).then(function() {
2111
- assert.equal(0, called);
2112
- });
2113
- });
2114
- });
2115
-
2116
- describe('testPromiseFulfilledInsideTask', function() {
2117
- it('1', function() {
2118
- var order = [];
2119
-
2120
- flow.execute(function() {
2121
- var d = promise.defer();
2122
-
2123
- d.promise.then(() => order.push('a'));
2124
- d.promise.then(() => order.push('b'));
2125
- d.promise.then(() => order.push('c'));
2126
- d.fulfill();
2127
-
2128
- flow.execute(() => order.push('d'));
2129
-
2130
- }).then(() => order.push('fin'));
2131
-
2132
- return waitForIdle().then(function() {
2133
- assert.deepEqual(['a', 'b', 'c', 'd', 'fin'], order);
2134
- });
2135
- });
2136
-
2137
- it('2', function() {
2138
- var order = [];
2139
-
2140
- flow.execute(function() {
2141
- flow.execute(() => order.push('a'));
2142
- flow.execute(() => order.push('b'));
2143
-
2144
- var d = promise.defer();
2145
- d.promise.then(() => order.push('c'));
2146
- d.promise.then(() => order.push('d'));
2147
- d.fulfill();
2148
-
2149
- flow.execute(() => order.push('e'));
2150
-
2151
- }).then(() => order.push('fin'));
2152
-
2153
- return waitForIdle().then(function() {
2154
- assert.deepEqual(['a', 'b', 'c', 'd', 'e', 'fin'], order);
2155
- });
2156
- });
2157
-
2158
- it('3', function() {
2159
- var order = [];
2160
- var d = promise.defer();
2161
- d.promise.then(() => order.push('c'));
2162
- d.promise.then(() => order.push('d'));
2163
-
2164
- flow.execute(function() {
2165
- flow.execute(() => order.push('a'));
2166
- flow.execute(() => order.push('b'));
2167
-
2168
- d.promise.then(() => order.push('e'));
2169
- d.fulfill();
2170
-
2171
- flow.execute(() => order.push('f'));
2172
-
2173
- }).then(() => order.push('fin'));
2174
-
2175
- return waitForIdle().then(function() {
2176
- assert.deepEqual(['c', 'd', 'a', 'b', 'e', 'f', 'fin'], order);
2177
- });
2178
- });
2179
-
2180
- it('4', function() {
2181
- var order = [];
2182
- var d = promise.defer();
2183
- d.promise.then(() => order.push('a'));
2184
- d.promise.then(() => order.push('b'));
2185
-
2186
- flow.execute(function() {
2187
- flow.execute(function() {
2188
- order.push('c');
2189
- flow.execute(() => order.push('d'));
2190
- d.promise.then(() => order.push('e'));
2191
- });
2192
- flow.execute(() => order.push('f'));
2193
-
2194
- d.promise.then(() => order.push('g'));
2195
- d.fulfill();
2196
-
2197
- flow.execute(() => order.push('h'));
2198
-
2199
- }).then(() => order.push('fin'));
2200
-
2201
- return waitForIdle().then(function() {
2202
- assert.deepEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'fin'], order);
2203
- });
2204
- });
2205
- });
2206
-
2207
- describe('testSettledPromiseCallbacksInsideATask', function() {
2208
- it('1', function() {
2209
- var order = [];
2210
- var p = promise.fulfilled();
2211
-
2212
- flow.execute(function() {
2213
- flow.execute(() => order.push('a'));
2214
- p.then(() => order.push('b'));
2215
- flow.execute(() => order.push('c'));
2216
- p.then(() => order.push('d'));
2217
- }).then(() => order.push('fin'));
2218
-
2219
- return waitForIdle().then(function() {
2220
- assert.deepEqual(['a', 'b', 'c', 'd', 'fin'], order);
2221
- });
2222
- });
2223
-
2224
- it('2', function() {
2225
- var order = [];
2226
-
2227
- flow.execute(function() {
2228
- flow.execute(() => order.push('a'))
2229
- .then( () => order.push('c'));
2230
- flow.execute(() => order.push('b'));
2231
- }).then(() => order.push('fin'));
2232
-
2233
- return waitForIdle().then(function() {
2234
- assert.deepEqual(['a', 'c', 'b', 'fin'], order);
2235
- });
2236
- });
2237
- });
2238
-
2239
- it('testTasksDoNotWaitForNewlyCreatedPromises', function() {
2240
- var order = [];
2241
-
2242
- flow.execute(function() {
2243
- var d = promise.defer();
2244
-
2245
- // This is a normal promise, not a task, so the task for this callback is
2246
- // considered volatile. Volatile tasks should be skipped when they reach
2247
- // the front of the task queue.
2248
- d.promise.then(() => order.push('a'));
2249
-
2250
- flow.execute(() => order.push('b'));
2251
- flow.execute(function() {
2252
- flow.execute(() => order.push('c'));
2253
- d.promise.then(() => order.push('d'));
2254
- d.fulfill();
2255
- });
2256
- flow.execute(() => order.push('e'));
2257
-
2258
- }).then(() => order.push('fin'));
2259
-
2260
- return waitForIdle().then(function() {
2261
- assert.deepEqual(['b', 'a', 'c', 'd', 'e', 'fin'], order);
2262
- });
2263
- });
2264
-
2265
- it('testCallbackDependenciesDoNotDeadlock', function() {
2266
- var order = [];
2267
- var root = promise.defer();
2268
- var dep = promise.fulfilled().then(function() {
2269
- order.push('a');
2270
- return root.promise.then(function() {
2271
- order.push('b');
2272
- });
2273
- });
2274
- // This callback depends on |dep|, which depends on another callback
2275
- // attached to |root| via a chain.
2276
- root.promise.then(function() {
2277
- order.push('c');
2278
- return dep.then(() => order.push('d'));
2279
- }).then(() => order.push('fin'));
2280
-
2281
- setTimeout(() => root.fulfill(), 20);
2282
-
2283
- return waitForIdle().then(function() {
2284
- assert.deepEqual(['a', 'b', 'c', 'd', 'fin'], order);
2285
- });
2286
- });
2287
- });
2288
- });