| 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 |
| 7 #include "base/test/ios/wait_util.h" |
| 8 #include "ios/testing/earl_grey/wait_util.h" |
| 9 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 10 #import "ios/web/public/test/http_server.h" |
| 11 #include "ios/web/public/test/http_server_util.h" |
| 12 #include "ios/web/shell/test/app/navigation_test_util.h" |
| 13 #import "ios/web/shell/test/app/web_shell_test_util.h" |
| 14 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h" |
| 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
| 20 namespace { |
| 21 // URL spec for test PDF page. |
| 22 const char kTestPDFURL[] = |
| 23 "http://ios/web/shell/test/http_server_files/testpage.pdf"; |
| 24 |
| 25 // Matcher for WKWebView displaying PDF. |
| 26 id<GREYMatcher> webViewWithPdf() { |
| 27 web::WebState* web_state = web::shell_test_util::GetCurrentWebState(); |
| 28 MatchesBlock matches = ^BOOL(UIView* view) { |
| 29 __block BOOL did_succeed = NO; |
| 30 NSDate* deadline = |
| 31 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; |
| 32 while ([[NSDate date] compare:deadline] != NSOrderedDescending) { |
| 33 if (web_state->GetContentsMimeType() == "application/pdf") { |
| 34 did_succeed = YES; |
| 35 break; |
| 36 } |
| 37 base::test::ios::SpinRunLoopWithMaxDelay( |
| 38 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); |
| 39 } |
| 40 return did_succeed; |
| 41 }; |
| 42 |
| 43 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 44 [description appendText:@"web view with PDF"]; |
| 45 }; |
| 46 |
| 47 return grey_allOf( |
| 48 webViewInWebState(web_state), |
| 49 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 50 descriptionBlock:describe], |
| 51 nil); |
| 52 } |
| 53 |
| 54 } // namespace |
| 55 |
| 56 using web::shell_test_util::LoadUrl; |
| 57 using web::test::HttpServer; |
| 58 |
| 59 // PDF test cases for the web shell. |
| 60 @interface PDFTest : ShellBaseTestCase |
| 61 @end |
| 62 |
| 63 @implementation PDFTest |
| 64 |
| 65 // Tests MIME type of the loaded PDF document. |
| 66 - (void)testMIMEType { |
| 67 web::test::SetUpFileBasedHttpServer(); |
| 68 LoadUrl(HttpServer::MakeUrl(kTestPDFURL)); |
| 69 [[EarlGrey selectElementWithMatcher:webViewWithPdf()] |
| 70 assertWithMatcher:grey_notNil()]; |
| 71 } |
| 72 |
| 73 @end |
| OLD | NEW |