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

Unified Diff: ios/web_view/test/chrome_web_view_kvo_unittest.mm

Issue 2892193002: Add unittest to test CWVWebView. (Closed)
Patch Set: Created 3 years, 7 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_view/test/chrome_web_view_kvo_unittest.mm
diff --git a/ios/web_view/test/chrome_web_view_kvo_unittest.mm b/ios/web_view/test/chrome_web_view_kvo_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..3561adc10328ab7e03d76beab821a1bcfde43733
--- /dev/null
+++ b/ios/web_view/test/chrome_web_view_kvo_unittest.mm
@@ -0,0 +1,85 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <ChromeWebView/ChromeWebView.h>
+#import <Foundation/Foundation.h>
+
Eugene But (OOO till 7-30) 2017/05/19 18:39:48 This test creates local HTTP server and it is not
michaeldo 2017/05/23 16:20:51 Done.
+#import "ios/web_view/test/boolean_observer.h"
+#import "ios/web_view/test/chrome_web_view_test.h"
+#include "ios/web_view/test/test_server.h"
+#import "ios/web_view/test/web_view_interaction_test_util.h"
+#import "net/base/mac/url_conversions.h"
+#include "testing/gtest_mac.h"
+#include "url/gurl.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+class ChromeWebViewKVOTest : public ChromeWebViewTest {};
Eugene But (OOO till 7-30) 2017/05/19 18:39:48 ChromeWebViewKvoTest because it's C++
michaeldo 2017/05/23 16:20:51 Done.
+
+namespace ios_web_view {
+
+TEST_F(ChromeWebViewKVOTest, CanGoBackForward) {
Eugene But (OOO till 7-30) 2017/05/19 18:39:48 Please add comments
michaeldo 2017/05/23 16:20:51 Done.
+ CWVWebViewConfiguration* configuration =
+ [CWVWebViewConfiguration defaultConfiguration];
+ CWVWebView* web_view =
+ [[CWVWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)
Eugene But (OOO till 7-30) 2017/05/19 18:39:48 Is this something that you want to do in ChromeWeb
michaeldo 2017/05/23 16:20:51 Good idea, moved to constructor.
+ configuration:configuration];
+
+ BooleanObserver* back_observer = [[BooleanObserver alloc] init];
+ [back_observer setObservedObject:web_view keyPath:@"canGoBack"];
+
+ BooleanObserver* forward_observer = [[BooleanObserver alloc] init];
+ [forward_observer setObservedObject:web_view keyPath:@"canGoForward"];
+
+ ASSERT_FALSE(back_observer.lastValue);
+ ASSERT_FALSE(forward_observer.lastValue);
+
+ // Define pages in reverse order so the links can reference the "next" page.
Eugene But (OOO till 7-30) 2017/05/19 18:39:48 This code which sets up server responses looks dif
michaeldo 2017/05/23 16:20:51 This is consistent with components/cronet/ios/test
+ std::string page_3 = TestServer::GetPageTitleURL("Page 3");
+
+ std::string page_2_html = "<a id='link_2' href='" + page_3 + "'>Link 2</a>";
+ std::string page_2 = TestServer::GetPageWithHTMLBody(page_2_html);
+
+ std::string page_1_html = "<a id='link_1' href='" + page_2 + "'>Link 1</a>";
+ std::string page_1 = TestServer::GetPageWithHTMLBody(page_1_html);
+
+ ChromeWebViewTest::LoadURL(web_view, net::NSURLWithGURL(GURL(page_1)));
Eugene But (OOO till 7-30) 2017/05/19 18:39:48 You don't need ChromeWebViewTest::
michaeldo 2017/05/23 16:20:51 Done.
+ // Loading initial URL should not affect back/forward navigation state.
+ EXPECT_FALSE(back_observer.lastValue);
+ EXPECT_FALSE(forward_observer.lastValue);
+
+ // Navigate to page 2.
+ EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view, @"link_1"));
+ ChromeWebViewTest::WaitForPageLoadCompletion(web_view);
+ EXPECT_TRUE(back_observer.lastValue);
+ EXPECT_FALSE(forward_observer.lastValue);
+
+ // Navigate back to page 1.
+ [web_view goBack];
+ ChromeWebViewTest::WaitForPageLoadCompletion(web_view);
+ EXPECT_FALSE(back_observer.lastValue);
+ EXPECT_TRUE(forward_observer.lastValue);
+
+ // Navigate forward to page 2.
+ [web_view goForward];
+ ChromeWebViewTest::WaitForPageLoadCompletion(web_view);
+ EXPECT_TRUE(back_observer.lastValue);
+ EXPECT_FALSE(forward_observer.lastValue);
+
+ // Navigate to page 3.
+ EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view, @"link_2"));
+ ChromeWebViewTest::WaitForPageLoadCompletion(web_view);
+ EXPECT_TRUE(back_observer.lastValue);
+ EXPECT_FALSE(forward_observer.lastValue);
+
+ // Navigate back to page 2.
+ [web_view goBack];
+ ChromeWebViewTest::WaitForPageLoadCompletion(web_view);
+ EXPECT_TRUE(back_observer.lastValue);
+ EXPECT_TRUE(forward_observer.lastValue);
+}
+
+} // namespace ios_web_view

Powered by Google App Engine
This is Rietveld 408576698