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" | |
9 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
10 #import "base/strings/sys_string_conversions.h" | 9 #import "base/strings/sys_string_conversions.h" |
11 #import "ios/testing/wait_util.h" | 10 #import "ios/testing/wait_util.h" |
12 #import "ios/web_view/test/chrome_web_view_test.h" | 11 #import "ios/web_view/test/chrome_web_view_test.h" |
13 #import "ios/web_view/test/observer.h" | 12 #import "ios/web_view/test/observer.h" |
14 #import "ios/web_view/test/web_view_interaction_test_util.h" | 13 #import "ios/web_view/test/web_view_test_util.h" |
15 #import "net/base/mac/url_conversions.h" | 14 #import "net/base/mac/url_conversions.h" |
16 #include "testing/gtest_mac.h" | 15 #include "testing/gtest_mac.h" |
17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
18 | 17 |
19 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
20 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
21 #endif | 20 #endif |
22 | 21 |
| 22 namespace ios_web_view { |
| 23 |
23 // Tests that the KVO compliant properties of CWVWebView correctly report | 24 // Tests that the KVO compliant properties of CWVWebView correctly report |
24 // changes. | 25 // changes. |
25 class ChromeWebViewKvoTest : public ios_web_view::ChromeWebViewTest { | 26 typedef ios_web_view::ChromeWebViewTest ChromeWebViewKvoTest; |
26 protected: | |
27 ChromeWebViewKvoTest() { | |
28 CWVWebViewConfiguration* configuration = | |
29 [CWVWebViewConfiguration defaultConfiguration]; | |
30 web_view_.reset([[CWVWebView alloc] | |
31 initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0) | |
32 configuration:configuration]); | |
33 } | |
34 | |
35 // Web View used to listen for expected KVO property changes. | |
36 base::scoped_nsobject<CWVWebView> web_view_; | |
37 }; | |
38 | |
39 namespace ios_web_view { | |
40 | 27 |
41 // Tests that CWVWebView correctly reports |canGoBack| and |canGoForward| state. | 28 // Tests that CWVWebView correctly reports |canGoBack| and |canGoForward| state. |
42 TEST_F(ChromeWebViewKvoTest, CanGoBackForward) { | 29 TEST_F(ChromeWebViewKvoTest, CanGoBackForward) { |
43 Observer* back_observer = [[Observer alloc] init]; | 30 Observer* back_observer = [[Observer alloc] init]; |
44 [back_observer setObservedObject:web_view_ keyPath:@"canGoBack"]; | 31 [back_observer setObservedObject:web_view_ keyPath:@"canGoBack"]; |
45 | 32 |
46 Observer* forward_observer = [[Observer alloc] init]; | 33 Observer* forward_observer = [[Observer alloc] init]; |
47 [forward_observer setObservedObject:web_view_ keyPath:@"canGoForward"]; | 34 [forward_observer setObservedObject:web_view_ keyPath:@"canGoForward"]; |
48 | 35 |
49 ASSERT_FALSE(back_observer.lastValue); | 36 ASSERT_FALSE(back_observer.lastValue); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 EXPECT_NSEQ(page_2_url, visible_url_observer.lastValue); | 173 EXPECT_NSEQ(page_2_url, visible_url_observer.lastValue); |
187 | 174 |
188 // Navigate back to page 1. | 175 // Navigate back to page 1. |
189 [web_view_ goBack]; | 176 [web_view_ goBack]; |
190 WaitForPageLoadCompletion(web_view_); | 177 WaitForPageLoadCompletion(web_view_); |
191 EXPECT_NSEQ(page_1_url, last_committed_url_observer.lastValue); | 178 EXPECT_NSEQ(page_1_url, last_committed_url_observer.lastValue); |
192 EXPECT_NSEQ(page_1_url, visible_url_observer.lastValue); | 179 EXPECT_NSEQ(page_1_url, visible_url_observer.lastValue); |
193 } | 180 } |
194 | 181 |
195 } // namespace ios_web_view | 182 } // namespace ios_web_view |
OLD | NEW |