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 <objc/runtime.h> | 5 #import <objc/runtime.h> |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/mac/scoped_nsautorelease_pool.h" | 8 #include "base/mac/scoped_nsautorelease_pool.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 // We could expose this as part of the service's public API, but again that | 47 // We could expose this as part of the service's public API, but again that |
48 // might encourage use where we don't want it. As a result, just use the | 48 // might encourage use where we don't want it. As a result, just use the |
49 // known private-for-testing method directly. | 49 // known private-for-testing method directly. |
50 @interface SessionServiceIOS (Testing) | 50 @interface SessionServiceIOS (Testing) |
51 - (void)performSaveWindow:(SessionWindowIOS*)window | 51 - (void)performSaveWindow:(SessionWindowIOS*)window |
52 toDirectory:(NSString*)directory; | 52 toDirectory:(NSString*)directory; |
53 @end | 53 @end |
54 | 54 |
55 @interface TabTest : Tab | 55 @interface TabTest : Tab |
56 | 56 |
57 - (instancetype)initWithWindowName:(NSString*)windowName | 57 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
58 lastVisitedTimestamp:(double)lastVisitedTimestamp | 58 lastVisitedTimestamp:(double)lastVisitedTimestamp |
59 browserState:(ios::ChromeBrowserState*)browserState | 59 tabModel:(TabModel*)tabModel; |
60 tabModel:(TabModel*)tabModel; | |
61 @end | 60 @end |
62 | 61 |
63 @implementation TabTest | 62 @implementation TabTest |
64 | 63 |
65 - (instancetype)initWithWindowName:(NSString*)windowName | 64 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
66 lastVisitedTimestamp:(double)lastVisitedTimestamp | 65 lastVisitedTimestamp:(double)lastVisitedTimestamp |
67 browserState:(ios::ChromeBrowserState*)browserState | 66 tabModel:(TabModel*)tabModel { |
68 tabModel:(TabModel*)tabModel { | |
69 id webControllerMock = | 67 id webControllerMock = |
70 [OCMockObject niceMockForClass:[CRWWebController class]]; | 68 [OCMockObject niceMockForClass:[CRWWebController class]]; |
71 | 69 |
72 auto webStateImpl = base::MakeUnique<WebStateImpl>(browserState); | 70 auto webStateImpl = base::MakeUnique<WebStateImpl>(browserState); |
73 webStateImpl->SetWebController(webControllerMock); | 71 webStateImpl->SetWebController(webControllerMock); |
74 webStateImpl->GetNavigationManagerImpl().InitializeSession(windowName, NO); | 72 webStateImpl->GetNavigationManagerImpl().InitializeSession(NO); |
75 [webStateImpl->GetNavigationManagerImpl().GetSessionController() | 73 [webStateImpl->GetNavigationManagerImpl().GetSessionController() |
76 setLastVisitedTimestamp:lastVisitedTimestamp]; | 74 setLastVisitedTimestamp:lastVisitedTimestamp]; |
77 | 75 |
78 WebStateImpl* webStateImplPtr = webStateImpl.get(); | 76 WebStateImpl* webStateImplPtr = webStateImpl.get(); |
79 [[[webControllerMock stub] andReturnValue:OCMOCK_VALUE(webStateImplPtr)] | 77 [[[webControllerMock stub] andReturnValue:OCMOCK_VALUE(webStateImplPtr)] |
80 webStateImpl]; | 78 webStateImpl]; |
81 BOOL yes = YES; | 79 BOOL yes = YES; |
82 [[[webControllerMock stub] andReturnValue:OCMOCK_VALUE(yes)] isViewAlive]; | 80 [[[webControllerMock stub] andReturnValue:OCMOCK_VALUE(yes)] isViewAlive]; |
83 | 81 |
84 if ((self = [super initWithWebState:std::move(webStateImpl) | 82 if ((self = [super initWithWebState:std::move(webStateImpl) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 tab_model_observer_.reset([[TabModelObserverPong alloc] init]); | 148 tab_model_observer_.reset([[TabModelObserverPong alloc] init]); |
151 [tab_model_ addObserver:tab_model_observer_]; | 149 [tab_model_ addObserver:tab_model_observer_]; |
152 } | 150 } |
153 | 151 |
154 ~TabModelTest() override { | 152 ~TabModelTest() override { |
155 [tab_model_ removeObserver:tab_model_observer_]; | 153 [tab_model_ removeObserver:tab_model_observer_]; |
156 [tab_model_ browserStateDestroyed]; | 154 [tab_model_ browserStateDestroyed]; |
157 } | 155 } |
158 | 156 |
159 protected: | 157 protected: |
160 std::unique_ptr<WebStateImpl> CreateWebState(NSString* windowName, | 158 std::unique_ptr<WebStateImpl> CreateWebState(NSString* opener, |
161 NSString* opener, | |
162 NSInteger index) { | 159 NSInteger index) { |
163 auto webState = base::MakeUnique<WebStateImpl>(chrome_browser_state_.get()); | 160 auto webState = base::MakeUnique<WebStateImpl>(chrome_browser_state_.get()); |
164 webState->GetNavigationManagerImpl().InitializeSession(windowName, NO); | 161 webState->GetNavigationManagerImpl().InitializeSession(NO); |
165 if ([opener length] != 0) { | 162 if ([opener length] != 0) { |
166 // Duplicate code from Tab initializer. Will be removed once the code | 163 // Duplicate code from Tab initializer. Will be removed once the code |
167 // is rewritten to remove the use of internal ios/web/ API (see issue | 164 // is rewritten to remove the use of internal ios/web/ API (see issue |
168 // http://crbug.com/620465 for progress). | 165 // http://crbug.com/620465 for progress). |
169 web::SerializableUserDataManager* userDataManager = | 166 web::SerializableUserDataManager* userDataManager = |
170 web::SerializableUserDataManager::FromWebState(webState.get()); | 167 web::SerializableUserDataManager::FromWebState(webState.get()); |
171 userDataManager->AddSerializableData(opener, @"OpenerID"); | 168 userDataManager->AddSerializableData(opener, @"OpenerID"); |
172 userDataManager->AddSerializableData(@(index), @"OpenerNavigationIndex"); | 169 userDataManager->AddSerializableData(@(index), @"OpenerNavigationIndex"); |
173 } | 170 } |
174 return webState; | 171 return webState; |
175 } | 172 } |
176 | 173 |
177 std::unique_ptr<WebStateImpl> CreateWebState(NSString* windowName) { | 174 std::unique_ptr<WebStateImpl> CreateWebState() { |
178 return CreateWebState(windowName, @"", -1); | 175 return CreateWebState(@"", -1); |
179 } | 176 } |
180 | 177 |
181 std::unique_ptr<WebStateImpl> CreateChildWebState(Tab* parent) { | 178 std::unique_ptr<WebStateImpl> CreateChildWebState(Tab* parent) { |
182 return CreateWebState([parent windowName], parent.tabId, -1); | 179 return CreateWebState(parent.tabId, -1); |
183 } | 180 } |
184 | 181 |
185 void RestoreSession(SessionWindowIOS* window) { | 182 void RestoreSession(SessionWindowIOS* window) { |
186 [tab_model_ restoreSessionWindow:window]; | 183 [tab_model_ restoreSessionWindow:window]; |
187 } | 184 } |
188 | 185 |
189 // Creates a session window with |entries| entries and a |selectedIndex| of 1. | 186 // Creates a session window with |entries| entries and a |selectedIndex| of 1. |
190 SessionWindowIOS* CreateSessionWindow(int entries) { | 187 SessionWindowIOS* CreateSessionWindow(int entries) { |
191 SessionWindowIOS* window = [[SessionWindowIOS alloc] init]; | 188 SessionWindowIOS* window = [[SessionWindowIOS alloc] init]; |
192 for (int i = 0; i < entries; i++) { | 189 for (int i = 0; i < entries; i++) { |
193 NSString* windowName = [NSString stringWithFormat:@"window %d", i + 1]; | 190 [window |
Eugene But (OOO till 7-30)
2017/02/28 16:04:09
Optional nit: Do you want to create local session_
sdefresne
2017/02/28 17:41:07
Done.
| |
194 [window addSerializedSessionStorage:CreateWebState(windowName) | 191 addSerializedSessionStorage:CreateWebState()->BuildSessionStorage()]; |
195 ->BuildSessionStorage()]; | |
196 } | 192 } |
197 if (entries) | 193 if (entries) |
198 [window setSelectedIndex:1]; | 194 [window setSelectedIndex:1]; |
199 return window; | 195 return window; |
200 } | 196 } |
201 | 197 |
202 web::TestWebThreadBundle thread_bundle_; | 198 web::TestWebThreadBundle thread_bundle_; |
203 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_; | 199 IOSChromeScopedTestingChromeBrowserStateManager scoped_browser_state_manager_; |
204 web::ScopedTestingWebClient web_client_; | 200 web::ScopedTestingWebClient web_client_; |
205 base::scoped_nsobject<SessionWindowIOS> session_window_; | 201 base::scoped_nsobject<SessionWindowIOS> session_window_; |
206 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 202 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
207 base::mac::ScopedNSAutoreleasePool pool_; | 203 base::mac::ScopedNSAutoreleasePool pool_; |
208 base::scoped_nsobject<TabModel> tab_model_; | 204 base::scoped_nsobject<TabModel> tab_model_; |
209 base::scoped_nsobject<TabModelObserverPong> tab_model_observer_; | 205 base::scoped_nsobject<TabModelObserverPong> tab_model_observer_; |
210 }; | 206 }; |
211 | 207 |
212 TEST_F(TabModelTest, IsEmpty) { | 208 TEST_F(TabModelTest, IsEmpty) { |
213 EXPECT_EQ([tab_model_ count], 0U); | 209 EXPECT_EQ([tab_model_ count], 0U); |
214 EXPECT_TRUE([tab_model_ isEmpty]); | 210 EXPECT_TRUE([tab_model_ isEmpty]); |
215 [tab_model_ insertTabWithURL:kURL | 211 [tab_model_ insertTabWithURL:kURL |
216 referrer:kReferrer | 212 referrer:kReferrer |
217 windowName:@"window 1" | |
218 opener:nil | 213 opener:nil |
219 atIndex:0]; | 214 atIndex:0]; |
220 ASSERT_EQ(1U, [tab_model_ count]); | 215 ASSERT_EQ(1U, [tab_model_ count]); |
221 EXPECT_FALSE([tab_model_ isEmpty]); | 216 EXPECT_FALSE([tab_model_ isEmpty]); |
222 } | 217 } |
223 | 218 |
224 TEST_F(TabModelTest, InsertUrlSingle) { | 219 TEST_F(TabModelTest, InsertUrlSingle) { |
225 [tab_model_ insertTabWithURL:kURL | 220 Tab* tab = [tab_model_ insertTabWithURL:kURL |
226 referrer:kReferrer | 221 referrer:kReferrer |
227 windowName:@"window 1" | 222 opener:nil |
228 opener:nil | 223 atIndex:0]; |
229 atIndex:0]; | |
230 ASSERT_EQ(1U, [tab_model_ count]); | 224 ASSERT_EQ(1U, [tab_model_ count]); |
231 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:0] windowName]); | 225 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); |
232 } | 226 } |
233 | 227 |
234 TEST_F(TabModelTest, InsertUrlMultiple) { | 228 TEST_F(TabModelTest, InsertUrlMultiple) { |
235 [tab_model_ insertTabWithURL:kURL | 229 Tab* tab0 = [tab_model_ insertTabWithURL:kURL |
236 referrer:kReferrer | 230 referrer:kReferrer |
237 windowName:@"window 1" | 231 opener:nil |
238 opener:nil | 232 atIndex:0]; |
239 atIndex:0]; | 233 Tab* tab1 = [tab_model_ insertTabWithURL:kURL |
240 [tab_model_ insertTabWithURL:kURL | 234 referrer:kReferrer |
241 referrer:kReferrer | 235 opener:nil |
242 windowName:@"window 2" | 236 atIndex:0]; |
243 opener:nil | 237 Tab* tab2 = [tab_model_ insertTabWithURL:kURL |
244 atIndex:0]; | 238 referrer:kReferrer |
245 [tab_model_ insertTabWithURL:kURL | 239 opener:nil |
246 referrer:kReferrer | 240 atIndex:1]; |
247 windowName:@"window 3" | |
248 opener:nil | |
249 atIndex:1]; | |
250 | 241 |
251 ASSERT_EQ(3U, [tab_model_ count]); | 242 ASSERT_EQ(3U, [tab_model_ count]); |
252 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:0] windowName]); | 243 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); |
253 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:1] windowName]); | 244 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
254 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:2] windowName]); | 245 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); |
255 } | 246 } |
256 | 247 |
257 TEST_F(TabModelTest, AppendUrlSingle) { | 248 TEST_F(TabModelTest, AppendUrlSingle) { |
258 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 249 Tab* tab = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
259 ASSERT_EQ(1U, [tab_model_ count]); | 250 ASSERT_EQ(1U, [tab_model_ count]); |
260 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:0] windowName]); | 251 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); |
261 } | 252 } |
262 | 253 |
263 TEST_F(TabModelTest, AppendUrlMultiple) { | 254 TEST_F(TabModelTest, AppendUrlMultiple) { |
264 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 255 Tab* tab0 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
265 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 2"]; | 256 Tab* tab1 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
266 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 3"]; | 257 Tab* tab2 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
267 | 258 |
268 ASSERT_EQ(3U, [tab_model_ count]); | 259 ASSERT_EQ(3U, [tab_model_ count]); |
269 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:0] windowName]); | 260 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
270 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:1] windowName]); | 261 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); |
271 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:2] windowName]); | 262 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); |
272 } | 263 } |
273 | 264 |
274 TEST_F(TabModelTest, CloseTabAtIndexBeginning) { | 265 TEST_F(TabModelTest, CloseTabAtIndexBeginning) { |
275 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 266 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
276 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 2"]; | 267 Tab* tab1 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
277 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 3"]; | 268 Tab* tab2 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
278 | 269 |
279 [tab_model_ closeTabAtIndex:0]; | 270 [tab_model_ closeTabAtIndex:0]; |
280 | 271 |
281 ASSERT_EQ(2U, [tab_model_ count]); | 272 ASSERT_EQ(2U, [tab_model_ count]); |
282 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:0] windowName]); | 273 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); |
283 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:1] windowName]); | 274 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
284 } | 275 } |
285 | 276 |
286 TEST_F(TabModelTest, CloseTabAtIndexMiddle) { | 277 TEST_F(TabModelTest, CloseTabAtIndexMiddle) { |
287 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 278 Tab* tab0 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
288 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 2"]; | 279 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
289 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 3"]; | 280 Tab* tab2 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
290 | 281 |
291 [tab_model_ closeTabAtIndex:1]; | 282 [tab_model_ closeTabAtIndex:1]; |
292 | 283 |
293 ASSERT_EQ(2U, [tab_model_ count]); | 284 ASSERT_EQ(2U, [tab_model_ count]); |
294 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:0] windowName]); | 285 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
295 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:1] windowName]); | 286 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
296 } | 287 } |
297 | 288 |
298 TEST_F(TabModelTest, CloseTabAtIndexLast) { | 289 TEST_F(TabModelTest, CloseTabAtIndexLast) { |
299 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 290 Tab* tab0 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
300 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 2"]; | 291 Tab* tab1 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
301 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 3"]; | 292 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
302 | 293 |
303 [tab_model_ closeTabAtIndex:2]; | 294 [tab_model_ closeTabAtIndex:2]; |
304 | 295 |
305 ASSERT_EQ(2U, [tab_model_ count]); | 296 ASSERT_EQ(2U, [tab_model_ count]); |
306 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:0] windowName]); | 297 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
307 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:1] windowName]); | 298 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); |
308 } | 299 } |
309 | 300 |
310 TEST_F(TabModelTest, CloseTabAtIndexOnlyOne) { | 301 TEST_F(TabModelTest, CloseTabAtIndexOnlyOne) { |
311 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 302 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
312 | 303 |
313 [tab_model_ closeTabAtIndex:0]; | 304 [tab_model_ closeTabAtIndex:0]; |
314 | 305 |
315 EXPECT_EQ(0U, [tab_model_ count]); | 306 EXPECT_EQ(0U, [tab_model_ count]); |
316 } | 307 } |
317 | 308 |
318 TEST_F(TabModelTest, RestoreSessionOnNTPTest) { | 309 TEST_F(TabModelTest, RestoreSessionOnNTPTest) { |
319 [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) | 310 Tab* tab = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) |
320 referrer:kEmptyReferrer | 311 referrer:kEmptyReferrer |
321 windowName:@"old window" | 312 opener:nil |
322 opener:nil | 313 atIndex:0]; |
323 atIndex:0]; | |
324 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); | 314 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); |
325 | 315 |
326 RestoreSession(window.get()); | 316 RestoreSession(window.get()); |
327 ASSERT_EQ(3U, [tab_model_ count]); | 317 ASSERT_EQ(3U, [tab_model_ count]); |
328 EXPECT_NSEQ(@"window 2", [[tab_model_ currentTab] windowName]); | 318 EXPECT_NSEQ([tab_model_ tabAtIndex:1], [tab_model_ currentTab]); |
329 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:0] windowName]); | 319 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:0]); |
330 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:1] windowName]); | 320 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); |
331 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:2] windowName]); | 321 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); |
332 } | 322 } |
333 | 323 |
334 TEST_F(TabModelTest, RestoreSessionOn2NtpTest) { | 324 TEST_F(TabModelTest, RestoreSessionOn2NtpTest) { |
335 [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) | 325 Tab* tab0 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) |
336 referrer:kEmptyReferrer | 326 referrer:kEmptyReferrer |
337 windowName:@"old window 1" | 327 opener:nil |
338 opener:nil | 328 atIndex:0]; |
339 atIndex:0]; | 329 Tab* tab1 = [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) |
340 [tab_model_ insertTabWithURL:GURL(kChromeUINewTabURL) | 330 referrer:kEmptyReferrer |
341 referrer:kEmptyReferrer | 331 opener:nil |
342 windowName:@"old window 2" | 332 atIndex:1]; |
343 opener:nil | |
344 atIndex:1]; | |
345 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); | 333 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); |
346 | 334 |
347 RestoreSession(window.get()); | 335 RestoreSession(window.get()); |
348 ASSERT_EQ(5U, [tab_model_ count]); | 336 ASSERT_EQ(5U, [tab_model_ count]); |
349 EXPECT_NSEQ(@"window 2", [[tab_model_ currentTab] windowName]); | 337 EXPECT_NSEQ([tab_model_ tabAtIndex:3], [tab_model_ currentTab]); |
350 EXPECT_NSEQ(@"old window 1", [[tab_model_ tabAtIndex:0] windowName]); | 338 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
351 EXPECT_NSEQ(@"old window 2", [[tab_model_ tabAtIndex:1] windowName]); | 339 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); |
352 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:2] windowName]); | 340 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:2]); |
353 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:3] windowName]); | 341 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:3]); |
354 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:4] windowName]); | 342 EXPECT_NSNE(tab0, [tab_model_ tabAtIndex:4]); |
343 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:2]); | |
344 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:3]); | |
345 EXPECT_NSNE(tab1, [tab_model_ tabAtIndex:4]); | |
355 } | 346 } |
356 | 347 |
357 TEST_F(TabModelTest, RestoreSessionOnAnyTest) { | 348 TEST_F(TabModelTest, RestoreSessionOnAnyTest) { |
358 [tab_model_ insertTabWithURL:kURL | 349 Tab* tab = [tab_model_ insertTabWithURL:kURL |
359 referrer:kEmptyReferrer | 350 referrer:kEmptyReferrer |
360 windowName:@"old window 1" | 351 opener:nil |
361 opener:nil | 352 atIndex:0]; |
362 atIndex:0]; | |
363 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); | 353 base::scoped_nsobject<SessionWindowIOS> window(CreateSessionWindow(3)); |
364 | 354 |
365 RestoreSession(window.get()); | 355 RestoreSession(window.get()); |
366 ASSERT_EQ(4U, [tab_model_ count]); | 356 ASSERT_EQ(4U, [tab_model_ count]); |
367 EXPECT_NSEQ(@"window 2", [[tab_model_ currentTab] windowName]); | 357 EXPECT_NSEQ([tab_model_ tabAtIndex:2], [tab_model_ currentTab]); |
368 EXPECT_NSEQ(@"old window 1", [[tab_model_ tabAtIndex:0] windowName]); | 358 EXPECT_NSEQ(tab, [tab_model_ tabAtIndex:0]); |
369 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:1] windowName]); | 359 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:1]); |
370 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:2] windowName]); | 360 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:2]); |
371 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:3] windowName]); | 361 EXPECT_NSNE(tab, [tab_model_ tabAtIndex:3]); |
372 } | |
373 | |
374 TEST_F(TabModelTest, TabForWindowName) { | |
375 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | |
376 [tab_model_ addTabWithURL:GURL("https://www.some.url2.com") | |
377 referrer:kReferrer2 | |
378 windowName:@"window 2"]; | |
379 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 3"]; | |
380 | |
381 Tab* tab = [tab_model_ tabWithWindowName:@"window 2"]; | |
382 | |
383 EXPECT_NSEQ([tab windowName], @"window 2"); | |
384 EXPECT_EQ(tab.url, GURL("https://www.some.url2.com/")); | |
385 } | |
386 | |
387 TEST_F(TabModelTest, TabForWindowNameNotFound) { | |
388 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | |
389 [tab_model_ addTabWithURL:GURL("https://www.some.url2.com") | |
390 referrer:kReferrer2 | |
391 windowName:@"window 2"]; | |
392 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 3"]; | |
393 | |
394 Tab* tab = [tab_model_ tabWithWindowName:@"window not found"]; | |
395 | |
396 EXPECT_EQ(nil, tab); | |
397 } | 362 } |
398 | 363 |
399 TEST_F(TabModelTest, CloseAllTabs) { | 364 TEST_F(TabModelTest, CloseAllTabs) { |
400 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 365 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
401 [tab_model_ addTabWithURL:GURL("https://www.some.url2.com") | 366 [tab_model_ addTabWithURL:GURL("https://www.some.url2.com") |
402 referrer:kReferrer2 | 367 referrer:kReferrer2]; |
403 windowName:@"window 2"]; | 368 [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
404 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 3"]; | |
405 | 369 |
406 [tab_model_ closeAllTabs]; | 370 [tab_model_ closeAllTabs]; |
407 | 371 |
408 EXPECT_EQ(0U, [tab_model_ count]); | 372 EXPECT_EQ(0U, [tab_model_ count]); |
409 } | 373 } |
410 | 374 |
411 TEST_F(TabModelTest, CloseAllTabsWithNoTabs) { | 375 TEST_F(TabModelTest, CloseAllTabsWithNoTabs) { |
412 [tab_model_ closeAllTabs]; | 376 [tab_model_ closeAllTabs]; |
413 | 377 |
414 EXPECT_EQ(0U, [tab_model_ count]); | 378 EXPECT_EQ(0U, [tab_model_ count]); |
415 } | 379 } |
416 | 380 |
417 TEST_F(TabModelTest, InsertWithSessionController) { | 381 TEST_F(TabModelTest, InsertWithSessionController) { |
418 EXPECT_EQ([tab_model_ count], 0U); | 382 EXPECT_EQ([tab_model_ count], 0U); |
419 EXPECT_TRUE([tab_model_ isEmpty]); | 383 EXPECT_TRUE([tab_model_ isEmpty]); |
420 | 384 |
421 Tab* new_tab = | 385 Tab* new_tab = [tab_model_ insertTabWithWebState:CreateWebState(@"opener", -1) |
422 [tab_model_ insertTabWithWebState:CreateWebState(@"window", @"opener", -1) | 386 atIndex:0]; |
423 atIndex:0]; | |
424 EXPECT_EQ([tab_model_ count], 1U); | 387 EXPECT_EQ([tab_model_ count], 1U); |
425 [tab_model_ setCurrentTab:new_tab]; | 388 [tab_model_ setCurrentTab:new_tab]; |
426 Tab* current_tab = [tab_model_ currentTab]; | 389 Tab* current_tab = [tab_model_ currentTab]; |
427 EXPECT_TRUE(current_tab); | 390 EXPECT_TRUE(current_tab); |
428 } | 391 } |
429 | 392 |
430 TEST_F(TabModelTest, OpenerOfTab) { | 393 TEST_F(TabModelTest, OpenerOfTab) { |
431 // Start off with a couple tabs. | 394 // Start off with a couple tabs. |
432 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 395 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
433 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 396 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
434 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 397 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
435 | 398 |
436 // Create parent tab. | 399 // Create parent tab. |
437 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState(@"window") | 400 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() |
438 atIndex:[tab_model_ count]]; | 401 atIndex:[tab_model_ count]]; |
439 // Create child tab. | 402 // Create child tab. |
440 Tab* child_tab = | 403 Tab* child_tab = |
441 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) | 404 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) |
442 atIndex:[tab_model_ count]]; | 405 atIndex:[tab_model_ count]]; |
443 // Create another unrelated tab. | 406 // Create another unrelated tab. |
444 Tab* another_tab = [tab_model_ insertTabWithWebState:CreateWebState(@"window") | 407 Tab* another_tab = [tab_model_ insertTabWithWebState:CreateWebState() |
445 atIndex:[tab_model_ count]]; | 408 atIndex:[tab_model_ count]]; |
446 | 409 |
447 // Create another child of the first tab. | 410 // Create another child of the first tab. |
448 Tab* child_tab2 = | 411 Tab* child_tab2 = |
449 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) | 412 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) |
450 atIndex:[tab_model_ count]]; | 413 atIndex:[tab_model_ count]]; |
451 | 414 |
452 EXPECT_FALSE([tab_model_ openerOfTab:parent_tab]); | 415 EXPECT_FALSE([tab_model_ openerOfTab:parent_tab]); |
453 EXPECT_FALSE([tab_model_ openerOfTab:another_tab]); | 416 EXPECT_FALSE([tab_model_ openerOfTab:another_tab]); |
454 EXPECT_EQ(parent_tab, [tab_model_ openerOfTab:child_tab]); | 417 EXPECT_EQ(parent_tab, [tab_model_ openerOfTab:child_tab]); |
455 EXPECT_EQ(parent_tab, [tab_model_ openerOfTab:child_tab2]); | 418 EXPECT_EQ(parent_tab, [tab_model_ openerOfTab:child_tab2]); |
456 } | 419 } |
457 | 420 |
458 TEST_F(TabModelTest, OpenerOfTabEmptyModel) { | 421 TEST_F(TabModelTest, OpenerOfTabEmptyModel) { |
459 EXPECT_FALSE([tab_model_ openerOfTab:nil]); | 422 EXPECT_FALSE([tab_model_ openerOfTab:nil]); |
460 } | 423 } |
461 | 424 |
462 TEST_F(TabModelTest, OpenersEmptyModel) { | 425 TEST_F(TabModelTest, OpenersEmptyModel) { |
463 // Empty model. | 426 // Empty model. |
464 EXPECT_TRUE([tab_model_ isEmpty]); | 427 EXPECT_TRUE([tab_model_ isEmpty]); |
465 EXPECT_FALSE([tab_model_ nextTabWithOpener:nil afterTab:nil]); | 428 EXPECT_FALSE([tab_model_ nextTabWithOpener:nil afterTab:nil]); |
466 EXPECT_FALSE([tab_model_ lastTabWithOpener:nil]); | 429 EXPECT_FALSE([tab_model_ lastTabWithOpener:nil]); |
467 } | 430 } |
468 | 431 |
469 TEST_F(TabModelTest, OpenersNothingOpenedGeneral) { | 432 TEST_F(TabModelTest, OpenersNothingOpenedGeneral) { |
470 // Start with a few tabs. | 433 // Start with a few tabs. |
471 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 434 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
472 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 435 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
473 | 436 |
474 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState(@"window") | 437 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() |
475 atIndex:[tab_model_ count]]; | 438 atIndex:[tab_model_ count]]; |
476 | 439 |
477 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 440 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
478 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 441 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
479 | 442 |
480 // All should fail since this hasn't opened anything else. | 443 // All should fail since this hasn't opened anything else. |
481 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); | 444 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); |
482 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); | 445 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); |
483 | 446 |
484 // Add more items to the tab, expect the same results. | 447 // Add more items to the tab, expect the same results. |
485 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 448 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
486 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 449 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
487 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); | 450 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); |
488 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); | 451 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); |
489 } | 452 } |
490 | 453 |
491 TEST_F(TabModelTest, OpenersNothingOpenedFirst) { | 454 TEST_F(TabModelTest, OpenersNothingOpenedFirst) { |
492 // Our tab is first. | 455 // Our tab is first. |
493 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState(@"window") | 456 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() |
494 atIndex:[tab_model_ count]]; | 457 atIndex:[tab_model_ count]]; |
495 | 458 |
496 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 459 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
497 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 460 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
498 | 461 |
499 // All should fail since this hasn't opened anything else. | 462 // All should fail since this hasn't opened anything else. |
500 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); | 463 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); |
501 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); | 464 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); |
502 } | 465 } |
503 | 466 |
504 TEST_F(TabModelTest, OpenersNothingOpenedLast) { | 467 TEST_F(TabModelTest, OpenersNothingOpenedLast) { |
505 // Our tab is last. | 468 // Our tab is last. |
506 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 469 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
507 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 470 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
508 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState(@"window") | 471 Tab* tab = [tab_model_ insertTabWithWebState:CreateWebState() |
509 atIndex:[tab_model_ count]]; | 472 atIndex:[tab_model_ count]]; |
510 | 473 |
511 // All should fail since this hasn't opened anything else. | 474 // All should fail since this hasn't opened anything else. |
512 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); | 475 EXPECT_FALSE([tab_model_ nextTabWithOpener:tab afterTab:nil]); |
513 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); | 476 EXPECT_FALSE([tab_model_ lastTabWithOpener:tab]); |
514 } | 477 } |
515 | 478 |
516 TEST_F(TabModelTest, OpenersChildTabBeforeOpener) { | 479 TEST_F(TabModelTest, OpenersChildTabBeforeOpener) { |
517 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState(@"window") | 480 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() |
518 atIndex:[tab_model_ count]]; | 481 atIndex:[tab_model_ count]]; |
519 // Insert child at start | 482 // Insert child at start |
520 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) atIndex:0]; | 483 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) atIndex:0]; |
521 | 484 |
522 // Insert a few more between them. | 485 // Insert a few more between them. |
523 [tab_model_ insertTabWithWebState:CreateWebState(@"window") atIndex:1]; | 486 [tab_model_ insertTabWithWebState:CreateWebState() atIndex:1]; |
524 [tab_model_ insertTabWithWebState:CreateWebState(@"window") atIndex:1]; | 487 [tab_model_ insertTabWithWebState:CreateWebState() atIndex:1]; |
525 | 488 |
526 EXPECT_FALSE([tab_model_ nextTabWithOpener:parent_tab afterTab:nil]); | 489 EXPECT_FALSE([tab_model_ nextTabWithOpener:parent_tab afterTab:nil]); |
527 EXPECT_FALSE([tab_model_ lastTabWithOpener:parent_tab]); | 490 EXPECT_FALSE([tab_model_ lastTabWithOpener:parent_tab]); |
528 } | 491 } |
529 | 492 |
530 TEST_F(TabModelTest, OpenersChildTabAfterOpener) { | 493 TEST_F(TabModelTest, OpenersChildTabAfterOpener) { |
531 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState(@"window") | 494 Tab* parent_tab = [tab_model_ insertTabWithWebState:CreateWebState() |
532 atIndex:[tab_model_ count]]; | 495 atIndex:[tab_model_ count]]; |
533 | 496 |
534 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 497 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
535 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 498 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
536 // Insert two children at end. | 499 // Insert two children at end. |
537 Tab* child_tab1 = | 500 Tab* child_tab1 = |
538 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) | 501 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) |
539 atIndex:[tab_model_ count]]; | 502 atIndex:[tab_model_ count]]; |
540 Tab* child_tab2 = | 503 Tab* child_tab2 = |
541 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) | 504 [tab_model_ insertTabWithWebState:CreateChildWebState(parent_tab) |
542 atIndex:[tab_model_ count]]; | 505 atIndex:[tab_model_ count]]; |
543 | 506 |
544 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:nil], child_tab1); | 507 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:nil], child_tab1); |
545 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:child_tab1], | 508 EXPECT_EQ([tab_model_ nextTabWithOpener:parent_tab afterTab:child_tab1], |
546 child_tab2); | 509 child_tab2); |
547 EXPECT_EQ([tab_model_ lastTabWithOpener:parent_tab], child_tab2); | 510 EXPECT_EQ([tab_model_ lastTabWithOpener:parent_tab], child_tab2); |
548 } | 511 } |
549 | 512 |
550 TEST_F(TabModelTest, AddWithOrderController) { | 513 TEST_F(TabModelTest, AddWithOrderController) { |
551 // Create a few tabs with the controller at the front. | 514 // Create a few tabs with the controller at the front. |
552 Tab* parent = | 515 Tab* parent = [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
553 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 516 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
554 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 517 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
555 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | |
556 | 518 |
557 // Add a new tab, it should be added behind the parent. | 519 // Add a new tab, it should be added behind the parent. |
558 Tab* child = [tab_model_ | 520 Tab* child = |
559 insertOrUpdateTabWithURL:kURL | 521 [tab_model_ insertTabWithURL:kURL |
560 referrer:kEmptyReferrer | 522 referrer:kEmptyReferrer |
561 transition:ui::PAGE_TRANSITION_LINK | 523 transition:ui::PAGE_TRANSITION_LINK |
562 windowName:nil | 524 opener:parent |
563 opener:parent | 525 openedByDOM:NO |
564 openedByDOM:NO | 526 atIndex:TabModelConstants::kTabPositionAutomatically |
565 atIndex:TabModelConstants::kTabPositionAutomatically | 527 inBackground:NO]; |
566 inBackground:NO]; | |
567 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); | 528 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); |
568 EXPECT_EQ([tab_model_ indexOfTab:child], 1U); | 529 EXPECT_EQ([tab_model_ indexOfTab:child], 1U); |
569 | 530 |
570 // Add another new tab without a parent, should go at the end. | 531 // Add another new tab without a parent, should go at the end. |
571 Tab* tab = [tab_model_ | 532 Tab* tab = |
572 insertOrUpdateTabWithURL:kURL | 533 [tab_model_ insertTabWithURL:kURL |
573 referrer:kEmptyReferrer | 534 referrer:kEmptyReferrer |
574 transition:ui::PAGE_TRANSITION_LINK | 535 transition:ui::PAGE_TRANSITION_LINK |
575 windowName:nil | 536 opener:nil |
576 opener:nil | 537 openedByDOM:NO |
577 openedByDOM:NO | 538 atIndex:TabModelConstants::kTabPositionAutomatically |
578 atIndex:TabModelConstants::kTabPositionAutomatically | 539 inBackground:NO]; |
579 inBackground:NO]; | |
580 EXPECT_EQ([tab_model_ indexOfTab:tab], [tab_model_ count] - 1); | 540 EXPECT_EQ([tab_model_ indexOfTab:tab], [tab_model_ count] - 1); |
581 | 541 |
582 // Same for a tab that's not opened via a LINK transition. | 542 // Same for a tab that's not opened via a LINK transition. |
583 Tab* tab2 = [tab_model_ insertOrUpdateTabWithURL:kURL | 543 Tab* tab2 = [tab_model_ insertTabWithURL:kURL |
584 referrer:kEmptyReferrer | 544 referrer:kEmptyReferrer |
585 transition:ui::PAGE_TRANSITION_TYPED | 545 transition:ui::PAGE_TRANSITION_TYPED |
586 windowName:nil | 546 opener:nil |
587 opener:nil | 547 openedByDOM:NO |
588 openedByDOM:NO | 548 atIndex:[tab_model_ count] |
589 atIndex:[tab_model_ count] | 549 inBackground:NO]; |
590 inBackground:NO]; | |
591 EXPECT_EQ([tab_model_ indexOfTab:tab2], [tab_model_ count] - 1); | 550 EXPECT_EQ([tab_model_ indexOfTab:tab2], [tab_model_ count] - 1); |
592 | 551 |
593 // Add a tab in the background. It should appear behind the opening tab. | 552 // Add a tab in the background. It should appear behind the opening tab. |
594 Tab* tab3 = [tab_model_ | 553 Tab* tab3 = |
595 insertOrUpdateTabWithURL:kURL | 554 [tab_model_ insertTabWithURL:kURL |
596 referrer:kEmptyReferrer | 555 referrer:kEmptyReferrer |
597 transition:ui::PAGE_TRANSITION_LINK | 556 transition:ui::PAGE_TRANSITION_LINK |
598 windowName:nil | 557 opener:tab |
599 opener:tab | 558 openedByDOM:NO |
600 openedByDOM:NO | 559 atIndex:TabModelConstants::kTabPositionAutomatically |
601 atIndex:TabModelConstants::kTabPositionAutomatically | 560 inBackground:YES]; |
602 inBackground:YES]; | |
603 EXPECT_EQ([tab_model_ indexOfTab:tab3], [tab_model_ indexOfTab:tab] + 1); | 561 EXPECT_EQ([tab_model_ indexOfTab:tab3], [tab_model_ indexOfTab:tab] + 1); |
604 | 562 |
605 // Add another background tab behind the one we just opened. | 563 // Add another background tab behind the one we just opened. |
606 Tab* tab4 = [tab_model_ | 564 Tab* tab4 = |
607 insertOrUpdateTabWithURL:kURL | 565 [tab_model_ insertTabWithURL:kURL |
608 referrer:kEmptyReferrer | 566 referrer:kEmptyReferrer |
609 transition:ui::PAGE_TRANSITION_LINK | 567 transition:ui::PAGE_TRANSITION_LINK |
610 windowName:nil | 568 opener:tab3 |
611 opener:tab3 | 569 openedByDOM:NO |
612 openedByDOM:NO | 570 atIndex:TabModelConstants::kTabPositionAutomatically |
613 atIndex:TabModelConstants::kTabPositionAutomatically | 571 inBackground:YES]; |
614 inBackground:YES]; | |
615 EXPECT_EQ([tab_model_ indexOfTab:tab4], [tab_model_ indexOfTab:tab3] + 1); | 572 EXPECT_EQ([tab_model_ indexOfTab:tab4], [tab_model_ indexOfTab:tab3] + 1); |
616 } | 573 } |
617 | 574 |
618 TEST_F(TabModelTest, AddWithOrderControllerAndGrouping) { | 575 TEST_F(TabModelTest, AddWithOrderControllerAndGrouping) { |
619 // Create a few tabs with the controller at the front. | 576 // Create a few tabs with the controller at the front. |
620 Tab* parent = | 577 Tab* parent = [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
621 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | |
622 // Force the history to update, as it is used to determine grouping. | 578 // Force the history to update, as it is used to determine grouping. |
623 ASSERT_TRUE([parent navigationManager]); | 579 ASSERT_TRUE([parent navigationManager]); |
624 [[parent navigationManager]->GetSessionController() commitPendingItem]; | 580 [[parent navigationManager]->GetSessionController() commitPendingItem]; |
625 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 581 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
626 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 582 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
627 | 583 |
628 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); | 584 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); |
629 | 585 |
630 // Add a new tab, it should be added behind the parent. | 586 // Add a new tab, it should be added behind the parent. |
631 Tab* child1 = [tab_model_ | 587 Tab* child1 = |
632 insertOrUpdateTabWithURL:kURL | 588 [tab_model_ insertTabWithURL:kURL |
633 referrer:kEmptyReferrer | 589 referrer:kEmptyReferrer |
634 transition:ui::PAGE_TRANSITION_LINK | 590 transition:ui::PAGE_TRANSITION_LINK |
635 windowName:nil | 591 opener:parent |
636 opener:parent | 592 openedByDOM:NO |
637 openedByDOM:NO | 593 atIndex:TabModelConstants::kTabPositionAutomatically |
638 atIndex:TabModelConstants::kTabPositionAutomatically | 594 inBackground:NO]; |
639 inBackground:NO]; | |
640 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); | 595 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); |
641 EXPECT_EQ([tab_model_ indexOfTab:child1], 1U); | 596 EXPECT_EQ([tab_model_ indexOfTab:child1], 1U); |
642 | 597 |
643 // Add a second child tab in the background. It should be added behind the | 598 // Add a second child tab in the background. It should be added behind the |
644 // first child. | 599 // first child. |
645 Tab* child2 = [tab_model_ | 600 Tab* child2 = |
646 insertOrUpdateTabWithURL:kURL | 601 [tab_model_ insertTabWithURL:kURL |
647 referrer:kEmptyReferrer | 602 referrer:kEmptyReferrer |
648 transition:ui::PAGE_TRANSITION_LINK | 603 transition:ui::PAGE_TRANSITION_LINK |
649 windowName:nil | 604 opener:parent |
650 opener:parent | 605 openedByDOM:NO |
651 openedByDOM:NO | 606 atIndex:TabModelConstants::kTabPositionAutomatically |
652 atIndex:TabModelConstants::kTabPositionAutomatically | 607 inBackground:YES]; |
653 inBackground:YES]; | |
654 EXPECT_EQ([tab_model_ indexOfTab:child2], 2U); | 608 EXPECT_EQ([tab_model_ indexOfTab:child2], 2U); |
655 | 609 |
656 // Navigate the parent tab to a new URL. It should not change any ordering. | 610 // Navigate the parent tab to a new URL. It should not change any ordering. |
657 web::NavigationManager::WebLoadParams parent_params( | 611 web::NavigationManager::WebLoadParams parent_params( |
658 GURL("http://www.espn.com")); | 612 GURL("http://www.espn.com")); |
659 parent_params.transition_type = ui::PAGE_TRANSITION_TYPED; | 613 parent_params.transition_type = ui::PAGE_TRANSITION_TYPED; |
660 [[parent webController] loadWithParams:parent_params]; | 614 [[parent webController] loadWithParams:parent_params]; |
661 ASSERT_TRUE([parent navigationManager]); | 615 ASSERT_TRUE([parent navigationManager]); |
662 [[parent navigationManager]->GetSessionController() commitPendingItem]; | 616 [[parent navigationManager]->GetSessionController() commitPendingItem]; |
663 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); | 617 EXPECT_EQ([tab_model_ indexOfTab:parent], 0U); |
664 | 618 |
665 // Add a new tab. It should be added behind the parent. It should not be added | 619 // Add a new tab. It should be added behind the parent. It should not be added |
666 // after the previous two children. | 620 // after the previous two children. |
667 Tab* child3 = [tab_model_ | 621 Tab* child3 = |
668 insertOrUpdateTabWithURL:kURL | 622 [tab_model_ insertTabWithURL:kURL |
669 referrer:kEmptyReferrer | 623 referrer:kEmptyReferrer |
670 transition:ui::PAGE_TRANSITION_LINK | 624 transition:ui::PAGE_TRANSITION_LINK |
671 windowName:nil | 625 opener:parent |
672 opener:parent | 626 openedByDOM:NO |
673 openedByDOM:NO | 627 atIndex:TabModelConstants::kTabPositionAutomatically |
674 atIndex:TabModelConstants::kTabPositionAutomatically | 628 inBackground:NO]; |
675 inBackground:NO]; | |
676 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U); | 629 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U); |
677 | 630 |
678 // Add a fourt child tab in the background. It should be added behind the | 631 // Add a fourt child tab in the background. It should be added behind the |
679 // third child. | 632 // third child. |
680 Tab* child4 = [tab_model_ | 633 Tab* child4 = |
681 insertOrUpdateTabWithURL:kURL | 634 [tab_model_ insertTabWithURL:kURL |
682 referrer:kEmptyReferrer | 635 referrer:kEmptyReferrer |
683 transition:ui::PAGE_TRANSITION_LINK | 636 transition:ui::PAGE_TRANSITION_LINK |
684 windowName:nil | 637 opener:parent |
685 opener:parent | 638 openedByDOM:NO |
686 openedByDOM:NO | 639 atIndex:TabModelConstants::kTabPositionAutomatically |
687 atIndex:TabModelConstants::kTabPositionAutomatically | 640 inBackground:YES]; |
688 inBackground:YES]; | |
689 EXPECT_EQ([tab_model_ indexOfTab:child4], 2U); | 641 EXPECT_EQ([tab_model_ indexOfTab:child4], 2U); |
690 | 642 |
691 // The first two children should have been moved to the right. | 643 // The first two children should have been moved to the right. |
692 EXPECT_EQ([tab_model_ indexOfTab:child1], 3U); | 644 EXPECT_EQ([tab_model_ indexOfTab:child1], 3U); |
693 EXPECT_EQ([tab_model_ indexOfTab:child2], 4U); | 645 EXPECT_EQ([tab_model_ indexOfTab:child2], 4U); |
694 | 646 |
695 // Now add a non-owned tab and make sure it is added at the end. | 647 // Now add a non-owned tab and make sure it is added at the end. |
696 Tab* nonChild = | 648 Tab* nonChild = [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
697 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | |
698 EXPECT_EQ([tab_model_ indexOfTab:nonChild], [tab_model_ count] - 1); | 649 EXPECT_EQ([tab_model_ indexOfTab:nonChild], [tab_model_ count] - 1); |
699 } | 650 } |
700 | 651 |
701 TEST_F(TabModelTest, AddWithLinkTransitionAndIndex) { | 652 TEST_F(TabModelTest, AddWithLinkTransitionAndIndex) { |
702 // Create a few tabs with the controller at the front. | 653 // Create a few tabs with the controller at the front. |
703 Tab* parent = | 654 Tab* parent = [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
704 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | |
705 // Force the history to update, as it is used to determine grouping. | 655 // Force the history to update, as it is used to determine grouping. |
706 ASSERT_TRUE([parent navigationManager]); | 656 ASSERT_TRUE([parent navigationManager]); |
707 [[parent navigationManager]->GetSessionController() commitPendingItem]; | 657 [[parent navigationManager]->GetSessionController() commitPendingItem]; |
708 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 658 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
709 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer windowName:nil]; | 659 [tab_model_ addTabWithURL:kURL referrer:kEmptyReferrer]; |
710 | 660 |
711 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); | 661 ASSERT_TRUE(chrome_browser_state_->CreateHistoryService(true)); |
712 | 662 |
713 // Add a new tab, it should be added before the parent since the index | 663 // Add a new tab, it should be added before the parent since the index |
714 // parameter has been specified with a valid value. | 664 // parameter has been specified with a valid value. |
715 Tab* child1 = [tab_model_ insertOrUpdateTabWithURL:kURL | 665 Tab* child1 = [tab_model_ insertTabWithURL:kURL |
716 referrer:kEmptyReferrer | 666 referrer:kEmptyReferrer |
717 transition:ui::PAGE_TRANSITION_LINK | 667 transition:ui::PAGE_TRANSITION_LINK |
718 windowName:nil | 668 opener:parent |
719 opener:parent | 669 openedByDOM:NO |
720 openedByDOM:NO | 670 atIndex:0 |
721 atIndex:0 | 671 inBackground:NO]; |
722 inBackground:NO]; | |
723 EXPECT_EQ([tab_model_ indexOfTab:parent], 1U); | 672 EXPECT_EQ([tab_model_ indexOfTab:parent], 1U); |
724 EXPECT_EQ([tab_model_ indexOfTab:child1], 0U); | 673 EXPECT_EQ([tab_model_ indexOfTab:child1], 0U); |
725 | 674 |
726 // Add a new tab, it should be added at the beginning of the stack because | 675 // Add a new tab, it should be added at the beginning of the stack because |
727 // the index parameter has been specified with a valid value. | 676 // the index parameter has been specified with a valid value. |
728 Tab* child2 = [tab_model_ insertOrUpdateTabWithURL:kURL | 677 Tab* child2 = [tab_model_ insertTabWithURL:kURL |
729 referrer:kEmptyReferrer | 678 referrer:kEmptyReferrer |
730 transition:ui::PAGE_TRANSITION_LINK | 679 transition:ui::PAGE_TRANSITION_LINK |
731 windowName:nil | 680 opener:parent |
732 opener:parent | 681 openedByDOM:NO |
733 openedByDOM:NO | 682 atIndex:0 |
734 atIndex:0 | 683 inBackground:NO]; |
735 inBackground:NO]; | |
736 EXPECT_EQ([tab_model_ indexOfTab:parent], 2U); | 684 EXPECT_EQ([tab_model_ indexOfTab:parent], 2U); |
737 EXPECT_EQ([tab_model_ indexOfTab:child1], 1U); | 685 EXPECT_EQ([tab_model_ indexOfTab:child1], 1U); |
738 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U); | 686 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U); |
739 | 687 |
740 // Add a new tab, it should be added at position 1 because the index parameter | 688 // Add a new tab, it should be added at position 1 because the index parameter |
741 // has been specified with a valid value. | 689 // has been specified with a valid value. |
742 Tab* child3 = [tab_model_ insertOrUpdateTabWithURL:kURL | 690 Tab* child3 = [tab_model_ insertTabWithURL:kURL |
743 referrer:kEmptyReferrer | 691 referrer:kEmptyReferrer |
744 transition:ui::PAGE_TRANSITION_LINK | 692 transition:ui::PAGE_TRANSITION_LINK |
745 windowName:nil | 693 opener:parent |
746 opener:parent | 694 openedByDOM:NO |
747 openedByDOM:NO | 695 atIndex:1 |
748 atIndex:1 | 696 inBackground:NO]; |
749 inBackground:NO]; | |
750 EXPECT_EQ([tab_model_ indexOfTab:parent], 3U); | 697 EXPECT_EQ([tab_model_ indexOfTab:parent], 3U); |
751 EXPECT_EQ([tab_model_ indexOfTab:child1], 2U); | 698 EXPECT_EQ([tab_model_ indexOfTab:child1], 2U); |
752 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U); | 699 EXPECT_EQ([tab_model_ indexOfTab:child3], 1U); |
753 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U); | 700 EXPECT_EQ([tab_model_ indexOfTab:child2], 0U); |
754 } | 701 } |
755 | 702 |
756 TEST_F(TabModelTest, MoveTabs) { | 703 TEST_F(TabModelTest, MoveTabs) { |
757 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 704 Tab* tab0 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
758 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 2"]; | 705 Tab* tab1 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
759 [tab_model_ addTabWithURL:kURL referrer:kReferrer windowName:@"window 3"]; | 706 Tab* tab2 = [tab_model_ addTabWithURL:kURL referrer:kReferrer]; |
760 | 707 |
761 // Basic sanity checks before moving on. | 708 // Basic sanity checks before moving on. |
762 ASSERT_EQ(3U, [tab_model_ count]); | 709 ASSERT_EQ(3U, [tab_model_ count]); |
763 ASSERT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:0] windowName]); | 710 ASSERT_NSEQ(tab0, [tab_model_ tabAtIndex:0]); |
764 ASSERT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:1] windowName]); | 711 ASSERT_NSEQ(tab1, [tab_model_ tabAtIndex:1]); |
765 ASSERT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:2] windowName]); | 712 ASSERT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); |
766 | 713 |
767 // Move a tab from index 1 to index 0 (move tab left by one). | 714 // Move a tab from index 1 to index 0 (move tab left by one). |
768 [tab_model_observer_ setTabMovedWasCalled:NO]; | 715 [tab_model_observer_ setTabMovedWasCalled:NO]; |
769 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:0]; | 716 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:0]; |
770 ASSERT_EQ(3U, [tab_model_ count]); | 717 ASSERT_EQ(3U, [tab_model_ count]); |
771 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:0] windowName]); | 718 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); |
772 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:1] windowName]); | 719 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:1]); |
773 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:2] windowName]); | 720 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:2]); |
774 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); | 721 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); |
775 | 722 |
776 // Move a tab from index 1 to index 2 (move tab right by one). | 723 // Move a tab from index 1 to index 2 (move tab right by one). |
777 [tab_model_observer_ setTabMovedWasCalled:NO]; | 724 [tab_model_observer_ setTabMovedWasCalled:NO]; |
778 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:2]; | 725 [tab_model_ moveTab:[tab_model_ tabAtIndex:1] toIndex:2]; |
779 ASSERT_EQ(3U, [tab_model_ count]); | 726 ASSERT_EQ(3U, [tab_model_ count]); |
780 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:0] windowName]); | 727 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); |
781 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:1] windowName]); | 728 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
782 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:2] windowName]); | 729 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); |
783 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); | 730 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); |
784 | 731 |
785 // Move a tab from index 0 to index 2 (move tab right by more than one). | 732 // Move a tab from index 0 to index 2 (move tab right by more than one). |
786 [tab_model_observer_ setTabMovedWasCalled:NO]; | 733 [tab_model_observer_ setTabMovedWasCalled:NO]; |
787 [tab_model_ moveTab:[tab_model_ tabAtIndex:0] toIndex:2]; | 734 [tab_model_ moveTab:[tab_model_ tabAtIndex:0] toIndex:2]; |
788 ASSERT_EQ(3U, [tab_model_ count]); | 735 ASSERT_EQ(3U, [tab_model_ count]); |
789 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:0] windowName]); | 736 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:0]); |
790 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:1] windowName]); | 737 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:1]); |
791 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:2] windowName]); | 738 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:2]); |
792 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); | 739 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); |
793 | 740 |
794 // Move a tab from index 2 to index 0 (move tab left by more than one). | 741 // Move a tab from index 2 to index 0 (move tab left by more than one). |
795 [tab_model_observer_ setTabMovedWasCalled:NO]; | 742 [tab_model_observer_ setTabMovedWasCalled:NO]; |
796 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:0]; | 743 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:0]; |
797 ASSERT_EQ(3U, [tab_model_ count]); | 744 ASSERT_EQ(3U, [tab_model_ count]); |
798 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:0] windowName]); | 745 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); |
799 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:1] windowName]); | 746 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
800 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:2] windowName]); | 747 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); |
801 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); | 748 EXPECT_TRUE([tab_model_observer_ tabMovedWasCalled]); |
802 | 749 |
803 // Move a tab from index 2 to index 2 (move tab to the same index). | 750 // Move a tab from index 2 to index 2 (move tab to the same index). |
804 [tab_model_observer_ setTabMovedWasCalled:NO]; | 751 [tab_model_observer_ setTabMovedWasCalled:NO]; |
805 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:2]; | 752 [tab_model_ moveTab:[tab_model_ tabAtIndex:2] toIndex:2]; |
806 ASSERT_EQ(3U, [tab_model_ count]); | 753 ASSERT_EQ(3U, [tab_model_ count]); |
807 EXPECT_NSEQ(@"window 2", [[tab_model_ tabAtIndex:0] windowName]); | 754 EXPECT_NSEQ(tab1, [tab_model_ tabAtIndex:0]); |
808 EXPECT_NSEQ(@"window 3", [[tab_model_ tabAtIndex:1] windowName]); | 755 EXPECT_NSEQ(tab2, [tab_model_ tabAtIndex:1]); |
809 EXPECT_NSEQ(@"window 1", [[tab_model_ tabAtIndex:2] windowName]); | 756 EXPECT_NSEQ(tab0, [tab_model_ tabAtIndex:2]); |
810 EXPECT_FALSE([tab_model_observer_ tabMovedWasCalled]); | 757 EXPECT_FALSE([tab_model_observer_ tabMovedWasCalled]); |
811 } | 758 } |
812 | 759 |
813 TEST_F(TabModelTest, SetParentModel) { | 760 TEST_F(TabModelTest, SetParentModel) { |
814 // Create a tab without a parent model and make sure it doesn't crash. Then | 761 // Create a tab without a parent model and make sure it doesn't crash. Then |
815 // set its parent TabModel and make sure that works as well. | 762 // set its parent TabModel and make sure that works as well. |
816 base::scoped_nsobject<TabTest> tab([[TabTest alloc] | 763 base::scoped_nsobject<TabTest> tab([[TabTest alloc] |
817 initWithWindowName:@"parentless" | 764 initWithBrowserState:chrome_browser_state_.get() |
818 lastVisitedTimestamp:100 | 765 lastVisitedTimestamp:100 |
819 browserState:chrome_browser_state_.get() | |
820 tabModel:nil]); | 766 tabModel:nil]); |
821 EXPECT_TRUE([tab parentTabModel] == nil); | 767 EXPECT_TRUE([tab parentTabModel] == nil); |
822 [tab_model_ insertTab:tab atIndex:0]; | 768 [tab_model_ insertTab:tab atIndex:0]; |
823 [tab setParentTabModel:tab_model_.get()]; | 769 [tab setParentTabModel:tab_model_.get()]; |
824 EXPECT_FALSE([tab parentTabModel] == nil); | 770 EXPECT_FALSE([tab parentTabModel] == nil); |
825 [tab_model_ closeTabAtIndex:0]; | 771 [tab_model_ closeTabAtIndex:0]; |
826 } | 772 } |
827 | 773 |
828 TEST_F(TabModelTest, PersistSelectionChange) { | 774 TEST_F(TabModelTest, PersistSelectionChange) { |
829 TestChromeBrowserState::Builder test_cbs_builder; | 775 TestChromeBrowserState::Builder test_cbs_builder; |
830 auto chrome_browser_state = test_cbs_builder.Build(); | 776 auto chrome_browser_state = test_cbs_builder.Build(); |
831 | 777 |
832 // Tabs register some observers with the ChromeBrowserState in an ObserverList | 778 // Tabs register some observers with the ChromeBrowserState in an ObserverList |
833 // that assert it is empty in its destructor. As Tab are Objective-C object, | 779 // that assert it is empty in its destructor. As Tab are Objective-C object, |
834 // it is necessary to use a local pool to ensure all autoreleased object that | 780 // it is necessary to use a local pool to ensure all autoreleased object that |
835 // may reference those Tabs are deallocated before the TestChromeBrowserState | 781 // may reference those Tabs are deallocated before the TestChromeBrowserState |
836 // is destroyed (this cannot use the TabModelTest ScopedNSAutoreleasePool as | 782 // is destroyed (this cannot use the TabModelTest ScopedNSAutoreleasePool as |
837 // it will be drained after the local variable chrome_browser_state). | 783 // it will be drained after the local variable chrome_browser_state). |
838 base::mac::ScopedNSAutoreleasePool pool; | 784 base::mac::ScopedNSAutoreleasePool pool; |
839 | 785 |
840 NSString* stashPath = | 786 NSString* stashPath = |
841 base::SysUTF8ToNSString(chrome_browser_state->GetStatePath().value()); | 787 base::SysUTF8ToNSString(chrome_browser_state->GetStatePath().value()); |
842 | 788 |
843 base::scoped_nsobject<TabModel> model([[TabModel alloc] | 789 base::scoped_nsobject<TabModel> model([[TabModel alloc] |
844 initWithSessionWindow:session_window_.get() | 790 initWithSessionWindow:session_window_.get() |
845 sessionService:[SessionServiceIOS sharedService] | 791 sessionService:[SessionServiceIOS sharedService] |
846 browserState:chrome_browser_state.get()]); | 792 browserState:chrome_browser_state.get()]); |
847 | 793 |
848 [model addTabWithURL:kURL referrer:kReferrer windowName:@"window 1"]; | 794 [model addTabWithURL:kURL referrer:kReferrer]; |
849 [model insertTabWithURL:kURL | 795 [model insertTabWithURL:kURL |
850 referrer:kReferrer | 796 referrer:kReferrer |
851 windowName:@"window 3" | |
852 opener:[model tabAtIndex:0] | 797 opener:[model tabAtIndex:0] |
853 atIndex:[model count]]; | 798 atIndex:[model count]]; |
854 [model insertTabWithURL:kURL | 799 [model insertTabWithURL:kURL |
855 referrer:kReferrer | 800 referrer:kReferrer |
856 windowName:@"window 3" | |
857 opener:[model tabAtIndex:1] | 801 opener:[model tabAtIndex:1] |
858 atIndex:0]; | 802 atIndex:0]; |
859 | 803 |
860 ASSERT_EQ(3U, [model count]); | 804 ASSERT_EQ(3U, [model count]); |
861 [model setCurrentTab:[model tabAtIndex:1]]; | 805 [model setCurrentTab:[model tabAtIndex:1]]; |
862 | 806 |
863 EXPECT_EQ(nil, [model openerOfTab:[model tabAtIndex:1]]); | 807 EXPECT_EQ(nil, [model openerOfTab:[model tabAtIndex:1]]); |
864 EXPECT_EQ([model tabAtIndex:1], [model openerOfTab:[model tabAtIndex:2]]); | 808 EXPECT_EQ([model tabAtIndex:1], [model openerOfTab:[model tabAtIndex:2]]); |
865 EXPECT_EQ([model tabAtIndex:2], [model openerOfTab:[model tabAtIndex:0]]); | 809 EXPECT_EQ([model tabAtIndex:2], [model openerOfTab:[model tabAtIndex:0]]); |
866 | 810 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
900 // Restoring TabModel session sends asynchronous tasks to IO thread, wait | 844 // Restoring TabModel session sends asynchronous tasks to IO thread, wait |
901 // for them to complete after destroying the TabModel. | 845 // for them to complete after destroying the TabModel. |
902 base::RunLoop().RunUntilIdle(); | 846 base::RunLoop().RunUntilIdle(); |
903 | 847 |
904 // Clean up. | 848 // Clean up. |
905 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath | 849 EXPECT_TRUE([[NSFileManager defaultManager] removeItemAtPath:stashPath |
906 error:nullptr]); | 850 error:nullptr]); |
907 } | 851 } |
908 | 852 |
909 } // anonymous namespace | 853 } // anonymous namespace |
OLD | NEW |