| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.h" | 5 #import "ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | |
| 8 #import "ios/chrome/browser/tabs/tab.h" | 7 #import "ios/chrome/browser/tabs/tab.h" |
| 9 #include "testing/platform_test.h" | 8 #include "testing/platform_test.h" |
| 10 #import "third_party/ocmock/OCMock/OCMock.h" | 9 #import "third_party/ocmock/OCMock/OCMock.h" |
| 11 | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
| 12 @interface TabModelMock : NSObject<NSFastEnumeration> { | 15 @interface TabModelMock : NSObject<NSFastEnumeration> { |
| 13 base::scoped_nsobject<NSArray> tabs_; | 16 NSArray* tabs_; |
| 14 } | 17 } |
| 15 @end | 18 @end |
| 16 | 19 |
| 17 @implementation TabModelMock | 20 @implementation TabModelMock |
| 18 | 21 |
| 19 - (id)initWithTabs:(NSArray*)tabs { | 22 - (id)initWithTabs:(NSArray*)tabs { |
| 20 if ((self = [super init])) { | 23 if ((self = [super init])) { |
| 21 tabs_.reset([tabs retain]); | 24 tabs_ = tabs; |
| 22 } | 25 } |
| 23 return self; | 26 return self; |
| 24 } | 27 } |
| 25 | 28 |
| 26 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state | 29 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state |
| 27 objects:(id*)stackbuf | 30 objects:(id __unsafe_unretained*)stackbuf |
| 28 count:(NSUInteger)len { | 31 count:(NSUInteger)len { |
| 29 return [tabs_ countByEnumeratingWithState:state objects:stackbuf count:len]; | 32 return [tabs_ countByEnumeratingWithState:state objects:stackbuf count:len]; |
| 30 } | 33 } |
| 31 | 34 |
| 32 @end | 35 @end |
| 33 | 36 |
| 34 namespace { | 37 namespace { |
| 35 | 38 |
| 36 class TabModelSnapshotTest : public PlatformTest { | 39 class TabModelSnapshotTest : public PlatformTest { |
| 37 protected: | 40 protected: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 68 // Different timestamps | 71 // Different timestamps |
| 69 size_t hash7 = TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(tab1); | 72 size_t hash7 = TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(tab1); |
| 70 size_t hash8 = TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(tab4); | 73 size_t hash8 = TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(tab4); |
| 71 EXPECT_NE(hash7, hash8); | 74 EXPECT_NE(hash7, hash8); |
| 72 } | 75 } |
| 73 | 76 |
| 74 TEST_F(TabModelSnapshotTest, TestSnapshotHashes) { | 77 TEST_F(TabModelSnapshotTest, TestSnapshotHashes) { |
| 75 Tab* tab1 = TabMock(@"id1", @"url1", 12345.6789); | 78 Tab* tab1 = TabMock(@"id1", @"url1", 12345.6789); |
| 76 Tab* tab2 = TabMock(@"id2", @"url1", 12345.6789); | 79 Tab* tab2 = TabMock(@"id2", @"url1", 12345.6789); |
| 77 | 80 |
| 78 base::scoped_nsobject<TabModelMock> tabModel( | 81 TabModelMock* tabModel = [[TabModelMock alloc] initWithTabs:@[ tab1, tab2 ]]; |
| 79 [[TabModelMock alloc] initWithTabs:@[ tab1, tab2 ]]); | 82 TabModelSnapshot tabModelSnapshot((TabModel*)tabModel); |
| 80 TabModelSnapshot tabModelSnapshot((TabModel*)tabModel.get()); | 83 tabModel = nil; |
| 81 tabModel.reset(); | |
| 82 | 84 |
| 83 EXPECT_EQ(tabModelSnapshot.hashes().size(), 2UL); | 85 EXPECT_EQ(tabModelSnapshot.hashes().size(), 2UL); |
| 84 EXPECT_EQ(tabModelSnapshot.hashes()[0], | 86 EXPECT_EQ(tabModelSnapshot.hashes()[0], |
| 85 TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(tab1)); | 87 TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(tab1)); |
| 86 EXPECT_EQ(tabModelSnapshot.hashes()[1], | 88 EXPECT_EQ(tabModelSnapshot.hashes()[1], |
| 87 TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(tab2)); | 89 TabModelSnapshot::hashOfTheVisiblePropertiesOfATab(tab2)); |
| 88 } | 90 } |
| 89 | 91 |
| 90 } // namespace | 92 } // namespace |
| OLD | NEW |