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 <XCTest/XCTest.h> | 6 #import <XCTest/XCTest.h> |
7 #import <WebKit/WebKit.h> | |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
Please sort includes alphabetically
baxley
2016/04/21 16:09:18
Done.
| |
7 | 8 |
8 #import <EarlGrey/EarlGrey.h> | 9 #import <EarlGrey/EarlGrey.h> |
9 | 10 |
11 #include "base/strings/sys_string_conversions.h" | |
12 #include "ios/web/public/test/http_server_util.h" | |
13 #import "ios/web/shell/test/utils/web_view_egutil.h" | |
10 #import "ios/web/shell/view_controller.h" | 14 #import "ios/web/shell/view_controller.h" |
11 | 15 |
12 @interface CRWWebShellNavigationTest : XCTestCase | 16 @interface CRWWebShellNavigationTest : XCTestCase |
13 | 17 |
14 @end | 18 @end |
15 | 19 |
16 @implementation CRWWebShellNavigationTest | 20 @implementation CRWWebShellNavigationTest |
17 | 21 |
18 // Sample test to load a live URL, go back and then forward. | 22 // Set up called once for the class. |
19 - (void)testExternalURLBackAndForward { | 23 + (void)setUp { |
24 [super setUp]; | |
25 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); | |
26 server.StartOrDie(); | |
27 DCHECK(server.IsRunning()); | |
28 } | |
29 | |
30 // Tear down called once for the class. | |
31 + (void)tearDown { | |
32 [super tearDown]; | |
33 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); | |
34 server.Stop(); | |
35 DCHECK(!server.IsRunning()); | |
36 } | |
37 | |
38 // Tear down called after each test. | |
39 - (void)tearDown { | |
40 [super tearDown]; | |
41 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); | |
42 server.RemoveAllResponseProviders(); | |
43 } | |
44 | |
45 // Tests the back and forward button after entering two URLs. | |
46 - (void)testWebScenarioBrowsingBackAndForward { | |
47 // Create map of canned responses and set up the test HTML server. | |
48 std::map<GURL, std::string> responses; | |
49 const GURL firstGURL = web::test::HttpServer::MakeUrl("http://firstURL"); | |
50 NSString* firstURL = base::SysUTF8ToNSString(firstGURL.spec().c_str()); | |
51 NSString* firstResponse = @"Test Page 1"; | |
52 responses[firstGURL] = base::SysNSStringToUTF8(firstResponse); | |
53 | |
54 const GURL secondGURL = web::test::HttpServer::MakeUrl("http://secondURL"); | |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
Optional NIT: s/secondGURL/secondURL
baxley
2016/04/21 16:09:18
Done.
| |
55 NSString* secondURL = base::SysUTF8ToNSString(secondGURL.spec().c_str()); | |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
Optional NIT: s/secondURL/secondURLSpec
Eugene But (OOO till 7-30)
2016/04/16 00:38:41
Drop |.c_str()|. SysUTF8ToNSString takes std::stri
baxley
2016/04/21 16:09:18
Acknowledged.
baxley
2016/04/21 16:09:18
Acknowledged.
| |
56 NSString* secondResponse = @"Test Page 2"; | |
57 responses[secondGURL] = base::SysNSStringToUTF8(secondResponse); | |
58 | |
59 web::test::http_server_util::SetUpSimpleHttpServer(responses); | |
60 | |
20 [[EarlGrey | 61 [[EarlGrey |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
Can we group these methods into a single "enter UR
baxley
2016/04/21 16:09:18
I think that's a reasonable approach, but isn't ne
| |
21 selectElementWithMatcher:grey_accessibilityLabel( | 62 selectElementWithMatcher:grey_accessibilityLabel( |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
NIT: Can you move matcher to a separate variable t
baxley
2016/04/21 16:09:18
n/a
| |
22 kWebShellAddressFieldAccessibilityLabel)] | 63 kWebShellAddressFieldAccessibilityLabel)] |
23 performAction:grey_tap()]; | 64 performAction:grey_tap()]; |
24 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] | 65 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] |
Eugene But (OOO till 7-30)
2016/04/16 00:38:41
Please make constant for "Clear Text"
baxley
2016/04/21 16:09:18
n/a
| |
25 performAction:grey_tap()]; | 66 performAction:grey_tap()]; |
26 [[EarlGrey | 67 [[[EarlGrey |
27 selectElementWithMatcher:grey_accessibilityLabel( | 68 selectElementWithMatcher:grey_accessibilityLabel( |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
NIT: Separate variable for matcher?
baxley
2016/04/21 16:09:18
n/a for this CL, but good idea for the future.
| |
28 kWebShellAddressFieldAccessibilityLabel)] | 69 kWebShellAddressFieldAccessibilityLabel)] |
29 performAction:grey_typeText(@"http://browsingtest.appspot.com\n")]; | 70 performAction:grey_typeText(firstURL)] |
71 performAction:grey_typeText(@"\n")]; | |
72 | |
30 [[EarlGrey | 73 [[EarlGrey |
31 selectElementWithMatcher:grey_accessibilityLabel( | 74 selectElementWithMatcher:shell_webViewContainingText(firstResponse)] |
32 kWebShellBackButtonAccessibilityLabel)] | 75 assertWithMatcher:grey_notNil()]; |
33 performAction:grey_tap()]; | |
34 [[EarlGrey | |
35 selectElementWithMatcher:grey_accessibilityLabel( | |
36 kWebShellForwardButtonAccessibilityLabel)] | |
37 performAction:grey_tap()]; | |
38 } | |
39 | 76 |
40 // Sample test to load a live URL, go back, forward, and then back again. | |
41 - (void)testExternalURLBackAndForwardAndBack { | |
42 [[EarlGrey | 77 [[EarlGrey |
43 selectElementWithMatcher:grey_accessibilityLabel( | 78 selectElementWithMatcher:grey_accessibilityLabel( |
44 kWebShellAddressFieldAccessibilityLabel)] | 79 kWebShellAddressFieldAccessibilityLabel)] |
45 performAction:grey_tap()]; | 80 performAction:grey_tap()]; |
46 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] | 81 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] |
47 performAction:grey_tap()]; | 82 performAction:grey_tap()]; |
48 [[EarlGrey | 83 [[[EarlGrey |
49 selectElementWithMatcher:grey_accessibilityLabel( | 84 selectElementWithMatcher:grey_accessibilityLabel( |
50 kWebShellAddressFieldAccessibilityLabel)] | 85 kWebShellAddressFieldAccessibilityLabel)] |
51 performAction:grey_typeText(@"http://browsingtest.appspot.com\n")]; | 86 performAction:grey_typeText(secondURL)] |
87 performAction:grey_typeText(@"\n")]; | |
88 | |
89 [[EarlGrey | |
90 selectElementWithMatcher:shell_webViewContainingText(secondResponse)] | |
91 assertWithMatcher:grey_notNil()]; | |
92 | |
52 [[EarlGrey | 93 [[EarlGrey |
53 selectElementWithMatcher:grey_accessibilityLabel( | 94 selectElementWithMatcher:grey_accessibilityLabel( |
54 kWebShellBackButtonAccessibilityLabel)] | 95 kWebShellBackButtonAccessibilityLabel)] |
55 performAction:grey_tap()]; | 96 performAction:grey_tap()]; |
56 [[EarlGrey | 97 [[EarlGrey |
98 selectElementWithMatcher:shell_webViewContainingText(firstResponse)] | |
99 assertWithMatcher:grey_notNil()]; | |
100 [[EarlGrey | |
57 selectElementWithMatcher:grey_accessibilityLabel( | 101 selectElementWithMatcher:grey_accessibilityLabel( |
58 kWebShellForwardButtonAccessibilityLabel)] | 102 kWebShellForwardButtonAccessibilityLabel)] |
59 performAction:grey_tap()]; | 103 performAction:grey_tap()]; |
104 | |
60 [[EarlGrey | 105 [[EarlGrey |
61 selectElementWithMatcher:grey_accessibilityLabel( | 106 selectElementWithMatcher:shell_webViewContainingText(secondResponse)] |
62 kWebShellBackButtonAccessibilityLabel)] | 107 assertWithMatcher:grey_notNil()]; |
63 performAction:grey_tap()]; | |
64 } | 108 } |
109 | |
65 @end | 110 @end |
OLD | NEW |