Chromium Code Reviews| 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 #include "testing/gtest_mac.h" | |
| 9 | |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 11 #error "This file requires ARC support." | |
| 12 #endif | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Creates web view for testing. | |
| 17 CWVWebView* CreateWebView() { | |
| 18 return [[CWVWebView alloc] | |
| 19 initWithFrame:CGRectMake(0, 0, 50, 50) | |
| 20 configuration:[CWVWebViewConfiguration defaultConfiguration]]; | |
| 21 } | |
| 22 | |
| 23 // Creates a new web view and restores its state from |source_web_view|. | |
| 24 CWVWebView* CreateWebViewWithState(CWVWebView* source_web_view) { | |
| 25 NSMutableData* data = [[NSMutableData alloc] init]; | |
| 26 NSKeyedArchiver* archiver = | |
| 27 [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; | |
| 28 [source_web_view encodeRestorableStateWithCoder:archiver]; | |
| 29 [archiver finishEncoding]; | |
| 30 NSKeyedUnarchiver* unarchiver = | |
| 31 [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; | |
| 32 CWVWebView* result = [[CWVWebView alloc] | |
| 33 initWithFrame:CGRectZero | |
| 34 configuration:[CWVWebViewConfiguration defaultConfiguration]]; | |
| 35 [result decodeRestorableStateWithCoder:unarchiver]; | |
| 36 return result; | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 namespace ios_web_view { | |
| 42 | |
| 43 // Tests encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder: | |
| 44 // methods. | |
| 45 typedef ios_web_view::ChromeWebViewTest ChromeWebViewRestorableStateTest; | |
|
michaeldo
2017/06/13 14:51:35
Should this typedef go above in the anonymous name
Eugene But (OOO till 7-30)
2017/06/14 00:54:09
No, I think ChromeWebViewRestorableStateTest is co
| |
| 46 TEST_F(ChromeWebViewRestorableStateTest, EncodeDecode) { | |
| 47 // Create web view that will be used as a source for state restoration. | |
| 48 CWVWebView* web_view = CreateWebView(); | |
| 49 | |
| 50 // Load 2 URLs to create non-default state. | |
| 51 ASSERT_FALSE(web_view.lastCommittedURL); | |
| 52 ASSERT_FALSE(web_view.visibleURL); | |
| 53 ASSERT_FALSE(web_view.canGoBack); | |
| 54 ASSERT_FALSE(web_view.canGoForward); | |
| 55 LoadUrl(web_view, [NSURL URLWithString:@"about:newtab"]); | |
| 56 ASSERT_NSEQ(@"about:newtab", web_view.lastCommittedURL.absoluteString); | |
| 57 ASSERT_NSEQ(@"about:newtab", web_view.visibleURL.absoluteString); | |
| 58 LoadUrl(web_view, [NSURL URLWithString:@"about:blank"]); | |
| 59 ASSERT_NSEQ(@"about:blank", web_view.lastCommittedURL.absoluteString); | |
| 60 ASSERT_NSEQ(@"about:blank", web_view.visibleURL.absoluteString); | |
| 61 ASSERT_TRUE(web_view.canGoBack); | |
| 62 ASSERT_FALSE(web_view.canGoForward); | |
| 63 | |
| 64 // Create second web view and restore its state from the first web view. | |
| 65 CWVWebView* restored_web_view = CreateWebViewWithState(web_view); | |
| 66 | |
| 67 // Verify that the state has been restored correctly. | |
| 68 EXPECT_NSEQ(@"about:blank", | |
| 69 restored_web_view.lastCommittedURL.absoluteString); | |
| 70 EXPECT_NSEQ(@"about:blank", restored_web_view.visibleURL.absoluteString); | |
| 71 EXPECT_TRUE(web_view.canGoBack); | |
| 72 EXPECT_FALSE(web_view.canGoForward); | |
| 73 } | |
| 74 | |
| 75 } // namespace ios_web_view | |
| OLD | NEW |