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