Chromium Code Reviews| OLD | NEW |
|---|---|
| (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" | |
|
grt (UTC plus 2)
2017/05/30 08:51:42
<algorithm>
chengx
2017/05/30 19:37:02
Done.
| |
| 8 | |
| 9 #include "base/containers/hash_tables.h" | |
|
grt (UTC plus 2)
2017/05/30 08:51:42
a comment in this file says:
// This header file
chengx
2017/05/30 19:37:02
I've removed this header file since kTestData does
| |
| 10 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // An url-title map used to initilize the member variables in class | |
| 16 // JumpListUpdateUtilTest. | |
| 17 base::hash_map<std::string, std::string> url_title = { | |
| 18 {"https://www.google.com/", "Google"}, | |
| 19 {"https://www.youtube.com/", "Youtube"}, | |
| 20 {"https://www.gmail.com/", "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 scoped_refptr<ShellLinkItem> item(new ShellLinkItem); | |
|
grt (UTC plus 2)
2017/05/30 08:51:42
auto item = base::MakeRefCounted<ShellLinkItem>();
chengx
2017/05/30 19:37:02
Done.
| |
| 25 item->set_url(url); | |
| 26 return item; | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 class JumpListUpdateUtilTest : public testing::Test { | |
|
grt (UTC plus 2)
2017/05/30 08:51:42
i don't think this test fixture adds any value as-
chengx
2017/05/30 19:37:03
Done.
| |
| 32 protected: | |
| 33 // A list of ShellLinkItem and each ShellLinkItem contains an URL. | |
| 34 ShellLinkItemList item_list; | |
| 35 | |
| 36 // A list of history::MostVisitedURL, each of which contains an URL. | |
| 37 history::MostVisitedURLList url_list; | |
| 38 }; | |
| 39 | |
| 40 TEST_F(JumpListUpdateUtilTest, MostVisitedItemsUnchanged) { | |
| 41 // Initialize item_list and url_list using the url_title map. | |
|
grt (UTC plus 2)
2017/05/30 08:51:42
replace url_title in the unnamed namespace with th
chengx
2017/05/30 19:37:02
Done.
| |
| 42 for (const auto& url_title_pair : url_title) { | |
| 43 item_list.push_back(CreateShellLinkWithURL(url_title_pair.first)); | |
| 44 | |
| 45 GURL url(base::UTF8ToUTF16(url_title_pair.first)); | |
|
grt (UTC plus 2)
2017/05/30 08:51:42
this conversion isn't needed -- GURL has a ctor th
chengx
2017/05/30 19:37:02
Done.
| |
| 46 history::MostVisitedURL most_visited_url( | |
| 47 url, base::UTF8ToUTF16(url_title_pair.second)); | |
|
grt (UTC plus 2)
2017/05/30 08:51:42
remove this conversion in favor of using a wchar_t
chengx
2017/05/30 19:37:03
Done.
| |
| 48 url_list.push_back(most_visited_url); | |
| 49 } | |
| 50 | |
| 51 // Now both item_list and url_list have 3 urls: Google, Youtube, Gmail. | |
| 52 // Also, their urls have the same order. | |
| 53 EXPECT_TRUE(MostVisitedItemsUnchanged(item_list, url_list, 3)); | |
| 54 EXPECT_FALSE(MostVisitedItemsUnchanged(item_list, url_list, 2)); | |
| 55 EXPECT_FALSE(MostVisitedItemsUnchanged(item_list, url_list, 1)); | |
| 56 | |
| 57 // Reverse url_list. | |
| 58 // Now item_list has 3 urls: Google, Youtube, Gmail, | |
| 59 // and url_list's 3 urls are in reverse order: Gmail, Youtube, Google. | |
| 60 std::reverse(url_list.begin(), url_list.end()); | |
| 61 EXPECT_FALSE(MostVisitedItemsUnchanged(item_list, url_list, 3)); | |
| 62 | |
| 63 // Reverse url_list back. | |
| 64 std::reverse(url_list.begin(), url_list.end()); | |
| 65 EXPECT_TRUE(MostVisitedItemsUnchanged(item_list, url_list, 3)); | |
| 66 | |
| 67 // Pop out the last url ("Gmail") from item_list. | |
| 68 // Now item_list has 2 urls: Google, Youtube, | |
| 69 // and url_list has 3 urls: Google, Youtube, Gmail. | |
| 70 item_list.pop_back(); | |
|
grt (UTC plus 2)
2017/05/30 08:51:42
i'm finding it hard to follow what "url_list" and
chengx
2017/05/30 19:37:03
I changed to history_items and jumplist_items.
| |
| 71 EXPECT_FALSE(MostVisitedItemsUnchanged(item_list, url_list, 3)); | |
| 72 EXPECT_TRUE(MostVisitedItemsUnchanged(item_list, url_list, 2)); | |
| 73 EXPECT_FALSE(MostVisitedItemsUnchanged(item_list, url_list, 1)); | |
| 74 | |
| 75 // Pop out the last two urls ("Youtube", "Gmail") from url_list. | |
| 76 // Now item_list has 2 urls: Google, Youtube, | |
| 77 // and url_list has 1 url: Google. | |
| 78 url_list.pop_back(); | |
| 79 url_list.pop_back(); | |
| 80 EXPECT_FALSE(MostVisitedItemsUnchanged(item_list, url_list, 3)); | |
| 81 EXPECT_FALSE(MostVisitedItemsUnchanged(item_list, url_list, 2)); | |
| 82 EXPECT_FALSE(MostVisitedItemsUnchanged(item_list, url_list, 1)); | |
| 83 } | |
| OLD | NEW |