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 <UIKit/UIKit.h> | 5 #import <UIKit/UIKit.h> |
| 6 #import <WebKit/WebKit.h> |
6 #import <XCTest/XCTest.h> | 7 #import <XCTest/XCTest.h> |
7 | 8 |
8 #import <EarlGrey/EarlGrey.h> | 9 #import <EarlGrey/EarlGrey.h> |
9 | 10 |
10 #import "ios/web/shell/view_controller.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #import "ios/web/public/test/http_server.h" |
| 13 #include "ios/web/public/test/http_server_util.h" |
| 14 #include "ios/web/shell/test/navigation_test_util.h" |
| 15 #import "ios/web/shell/test/shell_matchers.h" |
| 16 #import "ios/web/shell/test/web_view_matchers.h" |
11 | 17 |
| 18 // Navigation test cases for the web shell. These are Earl Grey integration |
| 19 // tests, which are based on XCTest. |
12 @interface CRWWebShellNavigationTest : XCTestCase | 20 @interface CRWWebShellNavigationTest : XCTestCase |
13 | 21 |
14 @end | 22 @end |
15 | 23 |
16 @implementation CRWWebShellNavigationTest | 24 @implementation CRWWebShellNavigationTest |
17 | 25 |
18 // Sample test to load a live URL, go back and then forward. | 26 // Set up called once for the class. |
19 - (void)testExternalURLBackAndForward { | 27 + (void)setUp { |
20 [[EarlGrey | 28 [super setUp]; |
21 selectElementWithMatcher:grey_accessibilityLabel( | 29 [[EarlGrey selectElementWithMatcher:shell_webViewContainingText(@"Chromium")] |
22 kWebShellAddressFieldAccessibilityLabel)] | 30 assertWithMatcher:grey_notNil()]; |
23 performAction:grey_tap()]; | 31 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
24 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] | 32 server.StartOrDie(); |
25 performAction:grey_tap()]; | 33 DCHECK(server.IsRunning()); |
26 [[EarlGrey | |
27 selectElementWithMatcher:grey_accessibilityLabel( | |
28 kWebShellAddressFieldAccessibilityLabel)] | |
29 performAction:grey_typeText(@"http://browsingtest.appspot.com\n")]; | |
30 [[EarlGrey | |
31 selectElementWithMatcher:grey_accessibilityLabel( | |
32 kWebShellBackButtonAccessibilityLabel)] | |
33 performAction:grey_tap()]; | |
34 [[EarlGrey | |
35 selectElementWithMatcher:grey_accessibilityLabel( | |
36 kWebShellForwardButtonAccessibilityLabel)] | |
37 performAction:grey_tap()]; | |
38 } | 34 } |
39 | 35 |
40 // Sample test to load a live URL, go back, forward, and then back again. | 36 // Tear down called once for the class. |
41 - (void)testExternalURLBackAndForwardAndBack { | 37 + (void)tearDown { |
42 [[EarlGrey | 38 [super tearDown]; |
43 selectElementWithMatcher:grey_accessibilityLabel( | 39 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
44 kWebShellAddressFieldAccessibilityLabel)] | 40 server.Stop(); |
| 41 DCHECK(!server.IsRunning()); |
| 42 } |
| 43 |
| 44 // Tear down called after each test. |
| 45 - (void)tearDown { |
| 46 [super tearDown]; |
| 47 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
| 48 server.RemoveAllResponseProviders(); |
| 49 } |
| 50 |
| 51 // Tests the back and forward button after entering two URLs. |
| 52 - (void)testWebScenarioBrowsingBackAndForward { |
| 53 // Create map of canned responses and set up the test HTML server. |
| 54 std::map<GURL, std::string> responses; |
| 55 const GURL URL1 = web::test::HttpServer::MakeUrl("http://firstURL"); |
| 56 NSString* response1 = @"Test Page 1"; |
| 57 responses[URL1] = base::SysNSStringToUTF8(response1); |
| 58 |
| 59 const GURL URL2 = web::test::HttpServer::MakeUrl("http://secondURL"); |
| 60 NSString* response2 = @"Test Page 2"; |
| 61 responses[URL2] = base::SysNSStringToUTF8(response2); |
| 62 |
| 63 web::test::SetUpSimpleHttpServer(responses); |
| 64 |
| 65 web::navigation_test_util::LoadUrl(URL1); |
| 66 |
| 67 [[EarlGrey selectElementWithMatcher:shell_webViewContainingText(response1)] |
| 68 assertWithMatcher:grey_notNil()]; |
| 69 |
| 70 web::navigation_test_util::LoadUrl(URL2); |
| 71 |
| 72 [[EarlGrey selectElementWithMatcher:shell_webViewContainingText(response2)] |
| 73 assertWithMatcher:grey_notNil()]; |
| 74 |
| 75 [[EarlGrey selectElementWithMatcher:shell_backButton()] |
45 performAction:grey_tap()]; | 76 performAction:grey_tap()]; |
46 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] | 77 |
| 78 [[EarlGrey selectElementWithMatcher:shell_webViewContainingText(response1)] |
| 79 assertWithMatcher:grey_notNil()]; |
| 80 |
| 81 [[EarlGrey selectElementWithMatcher:shell_forwardButton()] |
47 performAction:grey_tap()]; | 82 performAction:grey_tap()]; |
48 [[EarlGrey | 83 |
49 selectElementWithMatcher:grey_accessibilityLabel( | 84 [[EarlGrey selectElementWithMatcher:shell_webViewContainingText(response2)] |
50 kWebShellAddressFieldAccessibilityLabel)] | 85 assertWithMatcher:grey_notNil()]; |
51 performAction:grey_typeText(@"http://browsingtest.appspot.com\n")]; | |
52 [[EarlGrey | |
53 selectElementWithMatcher:grey_accessibilityLabel( | |
54 kWebShellBackButtonAccessibilityLabel)] | |
55 performAction:grey_tap()]; | |
56 [[EarlGrey | |
57 selectElementWithMatcher:grey_accessibilityLabel( | |
58 kWebShellForwardButtonAccessibilityLabel)] | |
59 performAction:grey_tap()]; | |
60 [[EarlGrey | |
61 selectElementWithMatcher:grey_accessibilityLabel( | |
62 kWebShellBackButtonAccessibilityLabel)] | |
63 performAction:grey_tap()]; | |
64 } | 86 } |
| 87 |
65 @end | 88 @end |
OLD | NEW |