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 | 6 |
7 #import "ios/web_view/test/chrome_web_view_test.h" | 7 #import "ios/web_view/test/web_view_test.h" |
8 #import "ios/web_view/test/web_view_test_util.h" | 8 #import "ios/web_view/test/web_view_test_util.h" |
9 #include "testing/gtest_mac.h" | 9 #include "testing/gtest_mac.h" |
10 | 10 |
11 #if !defined(__has_feature) || !__has_feature(objc_arc) | 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
12 #error "This file requires ARC support." | 12 #error "This file requires ARC support." |
13 #endif | 13 #endif |
14 | 14 |
15 namespace ios_web_view { | 15 namespace ios_web_view { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Creates a new web view and restores its state from |source_web_view|. | 19 // Creates a new web view and restores its state from |source_web_view|. |
20 CWVWebView* CreateWebViewWithState(CWVWebView* source_web_view) { | 20 CWVWebView* CreateWebViewWithState(CWVWebView* source_web_view) { |
21 NSMutableData* data = [[NSMutableData alloc] init]; | 21 NSMutableData* data = [[NSMutableData alloc] init]; |
22 NSKeyedArchiver* archiver = | 22 NSKeyedArchiver* archiver = |
23 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; | 23 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; |
24 [source_web_view encodeRestorableStateWithCoder:archiver]; | 24 [source_web_view encodeRestorableStateWithCoder:archiver]; |
25 [archiver finishEncoding]; | 25 [archiver finishEncoding]; |
26 NSKeyedUnarchiver* unarchiver = | 26 NSKeyedUnarchiver* unarchiver = |
27 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; | 27 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; |
28 CWVWebView* result = test::CreateWebView(); | 28 CWVWebView* result = test::CreateWebView(); |
29 [result decodeRestorableStateWithCoder:unarchiver]; | 29 [result decodeRestorableStateWithCoder:unarchiver]; |
30 return result; | 30 return result; |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 // Tests encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder: | 35 // Tests encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder: |
36 // methods. | 36 // methods. |
37 typedef ios_web_view::ChromeWebViewTest ChromeWebViewRestorableStateTest; | 37 typedef ios_web_view::WebViewTest WebViewRestorableStateTest; |
38 TEST_F(ChromeWebViewRestorableStateTest, EncodeDecode) { | 38 TEST_F(WebViewRestorableStateTest, EncodeDecode) { |
39 // Load 2 URLs to create non-default state. | 39 // Load 2 URLs to create non-default state. |
40 ASSERT_FALSE([web_view_ lastCommittedURL]); | 40 ASSERT_FALSE([web_view_ lastCommittedURL]); |
41 ASSERT_FALSE([web_view_ visibleURL]); | 41 ASSERT_FALSE([web_view_ visibleURL]); |
42 ASSERT_FALSE([web_view_ canGoBack]); | 42 ASSERT_FALSE([web_view_ canGoBack]); |
43 ASSERT_FALSE([web_view_ canGoForward]); | 43 ASSERT_FALSE([web_view_ canGoForward]); |
44 ASSERT_TRUE(test::LoadUrl(web_view_, [NSURL URLWithString:@"about:newtab"])); | 44 ASSERT_TRUE(test::LoadUrl(web_view_, [NSURL URLWithString:@"about:newtab"])); |
45 ASSERT_NSEQ(@"about:newtab", [web_view_ lastCommittedURL].absoluteString); | 45 ASSERT_NSEQ(@"about:newtab", [web_view_ lastCommittedURL].absoluteString); |
46 ASSERT_NSEQ(@"about:newtab", [web_view_ visibleURL].absoluteString); | 46 ASSERT_NSEQ(@"about:newtab", [web_view_ visibleURL].absoluteString); |
47 ASSERT_TRUE(test::LoadUrl(web_view_, [NSURL URLWithString:@"about:blank"])); | 47 ASSERT_TRUE(test::LoadUrl(web_view_, [NSURL URLWithString:@"about:blank"])); |
48 ASSERT_NSEQ(@"about:blank", [web_view_ lastCommittedURL].absoluteString); | 48 ASSERT_NSEQ(@"about:blank", [web_view_ lastCommittedURL].absoluteString); |
49 ASSERT_NSEQ(@"about:blank", [web_view_ visibleURL].absoluteString); | 49 ASSERT_NSEQ(@"about:blank", [web_view_ visibleURL].absoluteString); |
50 ASSERT_TRUE([web_view_ canGoBack]); | 50 ASSERT_TRUE([web_view_ canGoBack]); |
51 ASSERT_FALSE([web_view_ canGoForward]); | 51 ASSERT_FALSE([web_view_ canGoForward]); |
52 | 52 |
53 // Create second web view and restore its state from the first web view. | 53 // Create second web view and restore its state from the first web view. |
54 CWVWebView* restored_web_view = CreateWebViewWithState(web_view_); | 54 CWVWebView* restored_web_view = CreateWebViewWithState(web_view_); |
55 | 55 |
56 // Verify that the state has been restored correctly. | 56 // Verify that the state has been restored correctly. |
57 EXPECT_NSEQ(@"about:blank", | 57 EXPECT_NSEQ(@"about:blank", |
58 [restored_web_view lastCommittedURL].absoluteString); | 58 [restored_web_view lastCommittedURL].absoluteString); |
59 EXPECT_NSEQ(@"about:blank", [restored_web_view visibleURL].absoluteString); | 59 EXPECT_NSEQ(@"about:blank", [restored_web_view visibleURL].absoluteString); |
60 EXPECT_TRUE([web_view_ canGoBack]); | 60 EXPECT_TRUE([web_view_ canGoBack]); |
61 EXPECT_FALSE([web_view_ canGoForward]); | 61 EXPECT_FALSE([web_view_ canGoForward]); |
62 } | 62 } |
63 | 63 |
64 } // namespace ios_web_view | 64 } // namespace ios_web_view |
OLD | NEW |