OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <EarlGrey/EarlGrey.h> |
| 6 #import <XCTest/XCTest.h> |
| 7 #include <map> |
| 8 |
| 9 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 10 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 11 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 12 #import "ios/web/public/test/http_server.h" |
| 13 #import "ios/web/public/test/http_server_util.h" |
| 14 |
| 15 using chrome_test_util::webViewContainingText; |
| 16 |
| 17 // Test case for bringing up the print dialog when a web site's JavaScript runs |
| 18 // "window.print". |
| 19 @interface JSPrintTestCase : ChromeTestCase |
| 20 @end |
| 21 |
| 22 @implementation JSPrintTestCase |
| 23 |
| 24 // Tests that tapping a button with onclick='window.print' brings up the |
| 25 // print dialog. |
| 26 - (void)testWebPrintButton { |
| 27 // Create map of canned responses and set up the test HTML server. |
| 28 std::map<GURL, std::string> responses; |
| 29 const GURL testURL = web::test::HttpServer::MakeUrl("http://printpage"); |
| 30 |
| 31 // Page containing button with onclick attribute calling window.print. |
| 32 responses[testURL] = |
| 33 "<input onclick='window.print();' type='button' id=\"printButton\" " |
| 34 "value='Print Page' />"; |
| 35 |
| 36 web::test::SetUpSimpleHttpServer(responses); |
| 37 [ChromeEarlGrey loadURL:testURL]; |
| 38 |
| 39 // Tap print button. |
| 40 [ChromeEarlGrey tapWebViewElementWithID:@"printButton"]; |
| 41 |
| 42 // Test if print dialog appeared. |
| 43 id<GREYMatcher> printerOption = grey_allOf( |
| 44 grey_accessibilityLabel(@"Printer Options"), |
| 45 grey_not(grey_accessibilityTrait(UIAccessibilityTraitHeader)), nil); |
| 46 [[EarlGrey selectElementWithMatcher:printerOption] |
| 47 assertWithMatcher:grey_sufficientlyVisible()]; |
| 48 |
| 49 // Clean up and close print dialog. |
| 50 id<GREYMatcher> cancelButton = |
| 51 grey_allOf(grey_accessibilityLabel(@"Cancel"), |
| 52 grey_accessibilityTrait(UIAccessibilityTraitButton), nil); |
| 53 [[EarlGrey selectElementWithMatcher:cancelButton] performAction:grey_tap()]; |
| 54 } |
| 55 |
| 56 @end |
OLD | NEW |