OLD | NEW |
---|---|
(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 | |
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.
| |
8 #import "ios/web_view/test/boolean_observer.h" | |
9 #import "ios/web_view/test/chrome_web_view_test.h" | |
10 #include "ios/web_view/test/test_server.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 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.
| |
21 | |
22 namespace ios_web_view { | |
23 | |
24 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.
| |
25 CWVWebViewConfiguration* configuration = | |
26 [CWVWebViewConfiguration defaultConfiguration]; | |
27 CWVWebView* web_view = | |
28 [[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.
| |
29 configuration:configuration]; | |
30 | |
31 BooleanObserver* back_observer = [[BooleanObserver alloc] init]; | |
32 [back_observer setObservedObject:web_view keyPath:@"canGoBack"]; | |
33 | |
34 BooleanObserver* forward_observer = [[BooleanObserver alloc] init]; | |
35 [forward_observer setObservedObject:web_view keyPath:@"canGoForward"]; | |
36 | |
37 ASSERT_FALSE(back_observer.lastValue); | |
38 ASSERT_FALSE(forward_observer.lastValue); | |
39 | |
40 // 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
| |
41 std::string page_3 = TestServer::GetPageTitleURL("Page 3"); | |
42 | |
43 std::string page_2_html = "<a id='link_2' href='" + page_3 + "'>Link 2</a>"; | |
44 std::string page_2 = TestServer::GetPageWithHTMLBody(page_2_html); | |
45 | |
46 std::string page_1_html = "<a id='link_1' href='" + page_2 + "'>Link 1</a>"; | |
47 std::string page_1 = TestServer::GetPageWithHTMLBody(page_1_html); | |
48 | |
49 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.
| |
50 // Loading initial URL should not affect back/forward navigation state. | |
51 EXPECT_FALSE(back_observer.lastValue); | |
52 EXPECT_FALSE(forward_observer.lastValue); | |
53 | |
54 // Navigate to page 2. | |
55 EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view, @"link_1")); | |
56 ChromeWebViewTest::WaitForPageLoadCompletion(web_view); | |
57 EXPECT_TRUE(back_observer.lastValue); | |
58 EXPECT_FALSE(forward_observer.lastValue); | |
59 | |
60 // Navigate back to page 1. | |
61 [web_view goBack]; | |
62 ChromeWebViewTest::WaitForPageLoadCompletion(web_view); | |
63 EXPECT_FALSE(back_observer.lastValue); | |
64 EXPECT_TRUE(forward_observer.lastValue); | |
65 | |
66 // Navigate forward to page 2. | |
67 [web_view goForward]; | |
68 ChromeWebViewTest::WaitForPageLoadCompletion(web_view); | |
69 EXPECT_TRUE(back_observer.lastValue); | |
70 EXPECT_FALSE(forward_observer.lastValue); | |
71 | |
72 // Navigate to page 3. | |
73 EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view, @"link_2")); | |
74 ChromeWebViewTest::WaitForPageLoadCompletion(web_view); | |
75 EXPECT_TRUE(back_observer.lastValue); | |
76 EXPECT_FALSE(forward_observer.lastValue); | |
77 | |
78 // Navigate back to page 2. | |
79 [web_view goBack]; | |
80 ChromeWebViewTest::WaitForPageLoadCompletion(web_view); | |
81 EXPECT_TRUE(back_observer.lastValue); | |
82 EXPECT_TRUE(forward_observer.lastValue); | |
83 } | |
84 | |
85 } // namespace ios_web_view | |
OLD | NEW |