Chromium Code Reviews| Index: chrome/browser/win/jumplist_update_util_unittest.cc |
| diff --git a/chrome/browser/win/jumplist_update_util_unittest.cc b/chrome/browser/win/jumplist_update_util_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5ae46c08153e8feb2f9536605255506c9b837728 |
| --- /dev/null |
| +++ b/chrome/browser/win/jumplist_update_util_unittest.cc |
| @@ -0,0 +1,74 @@ |
| +// Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/win/jumplist_update_util.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +// Test data. |
| +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.
|
| + const char* url; |
| + const wchar_t* title; |
| +} kTestData[] = {{"https://www.google.com/", L"Google"}, |
| + {"https://www.youtube.com/", L"Youtube"}, |
| + {"https://www.gmail.com/", L"Gmail"}}; |
| + |
| +// Helper function to create a ShellLinkItem whose url is specified by |url|. |
| +scoped_refptr<ShellLinkItem> CreateShellLinkWithURL(const std::string& url) { |
| + auto item = base::MakeRefCounted<ShellLinkItem>(); |
| + item->set_url(url); |
| + return item; |
| +} |
| + |
| +} // namespace |
| + |
| +TEST(JumpListUpdateUtilTest, MostVisitedItemsUnchanged) { |
| + // Initialize jumplist_items and history_items using kTestData. |
| + ShellLinkItemList jumplist_items; |
| + history::MostVisitedURLList history_items; |
| + 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.
|
| + jumplist_items.push_back(CreateShellLinkWithURL(pair.url)); |
| + 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!
|
| + history::MostVisitedURL most_visited_url(url, pair.title); |
| + history_items.push_back(most_visited_url); |
| + } |
| + |
| + // Both jumplist_items and history_items have 3 urls: Google, Youtube, Gmail. |
| + // Also, their urls have the same order. |
| + EXPECT_TRUE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| + EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 2)); |
| + EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 1)); |
| + |
| + // Reverse history_items, so the 3 urls in history_items are in reverse order: |
| + // Gmail, Youtube, Google. |
| + // The 3 urls in jumplist_items remain the same: Google, Youtube, Gmail. |
| + std::reverse(history_items.begin(), history_items.end()); |
| + EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| + |
| + // Reverse history_items back. |
| + std::reverse(history_items.begin(), history_items.end()); |
| + EXPECT_TRUE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| + |
| + // Pop out the last url ("Gmail") from jumplist_items. |
| + // Now jumplist_items has 2 urls: Google, Youtube, |
| + // and history_items has 3 urls: Google, Youtube, Gmail. |
| + jumplist_items.pop_back(); |
| + EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| + EXPECT_TRUE(MostVisitedItemsUnchanged(jumplist_items, history_items, 2)); |
| + EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 1)); |
| + |
| + // Pop out the last two urls ("Youtube", "Gmail") from history_items. |
| + // Now jumplist_items has 2 urls: Google, Youtube, |
| + // and history_items has 1 url: Google. |
| + history_items.pop_back(); |
| + history_items.pop_back(); |
| + EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 3)); |
| + EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 2)); |
| + EXPECT_FALSE(MostVisitedItemsUnchanged(jumplist_items, history_items, 1)); |
| +} |