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

Side by Side Diff: chrome/browser/win/jumplist_update_util_unittest.cc

Issue 2896233003: Cancel the JumpList update if top 5 most visited URLs are unchanged (Closed)
Patch Set: Address comments Created 3 years, 6 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
(Empty)
1 // Copyright (c) 2017 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 #include "chrome/browser/win/jumplist_update_util.h"
6
7 #include <algorithm>
8
9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 // Test data.
15 static constexpr struct {
grt (UTC plus 2) 2017/05/31 06:59:53 move this into the test function as per https://go
chengx 2017/05/31 20:46:22 Done.
16 const char* url;
17 const wchar_t* title;
18 } kTestData[] = {{"https://www.google.com/", L"Google"},
19 {"https://www.youtube.com/", L"Youtube"},
20 {"https://www.gmail.com/", L"Gmail"}};
21
22 // Helper function to create a ShellLinkItem whose url is specified by |url|.
23 scoped_refptr<ShellLinkItem> CreateShellLinkWithURL(const std::string& url) {
24 auto item = base::MakeRefCounted<ShellLinkItem>();
25 item->set_url(url);
26 return item;
27 }
28
29 } // namespace
30
31 TEST(JumpListUpdateUtilTest, MostVisitedItemsUnchanged) {
32 // Initialize jumplist_items and history_items using kTestData.
33 ShellLinkItemList jumplist_items;
34 history::MostVisitedURLList history_items;
35 for (const auto& pair : kTestData) {
grt (UTC plus 2) 2017/05/31 06:59:53 nit: pair -> test_data or something
chengx 2017/05/31 20:46:22 Done.
36 jumplist_items.push_back(CreateShellLinkWithURL(pair.url));
37 GURL url(pair.url);
grt (UTC plus 2) 2017/05/31 06:59:53 replace these next three lines with: history_i
chengx 2017/05/31 20:46:22 This is super handy! Thanks!
38 history::MostVisitedURL most_visited_url(url, pair.title);
39 history_items.push_back(most_visited_url);
40 }
41
42 // Both jumplist_items and history_items have 3 urls: Google, Youtube, Gmail.
43 // Also, their urls have the same order.
44 EXPECT_TRUE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3));
45 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 2));
46 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 1));
47
48 // Reverse history_items, so the 3 urls in history_items are in reverse order:
49 // Gmail, Youtube, Google.
50 // The 3 urls in jumplist_items remain the same: Google, Youtube, Gmail.
51 std::reverse(history_items.begin(), history_items.end());
52 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3));
53
54 // Reverse history_items back.
55 std::reverse(history_items.begin(), history_items.end());
56 EXPECT_TRUE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3));
57
58 // Pop out the last url ("Gmail") from jumplist_items.
59 // Now jumplist_items has 2 urls: Google, Youtube,
60 // and history_items has 3 urls: Google, Youtube, Gmail.
61 jumplist_items.pop_back();
62 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3));
63 EXPECT_TRUE(MostVisitedItemsUnchanged(jumplist_items, history_items, 2));
64 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 1));
65
66 // Pop out the last two urls ("Youtube", "Gmail") from history_items.
67 // Now jumplist_items has 2 urls: Google, Youtube,
68 // and history_items has 1 url: Google.
69 history_items.pop_back();
70 history_items.pop_back();
71 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3));
72 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 2));
73 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 1));
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698