Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: ios/web_view/test/chrome_web_view_restorable_state_inttest.mm

Issue 2933313002: CWVWebView integration test for state restoration. (Closed)
Patch Set: Use CreateWebView inside CreateWebViewWithState Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web_view/test/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 = CreateWebView();
33 [result decodeRestorableStateWithCoder:unarchiver];
34 return result;
35 }
36
37 } // namespace
38
39 namespace ios_web_view {
40
41 // Tests encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder:
42 // methods.
43 typedef ios_web_view::ChromeWebViewTest ChromeWebViewRestorableStateTest;
44 TEST_F(ChromeWebViewRestorableStateTest, EncodeDecode) {
45 // Create web view that will be used as a source for state restoration.
46 CWVWebView* web_view = CreateWebView();
47
48 // Load 2 URLs to create non-default state.
49 ASSERT_FALSE(web_view.lastCommittedURL);
50 ASSERT_FALSE(web_view.visibleURL);
51 ASSERT_FALSE(web_view.canGoBack);
52 ASSERT_FALSE(web_view.canGoForward);
53 LoadUrl(web_view, [NSURL URLWithString:@"about:newtab"]);
54 ASSERT_NSEQ(@"about:newtab", web_view.lastCommittedURL.absoluteString);
55 ASSERT_NSEQ(@"about:newtab", web_view.visibleURL.absoluteString);
56 LoadUrl(web_view, [NSURL URLWithString:@"about:blank"]);
57 ASSERT_NSEQ(@"about:blank", web_view.lastCommittedURL.absoluteString);
58 ASSERT_NSEQ(@"about:blank", web_view.visibleURL.absoluteString);
59 ASSERT_TRUE(web_view.canGoBack);
60 ASSERT_FALSE(web_view.canGoForward);
61
62 // Create second web view and restore its state from the first web view.
63 CWVWebView* restored_web_view = CreateWebViewWithState(web_view);
64
65 // Verify that the state has been restored correctly.
66 EXPECT_NSEQ(@"about:blank",
67 restored_web_view.lastCommittedURL.absoluteString);
68 EXPECT_NSEQ(@"about:blank", restored_web_view.visibleURL.absoluteString);
69 EXPECT_TRUE(web_view.canGoBack);
70 EXPECT_FALSE(web_view.canGoForward);
71 }
72
73 } // namespace ios_web_view
OLDNEW
« no previous file with comments | « ios/web_view/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698