| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <ChromeWebView/ChromeWebView.h> | 5 #import <ChromeWebView/ChromeWebView.h> |
| 6 #import <Foundation/Foundation.h> | 6 #import <Foundation/Foundation.h> |
| 7 | 7 |
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #import "ios/web_view/test/boolean_observer.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #import "base/strings/sys_string_conversions.h" |
| 10 #import "ios/web_view/test/chrome_web_view_test.h" | 11 #import "ios/web_view/test/chrome_web_view_test.h" |
| 12 #import "ios/web_view/test/observers/boolean_observer.h" |
| 13 #import "ios/web_view/test/observers/string_observer.h" |
| 11 #import "ios/web_view/test/web_view_interaction_test_util.h" | 14 #import "ios/web_view/test/web_view_interaction_test_util.h" |
| 12 #import "net/base/mac/url_conversions.h" | 15 #import "net/base/mac/url_conversions.h" |
| 13 #include "testing/gtest_mac.h" | 16 #include "testing/gtest_mac.h" |
| 14 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 15 | 18 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 19 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 20 #error "This file requires ARC support." |
| 18 #endif | 21 #endif |
| 19 | 22 |
| 20 // Tests that the KVO compliant properties of CWVWebView correctly report | 23 // Tests that the KVO compliant properties of CWVWebView correctly report |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 EXPECT_TRUE([back_observer.lastValue boolValue]); | 89 EXPECT_TRUE([back_observer.lastValue boolValue]); |
| 87 EXPECT_FALSE([forward_observer.lastValue boolValue]); | 90 EXPECT_FALSE([forward_observer.lastValue boolValue]); |
| 88 | 91 |
| 89 // Navigate back to page 2. | 92 // Navigate back to page 2. |
| 90 [web_view_ goBack]; | 93 [web_view_ goBack]; |
| 91 WaitForPageLoadCompletion(web_view_); | 94 WaitForPageLoadCompletion(web_view_); |
| 92 EXPECT_TRUE([back_observer.lastValue boolValue]); | 95 EXPECT_TRUE([back_observer.lastValue boolValue]); |
| 93 EXPECT_TRUE([forward_observer.lastValue boolValue]); | 96 EXPECT_TRUE([forward_observer.lastValue boolValue]); |
| 94 } | 97 } |
| 95 | 98 |
| 99 // Tests that CWVWebView correctly reports current |title|. |
| 100 TEST_F(ChromeWebViewKvoTest, Title) { |
| 101 StringObserver* observer = [[StringObserver alloc] init]; |
| 102 [observer setObservedObject:web_view_ keyPath:@"title"]; |
| 103 |
| 104 NSString* page_2_title = @"Page 2"; |
| 105 GURL page_2_url = |
| 106 GetUrlForPageWithTitle(base::SysNSStringToUTF8(page_2_title)); |
| 107 |
| 108 NSString* page_1_title = @"Page 1"; |
| 109 std::string page_1_html = base::StringPrintf( |
| 110 "<a id='link_1' href='%s'>Link 1</a>", page_2_url.spec().c_str()); |
| 111 GURL page_1_url = GetUrlForPageWithTitleAndBody( |
| 112 base::SysNSStringToUTF8(page_1_title), page_1_html); |
| 113 |
| 114 LoadUrl(web_view_, net::NSURLWithGURL(page_1_url)); |
| 115 EXPECT_NSEQ(page_1_title, observer.lastValue); |
| 116 |
| 117 // Navigate to page 2. |
| 118 EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view_, @"link_1")); |
| 119 WaitForPageLoadCompletion(web_view_); |
| 120 EXPECT_NSEQ(page_2_title, observer.lastValue); |
| 121 |
| 122 // Navigate back to page 1. |
| 123 [web_view_ goBack]; |
| 124 WaitForPageLoadCompletion(web_view_); |
| 125 EXPECT_NSEQ(page_1_title, observer.lastValue); |
| 126 } |
| 127 |
| 96 } // namespace ios_web_view | 128 } // namespace ios_web_view |
| OLD | NEW |