| 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_fast_enumeration_helper.h
" | 5 #import "ios/shared/chrome/browser/tabs/web_state_list_fast_enumeration_helper.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 #import "ios/shared/chrome/browser/tabs/web_state_list.h" | 9 #import "ios/shared/chrome/browser/tabs/web_state_list.h" |
| 10 #import "ios/web/public/test/fakes/test_web_state.h" | 10 #import "ios/web/public/test/fakes/test_web_state.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 60 } |
| 61 return [array copy]; | 61 return [array copy]; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void InsertTestWebStateForURLs(const char* const* urls, size_t count) { | 64 void InsertTestWebStateForURLs(const char* const* urls, size_t count) { |
| 65 for (size_t index = 0; index < count; ++index) { | 65 for (size_t index = 0; index < count; ++index) { |
| 66 auto test_web_state = base::MakeUnique<web::TestWebState>(); | 66 auto test_web_state = base::MakeUnique<web::TestWebState>(); |
| 67 test_web_state->SetCurrentURL(GURL(urls[index])); | 67 test_web_state->SetCurrentURL(GURL(urls[index])); |
| 68 | 68 |
| 69 web_state_list_.InsertWebState(web_state_list_.count(), | 69 web_state_list_.InsertWebState(web_state_list_.count(), |
| 70 test_web_state.release()); | 70 test_web_state.release(), nullptr); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 WebStateList web_state_list_; | 75 WebStateList web_state_list_; |
| 76 | 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(WebStateListFastEnumerationHelperTest); | 77 DISALLOW_COPY_AND_ASSIGN(WebStateListFastEnumerationHelperTest); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 TEST_F(WebStateListFastEnumerationHelperTest, Empty) { | 80 TEST_F(WebStateListFastEnumerationHelperTest, Empty) { |
| 81 NSArray* array = ArrayFromWebStateList(); | 81 NSArray* array = ArrayFromWebStateList(); |
| 82 EXPECT_EQ(0u, [array count]); | 82 EXPECT_EQ(0u, [array count]); |
| 83 } | 83 } |
| 84 | 84 |
| 85 TEST_F(WebStateListFastEnumerationHelperTest, FastEnumeration) { | 85 TEST_F(WebStateListFastEnumerationHelperTest, FastEnumeration) { |
| 86 InsertTestWebStateForURLs(kURLs, arraysize(kURLs)); | 86 InsertTestWebStateForURLs(kURLs, arraysize(kURLs)); |
| 87 NSArray* array = ArrayFromWebStateList(); | 87 NSArray* array = ArrayFromWebStateList(); |
| 88 ASSERT_EQ(arraysize(kURLs), [array count]); | 88 ASSERT_EQ(arraysize(kURLs), [array count]); |
| 89 for (size_t index = 0; index < arraysize(kURLs); ++index) { | 89 for (size_t index = 0; index < arraysize(kURLs); ++index) { |
| 90 EXPECT_NSEQ([NSURL URLWithString:@(kURLs[index])], array[index]); | 90 EXPECT_NSEQ([NSURL URLWithString:@(kURLs[index])], array[index]); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST_F(WebStateListFastEnumerationHelperTest, NilWrapper) { | 94 TEST_F(WebStateListFastEnumerationHelperTest, NilWrapper) { |
| 95 const char* const urls[] = {""}; | 95 const char* const urls[] = {""}; |
| 96 InsertTestWebStateForURLs(urls, arraysize(urls)); | 96 InsertTestWebStateForURLs(urls, arraysize(urls)); |
| 97 NSArray* array = ArrayFromWebStateList(); | 97 NSArray* array = ArrayFromWebStateList(); |
| 98 ASSERT_EQ(0u, [array count]); | 98 ASSERT_EQ(0u, [array count]); |
| 99 } | 99 } |
| OLD | NEW |