Chromium Code Reviews| 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 #import "base/strings/sys_string_conversions.h" |
| 10 #import "ios/web_view/test/chrome_web_view_test.h" | 10 #import "ios/web_view/test/chrome_web_view_test.h" |
| 11 #import "ios/web_view/test/observers/boolean_observer.h" | |
| 12 #import "ios/web_view/test/observers/string_observer.h" | |
|
Eugene But (OOO till 7-30)
2017/05/25 17:43:03
Do we actually need 2 different observers for BOOL
michaeldo
2017/05/26 14:59:01
It's true that they are not required as the one th
Eugene But (OOO till 7-30)
2017/05/31 22:10:00
Objective-C has one KVO callback for all types, be
Eugene But (OOO till 7-30)
2017/06/01 15:53:54
Please look at this comment
| |
| 11 #import "ios/web_view/test/web_view_interaction_test_util.h" | 13 #import "ios/web_view/test/web_view_interaction_test_util.h" |
| 12 #import "net/base/mac/url_conversions.h" | 14 #import "net/base/mac/url_conversions.h" |
| 13 #include "testing/gtest_mac.h" | 15 #include "testing/gtest_mac.h" |
| 14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 15 | 17 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
| 18 #endif | 20 #endif |
| 19 | 21 |
| 20 // Tests that the KVO compliant properties of CWVWebView correctly report | 22 // 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]); | 88 EXPECT_TRUE([back_observer.lastValue boolValue]); |
| 87 EXPECT_FALSE([forward_observer.lastValue boolValue]); | 89 EXPECT_FALSE([forward_observer.lastValue boolValue]); |
| 88 | 90 |
| 89 // Navigate back to page 2. | 91 // Navigate back to page 2. |
| 90 [web_view_ goBack]; | 92 [web_view_ goBack]; |
| 91 WaitForPageLoadCompletion(web_view_); | 93 WaitForPageLoadCompletion(web_view_); |
| 92 EXPECT_TRUE([back_observer.lastValue boolValue]); | 94 EXPECT_TRUE([back_observer.lastValue boolValue]); |
| 93 EXPECT_TRUE([forward_observer.lastValue boolValue]); | 95 EXPECT_TRUE([forward_observer.lastValue boolValue]); |
| 94 } | 96 } |
| 95 | 97 |
| 98 // Tests that CWVWebView correctly reports current |title|. | |
| 99 TEST_F(ChromeWebViewKvoTest, Title) { | |
| 100 StringObserver* observer = [[StringObserver alloc] init]; | |
| 101 [observer setObservedObject:web_view_ keyPath:@"title"]; | |
| 102 | |
| 103 NSString* page_2_title = @"Page 2"; | |
| 104 GURL page_2_url = | |
| 105 GetUrlForPageWithTitle(base::SysNSStringToUTF8(page_2_title)); | |
| 106 | |
| 107 NSString* page_1_title = @"Page 1"; | |
| 108 std::string page_1_html = | |
| 109 "<a id='link_1' href='" + page_2_url.spec() + "'>Link 1</a>"; | |
|
Eugene But (OOO till 7-30)
2017/05/25 17:43:03
Please se StringPrint instead of +
michaeldo
2017/05/26 14:59:01
Done.
| |
| 110 GURL page_1_url = GetUrlForPageWithTitleAndBody( | |
| 111 base::SysNSStringToUTF8(page_1_title), page_1_html); | |
| 112 | |
| 113 LoadUrl(web_view_, net::NSURLWithGURL(page_1_url)); | |
| 114 EXPECT_NSEQ(observer.lastValue, page_1_title); | |
| 115 | |
| 116 // Navigate to page 2. | |
| 117 EXPECT_TRUE(test::TapChromeWebViewElementWithId(web_view_, @"link_1")); | |
| 118 WaitForPageLoadCompletion(web_view_); | |
| 119 EXPECT_NSEQ(observer.lastValue, page_2_title); | |
|
Eugene But (OOO till 7-30)
2017/05/25 17:43:03
EXPECT_NSEQ takes first argument as expected value
michaeldo
2017/05/26 14:59:01
Done.
| |
| 120 | |
| 121 // Navigate back to page 1. | |
| 122 [web_view_ goBack]; | |
| 123 WaitForPageLoadCompletion(web_view_); | |
| 124 EXPECT_NSEQ(observer.lastValue, page_1_title); | |
| 125 } | |
| 126 | |
| 96 } // namespace ios_web_view | 127 } // namespace ios_web_view |
| OLD | NEW |