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

Side by Side Diff: ios/chrome/browser/ui/history/history_entry_item_unittest.mm

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

Powered by Google App Engine
This is Rietveld 408576698