| 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/history/history_entry_item.h" | 5 #import "ios/chrome/browser/ui/history/history_entry_item.h" |
| 6 | 6 |
| 7 #include "base/i18n/time_formatting.h" | 7 #include "base/i18n/time_formatting.h" |
| 8 #include "base/mac/scoped_nsobject.h" | |
| 9 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 12 #include "ios/chrome/browser/ui/history/history_entry.h" | 11 #include "ios/chrome/browser/ui/history/history_entry.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/gtest_mac.h" | 13 #include "testing/gtest_mac.h" |
| 15 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." |
| 17 #endif |
| 18 |
| 16 namespace { | 19 namespace { |
| 17 const char kTestUrl[] = "http://test/"; | 20 const char kTestUrl[] = "http://test/"; |
| 18 const char kTestUrl2[] = "http://test2/"; | 21 const char kTestUrl2[] = "http://test2/"; |
| 19 const char kTestTitle[] = "Test"; | 22 const char kTestTitle[] = "Test"; |
| 20 } | 23 } |
| 21 | 24 |
| 22 HistoryEntryItem* GetHistoryEntryItem(const GURL& url, | 25 HistoryEntryItem* GetHistoryEntryItem(const GURL& url, |
| 23 const char title[], | 26 const char title[], |
| 24 base::Time timestamp) { | 27 base::Time timestamp) { |
| 25 history::HistoryEntry entry = history::HistoryEntry( | 28 history::HistoryEntry entry = history::HistoryEntry( |
| 26 history::HistoryEntry::LOCAL_ENTRY, GURL(url), base::UTF8ToUTF16(title), | 29 history::HistoryEntry::LOCAL_ENTRY, GURL(url), base::UTF8ToUTF16(title), |
| 27 timestamp, "", false, base::string16(), false); | 30 timestamp, "", false, base::string16(), false); |
| 28 HistoryEntryItem* item = | 31 HistoryEntryItem* item = [[HistoryEntryItem alloc] initWithType:0 |
| 29 [[[HistoryEntryItem alloc] initWithType:0 | 32 historyEntry:entry |
| 30 historyEntry:entry | 33 browserState:nil |
| 31 browserState:nil | 34 delegate:nil]; |
| 32 delegate:nil] autorelease]; | |
| 33 return item; | 35 return item; |
| 34 } | 36 } |
| 35 | 37 |
| 36 // Tests that -[HistoryEntryItem configureCell:] sets the cell's textLabel text | 38 // Tests that -[HistoryEntryItem configureCell:] sets the cell's textLabel text |
| 37 // to the item title, the detailTextLabel text to the URL, and the timeLabel | 39 // to the item title, the detailTextLabel text to the URL, and the timeLabel |
| 38 // text to the timestamp. | 40 // text to the timestamp. |
| 39 TEST(HistoryEntryItemTest, ConfigureCell) { | 41 TEST(HistoryEntryItemTest, ConfigureCell) { |
| 40 base::Time timestamp = base::Time::Now(); | 42 base::Time timestamp = base::Time::Now(); |
| 41 HistoryEntryItem* item = | 43 HistoryEntryItem* item = |
| 42 GetHistoryEntryItem(GURL(kTestUrl), kTestTitle, timestamp); | 44 GetHistoryEntryItem(GURL(kTestUrl), kTestTitle, timestamp); |
| 43 | 45 |
| 44 base::scoped_nsobject<HistoryEntryCell> cell([[[item cellClass] alloc] init]); | 46 HistoryEntryCell* cell = [[[item cellClass] alloc] init]; |
| 45 EXPECT_TRUE([cell isMemberOfClass:[HistoryEntryCell class]]); | 47 EXPECT_TRUE([cell isMemberOfClass:[HistoryEntryCell class]]); |
| 46 [item configureCell:cell]; | 48 [item configureCell:cell]; |
| 47 EXPECT_NSEQ(base::SysUTF8ToNSString(kTestTitle), cell.get().textLabel.text); | 49 EXPECT_NSEQ(base::SysUTF8ToNSString(kTestTitle), cell.textLabel.text); |
| 48 EXPECT_NSEQ(base::SysUTF8ToNSString(kTestUrl), | 50 EXPECT_NSEQ(base::SysUTF8ToNSString(kTestUrl), cell.detailTextLabel.text); |
| 49 cell.get().detailTextLabel.text); | |
| 50 EXPECT_NSEQ(base::SysUTF16ToNSString(base::TimeFormatTimeOfDay(timestamp)), | 51 EXPECT_NSEQ(base::SysUTF16ToNSString(base::TimeFormatTimeOfDay(timestamp)), |
| 51 cell.get().timeLabel.text); | 52 cell.timeLabel.text); |
| 52 } | 53 } |
| 53 | 54 |
| 54 // Tests that -[HistoryItem isEqualToHistoryItem:] returns YES if the two items | 55 // Tests that -[HistoryItem isEqualToHistoryItem:] returns YES if the two items |
| 55 // have the same URL and timestamp, and NO otherwise. | 56 // have the same URL and timestamp, and NO otherwise. |
| 56 TEST(HistoryEntryItemTest, IsEqual) { | 57 TEST(HistoryEntryItemTest, IsEqual) { |
| 57 base::Time timestamp = base::Time::Now(); | 58 base::Time timestamp = base::Time::Now(); |
| 58 base::Time timestamp2 = timestamp - base::TimeDelta::FromMinutes(1); | 59 base::Time timestamp2 = timestamp - base::TimeDelta::FromMinutes(1); |
| 59 HistoryEntryItem* history_entry = | 60 HistoryEntryItem* history_entry = |
| 60 GetHistoryEntryItem(GURL(kTestUrl), kTestTitle, timestamp); | 61 GetHistoryEntryItem(GURL(kTestUrl), kTestTitle, timestamp); |
| 61 HistoryEntryItem* same_entry = | 62 HistoryEntryItem* same_entry = |
| 62 GetHistoryEntryItem(GURL(kTestUrl), kTestTitle, timestamp); | 63 GetHistoryEntryItem(GURL(kTestUrl), kTestTitle, timestamp); |
| 63 | 64 |
| 64 HistoryEntryItem* different_time_entry = | 65 HistoryEntryItem* different_time_entry = |
| 65 GetHistoryEntryItem(GURL(kTestUrl), kTestTitle, timestamp2); | 66 GetHistoryEntryItem(GURL(kTestUrl), kTestTitle, timestamp2); |
| 66 HistoryEntryItem* different_url_entry = | 67 HistoryEntryItem* different_url_entry = |
| 67 GetHistoryEntryItem(GURL(kTestUrl2), kTestTitle, timestamp); | 68 GetHistoryEntryItem(GURL(kTestUrl2), kTestTitle, timestamp); |
| 68 | 69 |
| 69 EXPECT_TRUE([history_entry isEqualToHistoryEntryItem:same_entry]); | 70 EXPECT_TRUE([history_entry isEqualToHistoryEntryItem:same_entry]); |
| 70 EXPECT_FALSE([history_entry isEqualToHistoryEntryItem:different_time_entry]); | 71 EXPECT_FALSE([history_entry isEqualToHistoryEntryItem:different_time_entry]); |
| 71 EXPECT_FALSE([history_entry isEqualToHistoryEntryItem:different_url_entry]); | 72 EXPECT_FALSE([history_entry isEqualToHistoryEntryItem:different_url_entry]); |
| 72 } | 73 } |
| OLD | NEW |