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

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

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

Powered by Google App Engine
This is Rietveld 408576698