Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / bookmark_ui_utils_unittest.cc
bloba647b777cd15edd053769dfd9f388827b8f1c4ff
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)
14 using base::ASCIIToUTF16;
16 namespace {
18 TEST(BookmarkUIUtilsTest, HasBookmarkURLs) {
19 BookmarkModel model(NULL);
21 std::vector<const BookmarkNode*> nodes;
23 // This tests that |nodes| contains an URL.
24 const BookmarkNode* page1 = model.AddURL(model.bookmark_bar_node(), 0,
25 ASCIIToUTF16("Google"),
26 GURL("http://google.com"));
27 nodes.push_back(page1);
28 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes));
30 nodes.clear();
32 // This tests that |nodes| does not contain any URL.
33 const BookmarkNode* folder1 = model.AddFolder(model.bookmark_bar_node(), 0,
34 ASCIIToUTF16("Folder1"));
35 nodes.push_back(folder1);
36 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes));
38 // This verifies if HasBookmarkURLs iterates through immediate children.
39 model.AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
40 EXPECT_TRUE(chrome::HasBookmarkURLs(nodes));
42 // This verifies that HasBookmarkURLS does not iterate through descendants.
43 // i.e, it should not find an URL inside a two or three level hierarchy.
44 // So we add another folder to |folder1| and add another page to that new
45 // folder to create a two level hierarchy.
47 // But first we have to remove the URL from |folder1|.
48 model.Remove(folder1, 0);
50 const BookmarkNode* subfolder1 = model.AddFolder(folder1, 0,
51 ASCIIToUTF16("Subfolder1"));
53 // Now add the URL to that |subfolder1|.
54 model.AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
55 EXPECT_FALSE(chrome::HasBookmarkURLs(nodes));
58 TEST(BookmarkUIUtilsTest, HasBookmarkURLsAllowedInIncognitoMode) {
59 BookmarkModel model(NULL);
60 TestingProfile profile;
62 std::vector<const BookmarkNode*> nodes;
64 // This tests that |nodes| contains an disabled-in-incognito URL.
65 const BookmarkNode* page1 = model.AddURL(model.bookmark_bar_node(), 0,
66 ASCIIToUTF16("BookmarkManager"),
67 GURL("chrome://bookmarks"));
68 nodes.push_back(page1);
69 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
70 nodes.clear();
72 // This tests that |nodes| contains an URL that can be opened in incognito
73 // mode.
74 const BookmarkNode* page2 = model.AddURL(model.bookmark_bar_node(), 0,
75 ASCIIToUTF16("Google"),
76 GURL("http://google.com"));
77 nodes.push_back(page2);
78 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
80 nodes.clear();
82 // This tests that |nodes| does not contain any URL.
83 const BookmarkNode* folder1 = model.AddFolder(model.bookmark_bar_node(), 0,
84 ASCIIToUTF16("Folder1"));
85 nodes.push_back(folder1);
86 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
88 // This verifies if HasBookmarkURLsAllowedInIncognitoMode iterates through
89 // immediate children.
90 // Add disabled-in-incognito url.
91 model.AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("chrome://bookmarks"));
92 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
93 // Add normal url.
94 model.AddURL(folder1, 0, ASCIIToUTF16("Foo"), GURL("http://randomsite.com"));
95 EXPECT_TRUE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
97 // This verifies that HasBookmarkURLsAllowedInIncognitoMode does not iterate
98 // through descendants.
99 // i.e, it should not find an URL inside a two or three level hierarchy.
100 // So we add another folder to |folder1| and add another page to that new
101 // folder to create a two level hierarchy.
103 // But first we have to remove the URL from |folder1|.
104 model.Remove(folder1, 0);
106 const BookmarkNode* subfolder1 = model.AddFolder(folder1, 0,
107 ASCIIToUTF16("Subfolder1"));
109 // Now add the URL to that |subfolder1|.
110 model.AddURL(subfolder1, 0, ASCIIToUTF16("BAR"), GURL("http://bar-foo.com"));
111 EXPECT_FALSE(chrome::HasBookmarkURLsAllowedInIncognitoMode(nodes, &profile));
114 } // namespace
115 #endif