Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / bookmarks / bookmark_bubble_view_unittest.cc
blobb237cd531668b6a18a5c6080a2a54fe139febd2b
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"
7 #include <string>
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/browser/signin/fake_signin_manager_builder.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;
21 namespace {
22 const char kTestBookmarkURL[] = "http://www.google.com";
23 } // namespace
25 class BookmarkBubbleViewTest : public BrowserWithTestWindowTest {
26 public:
27 BookmarkBubbleViewTest() {}
29 // testing::Test:
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.
44 bubble_.reset();
46 BrowserWithTestWindowTest::TearDown();
49 // BrowserWithTestWindowTest:
50 TestingProfile* CreateProfile() override {
51 TestingProfile::Builder builder;
52 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
53 BuildFakeSigninManagerBase);
54 return builder.Build().release();
57 protected:
58 // Creates a bookmark bubble view.
59 void CreateBubbleView() {
60 scoped_ptr<BookmarkBubbleDelegate> delegate;
61 bubble_.reset(new BookmarkBubbleView(NULL,
62 NULL,
63 delegate.Pass(),
64 profile(),
65 GURL(kTestBookmarkURL),
66 true));
69 void SetUpSigninManager(const std::string& username) {
70 if (username.empty())
71 return;
73 SigninManagerBase* signin_manager = static_cast<SigninManagerBase*>(
74 SigninManagerFactory::GetForProfile(profile()));
75 ASSERT_TRUE(signin_manager);
76 signin_manager->SetAuthenticatedAccountInfo(username, username);
79 scoped_ptr<BookmarkBubbleView> bubble_;
81 private:
82 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleViewTest);
85 // Verifies that the sync promo is not displayed for a signed in user.
86 TEST_F(BookmarkBubbleViewTest, SyncPromoSignedIn) {
87 SetUpSigninManager("fake_username");
88 CreateBubbleView();
89 bubble_->Init();
90 EXPECT_FALSE(bubble_->sync_promo_view_);
93 // Verifies that the sync promo is displayed for a user that is not signed in.
94 TEST_F(BookmarkBubbleViewTest, SyncPromoNotSignedIn) {
95 CreateBubbleView();
96 bubble_->Init();
97 #if defined(OS_CHROMEOS)
98 EXPECT_FALSE(bubble_->sync_promo_view_);
99 #else // !defined(OS_CHROMEOS)
100 EXPECT_TRUE(bubble_->sync_promo_view_);
101 #endif