OLD | NEW |
(Empty) | |
| 1 // Copyright 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 // Helper function to create a ShellLinkItem whose url is specified by |url|. |
| 15 scoped_refptr<ShellLinkItem> CreateShellLinkWithURL(const std::string& url) { |
| 16 auto item = base::MakeRefCounted<ShellLinkItem>(); |
| 17 item->set_url(url); |
| 18 return item; |
| 19 } |
| 20 |
| 21 } // namespace |
| 22 |
| 23 TEST(JumpListUpdateUtilTest, MostVisitedItemsUnchanged) { |
| 24 // Test data. |
| 25 static constexpr struct { |
| 26 const char* url; |
| 27 const wchar_t* title; |
| 28 } kTestData[] = {{"https://www.google.com/", L"Google"}, |
| 29 {"https://www.youtube.com/", L"Youtube"}, |
| 30 {"https://www.gmail.com/", L"Gmail"}}; |
| 31 |
| 32 ShellLinkItemList jumplist_items; |
| 33 history::MostVisitedURLList history_items; |
| 34 |
| 35 for (const auto& test_data : kTestData) { |
| 36 jumplist_items.push_back(CreateShellLinkWithURL(test_data.url)); |
| 37 history_items.emplace_back(GURL(test_data.url), test_data.title); |
| 38 } |
| 39 |
| 40 // Both jumplist_items and history_items have 3 urls: Google, Youtube, Gmail. |
| 41 // Also, their urls have the same order. |
| 42 EXPECT_TRUE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| 43 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 2)); |
| 44 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 1)); |
| 45 |
| 46 // Reverse history_items, so the 3 urls in history_items are in reverse order: |
| 47 // Gmail, Youtube, Google. |
| 48 // The 3 urls in jumplist_items remain the same: Google, Youtube, Gmail. |
| 49 std::reverse(history_items.begin(), history_items.end()); |
| 50 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| 51 |
| 52 // Reverse history_items back. |
| 53 std::reverse(history_items.begin(), history_items.end()); |
| 54 EXPECT_TRUE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| 55 |
| 56 // Pop out the last url ("Gmail") from jumplist_items. |
| 57 // Now jumplist_items has 2 urls: Google, Youtube, |
| 58 // and history_items has 3 urls: Google, Youtube, Gmail. |
| 59 jumplist_items.pop_back(); |
| 60 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| 61 EXPECT_TRUE(MostVisitedItemsUnchanged(jumplist_items, history_items, 2)); |
| 62 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 1)); |
| 63 |
| 64 // Pop out the last two urls ("Youtube", "Gmail") from history_items. |
| 65 // Now jumplist_items has 2 urls: Google, Youtube, |
| 66 // and history_items has 1 url: Google. |
| 67 history_items.pop_back(); |
| 68 history_items.pop_back(); |
| 69 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| 70 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 2)); |
| 71 EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 1)); |
| 72 } |
OLD | NEW |