Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / bookmark_ui_utils_unittest.cc
blob770be539354cc4440e0734c81b63ca47e680f29d
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;
16 using bookmarks::BookmarkModel;
17 using bookmarks::BookmarkNode;
19 namespace {
21 TEST(BookmarkUIUtilsTest, HasBookmarkURLs) {
22 bookmarks::TestBookmarkClient client;
23 scoped_ptr<BookmarkModel> model(client.CreateModel());
25 std::vector<const BookmarkNode*> nodes;
27 // This tests that |nodes| contains an URL.
28 const BookmarkNode* page1 = model->AddURL(model->bookmark_bar_node(),
30 ASCIIToUTF16("Google"),
31 GURL("http://google.com"));
32 nodes.push_back(page1);
33 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes));
35 nodes.clear();
37 // This tests that |nodes| does not contain any URL.
38 const BookmarkNode* folder1 =
39 model->AddFolder(model->bookmark_bar_node(), 0, ASCIIToUTF16("Folder1"));
40 nodes.push_back(folder1);
41 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes));
43 // This verifies if HasBookmarkURLs iterates through immediate children.
44 model->AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
45 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes));
47 // This verifies that HasBookmarkURLS does not iterate through descendants.
48 // i.e, it should not find an URL inside a two or three level hierarchy.
49 // So we add another folder to |folder1| and add another page to that new
50 // folder to create a two level hierarchy.
52 // But first we have to remove the URL from |folder1|.
53 model->Remove(folder1, 0);
55 const BookmarkNode* subfolder1 =
56 model->AddFolder(folder1, 0, ASCIIToUTF16("Subfolder1"));
58 // Now add the URL to that |subfolder1|.
59 model->AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
60 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes));
63 TEST(BookmarkUIUtilsTest, HasBookmarkURLsAllowedInIncognitoMode) {
64 bookmarks::TestBookmarkClient client;
65 scoped_ptr<BookmarkModel> model(client.CreateModel());
66 TestingProfile profile;
68 std::vector<const BookmarkNode*> nodes;
70 // This tests that |nodes| contains an disabled-in-incognito URL.
71 const BookmarkNode* page1 = model->AddURL(model->bookmark_bar_node(),
73 ASCIIToUTF16("BookmarkManager"),
74 GURL("chrome://bookmarks"));
75 nodes.push_back(page1);
76 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
77 nodes.clear();
79 // This tests that |nodes| contains an URL that can be opened in incognito
80 // mode.
81 const BookmarkNode* page2 = model->AddURL(model->bookmark_bar_node(),
83 ASCIIToUTF16("Google"),
84 GURL("http://google.com"));
85 nodes.push_back(page2);
86 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
88 nodes.clear();
90 // This tests that |nodes| does not contain any URL.
91 const BookmarkNode* folder1 =
92 model->AddFolder(model->bookmark_bar_node(), 0, ASCIIToUTF16("Folder1"));
93 nodes.push_back(folder1);
94 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
96 // This verifies if HasBookmarkURLsAllowedInIncognitoMode iterates through
97 // immediate children.
98 // Add disabled-in-incognito url.
99 model->AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("chrome://bookmarks"));
100 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
101 // Add normal url.
102 model->AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
103 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
105 // This verifies that HasBookmarkURLsAllowedInIncognitoMode does not iterate
106 // through descendants.
107 // i.e, it should not find an URL inside a two or three level hierarchy.
108 // So we add another folder to |folder1| and add another page to that new
109 // folder to create a two level hierarchy.
111 // But first we have to remove the URL from |folder1|.
112 model->Remove(folder1, 0);
114 const BookmarkNode* subfolder1 =
115 model->AddFolder(folder1, 0, ASCIIToUTF16("Subfolder1"));
117 // Now add the URL to that |subfolder1|.
118 model->AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
119 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
122 } // namespace
123 #endif