Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / bookmarks / bookmark_bubble_view_unittest.cc
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.
4
5 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
6
7 #include <string>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/browser/bookmarks/bookmark_test_helpers.h"
12 #include "chrome/browser/bookmarks/bookmark_utils.h"
13 #include "chrome/browser/signin/fake_signin_manager.h"
14 #include "chrome/browser/signin/signin_manager.h"
15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
17 #include "chrome/test/base/browser_with_test_window_test.h"
18
19 namespace {
20 const char kTestBookmarkURL[] = "http://www.google.com";
21 } // namespace
22
23 class BookmarkBubbleViewTest : public BrowserWithTestWindowTest {
24  public:
25   BookmarkBubbleViewTest() {}
26
27   // testing::Test:
28   virtual void SetUp() OVERRIDE {
29     BrowserWithTestWindowTest::SetUp();
30
31     profile()->CreateBookmarkModel(true);
32     test::WaitForBookmarkModelToLoad(profile());
33
34     bookmark_utils::AddIfNotBookmarked(
35         BookmarkModelFactory::GetForProfile(profile()),
36         GURL(kTestBookmarkURL),
37         base::string16());
38   }
39
40   virtual void TearDown() OVERRIDE {
41     // Make sure the bubble is destroyed before the profile to avoid a crash.
42     bubble_.reset();
43
44     BrowserWithTestWindowTest::TearDown();
45   }
46
47  protected:
48   // Creates a bookmark bubble view.
49   void CreateBubbleView() {
50     scoped_ptr<BookmarkBubbleDelegate> delegate;
51     bubble_.reset(new BookmarkBubbleView(NULL,
52                                          NULL,
53                                          delegate.Pass(),
54                                          profile(),
55                                          GURL(kTestBookmarkURL),
56                                          true));
57   }
58
59   void CreateSigninManager(const std::string& username) {
60     SigninManagerBase* signin_manager =
61         static_cast<SigninManagerBase*>(
62             SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
63                 profile(),
64                 &BookmarkBubbleViewTest::BuildFakeSignInManager));
65     signin_manager->Initialize(profile(), NULL);
66
67     if (!username.empty()) {
68       ASSERT_TRUE(signin_manager);
69       signin_manager->SetAuthenticatedUsername(username);
70     }
71   }
72
73   scoped_ptr<BookmarkBubbleView> bubble_;
74
75  private:
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));
82 #endif
83   }
84
85   DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleViewTest);
86 };
87
88 // Verifies that the sync promo is not displayed for a signed in user.
89 TEST_F(BookmarkBubbleViewTest, SyncPromoSignedIn) {
90   CreateSigninManager("fake_username");
91   CreateBubbleView();
92   bubble_->Init();
93   EXPECT_FALSE(bubble_->sync_promo_view_);
94 }
95
96 // Verifies that the sync promo is displayed for a user that is not signed in.
97 TEST_F(BookmarkBubbleViewTest, SyncPromoNotSignedIn) {
98   CreateBubbleView();
99   bubble_->Init();
100 #if defined(OS_CHROMEOS)
101   EXPECT_FALSE(bubble_->sync_promo_view_);
102 #else  // !defined(OS_CHROMEOS)
103   EXPECT_TRUE(bubble_->sync_promo_view_);
104 #endif
105 }