Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / bookmarks / bookmark_bubble_view_unittest.cc
blob25dae71103c82805c265360b25a5f269e5987004
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.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 FakeSigninManagerBase::Build);
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;
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_;
80 private:
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");
87 CreateBubbleView();
88 bubble_->Init();
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) {
94 CreateBubbleView();
95 bubble_->Init();
96 #if defined(OS_CHROMEOS)
97 EXPECT_FALSE(bubble_->sync_promo_view_);
98 #else // !defined(OS_CHROMEOS)
99 EXPECT_TRUE(bubble_->sync_promo_view_);
100 #endif