Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / bookmarks / bookmark_bubble_view_unittest.cc
blob087afc717fee0c59270ddfbabff0880b39a6b9cc
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/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"
19 namespace {
20 const char kTestBookmarkURL[] = "http://www.google.com";
21 } // namespace
23 class BookmarkBubbleViewTest : public BrowserWithTestWindowTest {
24 public:
25 BookmarkBubbleViewTest() {}
27 // testing::Test:
28 virtual void SetUp() OVERRIDE {
29 BrowserWithTestWindowTest::SetUp();
31 profile()->CreateBookmarkModel(true);
32 test::WaitForBookmarkModelToLoad(profile());
34 bookmark_utils::AddIfNotBookmarked(
35 BookmarkModelFactory::GetForProfile(profile()),
36 GURL(kTestBookmarkURL),
37 base::string16());
40 virtual void TearDown() OVERRIDE {
41 // Make sure the bubble is destroyed before the profile to avoid a crash.
42 bubble_.reset();
44 BrowserWithTestWindowTest::TearDown();
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));
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);
67 if (!username.empty()) {
68 ASSERT_TRUE(signin_manager);
69 signin_manager->SetAuthenticatedUsername(username);
73 scoped_ptr<BookmarkBubbleView> bubble_;
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
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");
91 CreateBubbleView();
92 bubble_->Init();
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) {
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