| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/shared/chrome/browser/tabs/web_state_list.h" | 5 #import "ios/shared/chrome/browser/tabs/web_state_list.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/supports_user_data.h" | 9 #include "base/supports_user_data.h" |
| 10 #import "ios/shared/chrome/browser/tabs/fake_web_state_list_delegate.h" |
| 10 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" | 11 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" |
| 11 #import "ios/web/public/test/fakes/test_navigation_manager.h" | 12 #import "ios/web/public/test/fakes/test_navigation_manager.h" |
| 12 #import "ios/web/public/test/fakes/test_web_state.h" | 13 #import "ios/web/public/test/fakes/test_web_state.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 15 | 16 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 18 #error "This file requires ARC support." |
| 18 #endif | 19 #endif |
| 19 | 20 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 133 |
| 133 int current_item_index_ = 0; | 134 int current_item_index_ = 0; |
| 134 | 135 |
| 135 DISALLOW_COPY_AND_ASSIGN(FakeNavigationManer); | 136 DISALLOW_COPY_AND_ASSIGN(FakeNavigationManer); |
| 136 }; | 137 }; |
| 137 | 138 |
| 138 } // namespace | 139 } // namespace |
| 139 | 140 |
| 140 class WebStateListTest : public PlatformTest { | 141 class WebStateListTest : public PlatformTest { |
| 141 public: | 142 public: |
| 142 WebStateListTest() : web_state_list_(WebStateList::WebStateOwned) { | 143 WebStateListTest() |
| 144 : web_state_list_(&web_state_list_delegate_, |
| 145 WebStateList::WebStateOwned) { |
| 143 web_state_list_.AddObserver(&observer_); | 146 web_state_list_.AddObserver(&observer_); |
| 144 } | 147 } |
| 145 | 148 |
| 146 ~WebStateListTest() override { web_state_list_.RemoveObserver(&observer_); } | 149 ~WebStateListTest() override { web_state_list_.RemoveObserver(&observer_); } |
| 147 | 150 |
| 148 protected: | 151 protected: |
| 152 FakeWebStateListDelegate web_state_list_delegate_; |
| 149 WebStateList web_state_list_; | 153 WebStateList web_state_list_; |
| 150 WebStateListTestObserver observer_; | 154 WebStateListTestObserver observer_; |
| 151 | 155 |
| 152 // This method should return std::unique_ptr<> however, due to the complex | 156 // This method should return std::unique_ptr<> however, due to the complex |
| 153 // ownership of Tab, WebStateList currently uses raw pointers. Change this | 157 // ownership of Tab, WebStateList currently uses raw pointers. Change this |
| 154 // once Tab ownership is sane, see http://crbug.com/546222 for progress. | 158 // once Tab ownership is sane, see http://crbug.com/546222 for progress. |
| 155 web::WebState* CreateWebState(const char* url) { | 159 web::WebState* CreateWebState(const char* url) { |
| 156 auto test_web_state = base::MakeUnique<web::TestWebState>(); | 160 auto test_web_state = base::MakeUnique<web::TestWebState>(); |
| 157 test_web_state->SetCurrentURL(GURL(url)); | 161 test_web_state->SetCurrentURL(GURL(url)); |
| 158 test_web_state->SetNavigationManager( | 162 test_web_state->SetNavigationManager( |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 EXPECT_EQ(kURL1, web_state_list_.GetWebStateAt(1)->GetVisibleURL().spec()); | 387 EXPECT_EQ(kURL1, web_state_list_.GetWebStateAt(1)->GetVisibleURL().spec()); |
| 384 } | 388 } |
| 385 | 389 |
| 386 TEST_F(WebStateListTest, OwnershipBorrowed) { | 390 TEST_F(WebStateListTest, OwnershipBorrowed) { |
| 387 bool web_state_was_killed = false; | 391 bool web_state_was_killed = false; |
| 388 auto test_web_state = base::MakeUnique<web::TestWebState>(); | 392 auto test_web_state = base::MakeUnique<web::TestWebState>(); |
| 389 test_web_state->SetUserData( | 393 test_web_state->SetUserData( |
| 390 &kSupportsUserDataDeathGuardKey, | 394 &kSupportsUserDataDeathGuardKey, |
| 391 base::MakeUnique<SupportsUserDataDeathGuard>(&web_state_was_killed)); | 395 base::MakeUnique<SupportsUserDataDeathGuard>(&web_state_was_killed)); |
| 392 | 396 |
| 393 auto web_state_list = | 397 FakeWebStateListDelegate web_state_list_delegate; |
| 394 base::MakeUnique<WebStateList>(WebStateList::WebStateBorrowed); | 398 auto web_state_list = base::MakeUnique<WebStateList>( |
| 399 &web_state_list_delegate, WebStateList::WebStateBorrowed); |
| 395 web_state_list->InsertWebState(0, test_web_state.get(), nullptr); | 400 web_state_list->InsertWebState(0, test_web_state.get(), nullptr); |
| 396 EXPECT_FALSE(web_state_was_killed); | 401 EXPECT_FALSE(web_state_was_killed); |
| 397 | 402 |
| 398 web_state_list.reset(); | 403 web_state_list.reset(); |
| 399 EXPECT_FALSE(web_state_was_killed); | 404 EXPECT_FALSE(web_state_was_killed); |
| 400 } | 405 } |
| 401 | 406 |
| 402 TEST_F(WebStateListTest, OwnershipOwned) { | 407 TEST_F(WebStateListTest, OwnershipOwned) { |
| 403 bool web_state_was_killed = false; | 408 bool web_state_was_killed = false; |
| 404 auto test_web_state = base::MakeUnique<web::TestWebState>(); | 409 auto test_web_state = base::MakeUnique<web::TestWebState>(); |
| 405 test_web_state->SetUserData( | 410 test_web_state->SetUserData( |
| 406 &kSupportsUserDataDeathGuardKey, | 411 &kSupportsUserDataDeathGuardKey, |
| 407 base::MakeUnique<SupportsUserDataDeathGuard>(&web_state_was_killed)); | 412 base::MakeUnique<SupportsUserDataDeathGuard>(&web_state_was_killed)); |
| 408 | 413 |
| 409 auto web_state_list = | 414 FakeWebStateListDelegate web_state_list_delegate; |
| 410 base::MakeUnique<WebStateList>(WebStateList::WebStateOwned); | 415 auto web_state_list = base::MakeUnique<WebStateList>( |
| 416 &web_state_list_delegate, WebStateList::WebStateOwned); |
| 411 web_state_list->InsertWebState(0, test_web_state.release(), nullptr); | 417 web_state_list->InsertWebState(0, test_web_state.release(), nullptr); |
| 412 EXPECT_FALSE(web_state_was_killed); | 418 EXPECT_FALSE(web_state_was_killed); |
| 413 | 419 |
| 414 web_state_list.reset(); | 420 web_state_list.reset(); |
| 415 EXPECT_TRUE(web_state_was_killed); | 421 EXPECT_TRUE(web_state_was_killed); |
| 416 } | 422 } |
| 417 | 423 |
| 418 TEST_F(WebStateListTest, OpenersEmptyList) { | 424 TEST_F(WebStateListTest, OpenersEmptyList) { |
| 419 EXPECT_TRUE(web_state_list_.empty()); | 425 EXPECT_TRUE(web_state_list_.empty()); |
| 420 | 426 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 web_state_list_.GetIndexOfLastWebStateOpenedBy(opener, start_index, | 537 web_state_list_.GetIndexOfLastWebStateOpenedBy(opener, start_index, |
| 532 false)); | 538 false)); |
| 533 | 539 |
| 534 EXPECT_EQ(WebStateList::kInvalidIndex, | 540 EXPECT_EQ(WebStateList::kInvalidIndex, |
| 535 web_state_list_.GetIndexOfNextWebStateOpenedBy(opener, start_index, | 541 web_state_list_.GetIndexOfNextWebStateOpenedBy(opener, start_index, |
| 536 true)); | 542 true)); |
| 537 EXPECT_EQ(WebStateList::kInvalidIndex, | 543 EXPECT_EQ(WebStateList::kInvalidIndex, |
| 538 web_state_list_.GetIndexOfLastWebStateOpenedBy(opener, start_index, | 544 web_state_list_.GetIndexOfLastWebStateOpenedBy(opener, start_index, |
| 539 true)); | 545 true)); |
| 540 } | 546 } |
| OLD | NEW |