Temporarily re-enabling SizeAfterPrefChange test with traces (this time for Linux...
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / bookmark_ui_utils_unittest.cc
blob5d026613dded072c0fa4e01f2b53802744768703
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "components/bookmarks/browser/bookmark_model.h"
10 #include "components/bookmarks/test/test_bookmark_client.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 #if !defined(OS_ANDROID) && !defined(OS_IOS)
15 using base::ASCIIToUTF16;
17 namespace {
19 TEST(BookmarkUIUtilsTest, HasBookmarkURLs) {
20 test::TestBookmarkClient client;
21 scoped_ptr<BookmarkModel> model(client.CreateModel(false));
23 std::vector<const BookmarkNode*> nodes;
25 // This tests that |nodes| contains an URL.
26 const BookmarkNode* page1 = model->AddURL(model->bookmark_bar_node(),
28 ASCIIToUTF16("Google"),
29 GURL("http://google.com"));
30 nodes.push_back(page1);
31 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes));
33 nodes.clear();
35 // This tests that |nodes| does not contain any URL.
36 const BookmarkNode* folder1 =
37 model->AddFolder(model->bookmark_bar_node(), 0, ASCIIToUTF16("Folder1"));
38 nodes.push_back(folder1);
39 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes));
41 // This verifies if HasBookmarkURLs iterates through immediate children.
42 model->AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
43 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes));
45 // This verifies that HasBookmarkURLS does not iterate through descendants.
46 // i.e, it should not find an URL inside a two or three level hierarchy.
47 // So we add another folder to |folder1| and add another page to that new
48 // folder to create a two level hierarchy.
50 // But first we have to remove the URL from |folder1|.
51 model->Remove(folder1, 0);
53 const BookmarkNode* subfolder1 =
54 model->AddFolder(folder1, 0, ASCIIToUTF16("Subfolder1"));
56 // Now add the URL to that |subfolder1|.
57 model->AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
58 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes));
61 TEST(BookmarkUIUtilsTest, HasBookmarkURLsAllowedInIncognitoMode) {
62 test::TestBookmarkClient client;
63 scoped_ptr<BookmarkModel> model(client.CreateModel(false));
64 TestingProfile profile;
66 std::vector<const BookmarkNode*> nodes;
68 // This tests that |nodes| contains an disabled-in-incognito URL.
69 const BookmarkNode* page1 = model->AddURL(model->bookmark_bar_node(),
71 ASCIIToUTF16("BookmarkManager"),
72 GURL("chrome://bookmarks"));
73 nodes.push_back(page1);
74 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
75 nodes.clear();
77 // This tests that |nodes| contains an URL that can be opened in incognito
78 // mode.
79 const BookmarkNode* page2 = model->AddURL(model->bookmark_bar_node(),
81 ASCIIToUTF16("Google"),
82 GURL("http://google.com"));
83 nodes.push_back(page2);
84 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
86 nodes.clear();
88 // This tests that |nodes| does not contain any URL.
89 const BookmarkNode* folder1 =
90 model->AddFolder(model->bookmark_bar_node(), 0, ASCIIToUTF16("Folder1"));
91 nodes.push_back(folder1);
92 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
94 // This verifies if HasBookmarkURLsAllowedInIncognitoMode iterates through
95 // immediate children.
96 // Add disabled-in-incognito url.
97 model->AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("chrome://bookmarks"));
98 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
99 // Add normal url.
100 model->AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
101 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
103 // This verifies that HasBookmarkURLsAllowedInIncognitoMode does not iterate
104 // through descendants.
105 // i.e, it should not find an URL inside a two or three level hierarchy.
106 // So we add another folder to |folder1| and add another page to that new
107 // folder to create a two level hierarchy.
109 // But first we have to remove the URL from |folder1|.
110 model->Remove(folder1, 0);
112 const BookmarkNode* subfolder1 =
113 model->AddFolder(folder1, 0, ASCIIToUTF16("Subfolder1"));
115 // Now add the URL to that |subfolder1|.
116 model->AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
117 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
120 } // namespace
121 #endif