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 |
| 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 // Tests that the KVO compliant properties of CWVWebView correctly report |
| 21 // changes. |
| 22 class ChromeWebViewKvoTest : public ios_web_view::ChromeWebViewTest { |
| 23 protected: |
| 24 ChromeWebViewKvoTest() { |
| 25 CWVWebViewConfiguration* configuration = |
| 26 [CWVWebViewConfiguration defaultConfiguration]; |
| 27 web_view_.reset([[CWVWebView alloc] |
| 28 initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0) |
| 29 configuration:configuration]); |
| 30 } |
| 31 |
| 32 // Web View used to listen for expected KVO property changes. |
| 33 base::scoped_nsobject<CWVWebView> web_view_; |
| 34 }; |
| 35 |
| 36 namespace ios_web_view { |
| 37 |
| 38 // Tests that CWVWebView correctly reports |canGoBack| and |canGoForward| state. |
| 39 TEST_F(ChromeWebViewKvoTest, CanGoBackForward) { |
| 40 BooleanObserver* back_observer = [[BooleanObserver alloc] init]; |
| 41 [back_observer setObservedObject:web_view_ keyPath:@"canGoBack"]; |
| 42 |
| 43 BooleanObserver* forward_observer = [[BooleanObserver alloc] init]; |
| 44 [forward_observer setObservedObject:web_view_ keyPath:@"canGoForward"]; |
| 45 |
| 46 ASSERT_FALSE(back_observer.lastValue); |
| 47 ASSERT_FALSE(forward_observer.lastValue); |
| 48 |
| 49 // Define pages in reverse order so the links can reference the "next" page. |
| 50 GURL page_3_url = GetUrlForPageWithTitle("Page 3"); |
| 51 |
| 52 std::string page_2_html = |
| 53 "<a id='link_2' href='" + page_3_url.spec() + "'>Link 2</a>"; |
| 54 GURL page_2_url = GetUrlForPageWithHTMLBody(page_2_html); |
| 55 |
| 56 std::string page_1_html = |
| 57 "<a id='link_1' href='" + page_2_url.spec() + "'>Link 1</a>"; |
| 58 GURL page_1_url = GetUrlForPageWithHTMLBody(page_1_html); |
| 59 |
| 60 LoadUrl(web_view_, net::NSURLWithGURL(page_1_url)); |
| 61 // Loading initial URL should not affect back/forward navigation state. |
| 62 EXPECT_FALSE([back_observer.lastValue boolValue]); |
| 63 EXPECT_FALSE([forward_observer.lastValue boolValue]); |
| 64 |
| 65 // Navigate to page 2. |
| 66 EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view_, @"link_1")); |
| 67 WaitForPageLoadCompletion(web_view_); |
| 68 EXPECT_TRUE([back_observer.lastValue boolValue]); |
| 69 EXPECT_FALSE([forward_observer.lastValue boolValue]); |
| 70 |
| 71 // Navigate back to page 1. |
| 72 [web_view_ goBack]; |
| 73 WaitForPageLoadCompletion(web_view_); |
| 74 EXPECT_FALSE([back_observer.lastValue boolValue]); |
| 75 EXPECT_TRUE([forward_observer.lastValue boolValue]); |
| 76 |
| 77 // Navigate forward to page 2. |
| 78 [web_view_ goForward]; |
| 79 WaitForPageLoadCompletion(web_view_); |
| 80 EXPECT_TRUE([back_observer.lastValue boolValue]); |
| 81 EXPECT_FALSE([forward_observer.lastValue boolValue]); |
| 82 |
| 83 // Navigate to page 3. |
| 84 EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view_, @"link_2")); |
| 85 WaitForPageLoadCompletion(web_view_); |
| 86 EXPECT_TRUE([back_observer.lastValue boolValue]); |
| 87 EXPECT_FALSE([forward_observer.lastValue boolValue]); |
| 88 |
| 89 // Navigate back to page 2. |
| 90 [web_view_ goBack]; |
| 91 WaitForPageLoadCompletion(web_view_); |
| 92 EXPECT_TRUE([back_observer.lastValue boolValue]); |
| 93 EXPECT_TRUE([forward_observer.lastValue boolValue]); |
| 94 } |
| 95 |
| 96 } // namespace ios_web_view |
OLD | NEW |