selenium-webdriver 3.5.0 → 4.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +246 -0
- package/LICENSE +1 -1
- package/NOTICE +1 -1
- package/README.md +40 -40
- package/chrome.js +118 -134
- package/edge.js +43 -117
- package/example/chrome_android.js +8 -9
- package/example/chrome_mobile_emulation.js +8 -9
- package/example/firefox_channels.js +23 -19
- package/example/google_search.js +3 -3
- package/example/google_search_test.js +38 -27
- package/example/{chrome_headless.js → headless.js} +15 -7
- package/example/logging.js +40 -7
- package/firefox.js +789 -0
- package/http/index.js +62 -9
- package/http/util.js +11 -6
- package/ie.js +83 -97
- package/index.js +198 -114
- package/io/exec.js +29 -15
- package/io/index.js +1 -1
- package/io/zip.js +1 -1
- package/lib/actions.js +68 -63
- package/lib/atoms/get-attribute.js +86 -0
- package/lib/atoms/is-displayed.js +76 -76
- package/lib/by.js +7 -4
- package/lib/capabilities.js +310 -210
- package/lib/command.js +27 -51
- package/lib/error.js +100 -41
- package/lib/http.js +161 -120
- package/lib/input.js +1044 -8
- package/lib/logging.js +1 -5
- package/lib/promise.js +222 -3331
- package/lib/proxy.js +134 -39
- package/lib/session.js +2 -2
- package/lib/symbols.js +0 -0
- package/lib/until.js +1 -1
- package/lib/webdriver.js +717 -953
- package/net/index.js +21 -25
- package/net/portprober.js +51 -68
- package/package.json +17 -12
- package/proxy.js +0 -0
- package/remote/index.js +63 -44
- package/safari.js +41 -128
- package/testing/index.js +386 -315
- package/.npmignore +0 -2
- package/example/async_await_test.js +0 -68
- package/example/google_search_generator.js +0 -50
- package/example/parallel_flows.js +0 -54
- package/firefox/binary.js +0 -344
- package/firefox/extension.js +0 -224
- package/firefox/index.js +0 -626
- package/firefox/profile.js +0 -394
- package/lib/README +0 -5
- package/lib/atoms/getAttribute.js +0 -9
- package/lib/devmode.js +0 -34
- package/lib/events.js +0 -210
- package/lib/firefox/webdriver.json +0 -70
- package/lib/test/build.js +0 -151
- package/lib/test/data/ClickTest_testClicksASurroundingStrongTag.html +0 -11
- package/lib/test/data/Page.aspx +0 -17
- package/lib/test/data/Page.aspx.cs +0 -22
- package/lib/test/data/Redirect.aspx +0 -11
- package/lib/test/data/Redirect.aspx.cs +0 -9
- package/lib/test/data/Settings.StyleCop +0 -759
- package/lib/test/data/Web.Config +0 -59
- package/lib/test/data/actualXhtmlPage.xhtml +0 -14
- package/lib/test/data/ajaxy_page.html +0 -81
- package/lib/test/data/alerts.html +0 -85
- package/lib/test/data/banner.gif +0 -0
- package/lib/test/data/beach.jpg +0 -0
- package/lib/test/data/blank.html +0 -1
- package/lib/test/data/bodyTypingTest.html +0 -41
- package/lib/test/data/booleanAttributes.html +0 -19
- package/lib/test/data/child/childPage.html +0 -8
- package/lib/test/data/child/grandchild/grandchildPage.html +0 -8
- package/lib/test/data/clickEventPage.html +0 -26
- package/lib/test/data/click_frames.html +0 -10
- package/lib/test/data/click_jacker.html +0 -38
- package/lib/test/data/click_out_of_bounds.html +0 -23
- package/lib/test/data/click_out_of_bounds_overflow.html +0 -85
- package/lib/test/data/click_rtl.html +0 -19
- package/lib/test/data/click_source.html +0 -18
- package/lib/test/data/click_tests/click_iframe.html +0 -6
- package/lib/test/data/click_tests/click_in_iframe.html +0 -8
- package/lib/test/data/click_tests/disabled_element.html +0 -12
- package/lib/test/data/click_tests/disappearing_element.html +0 -62
- package/lib/test/data/click_tests/google_map.html +0 -15
- package/lib/test/data/click_tests/google_map.png +0 -0
- package/lib/test/data/click_tests/html5_submit_buttons.html +0 -16
- package/lib/test/data/click_tests/issue5237.html +0 -9
- package/lib/test/data/click_tests/issue5237_frame.html +0 -1
- package/lib/test/data/click_tests/issue5237_target.html +0 -10
- package/lib/test/data/click_tests/link_that_wraps.html +0 -11
- package/lib/test/data/click_tests/mapped_page1.html +0 -9
- package/lib/test/data/click_tests/mapped_page2.html +0 -9
- package/lib/test/data/click_tests/mapped_page3.html +0 -9
- package/lib/test/data/click_tests/overlapping_elements.html +0 -70
- package/lib/test/data/click_tests/partially_overlapping_elements.html +0 -124
- package/lib/test/data/click_tests/span_that_wraps.html +0 -11
- package/lib/test/data/click_tests/submitted_page.html +0 -9
- package/lib/test/data/click_tests/wrapped_overlapping_elements.html +0 -13
- package/lib/test/data/click_too_big.html +0 -10
- package/lib/test/data/click_too_big_in_frame.html +0 -11
- package/lib/test/data/clicks.html +0 -35
- package/lib/test/data/closeable_window.html +0 -8
- package/lib/test/data/cn-test.html +0 -156
- package/lib/test/data/colorPage.html +0 -20
- package/lib/test/data/cookies.html +0 -30
- package/lib/test/data/coordinates_tests/element_in_frame.html +0 -9
- package/lib/test/data/coordinates_tests/element_in_nested_frame.html +0 -9
- package/lib/test/data/coordinates_tests/page_with_element_out_of_view.html +0 -11
- package/lib/test/data/coordinates_tests/page_with_empty_element.html +0 -10
- package/lib/test/data/coordinates_tests/page_with_fixed_element.html +0 -12
- package/lib/test/data/coordinates_tests/page_with_hidden_element.html +0 -10
- package/lib/test/data/coordinates_tests/page_with_invisible_element.html +0 -10
- package/lib/test/data/coordinates_tests/page_with_transparent_element.html +0 -10
- package/lib/test/data/coordinates_tests/simple_page.html +0 -10
- package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/jquery-ui-1.8.10.custom.css +0 -573
- package/lib/test/data/cssTransform.html +0 -61
- package/lib/test/data/cssTransform2.html +0 -20
- package/lib/test/data/document_write_in_onload.html +0 -13
- package/lib/test/data/dragAndDropInsideScrolledDiv.html +0 -67
- package/lib/test/data/dragAndDropTest.html +0 -102
- package/lib/test/data/dragDropOverflow.html +0 -104
- package/lib/test/data/draggableLists.html +0 -67
- package/lib/test/data/droppableItems.html +0 -65
- package/lib/test/data/dynamic.html +0 -39
- package/lib/test/data/dynamicallyModifiedPage.html +0 -42
- package/lib/test/data/errors.html +0 -15
- package/lib/test/data/firefox/jetpack-sample.xpi +0 -0
- package/lib/test/data/firefox/sample.xpi +0 -0
- package/lib/test/data/firefox/webextension.xpi +0 -0
- package/lib/test/data/fixedFooterNoScroll.html +0 -13
- package/lib/test/data/fixedFooterNoScrollQuirksMode.html +0 -12
- package/lib/test/data/formPage.html +0 -175
- package/lib/test/data/formSelectionPage.html +0 -46
- package/lib/test/data/form_handling_js_submit.html +0 -30
- package/lib/test/data/framePage3.html +0 -7
- package/lib/test/data/frameScrollChild.html +0 -26
- package/lib/test/data/frameScrollPage.html +0 -14
- package/lib/test/data/frameScrollParent.html +0 -11
- package/lib/test/data/frameWithAnimals.html +0 -11
- package/lib/test/data/frame_switching_tests/bug4876.html +0 -9
- package/lib/test/data/frame_switching_tests/bug4876_iframe.html +0 -9
- package/lib/test/data/frame_switching_tests/deletingFrame.html +0 -29
- package/lib/test/data/frame_switching_tests/deletingFrame_iframe.html +0 -8
- package/lib/test/data/frame_switching_tests/deletingFrame_iframe2.html +0 -7
- package/lib/test/data/frameset.html +0 -14
- package/lib/test/data/framesetPage2.html +0 -7
- package/lib/test/data/framesetPage3.html +0 -4
- package/lib/test/data/globalscope.html +0 -15
- package/lib/test/data/hidden.html +0 -5
- package/lib/test/data/hidden_partially.html +0 -45
- package/lib/test/data/html5/blue.jpg +0 -0
- package/lib/test/data/html5/database.js +0 -84
- package/lib/test/data/html5/geolocation.js +0 -18
- package/lib/test/data/html5/green.jpg +0 -0
- package/lib/test/data/html5/red.jpg +0 -0
- package/lib/test/data/html5/status.html +0 -1
- package/lib/test/data/html5/test.appcache +0 -11
- package/lib/test/data/html5/yellow.jpg +0 -0
- package/lib/test/data/html5Page.html +0 -32
- package/lib/test/data/icon.gif +0 -0
- package/lib/test/data/idElements.html +0 -2
- package/lib/test/data/iframeAtBottom.html +0 -15
- package/lib/test/data/iframeWithAlert.html +0 -1
- package/lib/test/data/iframeWithIframe.html +0 -1
- package/lib/test/data/iframes.html +0 -11
- package/lib/test/data/injectableContent.html +0 -22
- package/lib/test/data/javascriptEnhancedForm.html +0 -30
- package/lib/test/data/javascriptPage.html +0 -285
- package/lib/test/data/jquery-1.3.2.js +0 -4376
- package/lib/test/data/js/jquery-1.4.4.min.js +0 -167
- package/lib/test/data/js/jquery-ui-1.8.10.custom.min.js +0 -782
- package/lib/test/data/js/skins/lightgray/content.inline.min.css +0 -1
- package/lib/test/data/js/skins/lightgray/content.min.css +0 -1
- package/lib/test/data/js/skins/lightgray/fonts/readme.md +0 -1
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.dev.svg +0 -175
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.eot +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.svg +0 -62
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.ttf +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.woff +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.dev.svg +0 -153
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.eot +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.svg +0 -63
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.ttf +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.woff +0 -0
- package/lib/test/data/js/skins/lightgray/img/anchor.gif +0 -0
- package/lib/test/data/js/skins/lightgray/img/loader.gif +0 -0
- package/lib/test/data/js/skins/lightgray/img/object.gif +0 -0
- package/lib/test/data/js/skins/lightgray/img/trans.gif +0 -0
- package/lib/test/data/js/skins/lightgray/skin.ie7.min.css +0 -1
- package/lib/test/data/js/skins/lightgray/skin.min.css +0 -1
- package/lib/test/data/js/themes/modern/theme.min.js +0 -1
- package/lib/test/data/js/tinymce.min.js +0 -10
- package/lib/test/data/key_logger.html +0 -34
- package/lib/test/data/key_tests/remove_on_keypress.html +0 -36
- package/lib/test/data/keyboard_shortcut.html +0 -36
- package/lib/test/data/linked_image.html +0 -16
- package/lib/test/data/locators_tests/boolean_attribute_selected.html +0 -13
- package/lib/test/data/locators_tests/boolean_attribute_selected_html4.html +0 -13
- package/lib/test/data/longContentPage.html +0 -55
- package/lib/test/data/macbeth.html +0 -5255
- package/lib/test/data/map.png +0 -0
- package/lib/test/data/map_visibility.html +0 -8
- package/lib/test/data/markerTransparent.png +0 -0
- package/lib/test/data/messages.html +0 -15
- package/lib/test/data/meta-redirect.html +0 -11
- package/lib/test/data/missedJsReference.html +0 -11
- package/lib/test/data/modal_dialogs/modal_1.html +0 -21
- package/lib/test/data/modal_dialogs/modal_2.html +0 -21
- package/lib/test/data/modal_dialogs/modal_3.html +0 -15
- package/lib/test/data/modal_dialogs/modalindex.html +0 -21
- package/lib/test/data/mouseOver.html +0 -17
- package/lib/test/data/mousePositionTracker.html +0 -33
- package/lib/test/data/nestedElements.html +0 -164
- package/lib/test/data/overflow/x_auto_y_auto.html +0 -30
- package/lib/test/data/overflow/x_auto_y_hidden.html +0 -30
- package/lib/test/data/overflow/x_auto_y_scroll.html +0 -30
- package/lib/test/data/overflow/x_hidden_y_auto.html +0 -30
- package/lib/test/data/overflow/x_hidden_y_hidden.html +0 -30
- package/lib/test/data/overflow/x_hidden_y_scroll.html +0 -30
- package/lib/test/data/overflow/x_scroll_y_auto.html +0 -30
- package/lib/test/data/overflow/x_scroll_y_hidden.html +0 -30
- package/lib/test/data/overflow/x_scroll_y_scroll.html +0 -30
- package/lib/test/data/overflow-body.html +0 -15
- package/lib/test/data/pageWithOnBeforeUnloadMessage.html +0 -20
- package/lib/test/data/pageWithOnLoad.html +0 -6
- package/lib/test/data/pageWithOnUnload.html +0 -6
- package/lib/test/data/page_with_link_to_slow_loading_page.html +0 -6
- package/lib/test/data/plain.txt +0 -1
- package/lib/test/data/proxy/page1.html +0 -20
- package/lib/test/data/proxy/page2.html +0 -24
- package/lib/test/data/proxy/page3.html +0 -5
- package/lib/test/data/readOnlyPage.html +0 -24
- package/lib/test/data/rectangles.html +0 -40
- package/lib/test/data/resultPage.html +0 -25
- package/lib/test/data/rich_text.html +0 -161
- package/lib/test/data/safari/frames_benchmark.html +0 -31
- package/lib/test/data/screen/screen.css +0 -19
- package/lib/test/data/screen/screen.html +0 -72
- package/lib/test/data/screen/screen.js +0 -7
- package/lib/test/data/screen/screen_frame1.html +0 -72
- package/lib/test/data/screen/screen_frame2.html +0 -72
- package/lib/test/data/screen/screen_frames.html +0 -11
- package/lib/test/data/screen/screen_iframes.html +0 -12
- package/lib/test/data/screen/screen_too_long.html +0 -68
- package/lib/test/data/screen/screen_x_long.html +0 -72
- package/lib/test/data/screen/screen_x_too_long.html +0 -72
- package/lib/test/data/screen/screen_y_long.html +0 -72
- package/lib/test/data/screen/screen_y_too_long.html +0 -72
- package/lib/test/data/scroll.html +0 -27
- package/lib/test/data/scroll2.html +0 -21
- package/lib/test/data/scroll3.html +0 -8
- package/lib/test/data/scroll4.html +0 -7
- package/lib/test/data/scroll5.html +0 -18
- package/lib/test/data/scrolling_tests/frame_with_height_above_200.html +0 -26
- package/lib/test/data/scrolling_tests/frame_with_height_above_2000.html +0 -26
- package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame.html +0 -11
- package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html +0 -12
- package/lib/test/data/scrolling_tests/frame_with_small_height.html +0 -10
- package/lib/test/data/scrolling_tests/page_with_double_overflow_auto.html +0 -19
- package/lib/test/data/scrolling_tests/page_with_frame_out_of_view.html +0 -12
- package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames.html +0 -11
- package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames_out_of_view.html +0 -12
- package/lib/test/data/scrolling_tests/page_with_non_scrolling_frame.html +0 -11
- package/lib/test/data/scrolling_tests/page_with_scrolling_frame.html +0 -11
- package/lib/test/data/scrolling_tests/page_with_scrolling_frame_out_of_view.html +0 -12
- package/lib/test/data/scrolling_tests/page_with_tall_frame.html +0 -11
- package/lib/test/data/scrolling_tests/page_with_y_overflow_auto.html +0 -14
- package/lib/test/data/scrolling_tests/target_page.html +0 -9
- package/lib/test/data/selectPage.html +0 -58
- package/lib/test/data/selectableItems.html +0 -65
- package/lib/test/data/sessionCookie.html +0 -21
- package/lib/test/data/sessionCookieDest.html +0 -34
- package/lib/test/data/simple.xml +0 -5
- package/lib/test/data/simpleTest.html +0 -98
- package/lib/test/data/single_text_input.html +0 -12
- package/lib/test/data/slowLoadingAlert.html +0 -10
- package/lib/test/data/slowLoadingResourcePage.html +0 -12
- package/lib/test/data/slow_loading_iframes.html +0 -14
- package/lib/test/data/styledPage.html +0 -28
- package/lib/test/data/svgPiechart.xhtml +0 -81
- package/lib/test/data/svgTest.svg +0 -4
- package/lib/test/data/tables.html +0 -36
- package/lib/test/data/tinymce.html +0 -10
- package/lib/test/data/transformable.xml +0 -11
- package/lib/test/data/transformable.xsl +0 -37
- package/lib/test/data/transparentUpload.html +0 -70
- package/lib/test/data/underscore.html +0 -9
- package/lib/test/data/unicode_ltr.html +0 -8
- package/lib/test/data/upload.html +0 -45
- package/lib/test/data/userDefinedProperty.html +0 -8
- package/lib/test/data/veryLargeCanvas.html +0 -81
- package/lib/test/data/visibility-css.html +0 -21
- package/lib/test/data/win32frameset.html +0 -8
- package/lib/test/data/window_switching_tests/page_with_frame.html +0 -12
- package/lib/test/data/window_switching_tests/simple_page.html +0 -9
- package/lib/test/data/xhtmlFormPage.xhtml +0 -17
- package/lib/test/data/xhtmlTest.html +0 -76
- package/lib/test/fileserver.js +0 -321
- package/lib/test/httpserver.js +0 -120
- package/lib/test/index.js +0 -270
- package/lib/test/promise.js +0 -79
- package/lib/test/resources.js +0 -44
- package/opera.js +0 -405
- package/phantomjs.js +0 -282
- package/test/actions_test.js +0 -52
- package/test/chrome/options_test.js +0 -227
- package/test/chrome/service_test.js +0 -45
- package/test/cookie_test.js +0 -214
- package/test/element_finding_test.js +0 -426
- package/test/execute_script_test.js +0 -350
- package/test/fingerprint_test.js +0 -62
- package/test/firefox/extension_test.js +0 -120
- package/test/firefox/firefox_test.js +0 -261
- package/test/firefox/profile_test.js +0 -140
- package/test/http/http_test.js +0 -223
- package/test/http/util_test.js +0 -178
- package/test/io/io_test.js +0 -360
- package/test/io/zip_test.js +0 -128
- package/test/lib/by_test.js +0 -160
- package/test/lib/capabilities_test.js +0 -111
- package/test/lib/error_test.js +0 -305
- package/test/lib/events_test.js +0 -177
- package/test/lib/http_test.js +0 -696
- package/test/lib/logging_test.js +0 -272
- package/test/lib/promise_aplus_test.js +0 -78
- package/test/lib/promise_error_test.js +0 -884
- package/test/lib/promise_flow_test.js +0 -2288
- package/test/lib/promise_generator_test.js +0 -310
- package/test/lib/promise_test.js +0 -1109
- package/test/lib/testutil.js +0 -90
- package/test/lib/until_test.js +0 -478
- package/test/lib/webdriver_test.js +0 -2311
- package/test/logging_test.js +0 -167
- package/test/net/index_test.js +0 -60
- package/test/net/portprober_test.js +0 -128
- package/test/page_loading_test.js +0 -166
- package/test/phantomjs/execute_phantomjs_test.js +0 -59
- package/test/proxy_test.js +0 -180
- package/test/rect_test.js +0 -60
- package/test/remote_test.js +0 -117
- package/test/safari_test.js +0 -108
- package/test/session_test.js +0 -99
- package/test/stale_element_test.js +0 -63
- package/test/tag_name_test.js +0 -36
- package/test/testing/assert_test.js +0 -373
- package/test/testing/index_test.js +0 -224
- package/test/upload_test.js +0 -86
- package/test/window_test.js +0 -161
- package/testing/assert.js +0 -378
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
-
// or more contributor license agreements. See the NOTICE file
|
|
3
|
-
// distributed with this work for additional information
|
|
4
|
-
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
-
// to you under the Apache License, Version 2.0 (the
|
|
6
|
-
// "License"); you may not use this file except in compliance
|
|
7
|
-
// with the License. You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing,
|
|
12
|
-
// software distributed under the License is distributed on an
|
|
13
|
-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
// KIND, either express or implied. See the License for the
|
|
15
|
-
// specific language governing permissions and limitations
|
|
16
|
-
// under the License.
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
var path = require('path');
|
|
21
|
-
|
|
22
|
-
var firefox = require('../../firefox'),
|
|
23
|
-
io = require('../../io'),
|
|
24
|
-
test = require('../../lib/test'),
|
|
25
|
-
assert = require('../../testing/assert'),
|
|
26
|
-
Context = require('../../firefox').Context,
|
|
27
|
-
error = require('../..').error;
|
|
28
|
-
|
|
29
|
-
var {consume} = require('../../lib/promise');
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var JETPACK_EXTENSION = path.join(__dirname,
|
|
33
|
-
'../../lib/test/data/firefox/jetpack-sample.xpi');
|
|
34
|
-
var NORMAL_EXTENSION = path.join(__dirname,
|
|
35
|
-
'../../lib/test/data/firefox/sample.xpi');
|
|
36
|
-
var WEBEXTENSION_EXTENSION = path.join(__dirname,
|
|
37
|
-
'../../lib/test/data/firefox/webextension.xpi');
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
test.suite(function(env) {
|
|
41
|
-
describe('firefox', function() {
|
|
42
|
-
describe('Options', function() {
|
|
43
|
-
let driver;
|
|
44
|
-
|
|
45
|
-
beforeEach(function() {
|
|
46
|
-
driver = null;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
afterEach(function() {
|
|
50
|
-
if (driver) {
|
|
51
|
-
return driver.quit();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Runs a test that requires Firefox Developer Edition. The test will be
|
|
57
|
-
* skipped if dev cannot be found on the current system.
|
|
58
|
-
*/
|
|
59
|
-
function runWithFirefoxDev(options, testFn) {
|
|
60
|
-
return firefox.Channel.AURORA.locate().then(exe => {
|
|
61
|
-
options.setBinary(exe);
|
|
62
|
-
driver = env.builder()
|
|
63
|
-
.setFirefoxOptions(options)
|
|
64
|
-
.build();
|
|
65
|
-
return driver.call(testFn);
|
|
66
|
-
}, err => {
|
|
67
|
-
console.warn(
|
|
68
|
-
'Skipping test: could not find Firefox Dev Edition: ' + err);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
describe('can start Firefox with custom preferences', function() {
|
|
73
|
-
function runTest(opt_dir) {
|
|
74
|
-
return consume(function*() {
|
|
75
|
-
let profile = new firefox.Profile(opt_dir);
|
|
76
|
-
profile.setPreference('general.useragent.override', 'foo;bar');
|
|
77
|
-
|
|
78
|
-
let options = new firefox.Options().setProfile(profile);
|
|
79
|
-
|
|
80
|
-
driver = env.builder().
|
|
81
|
-
setFirefoxOptions(options).
|
|
82
|
-
build();
|
|
83
|
-
|
|
84
|
-
yield driver.get('data:text/html,<html><div>content</div></html>');
|
|
85
|
-
|
|
86
|
-
var userAgent = yield driver.executeScript(
|
|
87
|
-
'return window.navigator.userAgent');
|
|
88
|
-
assert(userAgent).equalTo('foo;bar');
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
test.it('profile created from scratch', function() {
|
|
93
|
-
return runTest();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test.it('profile created from template', function() {
|
|
97
|
-
return io.tmpDir().then(runTest);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test.it('can start Firefox with a jetpack extension', function() {
|
|
102
|
-
let profile = new firefox.Profile();
|
|
103
|
-
profile.addExtension(JETPACK_EXTENSION);
|
|
104
|
-
|
|
105
|
-
let options = new firefox.Options().setProfile(profile);
|
|
106
|
-
|
|
107
|
-
return runWithFirefoxDev(options, function*() {
|
|
108
|
-
yield loadJetpackPage(driver,
|
|
109
|
-
'data:text/html;charset=UTF-8,<html><div>content</div></html>');
|
|
110
|
-
|
|
111
|
-
let text =
|
|
112
|
-
yield driver.findElement({id: 'jetpack-sample-banner'}).getText();
|
|
113
|
-
assert(text).equalTo('Hello, world!');
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test.it('can start Firefox with a normal extension', function() {
|
|
118
|
-
let profile = new firefox.Profile();
|
|
119
|
-
profile.addExtension(NORMAL_EXTENSION);
|
|
120
|
-
|
|
121
|
-
let options = new firefox.Options().setProfile(profile);
|
|
122
|
-
|
|
123
|
-
return runWithFirefoxDev(options, function*() {
|
|
124
|
-
yield driver.get('data:text/html,<html><div>content</div></html>');
|
|
125
|
-
|
|
126
|
-
let footer =
|
|
127
|
-
yield driver.findElement({id: 'sample-extension-footer'});
|
|
128
|
-
let text = yield footer.getText();
|
|
129
|
-
assert(text).equalTo('Goodbye');
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test.it('can start Firefox with a webextension extension', function() {
|
|
134
|
-
let profile = new firefox.Profile();
|
|
135
|
-
profile.addExtension(WEBEXTENSION_EXTENSION);
|
|
136
|
-
|
|
137
|
-
let options = new firefox.Options().setProfile(profile);
|
|
138
|
-
|
|
139
|
-
return runWithFirefoxDev(options, function*() {
|
|
140
|
-
yield driver.get(test.Pages.echoPage);
|
|
141
|
-
|
|
142
|
-
let footer =
|
|
143
|
-
yield driver.findElement({id: 'webextensions-selenium-example'});
|
|
144
|
-
let text = yield footer.getText();
|
|
145
|
-
assert(text).equalTo('Content injected by webextensions-selenium-example');
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test.it('can start Firefox with multiple extensions', function() {
|
|
150
|
-
let profile = new firefox.Profile();
|
|
151
|
-
profile.addExtension(JETPACK_EXTENSION);
|
|
152
|
-
profile.addExtension(NORMAL_EXTENSION);
|
|
153
|
-
|
|
154
|
-
let options = new firefox.Options().setProfile(profile);
|
|
155
|
-
|
|
156
|
-
return runWithFirefoxDev(options, function*() {
|
|
157
|
-
yield loadJetpackPage(driver,
|
|
158
|
-
'data:text/html;charset=UTF-8,<html><div>content</div></html>');
|
|
159
|
-
|
|
160
|
-
let banner =
|
|
161
|
-
yield driver.findElement({id: 'jetpack-sample-banner'}).getText();
|
|
162
|
-
assert(banner).equalTo('Hello, world!');
|
|
163
|
-
|
|
164
|
-
let footer =
|
|
165
|
-
yield driver.findElement({id: 'sample-extension-footer'})
|
|
166
|
-
.getText();
|
|
167
|
-
assert(footer).equalTo('Goodbye');
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test.it('can be used alongside preset capabilities', function*() {
|
|
172
|
-
let binary = yield firefox.Channel.AURORA.locate();
|
|
173
|
-
|
|
174
|
-
let profile = new firefox.Profile();
|
|
175
|
-
profile.addExtension(JETPACK_EXTENSION);
|
|
176
|
-
profile.setPreference('general.useragent.override', 'foo;bar');
|
|
177
|
-
|
|
178
|
-
driver = yield env.builder()
|
|
179
|
-
.withCapabilities({'moz:firefoxOptions': {binary}})
|
|
180
|
-
.setFirefoxOptions(new firefox.Options().setProfile(profile))
|
|
181
|
-
.build();
|
|
182
|
-
|
|
183
|
-
yield loadJetpackPage(driver,
|
|
184
|
-
'data:text/html;charset=UTF-8,<html><div>content</div></html>');
|
|
185
|
-
|
|
186
|
-
let text =
|
|
187
|
-
yield driver.findElement({id: 'jetpack-sample-banner'}).getText();
|
|
188
|
-
assert(text).equalTo('Hello, world!');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
function loadJetpackPage(driver, url) {
|
|
192
|
-
// On linux the jetpack extension does not always run the first time
|
|
193
|
-
// we load a page. If this happens, just reload the page (a simple
|
|
194
|
-
// refresh doesn't appear to work).
|
|
195
|
-
return driver.wait(function() {
|
|
196
|
-
driver.get(url);
|
|
197
|
-
return driver.findElements({id: 'jetpack-sample-banner'})
|
|
198
|
-
.then(found => found.length > 0);
|
|
199
|
-
}, 3000);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe('binary management', function() {
|
|
204
|
-
var driver1, driver2;
|
|
205
|
-
|
|
206
|
-
test.ignore(env.isRemote).
|
|
207
|
-
it('can start multiple sessions with single binary instance', function*() {
|
|
208
|
-
var options = new firefox.Options().setBinary(new firefox.Binary);
|
|
209
|
-
env.builder().setFirefoxOptions(options);
|
|
210
|
-
driver1 = yield env.builder().build();
|
|
211
|
-
driver2 = yield env.builder().build();
|
|
212
|
-
// Ok if this doesn't fail.
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
test.afterEach(function*() {
|
|
216
|
-
if (driver1) {
|
|
217
|
-
yield driver1.quit();
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (driver2) {
|
|
221
|
-
yield driver2.quit();
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
describe('context switching', function() {
|
|
227
|
-
var driver;
|
|
228
|
-
|
|
229
|
-
test.beforeEach(function*() {
|
|
230
|
-
driver = yield env.builder().build();
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
test.afterEach(function() {
|
|
234
|
-
if (driver) {
|
|
235
|
-
return driver.quit();
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
test.it('can get context', function() {
|
|
240
|
-
return assert(driver.getContext()).equalTo(Context.CONTENT);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
test.it('can set context', function*() {
|
|
244
|
-
yield driver.setContext(Context.CHROME);
|
|
245
|
-
let ctxt = yield driver.getContext();
|
|
246
|
-
assert(ctxt).equalTo(Context.CHROME);
|
|
247
|
-
|
|
248
|
-
yield driver.setContext(Context.CONTENT);
|
|
249
|
-
ctxt = yield driver.getContext();
|
|
250
|
-
assert(ctxt).equalTo(Context.CONTENT);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test.it('throws on unknown context', function() {
|
|
254
|
-
return driver.setContext("foo").then(assert.fail, function(e) {
|
|
255
|
-
assert(e).instanceOf(error.InvalidArgumentError);
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
});
|
|
261
|
-
}, {browsers: ['firefox']});
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
-
// or more contributor license agreements. See the NOTICE file
|
|
3
|
-
// distributed with this work for additional information
|
|
4
|
-
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
-
// to you under the Apache License, Version 2.0 (the
|
|
6
|
-
// "License"); you may not use this file except in compliance
|
|
7
|
-
// with the License. You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing,
|
|
12
|
-
// software distributed under the License is distributed on an
|
|
13
|
-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
// KIND, either express or implied. See the License for the
|
|
15
|
-
// specific language governing permissions and limitations
|
|
16
|
-
// under the License.
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
var assert = require('assert'),
|
|
21
|
-
fs = require('fs'),
|
|
22
|
-
path = require('path');
|
|
23
|
-
|
|
24
|
-
var promise = require('../..').promise,
|
|
25
|
-
Profile = require('../../firefox/profile').Profile,
|
|
26
|
-
decode = require('../../firefox/profile').decode,
|
|
27
|
-
loadUserPrefs = require('../../firefox/profile').loadUserPrefs,
|
|
28
|
-
io = require('../../io');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var JETPACK_EXTENSION = path.join(__dirname,
|
|
32
|
-
'../../lib/test/data/firefox/jetpack-sample.xpi');
|
|
33
|
-
var NORMAL_EXTENSION = path.join(__dirname,
|
|
34
|
-
'../../lib/test/data/firefox/sample.xpi');
|
|
35
|
-
var WEBEXTENSION_EXTENSION = path.join(__dirname,
|
|
36
|
-
'../../lib/test/data/firefox/webextension.xpi');
|
|
37
|
-
|
|
38
|
-
var JETPACK_EXTENSION_ID = 'jid1-EaXX7k0wwiZR7w@jetpack.xpi';
|
|
39
|
-
var NORMAL_EXTENSION_ID = 'sample@seleniumhq.org';
|
|
40
|
-
var WEBEXTENSION_EXTENSION_ID = 'webextensions-selenium-example@example.com';
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
describe('Profile', function() {
|
|
45
|
-
describe('setPreference', function() {
|
|
46
|
-
it('allows setting custom properties', function() {
|
|
47
|
-
var profile = new Profile();
|
|
48
|
-
assert.equal(undefined, profile.getPreference('foo'));
|
|
49
|
-
|
|
50
|
-
profile.setPreference('foo', 'bar');
|
|
51
|
-
assert.equal('bar', profile.getPreference('foo'));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('allows overriding mutable properties', function() {
|
|
55
|
-
var profile = new Profile();
|
|
56
|
-
|
|
57
|
-
profile.setPreference('browser.newtab.url', 'http://www.example.com');
|
|
58
|
-
assert.equal('http://www.example.com',
|
|
59
|
-
profile.getPreference('browser.newtab.url'));
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('writeToDisk', function() {
|
|
64
|
-
it('copies template directory recursively', function() {
|
|
65
|
-
var templateDir;
|
|
66
|
-
return io.tmpDir().then(function(td) {
|
|
67
|
-
templateDir = td;
|
|
68
|
-
var foo = path.join(templateDir, 'foo');
|
|
69
|
-
fs.writeFileSync(foo, 'Hello, world');
|
|
70
|
-
|
|
71
|
-
var bar = path.join(templateDir, 'subfolder/bar');
|
|
72
|
-
fs.mkdirSync(path.dirname(bar));
|
|
73
|
-
fs.writeFileSync(bar, 'Goodbye, world!');
|
|
74
|
-
|
|
75
|
-
return new Profile(templateDir).writeToDisk();
|
|
76
|
-
}).then(function(profileDir) {
|
|
77
|
-
assert.notEqual(profileDir, templateDir);
|
|
78
|
-
|
|
79
|
-
assert.equal('Hello, world',
|
|
80
|
-
fs.readFileSync(path.join(profileDir, 'foo')));
|
|
81
|
-
assert.equal('Goodbye, world!',
|
|
82
|
-
fs.readFileSync(path.join(profileDir, 'subfolder/bar')));
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('does not copy lock files', function() {
|
|
87
|
-
return io.tmpDir().then(function(dir) {
|
|
88
|
-
fs.writeFileSync(path.join(dir, 'parent.lock'), 'lock');
|
|
89
|
-
fs.writeFileSync(path.join(dir, 'lock'), 'lock');
|
|
90
|
-
fs.writeFileSync(path.join(dir, '.parentlock'), 'lock');
|
|
91
|
-
return new Profile(dir).writeToDisk();
|
|
92
|
-
}).then(function(dir) {
|
|
93
|
-
assert.ok(fs.existsSync(dir));
|
|
94
|
-
assert.ok(!fs.existsSync(path.join(dir, 'parent.lock')));
|
|
95
|
-
assert.ok(!fs.existsSync(path.join(dir, 'lock')));
|
|
96
|
-
assert.ok(!fs.existsSync(path.join(dir, '.parentlock')));
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('user.js', function() {
|
|
101
|
-
it('merges template user.js into preferences', function() {
|
|
102
|
-
return io.tmpDir().then(function(dir) {
|
|
103
|
-
fs.writeFileSync(path.join(dir, 'user.js'), [
|
|
104
|
-
'user_pref("browser.newtab.url", "http://www.example.com")',
|
|
105
|
-
'user_pref("dom.max_script_run_time", 1234)'
|
|
106
|
-
].join('\n'));
|
|
107
|
-
|
|
108
|
-
return new Profile(dir).writeToDisk();
|
|
109
|
-
}).then(function(profile) {
|
|
110
|
-
return loadUserPrefs(path.join(profile, 'user.js'));
|
|
111
|
-
}).then(function(prefs) {
|
|
112
|
-
assert.equal('http://www.example.com', prefs['browser.newtab.url']);
|
|
113
|
-
assert.equal(1234, prefs['dom.max_script_run_time']);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('extensions', function() {
|
|
119
|
-
it('are copied into new profile directory', function() {
|
|
120
|
-
var profile = new Profile();
|
|
121
|
-
profile.addExtension(JETPACK_EXTENSION);
|
|
122
|
-
profile.addExtension(NORMAL_EXTENSION);
|
|
123
|
-
profile.addExtension(WEBEXTENSION_EXTENSION);
|
|
124
|
-
|
|
125
|
-
return profile.writeToDisk().then(function(dir) {
|
|
126
|
-
dir = path.join(dir, 'extensions');
|
|
127
|
-
assertExists(JETPACK_EXTENSION_ID);
|
|
128
|
-
assertExists(NORMAL_EXTENSION_ID);
|
|
129
|
-
assertExists(WEBEXTENSION_EXTENSION_ID + '.xpi');
|
|
130
|
-
|
|
131
|
-
function assertExists(file) {
|
|
132
|
-
assert.ok(
|
|
133
|
-
fs.existsSync(path.join(dir, file)),
|
|
134
|
-
`expected ${file} to exist`);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
package/test/http/http_test.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
2
|
-
// or more contributor license agreements. See the NOTICE file
|
|
3
|
-
// distributed with this work for additional information
|
|
4
|
-
// regarding copyright ownership. The SFC licenses this file
|
|
5
|
-
// to you under the Apache License, Version 2.0 (the
|
|
6
|
-
// "License"); you may not use this file except in compliance
|
|
7
|
-
// with the License. You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing,
|
|
12
|
-
// software distributed under the License is distributed on an
|
|
13
|
-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
-
// KIND, either express or implied. See the License for the
|
|
15
|
-
// specific language governing permissions and limitations
|
|
16
|
-
// under the License.
|
|
17
|
-
|
|
18
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
var assert = require('assert'),
|
|
21
|
-
http = require('http'),
|
|
22
|
-
url = require('url');
|
|
23
|
-
|
|
24
|
-
var HttpClient = require('../../http').HttpClient,
|
|
25
|
-
HttpRequest = require('../../lib/http').Request,
|
|
26
|
-
HttpResponse = require('../../lib/http').Response,
|
|
27
|
-
Server = require('../../lib/test/httpserver').Server;
|
|
28
|
-
|
|
29
|
-
describe('HttpClient', function() {
|
|
30
|
-
this.timeout(4 * 1000);
|
|
31
|
-
|
|
32
|
-
var server = new Server(function(req, res) {
|
|
33
|
-
let parsedUrl = url.parse(req.url);
|
|
34
|
-
|
|
35
|
-
if (req.method == 'GET' && req.url == '/echo') {
|
|
36
|
-
res.writeHead(200, req.headers);
|
|
37
|
-
res.end();
|
|
38
|
-
|
|
39
|
-
} else if (req.method == 'GET' && req.url == '/redirect') {
|
|
40
|
-
res.writeHead(303, {'Location': server.url('/hello')});
|
|
41
|
-
res.end();
|
|
42
|
-
|
|
43
|
-
} else if (req.method == 'GET' && req.url == '/hello') {
|
|
44
|
-
res.writeHead(200, {'content-type': 'text/plain'});
|
|
45
|
-
res.end('hello, world!');
|
|
46
|
-
|
|
47
|
-
} else if (req.method == 'GET' && req.url == '/chunked') {
|
|
48
|
-
res.writeHead(200, {
|
|
49
|
-
'content-type': 'text/html; charset=utf-8',
|
|
50
|
-
'transfer-encoding': 'chunked'
|
|
51
|
-
});
|
|
52
|
-
res.write('<!DOCTYPE html>');
|
|
53
|
-
setTimeout(() => res.end('<h1>Hello, world!</h1>'), 20);
|
|
54
|
-
|
|
55
|
-
} else if (req.method == 'GET' && req.url == '/badredirect') {
|
|
56
|
-
res.writeHead(303, {});
|
|
57
|
-
res.end();
|
|
58
|
-
|
|
59
|
-
} else if (req.method == 'GET' && req.url == '/protected') {
|
|
60
|
-
var denyAccess = function() {
|
|
61
|
-
res.writeHead(401, {'WWW-Authenticate': 'Basic realm="test"'});
|
|
62
|
-
res.end('Access denied');
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
var basicAuthRegExp = /^\s*basic\s+([a-z0-9\-\._~\+\/]+)=*\s*$/i
|
|
66
|
-
var auth = req.headers.authorization;
|
|
67
|
-
var match = basicAuthRegExp.exec(auth || '');
|
|
68
|
-
if (!match) {
|
|
69
|
-
denyAccess();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
var userNameAndPass = new Buffer(match[1], 'base64').toString();
|
|
74
|
-
var parts = userNameAndPass.split(':', 2);
|
|
75
|
-
if (parts[0] !== 'genie' && parts[1] !== 'bottle') {
|
|
76
|
-
denyAccess();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
res.writeHead(200, {'content-type': 'text/plain'});
|
|
81
|
-
res.end('Access granted!');
|
|
82
|
-
|
|
83
|
-
} else if (req.method == 'GET'
|
|
84
|
-
&& parsedUrl.pathname
|
|
85
|
-
&& parsedUrl.pathname.endsWith('/proxy')) {
|
|
86
|
-
let headers = Object.assign({}, req.headers);
|
|
87
|
-
headers['x-proxy-request-uri'] = req.url;
|
|
88
|
-
res.writeHead(200, headers);
|
|
89
|
-
res.end();
|
|
90
|
-
|
|
91
|
-
} else if (req.method == 'GET'
|
|
92
|
-
&& parsedUrl.pathname
|
|
93
|
-
&& parsedUrl.pathname.endsWith('/proxy/redirect')) {
|
|
94
|
-
let path = `/proxy${parsedUrl.search || ''}${parsedUrl.hash || ''}`;
|
|
95
|
-
res.writeHead(303, {'Location': path});
|
|
96
|
-
res.end();
|
|
97
|
-
|
|
98
|
-
} else {
|
|
99
|
-
res.writeHead(404, {});
|
|
100
|
-
res.end();
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
before(function() {
|
|
105
|
-
return server.start();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
after(function() {
|
|
109
|
-
return server.stop();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('can send a basic HTTP request', function() {
|
|
113
|
-
var request = new HttpRequest('GET', '/echo');
|
|
114
|
-
request.headers.set('Foo', 'Bar');
|
|
115
|
-
|
|
116
|
-
var agent = new http.Agent();
|
|
117
|
-
agent.maxSockets = 1; // Only making 1 request.
|
|
118
|
-
|
|
119
|
-
var client = new HttpClient(server.url(), agent);
|
|
120
|
-
return client.send(request).then(function(response) {
|
|
121
|
-
assert.equal(200, response.status);
|
|
122
|
-
assert.equal(response.headers.get('content-length'), '0');
|
|
123
|
-
assert.equal(response.headers.get('connection'), 'keep-alive');
|
|
124
|
-
assert.equal(response.headers.get('host'), server.host());
|
|
125
|
-
|
|
126
|
-
assert.equal(request.headers.get('Foo'), 'Bar');
|
|
127
|
-
assert.equal(
|
|
128
|
-
request.headers.get('Accept'), 'application/json; charset=utf-8');
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('handles chunked responses', function() {
|
|
133
|
-
let request = new HttpRequest('GET', '/chunked');
|
|
134
|
-
|
|
135
|
-
let client = new HttpClient(server.url());
|
|
136
|
-
return client.send(request).then(response => {
|
|
137
|
-
assert.equal(200, response.status);
|
|
138
|
-
assert.equal(response.body, '<!DOCTYPE html><h1>Hello, world!</h1>');
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('can use basic auth', function() {
|
|
143
|
-
var parsed = url.parse(server.url());
|
|
144
|
-
parsed.auth = 'genie:bottle';
|
|
145
|
-
|
|
146
|
-
var client = new HttpClient(url.format(parsed));
|
|
147
|
-
var request = new HttpRequest('GET', '/protected');
|
|
148
|
-
return client.send(request).then(function(response) {
|
|
149
|
-
assert.equal(200, response.status);
|
|
150
|
-
assert.equal(response.headers.get('content-type'), 'text/plain');
|
|
151
|
-
assert.equal(response.body, 'Access granted!');
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('fails requests missing required basic auth', function() {
|
|
156
|
-
var client = new HttpClient(server.url());
|
|
157
|
-
var request = new HttpRequest('GET', '/protected');
|
|
158
|
-
return client.send(request).then(function(response) {
|
|
159
|
-
assert.equal(401, response.status);
|
|
160
|
-
assert.equal(response.body, 'Access denied');
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('automatically follows redirects', function() {
|
|
165
|
-
var request = new HttpRequest('GET', '/redirect');
|
|
166
|
-
var client = new HttpClient(server.url());
|
|
167
|
-
return client.send(request).then(function(response) {
|
|
168
|
-
assert.equal(200, response.status);
|
|
169
|
-
assert.equal(response.headers.get('content-type'), 'text/plain');
|
|
170
|
-
assert.equal(response.body, 'hello, world!');
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('handles malformed redirect responses', function() {
|
|
175
|
-
var request = new HttpRequest('GET', '/badredirect');
|
|
176
|
-
var client = new HttpClient(server.url());
|
|
177
|
-
return client.send(request).then(assert.fail, function(err) {
|
|
178
|
-
assert.ok(/Failed to parse "Location"/.test(err.message),
|
|
179
|
-
'Not the expected error: ' + err.message);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
describe('with proxy', function() {
|
|
184
|
-
it('sends request to proxy with absolute URI', function() {
|
|
185
|
-
var request = new HttpRequest('GET', '/proxy');
|
|
186
|
-
var client = new HttpClient(
|
|
187
|
-
'http://another.server.com', undefined, server.url());
|
|
188
|
-
return client.send(request).then(function(response) {
|
|
189
|
-
assert.equal(200, response.status);
|
|
190
|
-
assert.equal(response.headers.get('host'), 'another.server.com');
|
|
191
|
-
assert.equal(
|
|
192
|
-
response.headers.get('x-proxy-request-uri'),
|
|
193
|
-
'http://another.server.com/proxy');
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('uses proxy when following redirects', function() {
|
|
198
|
-
var request = new HttpRequest('GET', '/proxy/redirect');
|
|
199
|
-
var client = new HttpClient(
|
|
200
|
-
'http://another.server.com', undefined, server.url());
|
|
201
|
-
return client.send(request).then(function(response) {
|
|
202
|
-
assert.equal(200, response.status);
|
|
203
|
-
assert.equal(response.headers.get('host'), 'another.server.com');
|
|
204
|
-
assert.equal(
|
|
205
|
-
response.headers.get('x-proxy-request-uri'),
|
|
206
|
-
'http://another.server.com/proxy');
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('includes search and hash in redirect URI', function() {
|
|
211
|
-
var request = new HttpRequest('GET', '/proxy/redirect?foo#bar');
|
|
212
|
-
var client = new HttpClient(
|
|
213
|
-
'http://another.server.com', undefined, server.url());
|
|
214
|
-
return client.send(request).then(function(response) {
|
|
215
|
-
assert.equal(200, response.status);
|
|
216
|
-
assert.equal(response.headers.get('host'), 'another.server.com');
|
|
217
|
-
assert.equal(
|
|
218
|
-
response.headers.get('x-proxy-request-uri'),
|
|
219
|
-
'http://another.server.com/proxy?foo#bar');
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
});
|