Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: ios/chrome/browser/ui/tab_switcher/tab_switcher_model_unittest.mm

Issue 2689553002: [ObjC ARC] Converts ios/chrome/browser/ui/tab_switcher:unit_tests to ARC. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_model.h" 5 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_model.h"
6 6
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
9 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
10 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 9 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
11 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h" 10 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h"
12 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model_private.h" 11 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model_private.h"
13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.h" 12 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.h"
14 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
15 #import "third_party/ocmock/OCMock/OCMock.h" 14 #import "third_party/ocmock/OCMock/OCMock.h"
16 15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
17 namespace { 20 namespace {
18 21
19 // A lightweight DistantTab. 22 // A lightweight DistantTab.
20 class LightDT { 23 class LightDT {
21 public: 24 public:
22 LightDT(std::string const& urlSuffix, std::string const& title = "") 25 LightDT(std::string const& urlSuffix, std::string const& title = "")
23 : url("http://www.foo.com/" + urlSuffix), title(title) {} 26 : url("http://www.foo.com/" + urlSuffix), title(title) {}
24 std::string url; 27 std::string url;
25 std::string title; 28 std::string title;
26 }; 29 };
27 30
28 // A lightweight DistantSession. 31 // A lightweight DistantSession.
29 struct LightDS { 32 struct LightDS {
30 std::string tag; 33 std::string tag;
31 std::vector<LightDT> distantTabs; 34 std::vector<LightDT> distantTabs;
32 }; 35 };
33 36
34 // A lightweight SyncedSessions. 37 // A lightweight SyncedSessions.
35 using LightSS = std::vector<LightDS>; 38 using LightSS = std::vector<LightDS>;
36 39
37 } // namespace 40 } // namespace
38 41
39 // Helper class to test calls to the TabSwitcherModelDelegate. 42 // Helper class to test calls to the TabSwitcherModelDelegate.
40 @interface DelegateTester : NSObject<TabSwitcherModelDelegate> 43 @interface DelegateTester : NSObject<TabSwitcherModelDelegate>
41 @end 44 @end
42 45
43 @implementation DelegateTester { 46 @implementation DelegateTester {
44 base::scoped_nsobject<NSArray> _expectedSessionRemoved; 47 NSArray* _expectedSessionRemoved;
45 base::scoped_nsobject<NSArray> _expectedSessionInserted; 48 NSArray* _expectedSessionInserted;
46 std::set<std::string> _expectedTagsOfTheSessionsNeedingUpdates; 49 std::set<std::string> _expectedTagsOfTheSessionsNeedingUpdates;
47 } 50 }
48 51
49 - (void)expectSessionsRemoved:(NSArray*)expectedIndexes { 52 - (void)expectSessionsRemoved:(NSArray*)expectedIndexes {
50 _expectedSessionRemoved.reset([expectedIndexes retain]); 53 _expectedSessionRemoved = expectedIndexes;
51 } 54 }
52 55
53 - (void)expectSessionsInserted:(NSArray*)expectedIndexes { 56 - (void)expectSessionsInserted:(NSArray*)expectedIndexes {
54 _expectedSessionInserted.reset([expectedIndexes retain]); 57 _expectedSessionInserted = expectedIndexes;
55 } 58 }
56 59
57 - (void)expectSessionMayNeedUpdate:(std::set<std::string> const&)tags { 60 - (void)expectSessionMayNeedUpdate:(std::set<std::string> const&)tags {
58 _expectedTagsOfTheSessionsNeedingUpdates = tags; 61 _expectedTagsOfTheSessionsNeedingUpdates = tags;
59 } 62 }
60 63
61 - (void)verify { 64 - (void)verify {
62 EXPECT_EQ(0UL, [_expectedSessionRemoved count]); 65 EXPECT_EQ(0UL, [_expectedSessionRemoved count]);
63 EXPECT_EQ(0UL, [_expectedSessionInserted count]); 66 EXPECT_EQ(0UL, [_expectedSessionInserted count]);
64 EXPECT_EQ(0UL, _expectedTagsOfTheSessionsNeedingUpdates.size()); 67 EXPECT_EQ(0UL, _expectedTagsOfTheSessionsNeedingUpdates.size());
65 } 68 }
66 69
67 #pragma mark - TabSwitcherModelDelegate 70 #pragma mark - TabSwitcherModelDelegate
68 71
69 - (void)distantSessionsRemovedAtSortedIndexes:(NSArray*)removedIndexes 72 - (void)distantSessionsRemovedAtSortedIndexes:(NSArray*)removedIndexes
70 insertedAtSortedIndexes:(NSArray*)insertedIndexes { 73 insertedAtSortedIndexes:(NSArray*)insertedIndexes {
71 EXPECT_TRUE(removedIndexes == _expectedSessionRemoved.get() || 74 EXPECT_TRUE(removedIndexes == _expectedSessionRemoved ||
72 [removedIndexes isEqualToArray:_expectedSessionRemoved.get()]); 75 [removedIndexes isEqualToArray:_expectedSessionRemoved]);
73 EXPECT_TRUE(insertedIndexes == _expectedSessionInserted.get() || 76 EXPECT_TRUE(insertedIndexes == _expectedSessionInserted ||
74 [insertedIndexes isEqualToArray:_expectedSessionInserted.get()]); 77 [insertedIndexes isEqualToArray:_expectedSessionInserted]);
75 _expectedSessionRemoved.reset(); 78 _expectedSessionRemoved = nil;
76 _expectedSessionInserted.reset(); 79 _expectedSessionInserted = nil;
77 } 80 }
78 81
79 - (void)distantSessionMayNeedUpdate:(std::string const&)tag { 82 - (void)distantSessionMayNeedUpdate:(std::string const&)tag {
80 EXPECT_EQ(1UL, _expectedTagsOfTheSessionsNeedingUpdates.erase(tag)); 83 EXPECT_EQ(1UL, _expectedTagsOfTheSessionsNeedingUpdates.erase(tag));
81 } 84 }
82 85
83 - (void)localSessionMayNeedUpdate:(TabSwitcherSessionType)type { 86 - (void)localSessionMayNeedUpdate:(TabSwitcherSessionType)type {
84 NOTREACHED(); 87 NOTREACHED();
85 } 88 }
86 89
87 - (void)signInPanelChangedTo:(TabSwitcherSignInPanelsType)panelType { 90 - (void)signInPanelChangedTo:(TabSwitcherSignInPanelsType)panelType {
88 NOTREACHED(); 91 NOTREACHED();
89 } 92 }
90 - (CGSize)sizeForItemAtIndex:(NSUInteger)index 93 - (CGSize)sizeForItemAtIndex:(NSUInteger)index
91 inSession:(TabSwitcherSessionType)session { 94 inSession:(TabSwitcherSessionType)session {
92 return CGSizeZero; 95 return CGSizeZero;
93 } 96 }
94 @end 97 @end
95 98
96 namespace { 99 namespace {
97 100
98 class TabSwitcherModelTest : public PlatformTest { 101 class TabSwitcherModelTest : public PlatformTest {
99 protected: 102 protected:
100 void SetUp() override { delegate_.reset([[DelegateTester alloc] init]); } 103 void SetUp() override { delegate_ = [[DelegateTester alloc] init]; }
101 104
102 void AddSessionToSessions(synced_sessions::SyncedSessions& sessions, 105 void AddSessionToSessions(synced_sessions::SyncedSessions& sessions,
103 std::string const& session_tag, 106 std::string const& session_tag,
104 std::vector<size_t> const& tab_ids) { 107 std::vector<size_t> const& tab_ids) {
105 std::vector<LightDT> light_distant_tabs; 108 std::vector<LightDT> light_distant_tabs;
106 for (size_t tab_id : tab_ids) { 109 for (size_t tab_id : tab_ids) {
107 light_distant_tabs.push_back(LightDT(std::to_string(tab_id), "")); 110 light_distant_tabs.push_back(LightDT(std::to_string(tab_id), ""));
108 } 111 }
109 AddDetailedSessionToSessions(sessions, session_tag, light_distant_tabs); 112 AddDetailedSessionToSessions(sessions, session_tag, light_distant_tabs);
110 } 113 }
(...skipping 19 matching lines...) Expand all
130 133
131 for (auto const& light_distant_tab : light_distant_tabs) { 134 for (auto const& light_distant_tab : light_distant_tabs) {
132 auto temp_tab = base::MakeUnique<synced_sessions::DistantTab>(); 135 auto temp_tab = base::MakeUnique<synced_sessions::DistantTab>();
133 temp_tab->virtual_url = GURL(light_distant_tab.url); 136 temp_tab->virtual_url = GURL(light_distant_tab.url);
134 temp_tab->title = base::ASCIIToUTF16(light_distant_tab.title); 137 temp_tab->title = base::ASCIIToUTF16(light_distant_tab.title);
135 distant_session->tabs.push_back(std::move(temp_tab)); 138 distant_session->tabs.push_back(std::move(temp_tab));
136 } 139 }
137 140
138 sessions.AddDistantSessionForTest(std::move(distant_session)); 141 sessions.AddDistantSessionForTest(std::move(distant_session));
139 } 142 }
140 base::scoped_nsobject<DelegateTester> delegate_; 143 DelegateTester* delegate_;
141 base::scoped_nsobject<TabSwitcherModel> model_; 144 TabSwitcherModel* model_;
142 }; 145 };
143 146
144 TEST_F(TabSwitcherModelTest, TestNoDiffs) { 147 TEST_F(TabSwitcherModelTest, TestNoDiffs) {
145 // Test with 2 empty sessions. 148 // Test with 2 empty sessions.
146 synced_sessions::SyncedSessions old_sessions_1; 149 synced_sessions::SyncedSessions old_sessions_1;
147 synced_sessions::SyncedSessions new_sessions_1; 150 synced_sessions::SyncedSessions new_sessions_1;
148 [TabSwitcherModel notifyDelegate:delegate_ 151 [TabSwitcherModel notifyDelegate:delegate_
149 aboutChangeFrom:old_sessions_1 152 aboutChangeFrom:old_sessions_1
150 to:new_sessions_1]; 153 to:new_sessions_1];
151 [delegate_ verify]; 154 [delegate_ verify];
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 [delegate_ expectSessionsRemoved:@[ @1 ]]; 420 [delegate_ expectSessionsRemoved:@[ @1 ]];
418 [delegate_ expectSessionsInserted:@[ @0 ]]; 421 [delegate_ expectSessionsInserted:@[ @0 ]];
419 422
420 [TabSwitcherModel notifyDelegate:delegate_ 423 [TabSwitcherModel notifyDelegate:delegate_
421 aboutChangeFrom:*old_sessions 424 aboutChangeFrom:*old_sessions
422 to:*new_sessions]; 425 to:*new_sessions];
423 [delegate_ verify]; 426 [delegate_ verify];
424 } 427 }
425 428
426 } // namespace 429 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698