OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "ios/chrome/browser/sessions/session_window.h" | 5 #import "ios/chrome/browser/sessions/session_window.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 26 matching lines...) Expand all Loading... |
37 void SetUp() override { | 37 void SetUp() override { |
38 PlatformTest::SetUp(); | 38 PlatformTest::SetUp(); |
39 TestChromeBrowserState::Builder test_cbs_builder; | 39 TestChromeBrowserState::Builder test_cbs_builder; |
40 chrome_browser_state_ = test_cbs_builder.Build(); | 40 chrome_browser_state_ = test_cbs_builder.Build(); |
41 } | 41 } |
42 | 42 |
43 WebStateImpl* CreateWebState(NSString* window_name, | 43 WebStateImpl* CreateWebState(NSString* window_name, |
44 NSString* opener, | 44 NSString* opener, |
45 BOOL openedByDOM) const { | 45 BOOL openedByDOM) const { |
46 WebStateImpl* webState = new WebStateImpl(chrome_browser_state_.get()); | 46 WebStateImpl* webState = new WebStateImpl(chrome_browser_state_.get()); |
47 webState->GetNavigationManagerImpl().InitializeSession(window_name, opener, | 47 webState->GetNavigationManagerImpl().InitializeSession(window_name, |
48 openedByDOM, 0); | 48 openedByDOM); |
49 return webState; | 49 return webState; |
50 } | 50 } |
51 | 51 |
52 web::TestWebThreadBundle thread_bundle_; | 52 web::TestWebThreadBundle thread_bundle_; |
53 // TODO(crbug.com/661639): Switch to TestBrowserState once this test is moved | 53 // TODO(crbug.com/661639): Switch to TestBrowserState once this test is moved |
54 // to be in the ios_web_unittests target. | 54 // to be in the ios_web_unittests target. |
55 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 55 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
56 }; | 56 }; |
57 | 57 |
58 TEST_F(SessionWindowIOSTest, InitEmpty) { | 58 TEST_F(SessionWindowIOSTest, InitEmpty) { |
(...skipping 18 matching lines...) Expand all Loading... |
77 } | 77 } |
78 | 78 |
79 TEST_F(SessionWindowIOSTest, CodingEncoding) { | 79 TEST_F(SessionWindowIOSTest, CodingEncoding) { |
80 NSString* windowName1 = @"window1"; | 80 NSString* windowName1 = @"window1"; |
81 NSString* windowName2 = @"window2"; | 81 NSString* windowName2 = @"window2"; |
82 base::scoped_nsobject<SessionWindowIOS> sessionWindow( | 82 base::scoped_nsobject<SessionWindowIOS> sessionWindow( |
83 [[SessionWindowIOS alloc] init]); | 83 [[SessionWindowIOS alloc] init]); |
84 | 84 |
85 std::unique_ptr<WebStateImpl> webState1( | 85 std::unique_ptr<WebStateImpl> webState1( |
86 CreateWebState(windowName1, nil, YES)); | 86 CreateWebState(windowName1, nil, YES)); |
87 NSString* openerId1 = | |
88 webState1->GetNavigationManagerImpl().GetSessionController().openerId; | |
89 std::unique_ptr<WebStateImpl> webState2(CreateWebState(windowName2, nil, NO)); | 87 std::unique_ptr<WebStateImpl> webState2(CreateWebState(windowName2, nil, NO)); |
90 NSString* openerId2 = | |
91 webState2->GetNavigationManagerImpl().GetSessionController().openerId; | |
92 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()]; | 88 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()]; |
93 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()]; | 89 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()]; |
94 | 90 |
95 [sessionWindow setSelectedIndex:1]; | 91 [sessionWindow setSelectedIndex:1]; |
96 | 92 |
97 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:sessionWindow]; | 93 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:sessionWindow]; |
98 EXPECT_TRUE(data != nil); | 94 EXPECT_TRUE(data != nil); |
99 base::scoped_nsobject<SessionWindowUnarchiver> unarchiver( | 95 base::scoped_nsobject<SessionWindowUnarchiver> unarchiver( |
100 [[SessionWindowUnarchiver alloc] | 96 [[SessionWindowUnarchiver alloc] |
101 initForReadingWithData:data | 97 initForReadingWithData:data |
102 browserState:chrome_browser_state_.get()]); | 98 browserState:chrome_browser_state_.get()]); |
103 SessionWindowIOS* unarchivedObj = [unarchiver decodeObjectForKey:@"root"]; | 99 SessionWindowIOS* unarchivedObj = [unarchiver decodeObjectForKey:@"root"]; |
104 EXPECT_TRUE(unarchivedObj != nil); | 100 EXPECT_TRUE(unarchivedObj != nil); |
105 EXPECT_EQ(unarchivedObj.selectedIndex, sessionWindow.get().selectedIndex); | 101 EXPECT_EQ(unarchivedObj.selectedIndex, sessionWindow.get().selectedIndex); |
106 NSArray* sessions = unarchivedObj.sessions; | 102 NSArray* sessions = unarchivedObj.sessions; |
107 ASSERT_EQ(2U, sessions.count); | 103 ASSERT_EQ(2U, sessions.count); |
108 CRWSessionStorage* unarchivedSession1 = sessions[0]; | 104 CRWSessionStorage* unarchivedSession1 = sessions[0]; |
109 EXPECT_NSEQ(windowName1, unarchivedSession1.windowName); | 105 EXPECT_NSEQ(windowName1, unarchivedSession1.windowName); |
110 EXPECT_NSEQ(openerId1, unarchivedSession1.openerID); | |
111 EXPECT_TRUE(unarchivedSession1.openedByDOM); | 106 EXPECT_TRUE(unarchivedSession1.openedByDOM); |
112 | 107 |
113 CRWSessionStorage* unarchivedSession2 = sessions[1]; | 108 CRWSessionStorage* unarchivedSession2 = sessions[1]; |
114 EXPECT_NSEQ(windowName2, unarchivedSession2.windowName); | 109 EXPECT_NSEQ(windowName2, unarchivedSession2.windowName); |
115 EXPECT_NSEQ(openerId2, unarchivedSession2.openerID); | |
116 EXPECT_FALSE(unarchivedSession2.openedByDOM); | 110 EXPECT_FALSE(unarchivedSession2.openedByDOM); |
117 } | 111 } |
118 | 112 |
119 } // anonymous namespace | 113 } // anonymous namespace |
OLD | NEW |