Index: ios/web/shell/test/web_shell_navigation_egtest.mm |
diff --git a/ios/web/shell/test/web_shell_navigation_egtest.mm b/ios/web/shell/test/web_shell_navigation_egtest.mm |
index 38936aecbe8e41e3afd7e501e2542f321e2b89c4..0595a0f8fd81e4e616a349315f5ef10207f0188e 100644 |
--- a/ios/web/shell/test/web_shell_navigation_egtest.mm |
+++ b/ios/web/shell/test/web_shell_navigation_egtest.mm |
@@ -3,63 +3,90 @@ |
// found in the LICENSE file. |
#import <UIKit/UIKit.h> |
+#import <WebKit/WebKit.h> |
#import <XCTest/XCTest.h> |
#import <EarlGrey/EarlGrey.h> |
-#import "ios/web/shell/view_controller.h" |
+#include "base/strings/sys_string_conversions.h" |
+#import "ios/web/public/test/http_server.h" |
+#include "ios/web/public/test/http_server_util.h" |
+#include "ios/web/shell/test/navigation_test_util.h" |
+#import "ios/web/shell/test/shell_matchers.h" |
+#import "ios/web/shell/test/web_view_matchers.h" |
+// Navigation test cases for the web shell. These are Earl Grey integration |
+// tests, which are based on XCTest. |
@interface CRWWebShellNavigationTest : XCTestCase |
@end |
@implementation CRWWebShellNavigationTest |
-// Sample test to load a live URL, go back and then forward. |
-- (void)testExternalURLBackAndForward { |
- [[EarlGrey |
- selectElementWithMatcher:grey_accessibilityLabel( |
- kWebShellAddressFieldAccessibilityLabel)] |
- performAction:grey_tap()]; |
- [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] |
- performAction:grey_tap()]; |
- [[EarlGrey |
- selectElementWithMatcher:grey_accessibilityLabel( |
- kWebShellAddressFieldAccessibilityLabel)] |
- performAction:grey_typeText(@"http://browsingtest.appspot.com\n")]; |
- [[EarlGrey |
- selectElementWithMatcher:grey_accessibilityLabel( |
- kWebShellBackButtonAccessibilityLabel)] |
- performAction:grey_tap()]; |
- [[EarlGrey |
- selectElementWithMatcher:grey_accessibilityLabel( |
- kWebShellForwardButtonAccessibilityLabel)] |
- performAction:grey_tap()]; |
+// Set up called once for the class. |
++ (void)setUp { |
+ [super setUp]; |
+ [[EarlGrey selectElementWithMatcher:shell_webViewContainingText(@"Chromium")] |
+ assertWithMatcher:grey_notNil()]; |
+ web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
+ server.StartOrDie(); |
+ DCHECK(server.IsRunning()); |
} |
-// Sample test to load a live URL, go back, forward, and then back again. |
-- (void)testExternalURLBackAndForwardAndBack { |
- [[EarlGrey |
- selectElementWithMatcher:grey_accessibilityLabel( |
- kWebShellAddressFieldAccessibilityLabel)] |
- performAction:grey_tap()]; |
- [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Clear text")] |
- performAction:grey_tap()]; |
+// Tear down called once for the class. |
++ (void)tearDown { |
+ [super tearDown]; |
+ web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
+ server.Stop(); |
+ DCHECK(!server.IsRunning()); |
+} |
+ |
+// Tear down called after each test. |
+- (void)tearDown { |
+ [super tearDown]; |
+ web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
+ server.RemoveAllResponseProviders(); |
+} |
+ |
+// Tests the back and forward button after entering two URLs. |
+- (void)testWebScenarioBrowsingBackAndForward { |
+ // Create map of canned responses and set up the test HTML server. |
+ std::map<GURL, std::string> responses; |
+ const GURL firstURL = web::test::HttpServer::MakeUrl("http://firstURL"); |
+ NSString* firstResponse = @"Test Page 1"; |
+ responses[firstURL] = base::SysNSStringToUTF8(firstResponse); |
+ |
+ const GURL secondURL = web::test::HttpServer::MakeUrl("http://secondURL"); |
+ NSString* secondResponse = @"Test Page 2"; |
+ responses[secondURL] = base::SysNSStringToUTF8(secondResponse); |
+ |
+ web::test::SetUpSimpleHttpServer(responses); |
+ |
+ web::navigation_test_util::LoadUrl(firstURL); |
+ |
[[EarlGrey |
- selectElementWithMatcher:grey_accessibilityLabel( |
- kWebShellAddressFieldAccessibilityLabel)] |
- performAction:grey_typeText(@"http://browsingtest.appspot.com\n")]; |
+ 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.
|
+ assertWithMatcher:grey_notNil()]; |
+ |
+ web::navigation_test_util::LoadUrl(secondURL); |
+ |
[[EarlGrey |
- selectElementWithMatcher:grey_accessibilityLabel( |
- kWebShellBackButtonAccessibilityLabel)] |
+ selectElementWithMatcher:shell_webViewContainingText(secondResponse)] |
+ assertWithMatcher:grey_notNil()]; |
+ |
+ [[EarlGrey selectElementWithMatcher:shell_backButton()] |
performAction:grey_tap()]; |
+ |
[[EarlGrey |
- selectElementWithMatcher:grey_accessibilityLabel( |
- kWebShellForwardButtonAccessibilityLabel)] |
+ selectElementWithMatcher:shell_webViewContainingText(firstResponse)] |
+ assertWithMatcher:grey_notNil()]; |
+ |
+ [[EarlGrey selectElementWithMatcher:shell_forwardButton()] |
performAction:grey_tap()]; |
+ |
[[EarlGrey |
- selectElementWithMatcher:grey_accessibilityLabel( |
- kWebShellBackButtonAccessibilityLabel)] |
- performAction:grey_tap()]; |
+ selectElementWithMatcher:shell_webViewContainingText(secondResponse)] |
+ assertWithMatcher:grey_notNil()]; |
} |
+ |
@end |