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

Side by Side Diff: ios/chrome/browser/sessions/session_window_unittest.mm

Issue 2720983002: Remove windowName from CRWSessionController. (Closed)
Patch Set: Address comments. Created 3 years, 9 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 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 22 matching lines...) Expand all
33 namespace { 33 namespace {
34 34
35 class SessionWindowIOSTest : public PlatformTest { 35 class SessionWindowIOSTest : public PlatformTest {
36 protected: 36 protected:
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(BOOL openedByDOM) const {
44 NSString* opener,
45 BOOL openedByDOM) const {
46 WebStateImpl* webState = new WebStateImpl(chrome_browser_state_.get()); 44 WebStateImpl* webState = new WebStateImpl(chrome_browser_state_.get());
47 webState->GetNavigationManagerImpl().InitializeSession(window_name, 45 webState->GetNavigationManagerImpl().InitializeSession(openedByDOM);
48 openedByDOM);
49 return webState; 46 return webState;
50 } 47 }
51 48
52 web::TestWebThreadBundle thread_bundle_; 49 web::TestWebThreadBundle thread_bundle_;
53 // TODO(crbug.com/661639): Switch to TestBrowserState once this test is moved 50 // TODO(crbug.com/661639): Switch to TestBrowserState once this test is moved
54 // to be in the ios_web_unittests target. 51 // to be in the ios_web_unittests target.
55 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 52 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
56 }; 53 };
57 54
58 TEST_F(SessionWindowIOSTest, InitEmpty) { 55 TEST_F(SessionWindowIOSTest, InitEmpty) {
59 base::scoped_nsobject<SessionWindowIOS> sessionWindow( 56 base::scoped_nsobject<SessionWindowIOS> sessionWindow(
60 [[SessionWindowIOS alloc] init]); 57 [[SessionWindowIOS alloc] init]);
61 EXPECT_TRUE(sessionWindow.get() != nil); 58 EXPECT_TRUE(sessionWindow.get() != nil);
62 } 59 }
63 60
64 TEST_F(SessionWindowIOSTest, InitAddingSessions) { 61 TEST_F(SessionWindowIOSTest, InitAddingSessions) {
65 std::unique_ptr<WebStateImpl> webState1(CreateWebState(@"window1", nil, NO)); 62 std::unique_ptr<WebStateImpl> webState1(CreateWebState(NO));
66 std::unique_ptr<WebStateImpl> webState2(CreateWebState(@"window2", nil, NO)); 63 std::unique_ptr<WebStateImpl> webState2(CreateWebState(NO));
67 base::scoped_nsobject<SessionWindowIOS> sessionWindow( 64 base::scoped_nsobject<SessionWindowIOS> sessionWindow(
68 [[SessionWindowIOS alloc] init]); 65 [[SessionWindowIOS alloc] init]);
69 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()]; 66 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()];
70 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()]; 67 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()];
71 [sessionWindow setSelectedIndex:1]; 68 [sessionWindow setSelectedIndex:1];
72 69
73 EXPECT_TRUE(sessionWindow.get() != nil); 70 EXPECT_TRUE(sessionWindow.get() != nil);
74 EXPECT_EQ(2U, sessionWindow.get().sessions.count); 71 EXPECT_EQ(2U, sessionWindow.get().sessions.count);
75 [sessionWindow clearSessions]; 72 [sessionWindow clearSessions];
76 EXPECT_EQ(0U, sessionWindow.get().sessions.count); 73 EXPECT_EQ(0U, sessionWindow.get().sessions.count);
77 } 74 }
78 75
79 TEST_F(SessionWindowIOSTest, CodingEncoding) { 76 TEST_F(SessionWindowIOSTest, CodingEncoding) {
80 NSString* windowName1 = @"window1";
81 NSString* windowName2 = @"window2";
82 base::scoped_nsobject<SessionWindowIOS> sessionWindow( 77 base::scoped_nsobject<SessionWindowIOS> sessionWindow(
83 [[SessionWindowIOS alloc] init]); 78 [[SessionWindowIOS alloc] init]);
84 79
85 std::unique_ptr<WebStateImpl> webState1( 80 std::unique_ptr<WebStateImpl> webState1(CreateWebState(YES));
86 CreateWebState(windowName1, nil, YES)); 81 std::unique_ptr<WebStateImpl> webState2(CreateWebState(NO));
87 std::unique_ptr<WebStateImpl> webState2(CreateWebState(windowName2, nil, NO));
88 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()]; 82 [sessionWindow addSerializedSessionStorage:webState1->BuildSessionStorage()];
89 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()]; 83 [sessionWindow addSerializedSessionStorage:webState2->BuildSessionStorage()];
90 84
91 [sessionWindow setSelectedIndex:1]; 85 [sessionWindow setSelectedIndex:1];
92 86
93 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:sessionWindow]; 87 NSData* data = [NSKeyedArchiver archivedDataWithRootObject:sessionWindow];
94 EXPECT_TRUE(data != nil); 88 EXPECT_TRUE(data != nil);
95 base::scoped_nsobject<SessionWindowUnarchiver> unarchiver( 89 base::scoped_nsobject<SessionWindowUnarchiver> unarchiver(
96 [[SessionWindowUnarchiver alloc] 90 [[SessionWindowUnarchiver alloc]
97 initForReadingWithData:data 91 initForReadingWithData:data
98 browserState:chrome_browser_state_.get()]); 92 browserState:chrome_browser_state_.get()]);
99 SessionWindowIOS* unarchivedObj = [unarchiver decodeObjectForKey:@"root"]; 93 SessionWindowIOS* unarchivedObj = [unarchiver decodeObjectForKey:@"root"];
100 EXPECT_TRUE(unarchivedObj != nil); 94 EXPECT_TRUE(unarchivedObj != nil);
101 EXPECT_EQ(unarchivedObj.selectedIndex, sessionWindow.get().selectedIndex); 95 EXPECT_EQ(unarchivedObj.selectedIndex, sessionWindow.get().selectedIndex);
102 NSArray* sessions = unarchivedObj.sessions; 96 NSArray* sessions = unarchivedObj.sessions;
103 ASSERT_EQ(2U, sessions.count); 97 ASSERT_EQ(2U, sessions.count);
104 CRWSessionStorage* unarchivedSession1 = sessions[0]; 98 CRWSessionStorage* unarchivedSession1 = sessions[0];
105 EXPECT_NSEQ(windowName1, unarchivedSession1.windowName);
106 EXPECT_TRUE(unarchivedSession1.openedByDOM); 99 EXPECT_TRUE(unarchivedSession1.openedByDOM);
107 100
108 CRWSessionStorage* unarchivedSession2 = sessions[1]; 101 CRWSessionStorage* unarchivedSession2 = sessions[1];
109 EXPECT_NSEQ(windowName2, unarchivedSession2.windowName);
110 EXPECT_FALSE(unarchivedSession2.openedByDOM); 102 EXPECT_FALSE(unarchivedSession2.openedByDOM);
111 } 103 }
112 104
113 } // anonymous namespace 105 } // anonymous namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/passwords/ios_chrome_password_manager_infobar_delegate.mm ('k') | ios/chrome/browser/tabs/tab.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698