| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
| 6 | 6 |
| 7 #import "base/test/ios/wait_util.h" | 7 #import "base/test/ios/wait_util.h" |
| 8 #import "ios/testing/wait_util.h" | 8 #import "ios/testing/wait_util.h" |
| 9 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 9 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
| 10 #import "ios/web/public/test/http_server.h" | 10 #import "ios/web/public/test/http_server.h" |
| 11 #include "ios/web/public/test/http_server_util.h" | 11 #include "ios/web/public/test/http_server_util.h" |
| 12 #import "ios/web/shell/test/app/web_shell_test_util.h" | 12 #import "ios/web/shell/test/app/web_shell_test_util.h" |
| 13 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h" | 13 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h" |
| 14 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" | 14 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" |
| 15 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 // URL spec for test PDF page. | 21 // URL spec for test PDF page. |
| 22 const char kTestPDFURL[] = | 22 const char kTestPDFURL[] = |
| 23 "http://ios/web/shell/test/http_server_files/testpage.pdf"; | 23 "http://ios/web/shell/test/http_server_files/testpage.pdf"; |
| 24 | 24 |
| 25 // Matcher for WKWebView displaying PDF. | 25 // Matcher for WKWebView displaying PDF. |
| 26 id<GREYMatcher> webViewWithPdf() { | 26 id<GREYMatcher> WebViewWithPdf() { |
| 27 web::WebState* web_state = web::shell_test_util::GetCurrentWebState(); | 27 web::WebState* web_state = web::shell_test_util::GetCurrentWebState(); |
| 28 MatchesBlock matches = ^BOOL(UIView* view) { | 28 MatchesBlock matches = ^BOOL(UIView* view) { |
| 29 return testing::WaitUntilConditionOrTimeout( | 29 return testing::WaitUntilConditionOrTimeout( |
| 30 testing::kWaitForUIElementTimeout, ^{ | 30 testing::kWaitForUIElementTimeout, ^{ |
| 31 return web_state->GetContentsMimeType() == "application/pdf"; | 31 return web_state->GetContentsMimeType() == "application/pdf"; |
| 32 }); | 32 }); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 DescribeToBlock describe = ^(id<GREYDescription> description) { | 35 DescribeToBlock describe = ^(id<GREYDescription> description) { |
| 36 [description appendText:@"web view with PDF"]; | 36 [description appendText:@"web view with PDF"]; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 return grey_allOf( | 39 return grey_allOf( |
| 40 webViewInWebState(web_state), | 40 WebViewInWebState(web_state), |
| 41 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 41 [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
| 42 descriptionBlock:describe], | 42 descriptionBlock:describe], |
| 43 nil); | 43 nil); |
| 44 } | 44 } |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 using web::test::HttpServer; | 48 using web::test::HttpServer; |
| 49 | 49 |
| 50 // PDF test cases for the web shell. | 50 // PDF test cases for the web shell. |
| 51 @interface PDFTestCase : ShellBaseTestCase | 51 @interface PDFTestCase : ShellBaseTestCase |
| 52 @end | 52 @end |
| 53 | 53 |
| 54 @implementation PDFTestCase | 54 @implementation PDFTestCase |
| 55 | 55 |
| 56 // Tests MIME type of the loaded PDF document. | 56 // Tests MIME type of the loaded PDF document. |
| 57 - (void)testMIMEType { | 57 - (void)testMIMEType { |
| 58 web::test::SetUpFileBasedHttpServer(); | 58 web::test::SetUpFileBasedHttpServer(); |
| 59 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kTestPDFURL)]; | 59 [ShellEarlGrey loadURL:HttpServer::MakeUrl(kTestPDFURL)]; |
| 60 [[EarlGrey selectElementWithMatcher:webViewWithPdf()] | 60 [[EarlGrey selectElementWithMatcher:WebViewWithPdf()] |
| 61 assertWithMatcher:grey_notNil()]; | 61 assertWithMatcher:grey_notNil()]; |
| 62 } | 62 } |
| 63 | 63 |
| 64 @end | 64 @end |
| OLD | NEW |