Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: ios/web/shell/test/web_shell_navigation_egtest.mm

Issue 1890333002: Web shell test to go back and forward. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make webState a property Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/utils/navigation_egutil.h"
15 #import "ios/web/shell/test/utils/web_view_egutil.h"
10 #import "ios/web/shell/view_controller.h" 16 #import "ios/web/shell/view_controller.h"
11 17
12 @interface CRWWebShellNavigationTest : XCTestCase 18 @interface CRWWebShellNavigationTest : XCTestCase
Eugene But (OOO till 7-30) 2016/04/21 17:07:56 From Style Guide: Every non-trivial interface, pub
baxley 2016/04/21 21:52:52 Done.
13 19
14 @end 20 @end
15 21
16 @implementation CRWWebShellNavigationTest 22 @implementation CRWWebShellNavigationTest
17 23
18 // Sample test to load a live URL, go back and then forward. 24 // Set up called once for the class.
19 - (void)testExternalURLBackAndForward { 25 + (void)setUp {
26 [super setUp];
27 [[EarlGrey selectElementWithMatcher:shell_webViewContainingText(@"Chromium")]
28 assertWithMatcher:grey_notNil()];
29 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance();
30 server.StartOrDie();
31 DCHECK(server.IsRunning());
32 }
33
34 // Tear down called once for the class.
35 + (void)tearDown {
36 [super tearDown];
37 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance();
38 server.Stop();
39 DCHECK(!server.IsRunning());
40 }
41
42 // Tear down called after each test.
43 - (void)tearDown {
44 [super tearDown];
45 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance();
46 server.RemoveAllResponseProviders();
47 }
48
49 // Tests the back and forward button after entering two URLs.
50 - (void)testWebScenarioBrowsingBackAndForward {
51 // Create map of canned responses and set up the test HTML server.
52 std::map<GURL, std::string> responses;
53 const GURL firstURL = web::test::HttpServer::MakeUrl("http://firstURL");
54 NSString* firstResponse = @"Test Page 1";
55 responses[firstURL] = base::SysNSStringToUTF8(firstResponse);
56
57 const GURL secondURL = web::test::HttpServer::MakeUrl("http://secondURL");
58 NSString* secondResponse = @"Test Page 2";
59 responses[secondURL] = base::SysNSStringToUTF8(secondResponse);
60
61 web::test::SetUpSimpleHttpServer(responses);
62
63 navigation_egutil::LoadURL(firstURL);
64
20 [[EarlGrey 65 [[EarlGrey
21 selectElementWithMatcher:grey_accessibilityLabel( 66 selectElementWithMatcher:shell_webViewContainingText(firstResponse)]
22 kWebShellAddressFieldAccessibilityLabel)] 67 assertWithMatcher:grey_notNil()];
23 performAction:grey_tap()]; 68
24 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] 69 navigation_egutil::LoadURL(secondURL);
25 performAction:grey_tap()]; 70
26 [[EarlGrey 71 [[EarlGrey
27 selectElementWithMatcher:grey_accessibilityLabel( 72 selectElementWithMatcher:shell_webViewContainingText(secondResponse)]
28 kWebShellAddressFieldAccessibilityLabel)] 73 assertWithMatcher:grey_notNil()];
29 performAction:grey_typeText(@"http://browsingtest.appspot.com\n")]; 74
30 [[EarlGrey 75 [[EarlGrey
31 selectElementWithMatcher:grey_accessibilityLabel( 76 selectElementWithMatcher:grey_accessibilityLabel(
Eugene But (OOO till 7-30) 2016/04/21 17:07:56 This formatting does not look readable. How about
baxley 2016/04/21 21:52:52 Done.
32 kWebShellBackButtonAccessibilityLabel)] 77 kWebShellBackButtonAccessibilityLabel)]
33 performAction:grey_tap()]; 78 performAction:grey_tap()];
34 [[EarlGrey 79 [[EarlGrey
35 selectElementWithMatcher:grey_accessibilityLabel( 80 selectElementWithMatcher:shell_webViewContainingText(firstResponse)]
36 kWebShellForwardButtonAccessibilityLabel)] 81 assertWithMatcher:grey_notNil()];
37 performAction:grey_tap()];
38 }
39
40 // Sample test to load a live URL, go back, forward, and then back again.
41 - (void)testExternalURLBackAndForwardAndBack {
42 [[EarlGrey
43 selectElementWithMatcher:grey_accessibilityLabel(
44 kWebShellAddressFieldAccessibilityLabel)]
45 performAction:grey_tap()];
46 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")]
47 performAction:grey_tap()];
48 [[EarlGrey
49 selectElementWithMatcher:grey_accessibilityLabel(
50 kWebShellAddressFieldAccessibilityLabel)]
51 performAction:grey_typeText(@"http://browsingtest.appspot.com\n")];
52 [[EarlGrey
53 selectElementWithMatcher:grey_accessibilityLabel(
54 kWebShellBackButtonAccessibilityLabel)]
55 performAction:grey_tap()];
56 [[EarlGrey 82 [[EarlGrey
57 selectElementWithMatcher:grey_accessibilityLabel( 83 selectElementWithMatcher:grey_accessibilityLabel(
Eugene But (OOO till 7-30) 2016/04/21 17:07:56 ditto
baxley 2016/04/21 21:52:52 Done.
58 kWebShellForwardButtonAccessibilityLabel)] 84 kWebShellForwardButtonAccessibilityLabel)]
59 performAction:grey_tap()]; 85 performAction:grey_tap()];
86
60 [[EarlGrey 87 [[EarlGrey
61 selectElementWithMatcher:grey_accessibilityLabel( 88 selectElementWithMatcher:shell_webViewContainingText(secondResponse)]
62 kWebShellBackButtonAccessibilityLabel)] 89 assertWithMatcher:grey_notNil()];
63 performAction:grey_tap()];
64 } 90 }
91
65 @end 92 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698