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