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

Side by Side Diff: ios/web_view/test/chrome_web_view_kvo_inttest.mm

Issue 2892193002: Add unittest to test CWVWebView. (Closed)
Patch Set: Respond to comments. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import <ChromeWebView/ChromeWebView.h>
6 #import <Foundation/Foundation.h>
7
8 #import "base/mac/scoped_nsobject.h"
9 #import "ios/web_view/test/boolean_observer.h"
10 #import "ios/web_view/test/chrome_web_view_test.h"
11 #import "ios/web_view/test/web_view_interaction_test_util.h"
12 #import "net/base/mac/url_conversions.h"
13 #include "testing/gtest_mac.h"
14 #include "url/gurl.h"
15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
20 class ChromeWebViewKvoTest : public ios_web_view::ChromeWebViewTest {
Eugene But (OOO till 7-30) 2017/05/24 15:32:14 Do you want to explain in the comment what this fi
michaeldo 2017/05/24 16:37:08 Done.
21 protected:
22 ChromeWebViewKvoTest() {
23 CWVWebViewConfiguration* configuration =
24 [CWVWebViewConfiguration defaultConfiguration];
25 web_view_.reset([[CWVWebView alloc]
26 initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)
27 configuration:configuration]);
28 }
29
30 // Web View used to listen for expected KVO property changes.
31 base::scoped_nsobject<CWVWebView> web_view_;
32 };
33
34 namespace ios_web_view {
35
36 // Tests that CWVWebView correctly reports |canGoBack| and |canGoForward| state.
37 TEST_F(ChromeWebViewKvoTest, CanGoBackForward) {
38 BooleanObserver* back_observer = [[BooleanObserver alloc] init];
39 [back_observer setObservedObject:web_view_ keyPath:@"canGoBack"];
40
41 BooleanObserver* forward_observer = [[BooleanObserver alloc] init];
42 [forward_observer setObservedObject:web_view_ keyPath:@"canGoForward"];
43
44 ASSERT_FALSE(back_observer.lastValue);
45 ASSERT_FALSE(forward_observer.lastValue);
46
47 // Define pages in reverse order so the links can reference the "next" page.
48 GURL page_3_url = GetUrlForPageWithTitle("Page 3");
49
50 std::string page_2_html =
51 "<a id='link_2' href='" + page_3_url.spec() + "'>Link 2</a>";
52 GURL page_2_url = GetUrlForPageWithHTMLBody(page_2_html);
53
54 std::string page_1_html =
55 "<a id='link_1' href='" + page_2_url.spec() + "'>Link 1</a>";
56 GURL page_1_url = GetUrlForPageWithHTMLBody(page_1_html);
57
58 LoadUrl(web_view_, net::NSURLWithGURL(page_1_url));
59 // Loading initial URL should not affect back/forward navigation state.
60 EXPECT_FALSE([back_observer.lastValue boolValue]);
61 EXPECT_FALSE([forward_observer.lastValue boolValue]);
62
63 // Navigate to page 2.
64 EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view_, @"link_1"));
65 WaitForPageLoadCompletion(web_view_);
66 EXPECT_TRUE([back_observer.lastValue boolValue]);
67 EXPECT_FALSE([forward_observer.lastValue boolValue]);
68
69 // Navigate back to page 1.
70 [web_view_ goBack];
71 WaitForPageLoadCompletion(web_view_);
72 EXPECT_FALSE([back_observer.lastValue boolValue]);
73 EXPECT_TRUE([forward_observer.lastValue boolValue]);
74
75 // Navigate forward to page 2.
76 [web_view_ goForward];
77 WaitForPageLoadCompletion(web_view_);
78 EXPECT_TRUE([back_observer.lastValue boolValue]);
79 EXPECT_FALSE([forward_observer.lastValue boolValue]);
80
81 // Navigate to page 3.
82 EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view_, @"link_2"));
83 WaitForPageLoadCompletion(web_view_);
84 EXPECT_TRUE([back_observer.lastValue boolValue]);
85 EXPECT_FALSE([forward_observer.lastValue boolValue]);
86
87 // Navigate back to page 2.
88 [web_view_ goBack];
89 WaitForPageLoadCompletion(web_view_);
90 EXPECT_TRUE([back_observer.lastValue boolValue]);
91 EXPECT_TRUE([forward_observer.lastValue boolValue]);
92 }
93
94 } // namespace ios_web_view
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698