@inboxsdk/core 0.2.28-alpha.4 → 0.2.28-alpha.5
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.
- package/inboxsdk.js +1 -1
- package/package.json +5 -1
- package/src/inboxsdk-js/check-requirements.js +7 -3
- package/src/inboxsdk-js/header.js +1 -0
- package/src/inboxsdk-js/inboxsdk-NONREMOTE-INTEGRATED-PAGEWORLD.js +5 -6
- package/src/inboxsdk-js/inboxsdk-NONREMOTE.js +4 -3
- package/src/inboxsdk-js/inboxsdk-REMOTE.js +3 -1
- package/src/inboxsdk-js/inboxsdk-TEST.js +4 -3
- package/src/inboxsdk-js/inboxsdk.js +33 -39
- package/src/inboxsdk-js/loading/load-platform-implementation-DEV.js +15 -18
- package/src/injected-js/gmail/modify-suggestions.test.js +8 -9
- package/src/injected-js/gmail/setup-gmail-interceptor.js +340 -579
- package/src/injected-js/gmail/sync-compose-request-processor.test.js +39 -49
- package/src/injected-js/gmail/thread-identifier/click-and-get-popup-url.js +20 -33
- package/src/injected-js/gmail/thread-identifier/index.js +57 -93
- package/src/injected-js/gmail/thread-identifier/thread-row-parser.js +22 -31
- package/src/injected-js/gmail/thread-identifier/thread-row-parser.test.js +12 -28
- package/src/injected-js/inbox/setupAjaxInterceptor.js +64 -121
- package/src/injected-js/inbox/setupClickAndGetNewIframeSrc.js +53 -66
- package/src/injected-js/inbox/setupComposeViewDraftIDFinder.js +20 -36
- package/src/injected-js/inbox/setupInboxFakeWindowResizeListener.js +13 -13
- package/src/injected-js/main.js +11 -24
- package/src/injected-js/message-metadata-holder.js +52 -82
- package/src/injected-js/setup-data-exposer.js +89 -148
- package/src/injected-js/setup-error-silencer.js +21 -21
- package/src/injected-js/setup-event-reemitter.js +30 -22
- package/src/injected-js/setupInboxCustomViewLinkFixer.js +24 -29
- package/src/injected-js/setupPushStateListener.js +18 -11
- package/src/injected-js/xhr-helper.js +62 -65
- package/src/injected-js/xhr-proxy-factory.js +195 -445
- package/src/injected-js/xhr-proxy-factory.test.js +824 -991
- package/src/platform-implementation-js/constants/router.js +14 -9
- package/src/platform-implementation-js/constants/toolbars.js +8 -3
- package/src/platform-implementation-js/dom-driver/gmail/custom-style.js +13 -13
- package/src/platform-implementation-js/dom-driver/gmail/gmail-butter-bar-driver.js +115 -136
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/add-toolbar-button-for-app.js +13 -14
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/create-link.js +27 -48
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/get-draft-id-for-message-id.js +31 -42
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/get-native-nav-item.js +30 -40
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/get-url-object.js +10 -18
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/getSyncThreadForOldGmailThreadId.js +21 -28
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/getSyncThreadFromSyncThreadId.js +33 -45
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/gmail-load-event.js +31 -49
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/goto-view.js +58 -65
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/keyboard-shortcut-help-modifier.js +40 -124
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/open-compose-window.js +17 -22
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/open-draft-by-message-id.test.js +10 -11
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/override-gmail-back-button.js +44 -80
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/register-search-query-rewriter.js +19 -26
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/register-search-suggestions-provider.js +71 -147
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/setup-compose-view-driver-stream.js +91 -148
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/setup-route-view-driver-stream.js +150 -166
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/setup-route-view-driver-stream.test.js +70 -120
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/show-app-id-warning.js +15 -15
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/show-custom-route-view.js +44 -67
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/show-custom-thread-list.js +230 -379
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/show-custom-thread-list.test.js +121 -307
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/show-native-route-view.js +17 -24
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/suppressAddon.js +41 -49
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/temporary-track-download-url-validity.js +30 -40
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/thread-row-identifier.js +28 -60
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/track-events.js +61 -133
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/user-info.js +30 -42
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/user-info.test.js +52 -46
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver.js +354 -694
- package/src/platform-implementation-js/dom-driver/gmail/make-xhr-interceptor.js +77 -93
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/index.js +35 -82
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/index.test.js +44 -94
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/primary/add-companion-global-icon-area.js +12 -19
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/primary/add-companion-thread-icon-area.js +17 -29
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/primary/add-to-icon-area.js +26 -26
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/primary/index.js +391 -797
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-toolbar-button-view/monitor-top-banner-size-and-react.js +7 -9
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-toolbar-button-view.js +60 -109
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-attachment-area-view.js +95 -135
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-attachment-card-view.js +103 -211
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-attachment-card-view.test.js +61 -61
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-backdrop.js +17 -17
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-collapsible-section-view.js +188 -541
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/add-button.js +67 -135
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/add-compose-notice.js +27 -49
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/add-inner-sidebar.js +7 -13
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/add-outer-sidebar.js +9 -22
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/add-recipient-row.js +36 -63
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/add-tooltip-to-button.js +38 -113
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/ensure-app-button-toolbars-are-closed.js +11 -16
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/ensure-grouping-is-open.js +11 -17
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/focus.js +8 -11
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/from-manager.js +27 -47
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/get-additional-action-toolbar.js +11 -24
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/get-address-changes-stream.js +59 -111
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/get-body-changes-stream.js +15 -14
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/get-formatting-area-offset-left.js +11 -17
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/get-minimized-stream.js +18 -24
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/get-response-type-changes-stream.js +19 -23
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/insert-link-into-body.js +11 -19
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/manage-button-grouping.js +141 -376
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/monitor-selection-range.js +17 -28
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/override-edit-subject.js +34 -70
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/position-formatting-toolbar.js +10 -17
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/size-fixer.js +83 -137
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/update-insert-more-area-left.js +10 -19
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view.js +632 -1190
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-message-view/get-updated-contact.js +29 -38
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-message-view.js +327 -617
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-route-view/gmail-route-processor.js +26 -49
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-route-view/gmail-route-view.js +188 -380
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-row-list-view.js +104 -194
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-row-view.js +382 -811
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-sidebar-view/add-icon-area.js +34 -58
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-sidebar-view.js +330 -581
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-sidebar-view.test.js +123 -277
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-view/width-manager.js +15 -35
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-view.js +216 -571
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-toolbar-view.js +152 -336
- package/src/platform-implementation-js/dom-driver/gmail/views/native-gmail-nav-item-view.js +87 -211
- package/src/platform-implementation-js/dom-driver/gmail/widgets/buttons/inbox-dropdown-button-view.js +10 -11
- package/src/platform-implementation-js/dom-driver/gmail/widgets/gmail-action-button-view.js +20 -29
- package/src/platform-implementation-js/dom-driver/gmail/widgets/gmail-label-view.js +41 -76
- package/src/platform-implementation-js/dom-driver/gmail/widgets/gmail-modal-view-driver.js +45 -99
- package/src/platform-implementation-js/dom-driver/gmail/widgets/gmail-mole-view-driver.js +76 -128
- package/src/platform-implementation-js/dom-driver/gmail/widgets/gmail-tooltip-view.js +128 -319
- package/src/platform-implementation-js/dom-driver/gmail/widgets/gmail-top-message-bar-driver.js +45 -78
- package/src/platform-implementation-js/dom-driver/inbox/__mocks__/getSidebarClassnames.js +8 -4
- package/src/platform-implementation-js/dom-driver/inbox/addNavItem.js +36 -54
- package/src/platform-implementation-js/dom-driver/inbox/addRecipientRow.js +35 -53
- package/src/platform-implementation-js/dom-driver/inbox/createLink.js +13 -15
- package/src/platform-implementation-js/dom-driver/inbox/createLink.test.js +15 -18
- package/src/platform-implementation-js/dom-driver/inbox/custom-style.js +14 -13
- package/src/platform-implementation-js/dom-driver/inbox/detection/appToolbarLocation/parser.js +14 -20
- package/src/platform-implementation-js/dom-driver/inbox/detection/attachmentCard/parser.js +14 -13
- package/src/platform-implementation-js/dom-driver/inbox/detection/attachmentOverlay/parser.js +35 -67
- package/src/platform-implementation-js/dom-driver/inbox/detection/chatSidebar/parser.js +16 -18
- package/src/platform-implementation-js/dom-driver/inbox/detection/compose/parser.js +68 -185
- package/src/platform-implementation-js/dom-driver/inbox/detection/message/parser.js +28 -56
- package/src/platform-implementation-js/dom-driver/inbox/detection/nativeDrawer/parser.js +12 -10
- package/src/platform-implementation-js/dom-driver/inbox/detection/searchBar/parser.js +16 -16
- package/src/platform-implementation-js/dom-driver/inbox/detection/thread/parser.js +24 -35
- package/src/platform-implementation-js/dom-driver/inbox/detection/thread-row/parser.js +37 -89
- package/src/platform-implementation-js/dom-driver/inbox/getComposeViewDriverLiveSet.js +56 -78
- package/src/platform-implementation-js/dom-driver/inbox/getInboxMessageIdForInboxThreadId.js +26 -32
- package/src/platform-implementation-js/dom-driver/inbox/getSidebarClassnames.js +52 -109
- package/src/platform-implementation-js/dom-driver/inbox/getSidebarClassnames.test.js +7 -8
- package/src/platform-implementation-js/dom-driver/inbox/gotoView.js +16 -20
- package/src/platform-implementation-js/dom-driver/inbox/gotoView.test.js +15 -16
- package/src/platform-implementation-js/dom-driver/inbox/inbox-butter-bar-driver.js +75 -83
- package/src/platform-implementation-js/dom-driver/inbox/inbox-driver.js +530 -822
- package/src/platform-implementation-js/dom-driver/inbox/inbox-page-communicator.js +48 -61
- package/src/platform-implementation-js/dom-driver/inbox/inboxResponseProcessor.js +9 -12
- package/src/platform-implementation-js/dom-driver/inbox/inboxResponseProcessor.test.js +12 -19
- package/src/platform-implementation-js/dom-driver/inbox/makePageParserTree.js +24 -33
- package/src/platform-implementation-js/dom-driver/inbox/pageParserOptions.js +201 -388
- package/src/platform-implementation-js/dom-driver/inbox/registerSearchSuggestionsProvider.js +249 -265
- package/src/platform-implementation-js/dom-driver/inbox/setupCustomAutocompleteSelectionHandling.js +84 -152
- package/src/platform-implementation-js/dom-driver/inbox/setupRouteViewDriverStream.js +55 -67
- package/src/platform-implementation-js/dom-driver/inbox/setupRouteViewDriverStream.test.js +43 -65
- package/src/platform-implementation-js/dom-driver/inbox/views/InboxLabelView.js +31 -56
- package/src/platform-implementation-js/dom-driver/inbox/views/InboxMoleViewDriver.js +191 -294
- package/src/platform-implementation-js/dom-driver/inbox/views/InboxToolbarButtonView.js +32 -45
- package/src/platform-implementation-js/dom-driver/inbox/views/InboxToolbarView.js +21 -39
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-sidebar-view.js +153 -240
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-toolbar-button-view.js +75 -150
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-toolbar-tooltip-view.js +20 -37
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-attachment-card-view.js +60 -114
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-attachment-overlay-view.js +47 -65
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-backdrop.js +41 -52
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-chat-sidebar-view.js +27 -36
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-compose-button-view.js +52 -80
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-compose-view.js +465 -649
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-custom-route-view.js +37 -58
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-custom-route-view.test.js +14 -26
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-drawer-view.js +118 -235
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-dropdown-view.js +10 -11
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-dummy-route-view.js +28 -46
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-message-view.js +131 -202
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-modal-view.js +40 -80
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-route-view.js +35 -61
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-row-view.js +124 -221
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-view.js +125 -213
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-view.test.js +104 -126
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-tooltip-view.js +36 -51
- package/src/platform-implementation-js/dom-driver/inbox/views/inboxNavItemView.js +158 -297
- package/src/platform-implementation-js/dom-driver/inbox/waitForAnimationClickBlockerGone.js +21 -35
- package/src/platform-implementation-js/driver-common/compose/getDiscardStream.js +24 -43
- package/src/platform-implementation-js/driver-common/compose/getPresendingStream.js +39 -68
- package/src/platform-implementation-js/driver-common/getGmailMessageIdForSyncMessageId.js +14 -19
- package/src/platform-implementation-js/driver-common/getGmailThreadIdForRfcMessageId.js +27 -35
- package/src/platform-implementation-js/driver-common/getRfcMessageIdForSyncMessageId.js +16 -22
- package/src/platform-implementation-js/driver-common/getThreadIdFromMessageId.js +14 -14
- package/src/platform-implementation-js/driver-common/inboxAjax.js +12 -7
- package/src/platform-implementation-js/driver-common/requestGmailThread.js +19 -20
- package/src/platform-implementation-js/driver-common/sidebar/AppSidebar.js +197 -306
- package/src/platform-implementation-js/driver-common/sidebar/ContentPanelViewDriver.js +113 -161
- package/src/platform-implementation-js/driver-interfaces/compose-view-driver.js +1 -114
- package/src/platform-implementation-js/driver-interfaces/driver.js +1 -131
- package/src/platform-implementation-js/driver-interfaces/message-view-driver.js +4 -48
- package/src/platform-implementation-js/driver-interfaces/mole-view-driver.js +1 -29
- package/src/platform-implementation-js/driver-interfaces/route-view-driver.js +1 -32
- package/src/platform-implementation-js/driver-interfaces/thread-row-view-driver.js +1 -11
- package/src/platform-implementation-js/lib/array-to-lifetimes.js +43 -41
- package/src/platform-implementation-js/lib/array-to-lifetimes.test.js +139 -155
- package/src/platform-implementation-js/lib/copyAndValidateAutocompleteResults.js +19 -38
- package/src/platform-implementation-js/lib/css-selector-escape.js +7 -3
- package/src/platform-implementation-js/lib/dom/element-view-mapper.js +8 -11
- package/src/platform-implementation-js/lib/dom/get-selection.js +23 -52
- package/src/platform-implementation-js/lib/dom/insert-html-at-cursor.js +69 -101
- package/src/platform-implementation-js/lib/dom/is-node-in-range.js +8 -10
- package/src/platform-implementation-js/lib/dom/on-mouse-down-and-up.js +15 -17
- package/src/platform-implementation-js/lib/dom/querySelectorOne.js +8 -11
- package/src/platform-implementation-js/lib/dom/set-css.js +7 -3
- package/src/platform-implementation-js/lib/dom/set-value-and-dispatch-event.js +9 -11
- package/src/platform-implementation-js/lib/dom/simulate-drag-and-drop.js +32 -33
- package/src/platform-implementation-js/lib/extract-contact-from-email-contact-string.test.js +23 -26
- package/src/platform-implementation-js/lib/handle-compose-link-chips.js +86 -149
- package/src/platform-implementation-js/lib/insert-link-chip-into-body.js +42 -57
- package/src/platform-implementation-js/lib/make-revocable-function.js +19 -21
- package/src/platform-implementation-js/lib/make-revocable-function.test.js +20 -22
- package/src/platform-implementation-js/lib/parseParamsFromRouteID.js +15 -17
- package/src/platform-implementation-js/lib/parseParamsFromRouteID.test.js +9 -18
- package/src/platform-implementation-js/lib/populateRouteID.js +8 -9
- package/src/platform-implementation-js/lib/populateRouteID.test.js +20 -19
- package/src/platform-implementation-js/lib/react/ElementContainer.js +23 -20
- package/src/platform-implementation-js/lib/rewriteCssWithIdMap.js +10 -9
- package/src/platform-implementation-js/lib/rewriteCssWithIdMap.test.js +13 -20
- package/src/platform-implementation-js/lib/routeIDmatchesHash.js +13 -18
- package/src/platform-implementation-js/lib/routeIDmatchesHash.test.js +11 -17
- package/src/platform-implementation-js/lib/shared-style.js +14 -13
- package/src/platform-implementation-js/lib/toItemWithLifetimeStream.js +18 -17
- package/src/platform-implementation-js/lib/toLiveSet.js +17 -15
- package/src/platform-implementation-js/main-INTEGRATED-PAGEWORLD.js +6 -5
- package/src/platform-implementation-js/main.js +9 -24
- package/src/platform-implementation-js/namespaces/compose.js +37 -60
- package/src/platform-implementation-js/namespaces/conversations.js +52 -124
- package/src/platform-implementation-js/namespaces/global.js +27 -39
- package/src/platform-implementation-js/namespaces/keyboard.js +29 -33
- package/src/platform-implementation-js/namespaces/lists.js +25 -31
- package/src/platform-implementation-js/namespaces/modal.js +34 -28
- package/src/platform-implementation-js/namespaces/nav-menu.js +30 -45
- package/src/platform-implementation-js/namespaces/router.js +70 -137
- package/src/platform-implementation-js/namespaces/search.js +19 -17
- package/src/platform-implementation-js/namespaces/toolbars.js +71 -117
- package/src/platform-implementation-js/namespaces/user.js +36 -37
- package/src/platform-implementation-js/namespaces/widgets.js +54 -61
- package/src/platform-implementation-js/platform-implementation.js +98 -229
- package/src/platform-implementation-js/views/app-toolbar-button-view.js +26 -47
- package/src/platform-implementation-js/views/collapsible-section-view.js +66 -63
- package/src/platform-implementation-js/views/content-panel-view.js +28 -30
- package/src/platform-implementation-js/views/conversations/attachment-card-view.js +21 -44
- package/src/platform-implementation-js/views/conversations/custom-message-view.js +44 -104
- package/src/platform-implementation-js/views/conversations/message-view.js +131 -202
- package/src/platform-implementation-js/views/conversations/thread-view.js +75 -127
- package/src/platform-implementation-js/views/native-nav-item-view.js +32 -65
- package/src/platform-implementation-js/views/nav-item-view.js +51 -115
- package/src/platform-implementation-js/views/route-view/custom-route-view.js +25 -20
- package/src/platform-implementation-js/views/route-view/dummy-route-view-driver.js +18 -18
- package/src/platform-implementation-js/views/route-view/list-route-view.js +30 -52
- package/src/platform-implementation-js/views/route-view/route-view.js +24 -35
- package/src/platform-implementation-js/views/section-view.js +60 -52
- package/src/platform-implementation-js/views/thread-row-view.js +49 -74
- package/src/platform-implementation-js/widgets/drawer-view.js +29 -36
- package/src/platform-implementation-js/widgets/modal-view.js +39 -68
- package/src/platform-implementation-js/widgets/mole-view.js +22 -22
- package/src/platform-implementation-js/widgets/top-message-bar-view.js +13 -10
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import assert from 'assert';
|
|
4
|
-
import _ from 'lodash';
|
|
5
|
-
import noop from 'lodash/noop';
|
|
6
|
-
import sinon from 'sinon';
|
|
7
|
-
import delay from 'pdelay';
|
|
8
|
-
import MockServer from '../../test/lib/MockServer';
|
|
1
|
+
"use strict";
|
|
9
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _assert = _interopRequireDefault(require("assert"));
|
|
5
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
6
|
+
var _noop = _interopRequireDefault(require("lodash/noop"));
|
|
7
|
+
var _sinon = _interopRequireDefault(require("sinon"));
|
|
8
|
+
var _pdelay = _interopRequireDefault(require("pdelay"));
|
|
9
|
+
var _MockServer = _interopRequireDefault(require("../../test/lib/MockServer"));
|
|
10
|
+
var _xhrProxyFactory = _interopRequireDefault(require("./xhr-proxy-factory"));
|
|
10
11
|
const testError = new Error('TEST');
|
|
11
12
|
let logErrorTestCalls = 0;
|
|
12
|
-
|
|
13
13
|
function logError(error, label) {
|
|
14
14
|
if (error === testError) {
|
|
15
15
|
logErrorTestCalls++;
|
|
@@ -18,7 +18,6 @@ function logError(error, label) {
|
|
|
18
18
|
throw error || new Error(label);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
function thrower(err) {
|
|
23
22
|
return function () {
|
|
24
23
|
if (typeof err == 'string') {
|
|
@@ -30,550 +29,539 @@ function thrower(err) {
|
|
|
30
29
|
}
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
const server = new _MockServer.default();
|
|
33
|
+
server.respondWith({
|
|
34
|
+
method: 'GET',
|
|
35
|
+
path: '/foo',
|
|
36
|
+
headers: {
|
|
37
|
+
'X-Special': 'Value'
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
status: 200,
|
|
41
|
+
response: 'header value received'
|
|
42
|
+
});
|
|
43
|
+
server.respondWith({
|
|
44
|
+
method: 'GET',
|
|
45
|
+
path: '/foo',
|
|
46
|
+
responseType: 'testing'
|
|
47
|
+
}, {
|
|
48
|
+
status: 200,
|
|
49
|
+
response: 'testing here!'
|
|
50
|
+
});
|
|
51
|
+
server.respondWith({
|
|
52
|
+
method: 'GET',
|
|
53
|
+
path: '/foo'
|
|
54
|
+
}, {
|
|
55
|
+
status: 200,
|
|
56
|
+
response: 'Response here!',
|
|
57
|
+
partialResponse: 'Response here',
|
|
58
|
+
headers: {
|
|
59
|
+
'X-Test': 'Header Value'
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
server.respondWith({
|
|
63
|
+
method: 'POST',
|
|
64
|
+
path: '/foo',
|
|
65
|
+
body: 'somedata'
|
|
66
|
+
}, {
|
|
67
|
+
status: 200,
|
|
68
|
+
response: 'body received'
|
|
69
|
+
});
|
|
70
|
+
server.respondWith({
|
|
71
|
+
method: 'POST',
|
|
72
|
+
path: '/foo',
|
|
73
|
+
body: 'testab'
|
|
74
|
+
}, {
|
|
75
|
+
status: 200,
|
|
76
|
+
response: 'testab received'
|
|
77
|
+
});
|
|
78
|
+
server.respondWith({
|
|
79
|
+
method: 'POST',
|
|
80
|
+
path: '/foo'
|
|
81
|
+
}, {
|
|
82
|
+
status: 200,
|
|
83
|
+
response: 'POST request'
|
|
84
|
+
});
|
|
85
|
+
server.respondWith({
|
|
86
|
+
method: 'GET',
|
|
87
|
+
path: '/foo2'
|
|
88
|
+
}, {
|
|
89
|
+
status: 200,
|
|
90
|
+
response: 'foo2 response!',
|
|
91
|
+
partialResponse: 'foo2 response'
|
|
92
|
+
});
|
|
93
|
+
server.respondWith({
|
|
94
|
+
method: 'GET',
|
|
95
|
+
path: '/fooXml'
|
|
96
|
+
}, {
|
|
97
|
+
status: 200,
|
|
98
|
+
response: 'testing here!',
|
|
99
|
+
responseXML: {
|
|
100
|
+
fakeXml: true
|
|
52
101
|
}
|
|
53
|
-
);
|
|
54
|
-
server.respondWith(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
);
|
|
62
|
-
server.respondWith(
|
|
63
|
-
{ method: 'POST', path: '/foo' },
|
|
64
|
-
{ status: 200, response: 'POST request' }
|
|
65
|
-
);
|
|
66
|
-
server.respondWith(
|
|
67
|
-
{ method: 'GET', path: '/foo2' },
|
|
68
|
-
{ status: 200, response: 'foo2 response!', partialResponse: 'foo2 response' }
|
|
69
|
-
);
|
|
70
|
-
server.respondWith(
|
|
71
|
-
{ method: 'GET', path: '/fooXml' },
|
|
72
|
-
{ status: 200, response: 'testing here!', responseXML: { fakeXml: true } }
|
|
73
|
-
);
|
|
74
|
-
server.respondWith(
|
|
75
|
-
{ method: 'GETab', path: '/fooAB' },
|
|
76
|
-
{ status: 200, response: 'fooAB requested, data12 received' }
|
|
77
|
-
);
|
|
102
|
+
});
|
|
103
|
+
server.respondWith({
|
|
104
|
+
method: 'GETab',
|
|
105
|
+
path: '/fooAB'
|
|
106
|
+
}, {
|
|
107
|
+
status: 200,
|
|
108
|
+
response: 'fooAB requested, data12 received'
|
|
109
|
+
});
|
|
78
110
|
const XMLHttpRequest = server.XMLHttpRequest;
|
|
79
|
-
|
|
80
|
-
const constructors: { [name: string]: typeof XMLHttpRequest } = {
|
|
111
|
+
const constructors = {
|
|
81
112
|
XMLHttpRequest: XMLHttpRequest,
|
|
82
|
-
XHRProxy:
|
|
113
|
+
XHRProxy: (0, _xhrProxyFactory.default)(XMLHttpRequest, [], {
|
|
114
|
+
logError: logError
|
|
115
|
+
})
|
|
83
116
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
constructors['XHRProxy²'] = (0, _xhrProxyFactory.default)(constructors.XHRProxy, [], {
|
|
118
|
+
logError: logError
|
|
119
|
+
});
|
|
120
|
+
constructors['XHRProxy with changers'] = (0, _xhrProxyFactory.default)(XMLHttpRequest, [{
|
|
121
|
+
isRelevantTo: () => true,
|
|
122
|
+
requestChanger(connection, request) {
|
|
123
|
+
return Promise.resolve(request);
|
|
124
|
+
},
|
|
125
|
+
responseTextChanger(connection, response) {
|
|
126
|
+
return Promise.resolve(response);
|
|
127
|
+
}
|
|
128
|
+
}], {
|
|
129
|
+
logError: logError
|
|
87
130
|
});
|
|
88
|
-
constructors['XHRProxy with changers'] = XHRProxyFactory(
|
|
89
|
-
XMLHttpRequest,
|
|
90
|
-
[
|
|
91
|
-
{
|
|
92
|
-
isRelevantTo: () => true,
|
|
93
|
-
requestChanger(connection, request) {
|
|
94
|
-
return Promise.resolve(request);
|
|
95
|
-
},
|
|
96
|
-
responseTextChanger(connection, response) {
|
|
97
|
-
return Promise.resolve(response);
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
{ logError: logError }
|
|
102
|
-
);
|
|
103
|
-
|
|
104
131
|
beforeEach(() => {
|
|
105
132
|
logErrorTestCalls = 0;
|
|
106
133
|
});
|
|
107
134
|
|
|
108
135
|
// Test both the mock and the instrumented version
|
|
109
|
-
['XMLHttpRequest', 'XHRProxy', 'XHRProxy²', 'XHRProxy with changers'].forEach(
|
|
110
|
-
(XHRName) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
['XMLHttpRequest', 'XHRProxy', 'XHRProxy²', 'XHRProxy with changers'].forEach(XHRName => {
|
|
137
|
+
describe(XHRName, () => {
|
|
138
|
+
let XHRConstructor;
|
|
139
|
+
let xhr;
|
|
140
|
+
beforeEach(() => {
|
|
141
|
+
XHRConstructor = constructors[XHRName];
|
|
142
|
+
xhr = new XHRConstructor();
|
|
143
|
+
});
|
|
144
|
+
['onreadystatechange', 'addEventListener'].forEach(method => {
|
|
145
|
+
describe(method, () => {
|
|
146
|
+
it('should call all states and work on re-used object', done => {
|
|
147
|
+
const calledForState = {
|
|
148
|
+
'1': 0,
|
|
149
|
+
'2': 0,
|
|
150
|
+
'3': 0,
|
|
151
|
+
'4': 0
|
|
152
|
+
};
|
|
153
|
+
let runCount = 0;
|
|
154
|
+
const listener = function (event) {
|
|
155
|
+
_assert.default.strictEqual(this, xhr, 'check for correct this binding');
|
|
156
|
+
_assert.default.strictEqual(event.target, this, 'check for correct event target');
|
|
157
|
+
calledForState[this.readyState]++;
|
|
158
|
+
if (this.readyState >= 2) {
|
|
159
|
+
_assert.default.equal(this.status, 200, 'check http status');
|
|
160
|
+
}
|
|
161
|
+
if (this.readyState >= 3) {
|
|
162
|
+
_assert.default.equal(this.responseText, this.response, 'check responseText');
|
|
163
|
+
} else {
|
|
164
|
+
let responseText;
|
|
165
|
+
try {
|
|
166
|
+
responseText = this.responseText;
|
|
167
|
+
} catch (e) {
|
|
168
|
+
responseText = '';
|
|
135
169
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
);
|
|
170
|
+
_assert.default.strictEqual(responseText, '');
|
|
171
|
+
}
|
|
172
|
+
if (this.readyState == 3) {
|
|
173
|
+
if (XHRName === 'XHRProxy with changers') {
|
|
174
|
+
// No progress text should be given when a responseTextChanger is in use.
|
|
175
|
+
_assert.default.strictEqual(this.response, '');
|
|
142
176
|
} else {
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
responseText = this.responseText;
|
|
146
|
-
} catch (e) {
|
|
147
|
-
responseText = '';
|
|
148
|
-
}
|
|
149
|
-
assert.strictEqual(responseText, '');
|
|
150
|
-
}
|
|
151
|
-
if (this.readyState == 3) {
|
|
152
|
-
if (XHRName === 'XHRProxy with changers') {
|
|
153
|
-
// No progress text should be given when a responseTextChanger is in use.
|
|
154
|
-
assert.strictEqual(this.response, '');
|
|
155
|
-
} else {
|
|
156
|
-
assert.strictEqual(this.response, 'Response here');
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (this.readyState == 4) {
|
|
160
|
-
runCount++;
|
|
161
|
-
assert.equal(this.response, 'Response here!');
|
|
162
|
-
assert.deepEqual(
|
|
163
|
-
calledForState,
|
|
164
|
-
{
|
|
165
|
-
'1': runCount,
|
|
166
|
-
'2': runCount,
|
|
167
|
-
'3': runCount,
|
|
168
|
-
'4': runCount,
|
|
169
|
-
},
|
|
170
|
-
'check that listener was called for each state'
|
|
171
|
-
);
|
|
172
|
-
if (runCount === 1) {
|
|
173
|
-
start();
|
|
174
|
-
} else {
|
|
175
|
-
done();
|
|
176
|
-
}
|
|
177
|
+
_assert.default.strictEqual(this.response, 'Response here');
|
|
177
178
|
}
|
|
178
|
-
};
|
|
179
|
-
if (method == 'onreadystatechange') {
|
|
180
|
-
xhr.onreadystatechange = listener;
|
|
181
|
-
} else if (method == 'addEventListener') {
|
|
182
|
-
xhr.addEventListener('readystatechange', listener);
|
|
183
|
-
}
|
|
184
|
-
function start() {
|
|
185
|
-
xhr.open('GET', '/foo');
|
|
186
|
-
assert.equal(xhr.readyState, 1, 'readyState check');
|
|
187
|
-
xhr.send();
|
|
188
|
-
}
|
|
189
|
-
assert.equal(xhr.readyState, 0, 'readyState check');
|
|
190
|
-
start();
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
describe('multiple event listeners', () => {
|
|
196
|
-
it('should fire both together', (done) => {
|
|
197
|
-
let simpleFired = false,
|
|
198
|
-
addedFired = false;
|
|
199
|
-
xhr.onreadystatechange = function (event) {
|
|
200
|
-
simpleFired = true;
|
|
201
|
-
};
|
|
202
|
-
xhr.addEventListener('readystatechange', function (event: Object) {
|
|
203
|
-
addedFired = true;
|
|
204
|
-
});
|
|
205
|
-
xhr.addEventListener('readystatechange', function (event: Object) {
|
|
206
|
-
if (this.readyState == 4) {
|
|
207
|
-
assert(
|
|
208
|
-
simpleFired && addedFired,
|
|
209
|
-
'check that both listeners fired'
|
|
210
|
-
);
|
|
211
|
-
done();
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
xhr.open('GET', '/foo');
|
|
215
|
-
xhr.send();
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
describe('removeEventListener', () => {
|
|
220
|
-
it('should work', (done) => {
|
|
221
|
-
const badListener = function (event: Object) {
|
|
222
|
-
throw new Error('this listener should have been removed');
|
|
223
|
-
};
|
|
224
|
-
xhr.addEventListener('readystatechange', badListener);
|
|
225
|
-
xhr.addEventListener('readystatechange', function (event: Object) {
|
|
226
|
-
if (this.readyState == 4) {
|
|
227
|
-
done();
|
|
228
179
|
}
|
|
229
|
-
});
|
|
230
|
-
xhr.removeEventListener('readystatechange', badListener);
|
|
231
|
-
xhr.open('GET', '/foo');
|
|
232
|
-
xhr.send();
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe('abort', () => {
|
|
237
|
-
it('should work after send', (done) => {
|
|
238
|
-
let finishCount = 0;
|
|
239
|
-
xhr.onreadystatechange = function () {
|
|
240
180
|
if (this.readyState == 4) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
181
|
+
runCount++;
|
|
182
|
+
_assert.default.equal(this.response, 'Response here!');
|
|
183
|
+
_assert.default.deepEqual(calledForState, {
|
|
184
|
+
'1': runCount,
|
|
185
|
+
'2': runCount,
|
|
186
|
+
'3': runCount,
|
|
187
|
+
'4': runCount
|
|
188
|
+
}, 'check that listener was called for each state');
|
|
189
|
+
if (runCount === 1) {
|
|
190
|
+
start();
|
|
249
191
|
} else {
|
|
250
|
-
assert.equal(
|
|
251
|
-
this.responseText,
|
|
252
|
-
'foo2 response!',
|
|
253
|
-
'response check'
|
|
254
|
-
);
|
|
255
192
|
done();
|
|
256
193
|
}
|
|
257
194
|
}
|
|
258
195
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
196
|
+
if (method == 'onreadystatechange') {
|
|
197
|
+
xhr.onreadystatechange = listener;
|
|
198
|
+
} else if (method == 'addEventListener') {
|
|
199
|
+
xhr.addEventListener('readystatechange', listener);
|
|
200
|
+
}
|
|
201
|
+
function start() {
|
|
202
|
+
xhr.open('GET', '/foo');
|
|
203
|
+
_assert.default.equal(xhr.readyState, 1, 'readyState check');
|
|
204
|
+
xhr.send();
|
|
205
|
+
}
|
|
206
|
+
_assert.default.equal(xhr.readyState, 0, 'readyState check');
|
|
207
|
+
start();
|
|
262
208
|
});
|
|
263
209
|
});
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const stateCounts = { '1': 0, '2': 0, '3': 0, '4': 0 };
|
|
279
|
-
xhr.onreadystatechange = function () {
|
|
280
|
-
stateCounts[xhr.readyState]++;
|
|
281
|
-
};
|
|
282
|
-
xhr.onload = function () {
|
|
283
|
-
assert.deepEqual(stateCounts, { '1': 0, '2': 1, '3': 1, '4': 1 });
|
|
284
|
-
assert.strictEqual(xhr.responseText, 'foo2 response!');
|
|
210
|
+
});
|
|
211
|
+
describe('multiple event listeners', () => {
|
|
212
|
+
it('should fire both together', done => {
|
|
213
|
+
let simpleFired = false,
|
|
214
|
+
addedFired = false;
|
|
215
|
+
xhr.onreadystatechange = function (event) {
|
|
216
|
+
simpleFired = true;
|
|
217
|
+
};
|
|
218
|
+
xhr.addEventListener('readystatechange', function (event) {
|
|
219
|
+
addedFired = true;
|
|
220
|
+
});
|
|
221
|
+
xhr.addEventListener('readystatechange', function (event) {
|
|
222
|
+
if (this.readyState == 4) {
|
|
223
|
+
(0, _assert.default)(simpleFired && addedFired, 'check that both listeners fired');
|
|
285
224
|
done();
|
|
286
|
-
}
|
|
287
|
-
xhr.onloadend = noop;
|
|
225
|
+
}
|
|
288
226
|
});
|
|
227
|
+
xhr.open('GET', '/foo');
|
|
228
|
+
xhr.send();
|
|
289
229
|
});
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
assert.equal(xhr.responseText, 'Response here!', 'response check');
|
|
302
|
-
assert(onloadSpy.calledOnce, 'check onload was ran');
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it('async arg as undefined counts as false', () => {
|
|
306
|
-
const onloadSpy = sinon.spy();
|
|
307
|
-
xhr.onload = function () {
|
|
308
|
-
assert.strictEqual(this, xhr, 'this check');
|
|
309
|
-
onloadSpy();
|
|
310
|
-
};
|
|
311
|
-
xhr.open('GET', '/foo', undefined);
|
|
312
|
-
xhr.send();
|
|
313
|
-
assert.equal(xhr.readyState, 4, 'readyState check');
|
|
314
|
-
assert.equal(xhr.responseText, 'Response here!', 'response check');
|
|
315
|
-
assert(onloadSpy.calledOnce, 'check onload was ran');
|
|
230
|
+
});
|
|
231
|
+
describe('removeEventListener', () => {
|
|
232
|
+
it('should work', done => {
|
|
233
|
+
const badListener = function (event) {
|
|
234
|
+
throw new Error('this listener should have been removed');
|
|
235
|
+
};
|
|
236
|
+
xhr.addEventListener('readystatechange', badListener);
|
|
237
|
+
xhr.addEventListener('readystatechange', function (event) {
|
|
238
|
+
if (this.readyState == 4) {
|
|
239
|
+
done();
|
|
240
|
+
}
|
|
316
241
|
});
|
|
242
|
+
xhr.removeEventListener('readystatechange', badListener);
|
|
243
|
+
xhr.open('GET', '/foo');
|
|
244
|
+
xhr.send();
|
|
317
245
|
});
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
xhr.addEventListener('readystatechange', function (event: Object) {
|
|
332
|
-
if (this.readyState == 4) {
|
|
333
|
-
step();
|
|
246
|
+
});
|
|
247
|
+
describe('abort', () => {
|
|
248
|
+
it('should work after send', done => {
|
|
249
|
+
let finishCount = 0;
|
|
250
|
+
xhr.onreadystatechange = function () {
|
|
251
|
+
if (this.readyState == 4) {
|
|
252
|
+
if (finishCount++ === 0) {
|
|
253
|
+
_assert.default.equal(this.responseText, 'Response here', 'response check');
|
|
254
|
+
xhr.open('GET', '/foo2');
|
|
255
|
+
xhr.send();
|
|
256
|
+
} else {
|
|
257
|
+
_assert.default.equal(this.responseText, 'foo2 response!', 'response check');
|
|
258
|
+
done();
|
|
334
259
|
}
|
|
335
|
-
});
|
|
336
|
-
xhr.open('GET', '/foo');
|
|
337
|
-
xhr.send();
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
it('load', (done) => {
|
|
341
|
-
const step = _.after(2, done);
|
|
342
|
-
function checkEvent(event: Object) {
|
|
343
|
-
assert.strictEqual(event.target, xhr);
|
|
344
|
-
assert.strictEqual(typeof event.lengthComputable, 'boolean');
|
|
345
|
-
assert.strictEqual(typeof event.loaded, 'number');
|
|
346
|
-
assert.strictEqual(typeof event.total, 'number');
|
|
347
|
-
step();
|
|
348
260
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
xhr.
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
261
|
+
};
|
|
262
|
+
xhr.open('GET', '/foo');
|
|
263
|
+
xhr.send();
|
|
264
|
+
xhr.abort();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
describe('open', () => {
|
|
268
|
+
it('should cancel active request but without abort event', done => {
|
|
269
|
+
xhr.onreadystatechange = _sinon.default.spy();
|
|
270
|
+
xhr.onabort = xhr.onerror = xhr.onload = xhr.onloadend = thrower();
|
|
271
|
+
xhr.open('GET', '/foo');
|
|
272
|
+
_assert.default.strictEqual(xhr.readyState, 1);
|
|
273
|
+
(0, _assert.default)(xhr.onreadystatechange.calledOnce);
|
|
274
|
+
xhr.onreadystatechange = thrower('readyStateChange should not happen here');
|
|
275
|
+
xhr.send();
|
|
276
|
+
xhr.open('GET', '/foo2');
|
|
277
|
+
xhr.send();
|
|
278
|
+
const stateCounts = {
|
|
279
|
+
'1': 0,
|
|
280
|
+
'2': 0,
|
|
281
|
+
'3': 0,
|
|
282
|
+
'4': 0
|
|
283
|
+
};
|
|
284
|
+
xhr.onreadystatechange = function () {
|
|
285
|
+
stateCounts[xhr.readyState]++;
|
|
286
|
+
};
|
|
287
|
+
xhr.onload = function () {
|
|
288
|
+
_assert.default.deepEqual(stateCounts, {
|
|
289
|
+
'1': 0,
|
|
290
|
+
'2': 1,
|
|
291
|
+
'3': 1,
|
|
292
|
+
'4': 1
|
|
293
|
+
});
|
|
294
|
+
_assert.default.strictEqual(xhr.responseText, 'foo2 response!');
|
|
295
|
+
done();
|
|
296
|
+
};
|
|
297
|
+
xhr.onloadend = _noop.default;
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
describe('sync', () => {
|
|
301
|
+
it('can do synchronous requests', () => {
|
|
302
|
+
const onloadSpy = _sinon.default.spy();
|
|
303
|
+
xhr.onload = function () {
|
|
304
|
+
_assert.default.strictEqual(this, xhr, 'this check');
|
|
305
|
+
onloadSpy();
|
|
306
|
+
};
|
|
307
|
+
xhr.open('GET', '/foo', false);
|
|
308
|
+
xhr.send();
|
|
309
|
+
_assert.default.equal(xhr.readyState, 4, 'readyState check');
|
|
310
|
+
_assert.default.equal(xhr.responseText, 'Response here!', 'response check');
|
|
311
|
+
(0, _assert.default)(onloadSpy.calledOnce, 'check onload was ran');
|
|
312
|
+
});
|
|
313
|
+
it('async arg as undefined counts as false', () => {
|
|
314
|
+
const onloadSpy = _sinon.default.spy();
|
|
315
|
+
xhr.onload = function () {
|
|
316
|
+
_assert.default.strictEqual(this, xhr, 'this check');
|
|
317
|
+
onloadSpy();
|
|
318
|
+
};
|
|
319
|
+
xhr.open('GET', '/foo', undefined);
|
|
320
|
+
xhr.send();
|
|
321
|
+
_assert.default.equal(xhr.readyState, 4, 'readyState check');
|
|
322
|
+
_assert.default.equal(xhr.responseText, 'Response here!', 'response check');
|
|
323
|
+
(0, _assert.default)(onloadSpy.calledOnce, 'check onload was ran');
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
describe('events', () => {
|
|
327
|
+
it('readystatechange', done => {
|
|
328
|
+
const step = _lodash.default.after(2, done);
|
|
329
|
+
function checkEvent(event) {
|
|
330
|
+
_assert.default.strictEqual(event.target, xhr);
|
|
331
|
+
step();
|
|
332
|
+
}
|
|
333
|
+
xhr.onreadystatechange = function (event) {
|
|
334
|
+
if (this.readyState == 4) {
|
|
396
335
|
step();
|
|
397
336
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
xhr.onerror = checkEvent;
|
|
402
|
-
xhr.addEventListener('error', checkEvent);
|
|
403
|
-
xhr.open('GET', '/non-existent-page');
|
|
404
|
-
xhr.send();
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
it('abort', (done) => {
|
|
408
|
-
const step = _.after(2, done);
|
|
409
|
-
function checkEvent(event: Object) {
|
|
410
|
-
assert.strictEqual(event.target, xhr);
|
|
411
|
-
assert.strictEqual(typeof event.lengthComputable, 'boolean');
|
|
412
|
-
assert.strictEqual(typeof event.loaded, 'number');
|
|
413
|
-
assert.strictEqual(typeof event.total, 'number');
|
|
337
|
+
};
|
|
338
|
+
xhr.addEventListener('readystatechange', function (event) {
|
|
339
|
+
if (this.readyState == 4) {
|
|
414
340
|
step();
|
|
415
341
|
}
|
|
416
|
-
xhr.onabort = checkEvent;
|
|
417
|
-
xhr.addEventListener('abort', checkEvent);
|
|
418
|
-
xhr.open('GET', '/foo');
|
|
419
|
-
xhr.send();
|
|
420
|
-
xhr.abort();
|
|
421
342
|
});
|
|
343
|
+
xhr.open('GET', '/foo');
|
|
344
|
+
xhr.send();
|
|
422
345
|
});
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
assert.strictEqual(xhr.responseText, 'POST request');
|
|
438
|
-
done();
|
|
439
|
-
};
|
|
440
|
-
xhr.send();
|
|
441
|
-
});
|
|
346
|
+
it('load', done => {
|
|
347
|
+
const step = _lodash.default.after(2, done);
|
|
348
|
+
function checkEvent(event) {
|
|
349
|
+
_assert.default.strictEqual(event.target, xhr);
|
|
350
|
+
_assert.default.strictEqual(typeof event.lengthComputable, 'boolean');
|
|
351
|
+
_assert.default.strictEqual(typeof event.loaded, 'number');
|
|
352
|
+
_assert.default.strictEqual(typeof event.total, 'number');
|
|
353
|
+
step();
|
|
354
|
+
}
|
|
355
|
+
xhr.onload = checkEvent;
|
|
356
|
+
xhr.addEventListener('load', checkEvent);
|
|
357
|
+
xhr.onerror = thrower();
|
|
358
|
+
xhr.open('GET', '/foo');
|
|
359
|
+
xhr.send();
|
|
442
360
|
});
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
});
|
|
361
|
+
it('loadstart', done => {
|
|
362
|
+
const step = _lodash.default.after(2, done);
|
|
363
|
+
function checkEvent(event) {
|
|
364
|
+
_assert.default.strictEqual(event.target, xhr);
|
|
365
|
+
_assert.default.strictEqual(event.lengthComputable, false);
|
|
366
|
+
_assert.default.strictEqual(typeof event.loaded, 'number');
|
|
367
|
+
_assert.default.strictEqual(typeof event.total, 'number');
|
|
368
|
+
step();
|
|
369
|
+
}
|
|
370
|
+
xhr.onloadstart = checkEvent;
|
|
371
|
+
xhr.addEventListener('loadstart', checkEvent);
|
|
372
|
+
xhr.open('GET', '/foo');
|
|
373
|
+
xhr.send();
|
|
374
|
+
xhr.abort();
|
|
458
375
|
});
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
376
|
+
it('loadend', done => {
|
|
377
|
+
const step = _lodash.default.after(4, done);
|
|
378
|
+
function checkEvent(event) {
|
|
379
|
+
_assert.default.strictEqual(event.target, xhr);
|
|
380
|
+
_assert.default.strictEqual(typeof event.lengthComputable, 'boolean');
|
|
381
|
+
_assert.default.strictEqual(typeof event.loaded, 'number');
|
|
382
|
+
_assert.default.strictEqual(typeof event.total, 'number');
|
|
383
|
+
step();
|
|
384
|
+
}
|
|
385
|
+
xhr.onload = checkEvent;
|
|
386
|
+
xhr.addEventListener('load', checkEvent);
|
|
387
|
+
xhr.onloadend = checkEvent;
|
|
388
|
+
xhr.addEventListener('loadend', checkEvent);
|
|
389
|
+
xhr.open('GET', '/foo');
|
|
390
|
+
xhr.send();
|
|
391
|
+
});
|
|
392
|
+
it('error', done => {
|
|
393
|
+
const step = _lodash.default.after(4, done);
|
|
394
|
+
function checkEvent(event) {
|
|
395
|
+
_assert.default.strictEqual(event.target, xhr);
|
|
396
|
+
_assert.default.strictEqual(typeof event.lengthComputable, 'boolean');
|
|
397
|
+
_assert.default.strictEqual(typeof event.loaded, 'number');
|
|
398
|
+
_assert.default.strictEqual(typeof event.total, 'number');
|
|
399
|
+
step();
|
|
400
|
+
}
|
|
401
|
+
xhr.onload = thrower();
|
|
402
|
+
xhr.onloadend = step.bind(null, null);
|
|
403
|
+
xhr.addEventListener('loadend', step.bind(null, null));
|
|
404
|
+
xhr.onerror = checkEvent;
|
|
405
|
+
xhr.addEventListener('error', checkEvent);
|
|
406
|
+
xhr.open('GET', '/non-existent-page');
|
|
407
|
+
xhr.send();
|
|
408
|
+
});
|
|
409
|
+
it('abort', done => {
|
|
410
|
+
const step = _lodash.default.after(2, done);
|
|
411
|
+
function checkEvent(event) {
|
|
412
|
+
_assert.default.strictEqual(event.target, xhr);
|
|
413
|
+
_assert.default.strictEqual(typeof event.lengthComputable, 'boolean');
|
|
414
|
+
_assert.default.strictEqual(typeof event.loaded, 'number');
|
|
415
|
+
_assert.default.strictEqual(typeof event.total, 'number');
|
|
416
|
+
step();
|
|
417
|
+
}
|
|
418
|
+
xhr.onabort = checkEvent;
|
|
419
|
+
xhr.addEventListener('abort', checkEvent);
|
|
420
|
+
xhr.open('GET', '/foo');
|
|
421
|
+
xhr.send();
|
|
422
|
+
xhr.abort();
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
describe('post', () => {
|
|
426
|
+
it('works', done => {
|
|
427
|
+
xhr.open('POST', '/foo');
|
|
428
|
+
xhr.onload = function () {
|
|
429
|
+
_assert.default.strictEqual(xhr.responseText, 'body received');
|
|
430
|
+
done();
|
|
431
|
+
};
|
|
432
|
+
xhr.send('somedata');
|
|
433
|
+
});
|
|
434
|
+
it('works without body', done => {
|
|
435
|
+
xhr.open('POST', '/foo');
|
|
436
|
+
xhr.onload = function () {
|
|
437
|
+
_assert.default.strictEqual(xhr.responseText, 'POST request');
|
|
438
|
+
done();
|
|
439
|
+
};
|
|
440
|
+
xhr.send();
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
describe('properties', () => {
|
|
444
|
+
it('has the necessary constants', () => {
|
|
445
|
+
_assert.default.strictEqual(XHRConstructor.UNSENT, 0);
|
|
446
|
+
_assert.default.strictEqual(XHRConstructor.OPENED, 1);
|
|
447
|
+
_assert.default.strictEqual(XHRConstructor.HEADERS_RECEIVED, 2);
|
|
448
|
+
_assert.default.strictEqual(XHRConstructor.LOADING, 3);
|
|
449
|
+
_assert.default.strictEqual(XHRConstructor.DONE, 4);
|
|
450
|
+
_assert.default.strictEqual(xhr.UNSENT, 0);
|
|
451
|
+
_assert.default.strictEqual(xhr.OPENED, 1);
|
|
452
|
+
_assert.default.strictEqual(xhr.HEADERS_RECEIVED, 2);
|
|
453
|
+
_assert.default.strictEqual(xhr.LOADING, 3);
|
|
454
|
+
_assert.default.strictEqual(xhr.DONE, 4);
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
describe('responseType', () => {
|
|
458
|
+
it('supports non-text values', done => {
|
|
459
|
+
xhr.responseType = 'testing';
|
|
460
|
+
xhr.onreadystatechange = function () {
|
|
461
|
+
if (this.readyState == 4) {
|
|
462
|
+
_assert.default.equal(xhr.response, 'testing here!');
|
|
463
|
+
let rt = '';
|
|
464
|
+
try {
|
|
465
|
+
rt = xhr.responseText;
|
|
466
|
+
} catch (e) {
|
|
467
|
+
// ignore
|
|
474
468
|
}
|
|
475
|
-
|
|
476
|
-
xhr.open('GET', '/foo');
|
|
477
|
-
xhr.send();
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
it('supports responseXml', (done) => {
|
|
481
|
-
xhr.onload = function () {
|
|
482
|
-
assert.equal(xhr.responseText, 'testing here!');
|
|
483
|
-
assert.deepEqual(xhr.responseXML, { fakeXml: true });
|
|
469
|
+
_assert.default.strictEqual(rt, '', 'responseText check');
|
|
484
470
|
done();
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
xhr.open('GET', '/foo');
|
|
474
|
+
xhr.send();
|
|
489
475
|
});
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
xhr.
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
done();
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
assert.strictEqual(xhr.getResponseHeader('X-Test'), null);
|
|
504
|
-
xhr.open('GET', '/foo');
|
|
505
|
-
assert.strictEqual(xhr.getResponseHeader('X-Test'), null);
|
|
506
|
-
xhr.send();
|
|
507
|
-
assert.strictEqual(xhr.getResponseHeader('X-Test'), null);
|
|
508
|
-
});
|
|
476
|
+
it('supports responseXml', done => {
|
|
477
|
+
xhr.onload = function () {
|
|
478
|
+
_assert.default.equal(xhr.responseText, 'testing here!');
|
|
479
|
+
_assert.default.deepEqual(xhr.responseXML, {
|
|
480
|
+
fakeXml: true
|
|
481
|
+
});
|
|
482
|
+
done();
|
|
483
|
+
};
|
|
484
|
+
xhr.open('GET', '/fooXml');
|
|
485
|
+
xhr.send();
|
|
509
486
|
});
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
assert.strictEqual(xhr.getAllResponseHeaders(), null);
|
|
529
|
-
xhr.send();
|
|
530
|
-
assert.strictEqual(xhr.getAllResponseHeaders(), null);
|
|
531
|
-
});
|
|
487
|
+
});
|
|
488
|
+
describe('getResponseHeader', () => {
|
|
489
|
+
it('should work', done => {
|
|
490
|
+
xhr.onreadystatechange = function () {
|
|
491
|
+
if (this.readyState < 2) {
|
|
492
|
+
_assert.default.strictEqual(xhr.getResponseHeader('X-Test'), null);
|
|
493
|
+
} else {
|
|
494
|
+
_assert.default.equal(this.getResponseHeader('X-Test'), 'Header Value');
|
|
495
|
+
}
|
|
496
|
+
if (this.readyState == 4) {
|
|
497
|
+
done();
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
_assert.default.strictEqual(xhr.getResponseHeader('X-Test'), null);
|
|
501
|
+
xhr.open('GET', '/foo');
|
|
502
|
+
_assert.default.strictEqual(xhr.getResponseHeader('X-Test'), null);
|
|
503
|
+
xhr.send();
|
|
504
|
+
_assert.default.strictEqual(xhr.getResponseHeader('X-Test'), null);
|
|
532
505
|
});
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}
|
|
506
|
+
});
|
|
507
|
+
describe('getAllResponseHeaders', () => {
|
|
508
|
+
it('should work', done => {
|
|
509
|
+
xhr.onreadystatechange = function () {
|
|
510
|
+
if (this.readyState < 2) {
|
|
511
|
+
_assert.default.strictEqual(xhr.getAllResponseHeaders(), null);
|
|
512
|
+
} else {
|
|
513
|
+
_assert.default.equal(this.getAllResponseHeaders().trim().toLowerCase(), 'x-test: header value');
|
|
514
|
+
}
|
|
515
|
+
if (this.readyState == 4) {
|
|
516
|
+
done();
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
_assert.default.strictEqual(xhr.getAllResponseHeaders(), null);
|
|
520
|
+
xhr.open('GET', '/foo');
|
|
521
|
+
_assert.default.strictEqual(xhr.getAllResponseHeaders(), null);
|
|
522
|
+
xhr.send();
|
|
523
|
+
_assert.default.strictEqual(xhr.getAllResponseHeaders(), null);
|
|
546
524
|
});
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
525
|
+
});
|
|
526
|
+
describe('setRequestHeader', () => {
|
|
527
|
+
it('should work', done => {
|
|
528
|
+
xhr.onreadystatechange = function () {
|
|
529
|
+
if (this.readyState == 4) {
|
|
530
|
+
_assert.default.equal(this.response, 'header value received');
|
|
531
|
+
done();
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
xhr.open('GET', '/foo');
|
|
535
|
+
xhr.setRequestHeader('X-Special', 'Value');
|
|
536
|
+
xhr.send();
|
|
554
537
|
});
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
// set to a real XMLHttpRequest object.
|
|
562
|
-
|
|
563
|
-
it('works with MailTrack', (done) => {
|
|
564
|
-
const realXhr = new XMLHttpRequest();
|
|
565
|
-
realXhr.onload = () => done();
|
|
566
|
-
XHRConstructor.prototype.open.call(realXhr, 'GET', '/foo');
|
|
567
|
-
realXhr.send();
|
|
568
|
-
});
|
|
538
|
+
});
|
|
539
|
+
describe('prototype', () => {
|
|
540
|
+
it('should be present', () => {
|
|
541
|
+
(0, _assert.default)('prototype' in XHRConstructor);
|
|
542
|
+
(0, _assert.default)(typeof XHRConstructor.prototype.open === 'function');
|
|
543
|
+
(0, _assert.default)(typeof XHRConstructor.prototype.send === 'function');
|
|
569
544
|
});
|
|
570
545
|
});
|
|
571
|
-
|
|
572
|
-
|
|
546
|
+
describe('MailTrack compatibility', () => {
|
|
547
|
+
// MailTrack redefines js_frame's XMLHttpRequest.prototype.open to do
|
|
548
|
+
// some stuff, and then looks up the main frame's
|
|
549
|
+
// XMLHttpRequest.prototype.open and calls it.
|
|
550
|
+
// This can result in XHRProxy.prototype.open being called with `this`
|
|
551
|
+
// set to a real XMLHttpRequest object.
|
|
573
552
|
|
|
553
|
+
it('works with MailTrack', done => {
|
|
554
|
+
const realXhr = new XMLHttpRequest();
|
|
555
|
+
realXhr.onload = () => done();
|
|
556
|
+
XHRConstructor.prototype.open.call(realXhr, 'GET', '/foo');
|
|
557
|
+
realXhr.send();
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
});
|
|
574
562
|
describe('XHRProxyFactory', () => {
|
|
575
563
|
describe('wrappers', () => {
|
|
576
|
-
it('should be used with responseTextChanger present and work on re-used object',
|
|
564
|
+
it('should be used with responseTextChanger present and work on re-used object', done => {
|
|
577
565
|
let origResponse;
|
|
578
566
|
let originalSendBodyLoggerRan = 0;
|
|
579
567
|
let originalResponseTextLoggerRan = 0;
|
|
@@ -582,325 +570,241 @@ describe('XHRProxyFactory', () => {
|
|
|
582
570
|
let firstAfterListenersRan = 0;
|
|
583
571
|
let rsc4Ran = 0;
|
|
584
572
|
let runCount = 0;
|
|
585
|
-
function checkConnectionParam(
|
|
586
|
-
connection,
|
|
587
|
-
expectStatus,
|
|
588
|
-
expectOriginalSendBody
|
|
589
|
-
) {
|
|
590
|
-
assert.equal((connection: any)._flag, true, 'connection object check');
|
|
573
|
+
function checkConnectionParam(connection, expectStatus, expectOriginalSendBody) {
|
|
574
|
+
_assert.default.equal(connection._flag, true, 'connection object check');
|
|
591
575
|
if (expectStatus) {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
(connection: any).responseType,
|
|
595
|
-
'text',
|
|
596
|
-
'responseType check'
|
|
597
|
-
);
|
|
576
|
+
_assert.default.equal(connection.status, 200, 'status check');
|
|
577
|
+
_assert.default.equal(connection.responseType, 'text', 'responseType check');
|
|
598
578
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
);
|
|
604
|
-
assert.equal(connection.method, 'GET', 'method check');
|
|
605
|
-
assert.equal(connection.url, '/foo', 'url check');
|
|
606
|
-
assert.deepEqual(connection.params, {}, 'params check');
|
|
579
|
+
_assert.default.equal(connection.originalSendBody, expectOriginalSendBody ? 'body test' : undefined, 'body check');
|
|
580
|
+
_assert.default.equal(connection.method, 'GET', 'method check');
|
|
581
|
+
_assert.default.equal(connection.url, '/foo', 'url check');
|
|
582
|
+
_assert.default.deepEqual(connection.params, {}, 'params check');
|
|
607
583
|
}
|
|
608
|
-
const wrappers = [
|
|
609
|
-
{
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
);
|
|
616
|
-
(connection: any)._flag = true;
|
|
617
|
-
checkConnectionParam(connection, false, false);
|
|
618
|
-
return connection.url == '/foo';
|
|
619
|
-
},
|
|
620
|
-
originalSendBodyLogger(connection, body) {
|
|
621
|
-
assert.strictEqual(this, wrappers[0], 'this check');
|
|
622
|
-
checkConnectionParam(connection, false, true);
|
|
623
|
-
assert.equal(body, 'body test', 'body check');
|
|
624
|
-
originalSendBodyLoggerRan++;
|
|
625
|
-
},
|
|
626
|
-
originalResponseTextLogger(connection, response) {
|
|
627
|
-
assert.strictEqual(this, wrappers[0], 'this check');
|
|
628
|
-
checkConnectionParam(connection, true, true);
|
|
629
|
-
originalResponseTextLoggerRan++;
|
|
630
|
-
origResponse = response;
|
|
631
|
-
},
|
|
632
|
-
responseTextChanger(connection, response) {
|
|
633
|
-
assert.strictEqual(this, wrappers[0], 'this check');
|
|
634
|
-
checkConnectionParam(connection, true, true);
|
|
635
|
-
responseTextChangerRan++;
|
|
636
|
-
assert.equal(response, origResponse);
|
|
637
|
-
return response + '-modified' + runCount;
|
|
638
|
-
},
|
|
639
|
-
finalResponseTextLogger(connection, response) {
|
|
640
|
-
assert.strictEqual(this, wrappers[0], 'this check');
|
|
641
|
-
checkConnectionParam(connection, true, true);
|
|
642
|
-
finalResponseTextLoggerRan++;
|
|
643
|
-
assert.equal(response, origResponse + '-modified' + runCount);
|
|
644
|
-
},
|
|
645
|
-
afterListeners(connection) {
|
|
646
|
-
firstAfterListenersRan++;
|
|
647
|
-
},
|
|
584
|
+
const wrappers = [{
|
|
585
|
+
isRelevantTo(connection) {
|
|
586
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
587
|
+
(0, _assert.default)(!connection._flag, 'check that connection object is fresh');
|
|
588
|
+
connection._flag = true;
|
|
589
|
+
checkConnectionParam(connection, false, false);
|
|
590
|
+
return connection.url == '/foo';
|
|
648
591
|
},
|
|
649
|
-
{
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
1 * runCount,
|
|
668
|
-
'check that afterListeners ran correct number of times'
|
|
669
|
-
);
|
|
670
|
-
assert.equal(
|
|
671
|
-
rsc4Ran,
|
|
672
|
-
1 * runCount,
|
|
673
|
-
'check that readystatechange listener ran correct number of times'
|
|
674
|
-
);
|
|
675
|
-
if (runCount === 1) {
|
|
676
|
-
start();
|
|
677
|
-
} else {
|
|
678
|
-
done();
|
|
679
|
-
}
|
|
680
|
-
},
|
|
592
|
+
originalSendBodyLogger(connection, body) {
|
|
593
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
594
|
+
checkConnectionParam(connection, false, true);
|
|
595
|
+
_assert.default.equal(body, 'body test', 'body check');
|
|
596
|
+
originalSendBodyLoggerRan++;
|
|
597
|
+
},
|
|
598
|
+
originalResponseTextLogger(connection, response) {
|
|
599
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
600
|
+
checkConnectionParam(connection, true, true);
|
|
601
|
+
originalResponseTextLoggerRan++;
|
|
602
|
+
origResponse = response;
|
|
603
|
+
},
|
|
604
|
+
responseTextChanger(connection, response) {
|
|
605
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
606
|
+
checkConnectionParam(connection, true, true);
|
|
607
|
+
responseTextChangerRan++;
|
|
608
|
+
_assert.default.equal(response, origResponse);
|
|
609
|
+
return response + '-modified' + runCount;
|
|
681
610
|
},
|
|
682
|
-
{
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
throw new Error('should not run');
|
|
688
|
-
},
|
|
689
|
-
originalResponseTextLogger(connection, response) {
|
|
690
|
-
throw new Error('should not run');
|
|
691
|
-
},
|
|
692
|
-
responseTextChanger(connection, response) {
|
|
693
|
-
throw new Error('should not run');
|
|
694
|
-
},
|
|
695
|
-
finalResponseTextLogger(connection, response) {
|
|
696
|
-
throw new Error('should not run');
|
|
697
|
-
},
|
|
698
|
-
afterListeners(connection) {
|
|
699
|
-
throw new Error('should not run');
|
|
700
|
-
},
|
|
611
|
+
finalResponseTextLogger(connection, response) {
|
|
612
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
613
|
+
checkConnectionParam(connection, true, true);
|
|
614
|
+
finalResponseTextLoggerRan++;
|
|
615
|
+
_assert.default.equal(response, origResponse + '-modified' + runCount);
|
|
701
616
|
},
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
617
|
+
afterListeners(connection) {
|
|
618
|
+
firstAfterListenersRan++;
|
|
619
|
+
}
|
|
620
|
+
}, {
|
|
621
|
+
isRelevantTo(connection) {
|
|
622
|
+
return true;
|
|
623
|
+
},
|
|
624
|
+
originalSendBodyLogger(connection, body) {
|
|
625
|
+
originalSendBodyLoggerRan++;
|
|
626
|
+
},
|
|
627
|
+
originalResponseTextLogger(connection, response) {
|
|
628
|
+
originalResponseTextLoggerRan++;
|
|
629
|
+
_assert.default.equal(response, origResponse);
|
|
630
|
+
},
|
|
631
|
+
finalResponseTextLogger(connection, response) {
|
|
632
|
+
finalResponseTextLoggerRan++;
|
|
633
|
+
_assert.default.equal(response, origResponse + '-modified' + runCount);
|
|
634
|
+
},
|
|
635
|
+
afterListeners(connection) {
|
|
636
|
+
_assert.default.equal(firstAfterListenersRan, 1 * runCount, 'check that afterListeners ran correct number of times');
|
|
637
|
+
_assert.default.equal(rsc4Ran, 1 * runCount, 'check that readystatechange listener ran correct number of times');
|
|
638
|
+
if (runCount === 1) {
|
|
639
|
+
start();
|
|
640
|
+
} else {
|
|
641
|
+
done();
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}, {
|
|
645
|
+
isRelevantTo(connection) {
|
|
646
|
+
return false;
|
|
647
|
+
},
|
|
648
|
+
originalSendBodyLogger(connection, body) {
|
|
649
|
+
throw new Error('should not run');
|
|
650
|
+
},
|
|
651
|
+
originalResponseTextLogger(connection, response) {
|
|
652
|
+
throw new Error('should not run');
|
|
653
|
+
},
|
|
654
|
+
responseTextChanger(connection, response) {
|
|
655
|
+
throw new Error('should not run');
|
|
656
|
+
},
|
|
657
|
+
finalResponseTextLogger(connection, response) {
|
|
658
|
+
throw new Error('should not run');
|
|
659
|
+
},
|
|
660
|
+
afterListeners(connection) {
|
|
661
|
+
throw new Error('should not run');
|
|
662
|
+
}
|
|
663
|
+
}];
|
|
664
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
665
|
+
logError: logError
|
|
705
666
|
});
|
|
706
667
|
const xhr = new XHRProxy();
|
|
707
668
|
xhr.onreadystatechange = function () {
|
|
708
669
|
if (this.readyState == 3) {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
'',
|
|
712
|
-
'check response is empty until end when responseTextChanger is used'
|
|
713
|
-
);
|
|
714
|
-
assert.equal(this.responseText, this.response, 'check responseText');
|
|
670
|
+
_assert.default.equal(this.response, '', 'check response is empty until end when responseTextChanger is used');
|
|
671
|
+
_assert.default.equal(this.responseText, this.response, 'check responseText');
|
|
715
672
|
}
|
|
716
673
|
if (this.readyState == 4) {
|
|
717
674
|
runCount++;
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
);
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
2 * runCount,
|
|
726
|
-
'check that originalResponseTextLogger ran correct number of times'
|
|
727
|
-
);
|
|
728
|
-
assert.equal(
|
|
729
|
-
responseTextChangerRan,
|
|
730
|
-
1 * runCount,
|
|
731
|
-
'check that responseTextChanger ran correct number of times'
|
|
732
|
-
);
|
|
733
|
-
assert.equal(
|
|
734
|
-
finalResponseTextLoggerRan,
|
|
735
|
-
2 * runCount,
|
|
736
|
-
'check that finalResponseTextLogger ran correct number of times'
|
|
737
|
-
);
|
|
738
|
-
assert.equal(
|
|
739
|
-
firstAfterListenersRan,
|
|
740
|
-
1 * (runCount - 1),
|
|
741
|
-
'check that afterListeners ran correct number of times'
|
|
742
|
-
);
|
|
743
|
-
assert.equal(
|
|
744
|
-
this.response,
|
|
745
|
-
origResponse + '-modified' + (runCount - 1),
|
|
746
|
-
'check that response was modified'
|
|
747
|
-
);
|
|
748
|
-
assert.equal(this.responseText, this.response, 'check responseText');
|
|
675
|
+
_assert.default.equal(originalSendBodyLoggerRan, 2 * runCount, 'check that originalSendBodyLogger ran correct number of times');
|
|
676
|
+
_assert.default.equal(originalResponseTextLoggerRan, 2 * runCount, 'check that originalResponseTextLogger ran correct number of times');
|
|
677
|
+
_assert.default.equal(responseTextChangerRan, 1 * runCount, 'check that responseTextChanger ran correct number of times');
|
|
678
|
+
_assert.default.equal(finalResponseTextLoggerRan, 2 * runCount, 'check that finalResponseTextLogger ran correct number of times');
|
|
679
|
+
_assert.default.equal(firstAfterListenersRan, 1 * (runCount - 1), 'check that afterListeners ran correct number of times');
|
|
680
|
+
_assert.default.equal(this.response, origResponse + '-modified' + (runCount - 1), 'check that response was modified');
|
|
681
|
+
_assert.default.equal(this.responseText, this.response, 'check responseText');
|
|
749
682
|
rsc4Ran++;
|
|
750
683
|
// done is in afterListener wrapper
|
|
751
684
|
}
|
|
752
685
|
};
|
|
686
|
+
|
|
753
687
|
function start() {
|
|
754
688
|
xhr.open('GET', '/foo');
|
|
755
689
|
xhr.send('body test');
|
|
756
690
|
}
|
|
757
691
|
start();
|
|
758
692
|
});
|
|
759
|
-
|
|
760
|
-
it('should be used without responseTextChanger present', (done) => {
|
|
693
|
+
it('should be used without responseTextChanger present', done => {
|
|
761
694
|
let origResponse;
|
|
762
695
|
let originalResponseTextLoggerRan = 0;
|
|
763
696
|
let finalResponseTextLoggerRan = 0;
|
|
764
|
-
const wrappers = [
|
|
765
|
-
{
|
|
766
|
-
|
|
767
|
-
return true;
|
|
768
|
-
},
|
|
769
|
-
originalResponseTextLogger(connection, response) {
|
|
770
|
-
assert.strictEqual(this, wrappers[0], 'this check');
|
|
771
|
-
originalResponseTextLoggerRan++;
|
|
772
|
-
origResponse = response;
|
|
773
|
-
},
|
|
774
|
-
finalResponseTextLogger(connection, response) {
|
|
775
|
-
assert.strictEqual(this, wrappers[0], 'this check');
|
|
776
|
-
finalResponseTextLoggerRan++;
|
|
777
|
-
assert.equal(response, origResponse);
|
|
778
|
-
},
|
|
697
|
+
const wrappers = [{
|
|
698
|
+
isRelevantTo(connection) {
|
|
699
|
+
return true;
|
|
779
700
|
},
|
|
780
|
-
{
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
responseTextChanger(connection, response) {
|
|
785
|
-
throw new Error('should not run');
|
|
786
|
-
},
|
|
701
|
+
originalResponseTextLogger(connection, response) {
|
|
702
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
703
|
+
originalResponseTextLoggerRan++;
|
|
704
|
+
origResponse = response;
|
|
787
705
|
},
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
706
|
+
finalResponseTextLogger(connection, response) {
|
|
707
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
708
|
+
finalResponseTextLoggerRan++;
|
|
709
|
+
_assert.default.equal(response, origResponse);
|
|
710
|
+
}
|
|
711
|
+
}, {
|
|
712
|
+
isRelevantTo(connection) {
|
|
713
|
+
return false;
|
|
714
|
+
},
|
|
715
|
+
responseTextChanger(connection, response) {
|
|
716
|
+
throw new Error('should not run');
|
|
717
|
+
}
|
|
718
|
+
}];
|
|
719
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
720
|
+
logError: logError
|
|
791
721
|
});
|
|
792
722
|
const xhr = new XHRProxy();
|
|
793
723
|
xhr.onreadystatechange = function () {
|
|
794
|
-
|
|
724
|
+
_assert.default.equal(this.responseText, this.response, 'check responseText');
|
|
795
725
|
if (this.readyState == 3) {
|
|
796
|
-
|
|
726
|
+
_assert.default.equal(this.response, 'Response here', 'check response');
|
|
797
727
|
}
|
|
798
728
|
if (this.readyState == 4) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
1,
|
|
803
|
-
'check that originalResponseTextLogger ran correct number of times'
|
|
804
|
-
);
|
|
805
|
-
assert.equal(
|
|
806
|
-
finalResponseTextLoggerRan,
|
|
807
|
-
1,
|
|
808
|
-
'check that finalResponseTextLogger ran correct number of times'
|
|
809
|
-
);
|
|
729
|
+
_assert.default.equal(this.response, 'Response here!', 'check response');
|
|
730
|
+
_assert.default.equal(originalResponseTextLoggerRan, 1, 'check that originalResponseTextLogger ran correct number of times');
|
|
731
|
+
_assert.default.equal(finalResponseTextLoggerRan, 1, 'check that finalResponseTextLogger ran correct number of times');
|
|
810
732
|
done();
|
|
811
733
|
}
|
|
812
734
|
};
|
|
813
735
|
xhr.open('GET', '/foo');
|
|
814
736
|
xhr.send();
|
|
815
737
|
});
|
|
816
|
-
|
|
817
|
-
it('should not have errors prevent event listeners', (done) => {
|
|
738
|
+
it('should not have errors prevent event listeners', done => {
|
|
818
739
|
let loggerRan = 0;
|
|
819
|
-
const wrappers = [
|
|
820
|
-
{
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
740
|
+
const wrappers = [{
|
|
741
|
+
isRelevantTo(connection) {
|
|
742
|
+
throw testError;
|
|
743
|
+
},
|
|
744
|
+
originalResponseTextLogger(connection, response) {
|
|
745
|
+
throw new Error('should not run');
|
|
746
|
+
}
|
|
747
|
+
}, {
|
|
748
|
+
isRelevantTo(connection) {
|
|
749
|
+
return true;
|
|
827
750
|
},
|
|
828
|
-
{
|
|
829
|
-
|
|
830
|
-
return true;
|
|
831
|
-
},
|
|
832
|
-
originalSendBodyLogger(connection, body) {
|
|
833
|
-
throw testError;
|
|
834
|
-
},
|
|
835
|
-
requestChanger(connection, body) {
|
|
836
|
-
throw testError;
|
|
837
|
-
},
|
|
838
|
-
originalResponseTextLogger(connection, response) {
|
|
839
|
-
loggerRan++;
|
|
840
|
-
throw testError;
|
|
841
|
-
},
|
|
842
|
-
responseTextChanger(connection, response) {
|
|
843
|
-
throw testError;
|
|
844
|
-
},
|
|
845
|
-
finalResponseTextLogger(connection, response) {
|
|
846
|
-
throw testError;
|
|
847
|
-
},
|
|
751
|
+
originalSendBodyLogger(connection, body) {
|
|
752
|
+
throw testError;
|
|
848
753
|
},
|
|
849
|
-
{
|
|
850
|
-
|
|
851
|
-
return true;
|
|
852
|
-
},
|
|
853
|
-
originalSendBodyLogger(connection, body) {
|
|
854
|
-
throw testError;
|
|
855
|
-
},
|
|
856
|
-
originalResponseTextLogger(connection, response) {
|
|
857
|
-
throw testError;
|
|
858
|
-
},
|
|
859
|
-
finalResponseTextLogger(connection, response) {
|
|
860
|
-
throw testError;
|
|
861
|
-
},
|
|
754
|
+
requestChanger(connection, body) {
|
|
755
|
+
throw testError;
|
|
862
756
|
},
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
757
|
+
originalResponseTextLogger(connection, response) {
|
|
758
|
+
loggerRan++;
|
|
759
|
+
throw testError;
|
|
760
|
+
},
|
|
761
|
+
responseTextChanger(connection, response) {
|
|
762
|
+
throw testError;
|
|
763
|
+
},
|
|
764
|
+
finalResponseTextLogger(connection, response) {
|
|
765
|
+
throw testError;
|
|
766
|
+
}
|
|
767
|
+
}, {
|
|
768
|
+
isRelevantTo(connection) {
|
|
769
|
+
return true;
|
|
770
|
+
},
|
|
771
|
+
originalSendBodyLogger(connection, body) {
|
|
772
|
+
throw testError;
|
|
773
|
+
},
|
|
774
|
+
originalResponseTextLogger(connection, response) {
|
|
775
|
+
throw testError;
|
|
776
|
+
},
|
|
777
|
+
finalResponseTextLogger(connection, response) {
|
|
778
|
+
throw testError;
|
|
779
|
+
}
|
|
780
|
+
}];
|
|
781
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
782
|
+
logError: logError
|
|
866
783
|
});
|
|
867
784
|
const xhr = new XHRProxy();
|
|
868
785
|
xhr.onreadystatechange = function () {
|
|
869
786
|
if (this.readyState == 4) {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
'check that logError was called correct number of times'
|
|
874
|
-
);
|
|
875
|
-
assert.equal(
|
|
876
|
-
loggerRan,
|
|
877
|
-
1,
|
|
878
|
-
'check that originalResponseTextLogger was attempted'
|
|
879
|
-
);
|
|
880
|
-
assert.equal(this.response, 'Response here!', 'check response');
|
|
787
|
+
_assert.default.equal(logErrorTestCalls, 9, 'check that logError was called correct number of times');
|
|
788
|
+
_assert.default.equal(loggerRan, 1, 'check that originalResponseTextLogger was attempted');
|
|
789
|
+
_assert.default.equal(this.response, 'Response here!', 'check response');
|
|
881
790
|
done();
|
|
882
791
|
}
|
|
883
792
|
};
|
|
884
793
|
xhr.open('GET', '/foo');
|
|
885
794
|
xhr.send();
|
|
886
795
|
});
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
isRelevantTo(connection) {
|
|
892
|
-
throw new Error('should not run');
|
|
893
|
-
},
|
|
894
|
-
originalResponseTextLogger(connection, response) {
|
|
895
|
-
throw new Error('should not run');
|
|
896
|
-
},
|
|
796
|
+
it('can have wrappers changed after construction', done => {
|
|
797
|
+
const wrappers = [{
|
|
798
|
+
isRelevantTo(connection) {
|
|
799
|
+
throw new Error('should not run');
|
|
897
800
|
},
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
801
|
+
originalResponseTextLogger(connection, response) {
|
|
802
|
+
throw new Error('should not run');
|
|
803
|
+
}
|
|
804
|
+
}];
|
|
805
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
806
|
+
logError: logError
|
|
902
807
|
});
|
|
903
|
-
|
|
904
808
|
let loggerRan = 0;
|
|
905
809
|
wrappers.length = 0;
|
|
906
810
|
wrappers.push({
|
|
@@ -909,130 +813,98 @@ describe('XHRProxyFactory', () => {
|
|
|
909
813
|
},
|
|
910
814
|
originalResponseTextLogger(connection, response) {
|
|
911
815
|
loggerRan++;
|
|
912
|
-
}
|
|
816
|
+
}
|
|
913
817
|
});
|
|
914
|
-
|
|
915
818
|
const xhr = new XHRProxy();
|
|
916
819
|
xhr.onreadystatechange = function () {
|
|
917
820
|
if (this.readyState == 4) {
|
|
918
|
-
|
|
919
|
-
loggerRan,
|
|
920
|
-
1,
|
|
921
|
-
'check that originalResponseTextLogger has run'
|
|
922
|
-
);
|
|
821
|
+
_assert.default.equal(loggerRan, 1, 'check that originalResponseTextLogger has run');
|
|
923
822
|
done();
|
|
924
823
|
}
|
|
925
824
|
};
|
|
926
825
|
xhr.open('GET', '/foo');
|
|
927
826
|
xhr.send();
|
|
928
827
|
});
|
|
929
|
-
|
|
930
|
-
it('should support promises for responseTextChanger', (done) => {
|
|
828
|
+
it('should support promises for responseTextChanger', done => {
|
|
931
829
|
let origResponse;
|
|
932
830
|
let responseTextChangerRan = 0;
|
|
933
831
|
let finalResponseTextLoggerRan = 0;
|
|
934
832
|
function checkConnectionParam(connection) {
|
|
935
|
-
|
|
833
|
+
_assert.default.equal(connection._flag, true, 'connection object check');
|
|
936
834
|
}
|
|
937
|
-
const wrappers = [
|
|
938
|
-
{
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
return connection.url == '/foo';
|
|
944
|
-
},
|
|
945
|
-
originalResponseTextLogger(connection, response) {
|
|
946
|
-
assert.strictEqual(this, wrappers[0], 'this check');
|
|
947
|
-
checkConnectionParam(connection);
|
|
948
|
-
origResponse = response;
|
|
949
|
-
},
|
|
950
|
-
async responseTextChanger(connection, response) {
|
|
951
|
-
assert.strictEqual(this, wrappers[0], 'this check');
|
|
952
|
-
await delay(1);
|
|
953
|
-
checkConnectionParam(connection);
|
|
954
|
-
responseTextChangerRan++;
|
|
955
|
-
assert.equal(response, origResponse);
|
|
956
|
-
assert.equal(
|
|
957
|
-
xhr.readyState,
|
|
958
|
-
3,
|
|
959
|
-
'check that readyState is still LOADING'
|
|
960
|
-
);
|
|
961
|
-
return response + '-modified';
|
|
962
|
-
},
|
|
963
|
-
finalResponseTextLogger(connection, response) {
|
|
964
|
-
assert.strictEqual(this, wrappers[0], 'this check');
|
|
965
|
-
checkConnectionParam(connection);
|
|
966
|
-
finalResponseTextLoggerRan++;
|
|
967
|
-
assert.equal(response, origResponse + '-modified');
|
|
968
|
-
},
|
|
835
|
+
const wrappers = [{
|
|
836
|
+
isRelevantTo(connection) {
|
|
837
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
838
|
+
connection._flag = true;
|
|
839
|
+
checkConnectionParam(connection);
|
|
840
|
+
return connection.url == '/foo';
|
|
969
841
|
},
|
|
970
|
-
{
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
842
|
+
originalResponseTextLogger(connection, response) {
|
|
843
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
844
|
+
checkConnectionParam(connection);
|
|
845
|
+
origResponse = response;
|
|
846
|
+
},
|
|
847
|
+
async responseTextChanger(connection, response) {
|
|
848
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
849
|
+
await (0, _pdelay.default)(1);
|
|
850
|
+
checkConnectionParam(connection);
|
|
851
|
+
responseTextChangerRan++;
|
|
852
|
+
_assert.default.equal(response, origResponse);
|
|
853
|
+
_assert.default.equal(xhr.readyState, 3, 'check that readyState is still LOADING');
|
|
854
|
+
return response + '-modified';
|
|
978
855
|
},
|
|
979
|
-
{
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
},
|
|
989
|
-
finalResponseTextLogger(connection, response) {
|
|
990
|
-
throw new Error('should not run');
|
|
991
|
-
},
|
|
856
|
+
finalResponseTextLogger(connection, response) {
|
|
857
|
+
_assert.default.strictEqual(this, wrappers[0], 'this check');
|
|
858
|
+
checkConnectionParam(connection);
|
|
859
|
+
finalResponseTextLoggerRan++;
|
|
860
|
+
_assert.default.equal(response, origResponse + '-modified');
|
|
861
|
+
}
|
|
862
|
+
}, {
|
|
863
|
+
isRelevantTo(connection) {
|
|
864
|
+
return true;
|
|
992
865
|
},
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
866
|
+
finalResponseTextLogger(connection, response) {
|
|
867
|
+
finalResponseTextLoggerRan++;
|
|
868
|
+
_assert.default.equal(response, origResponse + '-modified');
|
|
869
|
+
}
|
|
870
|
+
}, {
|
|
871
|
+
isRelevantTo(connection) {
|
|
872
|
+
return false;
|
|
873
|
+
},
|
|
874
|
+
requestChanger() {
|
|
875
|
+
throw new Error('should not run');
|
|
876
|
+
},
|
|
877
|
+
responseTextChanger(connection, response) {
|
|
878
|
+
throw new Error('should not run');
|
|
879
|
+
},
|
|
880
|
+
finalResponseTextLogger(connection, response) {
|
|
881
|
+
throw new Error('should not run');
|
|
882
|
+
}
|
|
883
|
+
}];
|
|
884
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
885
|
+
logError: logError
|
|
996
886
|
});
|
|
997
887
|
const xhr = new XHRProxy();
|
|
998
|
-
|
|
999
888
|
let methodCalled = false,
|
|
1000
889
|
addedListenerCalled = false;
|
|
1001
|
-
const finishRsc =
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
1,
|
|
1007
|
-
'check that responseTextChanger ran correct number of times'
|
|
1008
|
-
);
|
|
1009
|
-
assert.equal(
|
|
1010
|
-
finalResponseTextLoggerRan,
|
|
1011
|
-
2,
|
|
1012
|
-
'check that finalResponseTextLogger ran correct number of times'
|
|
1013
|
-
);
|
|
890
|
+
const finishRsc = _lodash.default.after(2, () => {
|
|
891
|
+
(0, _assert.default)(methodCalled, 'check that onreadystatechange method was called');
|
|
892
|
+
(0, _assert.default)(addedListenerCalled, 'check that added listener was called');
|
|
893
|
+
_assert.default.equal(responseTextChangerRan, 1, 'check that responseTextChanger ran correct number of times');
|
|
894
|
+
_assert.default.equal(finalResponseTextLoggerRan, 2, 'check that finalResponseTextLogger ran correct number of times');
|
|
1014
895
|
done();
|
|
1015
896
|
});
|
|
1016
|
-
|
|
1017
897
|
xhr.onreadystatechange = function () {
|
|
1018
|
-
|
|
898
|
+
_assert.default.equal(this.responseText, this.response, 'check responseText');
|
|
1019
899
|
if (this.readyState == 4) {
|
|
1020
|
-
|
|
1021
|
-
this.response,
|
|
1022
|
-
origResponse + '-modified',
|
|
1023
|
-
'check that response was modified'
|
|
1024
|
-
);
|
|
900
|
+
_assert.default.equal(this.response, origResponse + '-modified', 'check that response was modified');
|
|
1025
901
|
methodCalled = true;
|
|
1026
902
|
finishRsc();
|
|
1027
903
|
}
|
|
1028
904
|
};
|
|
1029
905
|
xhr.addEventListener('readystatechange', function () {
|
|
1030
906
|
if (this.readyState == 4) {
|
|
1031
|
-
|
|
1032
|
-
this.response,
|
|
1033
|
-
origResponse + '-modified',
|
|
1034
|
-
'check that response was modified'
|
|
1035
|
-
);
|
|
907
|
+
_assert.default.equal(this.response, origResponse + '-modified', 'check that response was modified');
|
|
1036
908
|
addedListenerCalled = true;
|
|
1037
909
|
finishRsc();
|
|
1038
910
|
}
|
|
@@ -1040,175 +912,136 @@ describe('XHRProxyFactory', () => {
|
|
|
1040
912
|
xhr.open('GET', '/foo');
|
|
1041
913
|
xhr.send();
|
|
1042
914
|
});
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
await delay(1);
|
|
1057
|
-
|
|
1058
|
-
return response + '-modified';
|
|
1059
|
-
},
|
|
1060
|
-
finalResponseTextLogger(connection, response) {
|
|
1061
|
-
throw new Error('should not run');
|
|
1062
|
-
},
|
|
915
|
+
it('should have responseTextChanger promises respect abort', done => {
|
|
916
|
+
const wrappers = [{
|
|
917
|
+
isRelevantTo(connection) {
|
|
918
|
+
return connection.url == '/foo';
|
|
919
|
+
},
|
|
920
|
+
async responseTextChanger(connection, response) {
|
|
921
|
+
// start a new request, aborting the current one, so that the result
|
|
922
|
+
// of this responseTextChanger never gets seen.
|
|
923
|
+
xhr.open('GET', '/foo2');
|
|
924
|
+
xhr.send();
|
|
925
|
+
await (0, _pdelay.default)(1);
|
|
926
|
+
return response + '-modified';
|
|
1063
927
|
},
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
928
|
+
finalResponseTextLogger(connection, response) {
|
|
929
|
+
throw new Error('should not run');
|
|
930
|
+
}
|
|
931
|
+
}];
|
|
932
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
933
|
+
logError: logError
|
|
1067
934
|
});
|
|
1068
935
|
const xhr = new XHRProxy();
|
|
1069
|
-
|
|
1070
936
|
xhr.addEventListener('readystatechange', function () {
|
|
1071
937
|
if (this.readyState == 4) {
|
|
1072
|
-
|
|
938
|
+
_assert.default.equal(this.responseText, 'foo2 response!');
|
|
1073
939
|
done();
|
|
1074
940
|
}
|
|
1075
941
|
});
|
|
1076
942
|
xhr.open('GET', '/foo');
|
|
1077
943
|
xhr.send();
|
|
1078
944
|
});
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
{
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
responseTextChanger(connection, response) {
|
|
1100
|
-
assert.strictEqual(
|
|
1101
|
-
connection.originalResponseText,
|
|
1102
|
-
'foo2 response!'
|
|
1103
|
-
);
|
|
1104
|
-
assert.strictEqual(
|
|
1105
|
-
connection.modifiedResponseText,
|
|
1106
|
-
'foo2 response!a'
|
|
1107
|
-
);
|
|
1108
|
-
assert.strictEqual(connection.modifiedResponseText, response);
|
|
1109
|
-
return response + 'b';
|
|
1110
|
-
},
|
|
1111
|
-
},
|
|
1112
|
-
];
|
|
1113
|
-
const XHRProxy = XHRProxyFactory(XMLHttpRequest, wrappers, {
|
|
1114
|
-
logError: logError,
|
|
945
|
+
it('supports multiple responseTextChanger wrappers', done => {
|
|
946
|
+
const wrappers = [{
|
|
947
|
+
isRelevantTo: () => true,
|
|
948
|
+
responseTextChanger(connection, response) {
|
|
949
|
+
_assert.default.strictEqual(connection.originalResponseText, 'foo2 response!');
|
|
950
|
+
_assert.default.strictEqual(connection.modifiedResponseText, 'foo2 response!');
|
|
951
|
+
_assert.default.strictEqual(connection.modifiedResponseText, response);
|
|
952
|
+
return response + 'a';
|
|
953
|
+
}
|
|
954
|
+
}, {
|
|
955
|
+
isRelevantTo: () => true,
|
|
956
|
+
responseTextChanger(connection, response) {
|
|
957
|
+
_assert.default.strictEqual(connection.originalResponseText, 'foo2 response!');
|
|
958
|
+
_assert.default.strictEqual(connection.modifiedResponseText, 'foo2 response!a');
|
|
959
|
+
_assert.default.strictEqual(connection.modifiedResponseText, response);
|
|
960
|
+
return response + 'b';
|
|
961
|
+
}
|
|
962
|
+
}];
|
|
963
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
964
|
+
logError: logError
|
|
1115
965
|
});
|
|
1116
966
|
const xhr = new XHRProxy();
|
|
1117
|
-
|
|
1118
967
|
xhr.onload = function () {
|
|
1119
|
-
|
|
968
|
+
_assert.default.strictEqual(this.responseText, 'foo2 response!ab');
|
|
1120
969
|
done();
|
|
1121
970
|
};
|
|
1122
971
|
xhr.open('GET', '/foo2');
|
|
1123
972
|
xhr.send();
|
|
1124
973
|
});
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
{
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
];
|
|
1136
|
-
const XHRProxy = XHRProxyFactory(XMLHttpRequest, wrappers, {
|
|
1137
|
-
logError: logErrorSpy,
|
|
974
|
+
it('should ignore invalid responseTextChanger return value', done => {
|
|
975
|
+
const logErrorSpy = _sinon.default.spy();
|
|
976
|
+
const wrappers = [{
|
|
977
|
+
isRelevantTo: () => true,
|
|
978
|
+
responseTextChanger(connection, response) {
|
|
979
|
+
return null;
|
|
980
|
+
}
|
|
981
|
+
}];
|
|
982
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
983
|
+
logError: logErrorSpy
|
|
1138
984
|
});
|
|
1139
985
|
const xhr = new XHRProxy();
|
|
1140
|
-
|
|
1141
986
|
xhr.onload = function () {
|
|
1142
|
-
|
|
1143
|
-
|
|
987
|
+
_assert.default.strictEqual(this.responseText, 'foo2 response!');
|
|
988
|
+
(0, _assert.default)(logErrorSpy.calledOnce);
|
|
1144
989
|
done();
|
|
1145
990
|
};
|
|
1146
991
|
xhr.open('GET', '/foo2');
|
|
1147
992
|
xhr.send();
|
|
1148
993
|
});
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
{
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
},
|
|
1172
|
-
];
|
|
1173
|
-
const XHRProxy = XHRProxyFactory(XMLHttpRequest, wrappers, {
|
|
1174
|
-
logError: logError,
|
|
994
|
+
it('requestChanger should work', done => {
|
|
995
|
+
const wrappers = [{
|
|
996
|
+
isRelevantTo: () => true,
|
|
997
|
+
requestChanger(connection, request) {
|
|
998
|
+
return Promise.resolve({
|
|
999
|
+
method: request.method + 'a',
|
|
1000
|
+
url: request.url + 'A',
|
|
1001
|
+
body: request.body + '1'
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
}, {
|
|
1005
|
+
isRelevantTo: () => true,
|
|
1006
|
+
requestChanger(connection, request) {
|
|
1007
|
+
return {
|
|
1008
|
+
method: request.method + 'b',
|
|
1009
|
+
url: request.url + 'B',
|
|
1010
|
+
body: request.body + '2'
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
}];
|
|
1014
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
1015
|
+
logError: logError
|
|
1175
1016
|
});
|
|
1176
1017
|
const xhr = new XHRProxy();
|
|
1177
|
-
|
|
1178
1018
|
xhr.onload = function () {
|
|
1179
|
-
|
|
1180
|
-
this.responseText,
|
|
1181
|
-
'fooAB requested, data12 received'
|
|
1182
|
-
);
|
|
1019
|
+
_assert.default.strictEqual(this.responseText, 'fooAB requested, data12 received');
|
|
1183
1020
|
done();
|
|
1184
1021
|
};
|
|
1185
1022
|
xhr.onerror = done;
|
|
1186
1023
|
xhr.open('GET', '/foo');
|
|
1187
1024
|
xhr.send('data');
|
|
1188
1025
|
});
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
{
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
];
|
|
1204
|
-
const XHRProxy = XHRProxyFactory(XMLHttpRequest, wrappers, {
|
|
1205
|
-
logError: logErrorSpy,
|
|
1026
|
+
it('requestChanger should check returned value for sanity', done => {
|
|
1027
|
+
const logErrorSpy = _sinon.default.spy();
|
|
1028
|
+
const wrappers = [{
|
|
1029
|
+
isRelevantTo: () => true,
|
|
1030
|
+
requestChanger(connection, request) {
|
|
1031
|
+
return Promise.resolve({
|
|
1032
|
+
method: request.method + 'a',
|
|
1033
|
+
url: request.url + 'A',
|
|
1034
|
+
_MISSPELL_body: request.body + '1'
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
}];
|
|
1038
|
+
const XHRProxy = (0, _xhrProxyFactory.default)(XMLHttpRequest, wrappers, {
|
|
1039
|
+
logError: logErrorSpy
|
|
1206
1040
|
});
|
|
1207
1041
|
const xhr = new XHRProxy();
|
|
1208
|
-
|
|
1209
1042
|
xhr.onload = function () {
|
|
1210
|
-
|
|
1211
|
-
|
|
1043
|
+
_assert.default.strictEqual(this.responseText, 'body received');
|
|
1044
|
+
(0, _assert.default)(logErrorSpy.calledOnce);
|
|
1212
1045
|
done();
|
|
1213
1046
|
};
|
|
1214
1047
|
xhr.onerror = thrower('xhr error');
|
|
@@ -1216,4 +1049,4 @@ describe('XHRProxyFactory', () => {
|
|
|
1216
1049
|
xhr.send('somedata');
|
|
1217
1050
|
});
|
|
1218
1051
|
});
|
|
1219
|
-
});
|
|
1052
|
+
});
|