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/signin/fake_signin_manager.h"
12 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
14 #include "chrome/test/base/browser_with_test_window_test.h"
15 #include "components/bookmarks/browser/bookmark_utils.h"
16 #include "components/bookmarks/test/bookmark_test_helpers.h"
17 #include "components/signin/core/browser/signin_manager.h"
19 using bookmarks::BookmarkModel
;
22 const char kTestBookmarkURL
[] = "http://www.google.com";
25 class BookmarkBubbleViewTest
: public BrowserWithTestWindowTest
{
27 BookmarkBubbleViewTest() {}
30 void SetUp() override
{
31 BrowserWithTestWindowTest::SetUp();
33 profile()->CreateBookmarkModel(true);
34 BookmarkModel
* bookmark_model
=
35 BookmarkModelFactory::GetForProfile(profile());
36 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model
);
38 bookmarks::AddIfNotBookmarked(
39 bookmark_model
, GURL(kTestBookmarkURL
), base::string16());
42 void TearDown() override
{
43 // Make sure the bubble is destroyed before the profile to avoid a crash.
46 BrowserWithTestWindowTest::TearDown();
49 // BrowserWithTestWindowTest:
50 TestingProfile
* CreateProfile() override
{
51 TestingProfile::Builder builder
;
52 builder
.AddTestingFactory(SigninManagerFactory::GetInstance(),
53 FakeSigninManagerBase::Build
);
54 return builder
.Build().release();
58 // Creates a bookmark bubble view.
59 void CreateBubbleView() {
60 scoped_ptr
<BookmarkBubbleDelegate
> delegate
;
61 bubble_
.reset(new BookmarkBubbleView(NULL
,
65 GURL(kTestBookmarkURL
),
69 void SetUpSigninManager(const std::string
& username
) {
72 SigninManagerBase
* signin_manager
= static_cast<SigninManagerBase
*>(
73 SigninManagerFactory::GetForProfile(profile()));
74 ASSERT_TRUE(signin_manager
);
75 signin_manager
->SetAuthenticatedUsername(username
);
78 scoped_ptr
<BookmarkBubbleView
> bubble_
;
81 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleViewTest
);
84 // Verifies that the sync promo is not displayed for a signed in user.
85 TEST_F(BookmarkBubbleViewTest
, SyncPromoSignedIn
) {
86 SetUpSigninManager("fake_username");
89 EXPECT_FALSE(bubble_
->sync_promo_view_
);
92 // Verifies that the sync promo is displayed for a user that is not signed in.
93 TEST_F(BookmarkBubbleViewTest
, SyncPromoNotSignedIn
) {
96 #if defined(OS_CHROMEOS)
97 EXPECT_FALSE(bubble_
->sync_promo_view_
);
98 #else // !defined(OS_CHROMEOS)
99 EXPECT_TRUE(bubble_
->sync_promo_view_
);