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 { |
38 [super tearDown]; | |
39 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); | |
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 firstURL = web::test::HttpServer::MakeUrl("http://firstURL"); | |
56 NSString* firstResponse = @"Test Page 1"; | |
57 responses[firstURL] = base::SysNSStringToUTF8(firstResponse); | |
58 | |
59 const GURL secondURL = web::test::HttpServer::MakeUrl("http://secondURL"); | |
60 NSString* secondResponse = @"Test Page 2"; | |
61 responses[secondURL] = base::SysNSStringToUTF8(secondResponse); | |
62 | |
63 web::test::SetUpSimpleHttpServer(responses); | |
64 | |
65 web::navigation_test_util::LoadUrl(firstURL); | |
66 | |
42 [[EarlGrey | 67 [[EarlGrey |
43 selectElementWithMatcher:grey_accessibilityLabel( | 68 selectElementWithMatcher:shell_webViewContainingText(firstResponse)] |
Eugene But (OOO till 7-30)
2016/04/21 22:53:08
Optional NIT: I would name things response1/URL1 j
baxley
2016/04/22 02:02:59
Done.
| |
44 kWebShellAddressFieldAccessibilityLabel)] | 69 assertWithMatcher:grey_notNil()]; |
70 | |
71 web::navigation_test_util::LoadUrl(secondURL); | |
72 | |
73 [[EarlGrey | |
74 selectElementWithMatcher:shell_webViewContainingText(secondResponse)] | |
75 assertWithMatcher:grey_notNil()]; | |
76 | |
77 [[EarlGrey selectElementWithMatcher:shell_backButton()] | |
45 performAction:grey_tap()]; | 78 performAction:grey_tap()]; |
46 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] | 79 |
80 [[EarlGrey | |
81 selectElementWithMatcher:shell_webViewContainingText(firstResponse)] | |
82 assertWithMatcher:grey_notNil()]; | |
83 | |
84 [[EarlGrey selectElementWithMatcher:shell_forwardButton()] | |
47 performAction:grey_tap()]; | 85 performAction:grey_tap()]; |
86 | |
48 [[EarlGrey | 87 [[EarlGrey |
49 selectElementWithMatcher:grey_accessibilityLabel( | 88 selectElementWithMatcher:shell_webViewContainingText(secondResponse)] |
50 kWebShellAddressFieldAccessibilityLabel)] | 89 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 } | 90 } |
91 | |
65 @end | 92 @end |
OLD | NEW |