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/browser/bookmarks/bookmark_model.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 #if !defined(OS_ANDROID) && !defined(OS_IOS)
16 TEST(BookmarkUIUtilsTest
, HasBookmarkURLs
) {
17 BookmarkModel
model(NULL
);
19 std::vector
<const BookmarkNode
*> nodes
;
21 // This tests that |nodes| contains an URL.
22 const BookmarkNode
* page1
= model
.AddURL(model
.bookmark_bar_node(), 0,
23 ASCIIToUTF16("Google"),
24 GURL("http://google.com"));
25 nodes
.push_back(page1
);
26 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes
));
30 // This tests that |nodes| does not contain any URL.
31 const BookmarkNode
* folder1
= model
.AddFolder(model
.bookmark_bar_node(), 0,
32 ASCIIToUTF16("Folder1"));
33 nodes
.push_back(folder1
);
34 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes
));
36 // This verifies if HasBookmarkURLs iterates through immediate children.
37 model
.AddURL(folder1
, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
38 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes
));
40 // This verifies that HasBookmarkURLS does not iterate through descendants.
41 // i.e, it should not find an URL inside a two or three level hierarchy.
42 // So we add another folder to |folder1| and add another page to that new
43 // folder to create a two level hierarchy.
45 // But first we have to remove the URL from |folder1|.
46 model
.Remove(folder1
, 0);
48 const BookmarkNode
* subfolder1
= model
.AddFolder(folder1
, 0,
49 ASCIIToUTF16("Subfolder1"));
51 // Now add the URL to that |subfolder1|.
52 model
.AddURL(subfolder1
, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
53 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes
));
56 TEST(BookmarkUIUtilsTest
, HasBookmarkURLsAllowedInIncognitoMode
) {
57 BookmarkModel
model(NULL
);
58 TestingProfile profile
;
60 std::vector
<const BookmarkNode
*> nodes
;
62 // This tests that |nodes| contains an disabled-in-incognito URL.
63 const BookmarkNode
* page1
= model
.AddURL(model
.bookmark_bar_node(), 0,
64 ASCIIToUTF16("BookmarkManager"),
65 GURL("chrome://bookmarks"));
66 nodes
.push_back(page1
);
67 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes
, &profile
));
70 // This tests that |nodes| contains an URL that can be opened in incognito
72 const BookmarkNode
* page2
= model
.AddURL(model
.bookmark_bar_node(), 0,
73 ASCIIToUTF16("Google"),
74 GURL("http://google.com"));
75 nodes
.push_back(page2
);
76 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes
, &profile
));
80 // This tests that |nodes| does not contain any URL.
81 const BookmarkNode
* folder1
= model
.AddFolder(model
.bookmark_bar_node(), 0,
82 ASCIIToUTF16("Folder1"));
83 nodes
.push_back(folder1
);
84 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes
, &profile
));
86 // This verifies if HasBookmarkURLsAllowedInIncognitoMode iterates through
87 // immediate children.
88 // Add disabled-in-incognito url.
89 model
.AddURL(folder1
, 0, ASCIIToUTF16("Foo"), GURL("chrome://bookmarks"));
90 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes
, &profile
));
92 model
.AddURL(folder1
, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
93 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes
, &profile
));
95 // This verifies that HasBookmarkURLsAllowedInIncognitoMode does not iterate
96 // through descendants.
97 // i.e, it should not find an URL inside a two or three level hierarchy.
98 // So we add another folder to |folder1| and add another page to that new
99 // folder to create a two level hierarchy.
101 // But first we have to remove the URL from |folder1|.
102 model
.Remove(folder1
, 0);
104 const BookmarkNode
* subfolder1
= model
.AddFolder(folder1
, 0,
105 ASCIIToUTF16("Subfolder1"));
107 // Now add the URL to that |subfolder1|.
108 model
.AddURL(subfolder1
, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
109 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes
, &profile
));