1 // Copyright 2013 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/views/bookmarks/bookmark_bubble_view.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/browser/bookmarks/bookmark_utils.h"
12 #include "chrome/browser/signin/fake_signin_manager.h"
13 #include "chrome/browser/signin/signin_manager.h"
14 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
16 #include "chrome/test/base/browser_with_test_window_test.h"
17 #include "chrome/test/base/ui_test_utils.h"
20 const char kTestBookmarkURL
[] = "http://www.google.com";
23 class BookmarkBubbleViewTest
: public BrowserWithTestWindowTest
{
25 BookmarkBubbleViewTest() {}
28 virtual void SetUp() OVERRIDE
{
29 BrowserWithTestWindowTest::SetUp();
31 profile()->CreateBookmarkModel(true);
32 ui_test_utils::WaitForBookmarkModelToLoad(profile());
34 bookmark_utils::AddIfNotBookmarked(
35 BookmarkModelFactory::GetForProfile(profile()),
36 GURL(kTestBookmarkURL
),
40 virtual void TearDown() OVERRIDE
{
41 // Make sure the bubble is destroyed before the profile to avoid a crash.
44 BrowserWithTestWindowTest::TearDown();
48 // Creates a bookmark bubble view.
49 void CreateBubbleView() {
50 scoped_ptr
<BookmarkBubbleDelegate
> delegate
;
51 bubble_
.reset(new BookmarkBubbleView(NULL
,
55 GURL(kTestBookmarkURL
),
59 void CreateSigninManager(const std::string
& username
) {
60 SigninManagerBase
* signin_manager
=
61 static_cast<SigninManagerBase
*>(
62 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
64 &BookmarkBubbleViewTest::BuildFakeSignInManager
));
65 signin_manager
->Initialize(profile(), NULL
);
67 if (!username
.empty()) {
68 ASSERT_TRUE(signin_manager
);
69 signin_manager
->SetAuthenticatedUsername(username
);
73 scoped_ptr
<BookmarkBubbleView
> bubble_
;
76 static BrowserContextKeyedService
* BuildFakeSignInManager(
77 content::BrowserContext
* profile
) {
78 #if defined(OS_CHROMEOS)
79 return new FakeSigninManagerBase();
80 #else // !defined(OS_CHROMEOS)
81 return new FakeSigninManager(static_cast<Profile
*>(profile
));
85 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleViewTest
);
88 // Verifies that the sync promo is not displayed for a signed in user.
89 TEST_F(BookmarkBubbleViewTest
, SyncPromoSignedIn
) {
90 CreateSigninManager("fake_username");
93 EXPECT_FALSE(bubble_
->sync_promo_view_
);
96 // Verifies that the sync promo is displayed for a user that is not signed in.
97 TEST_F(BookmarkBubbleViewTest
, SyncPromoNotSignedIn
) {
100 #if defined(OS_CHROMEOS)
101 EXPECT_FALSE(bubble_
->sync_promo_view_
);
102 #else // !defined(OS_CHROMEOS)
103 EXPECT_TRUE(bubble_
->sync_promo_view_
);