bookmark_manager_private_apitest.cc revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
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.
4
5#include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h"
6
7#include "base/command_line.h"
8#include "base/prefs/pref_service.h"
9#include "base/strings/utf_string_conversions.h"
10#include "base/values.h"
11#include "chrome/browser/bookmarks/bookmark_model_factory.h"
12#include "chrome/browser/bookmarks/chrome_bookmark_client.h"
13#include "chrome/browser/extensions/extension_apitest.h"
14#include "chrome/browser/profiles/profile.h"
15#include "chrome/browser/ui/browser.h"
16#include "chrome/common/pref_names.h"
17#include "components/bookmarks/browser/bookmark_model.h"
18#include "components/bookmarks/common/bookmark_pref_names.h"
19#include "components/bookmarks/test/bookmark_test_helpers.h"
20#include "components/user_prefs/user_prefs.h"
21
22// Times out on win syzyasan, http://crbug.com/166026
23#if defined(SYZYASAN)
24#define MAYBE_BookmarkManager DISABLED_BookmarkManager
25#else
26#define MAYBE_BookmarkManager BookmarkManager
27#endif
28IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_BookmarkManager) {
29  // Add managed bookmarks.
30  Profile* profile = browser()->profile();
31  ChromeBookmarkClient* client =
32      BookmarkModelFactory::GetChromeBookmarkClientForProfile(profile);
33  BookmarkModel* model = client->model();
34  test::WaitForBookmarkModelToLoad(model);
35
36  base::ListValue list;
37  base::DictionaryValue* node = new base::DictionaryValue();
38  node->SetString("name", "Managed Bookmark");
39  node->SetString("url", "http://www.chromium.org");
40  list.Append(node);
41  node = new base::DictionaryValue();
42  node->SetString("name", "Managed Folder");
43  node->Set("children", new base::ListValue());
44  list.Append(node);
45  profile->GetPrefs()->Set(prefs::kManagedBookmarks, list);
46  ASSERT_EQ(2, client->managed_node()->child_count());
47
48  ASSERT_TRUE(RunComponentExtensionTest("bookmark_manager/standard"))
49      << message_;
50}
51
52IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BookmarkManagerEditDisabled) {
53  Profile* profile = browser()->profile();
54
55  // Provide some testing data here, since bookmark editing will be disabled
56  // within the extension.
57  BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
58  test::WaitForBookmarkModelToLoad(model);
59  const BookmarkNode* bar = model->bookmark_bar_node();
60  const BookmarkNode* folder =
61      model->AddFolder(bar, 0, base::ASCIIToUTF16("Folder"));
62  model->AddURL(bar, 1, base::ASCIIToUTF16("AAA"),
63                GURL("http://aaa.example.com"));
64  model->AddURL(folder, 0, base::ASCIIToUTF16("BBB"),
65                GURL("http://bbb.example.com"));
66
67  PrefService* prefs = user_prefs::UserPrefs::Get(profile);
68  prefs->SetBoolean(prefs::kEditBookmarksEnabled, false);
69
70  ASSERT_TRUE(RunComponentExtensionTest("bookmark_manager/edit_disabled"))
71      << message_;
72}
73