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

Unified 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: formatting 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 side-by-side diff with in-line comments
Download patch
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..283d212d66c4c3a39df40a97b0e38d090ac7c492 100644
--- a/ios/web/shell/test/web_shell_navigation_egtest.mm
+++ b/ios/web/shell/test/web_shell_navigation_egtest.mm
@@ -4,9 +4,13 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
+#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.
#import <EarlGrey/EarlGrey.h>
+#include "base/strings/sys_string_conversions.h"
+#include "ios/web/public/test/http_server_util.h"
+#import "ios/web/shell/test/utils/web_view_egutil.h"
#import "ios/web/shell/view_controller.h"
@interface CRWWebShellNavigationTest : XCTestCase
@@ -15,51 +19,92 @@
@implementation CRWWebShellNavigationTest
-// Sample test to load a live URL, go back and then forward.
-- (void)testExternalURLBackAndForward {
+// Set up called once for the class.
++ (void)setUp {
+ [super setUp];
+ web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance();
+ server.StartOrDie();
+ DCHECK(server.IsRunning());
+}
+
+// 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 firstGURL = web::test::HttpServer::MakeUrl("http://firstURL");
+ NSString* firstURL = base::SysUTF8ToNSString(firstGURL.spec().c_str());
+ NSString* firstResponse = @"Test Page 1";
+ responses[firstGURL] = base::SysNSStringToUTF8(firstResponse);
+
+ 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.
+ 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.
+ NSString* secondResponse = @"Test Page 2";
+ responses[secondGURL] = base::SysNSStringToUTF8(secondResponse);
+
+ web::test::http_server_util::SetUpSimpleHttpServer(responses);
+
[[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
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
kWebShellAddressFieldAccessibilityLabel)]
performAction:grey_tap()];
[[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
performAction:grey_tap()];
- [[EarlGrey
+ [[[EarlGrey
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.
kWebShellAddressFieldAccessibilityLabel)]
- performAction:grey_typeText(@"http://browsingtest.appspot.com\n")];
- [[EarlGrey
- selectElementWithMatcher:grey_accessibilityLabel(
- kWebShellBackButtonAccessibilityLabel)]
- performAction:grey_tap()];
+ performAction:grey_typeText(firstURL)]
+ performAction:grey_typeText(@"\n")];
+
[[EarlGrey
- selectElementWithMatcher:grey_accessibilityLabel(
- kWebShellForwardButtonAccessibilityLabel)]
- performAction:grey_tap()];
-}
+ selectElementWithMatcher:shell_webViewContainingText(firstResponse)]
+ assertWithMatcher:grey_notNil()];
-// 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()];
- [[EarlGrey
+ [[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(
kWebShellAddressFieldAccessibilityLabel)]
- performAction:grey_typeText(@"http://browsingtest.appspot.com\n")];
+ performAction:grey_typeText(secondURL)]
+ performAction:grey_typeText(@"\n")];
+
+ [[EarlGrey
+ selectElementWithMatcher:shell_webViewContainingText(secondResponse)]
+ assertWithMatcher:grey_notNil()];
+
[[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(
kWebShellBackButtonAccessibilityLabel)]
performAction:grey_tap()];
[[EarlGrey
+ selectElementWithMatcher:shell_webViewContainingText(firstResponse)]
+ assertWithMatcher:grey_notNil()];
+ [[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(
kWebShellForwardButtonAccessibilityLabel)]
performAction:grey_tap()];
+
[[EarlGrey
- selectElementWithMatcher:grey_accessibilityLabel(
- kWebShellBackButtonAccessibilityLabel)]
- performAction:grey_tap()];
+ selectElementWithMatcher:shell_webViewContainingText(secondResponse)]
+ assertWithMatcher:grey_notNil()];
}
+
@end

Powered by Google App Engine
This is Rietveld 408576698