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