| OLD | NEW |
| (Empty) | |
| 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/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model_factory.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/common/chrome_switches.h" |
| 18 #include "chrome/test/base/browser_with_test_window_test.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 |
| 21 namespace { |
| 22 const char kTestBookmarkURL[] = "http://www.google.com"; |
| 23 } // namespace |
| 24 |
| 25 class BookmarkBubbleViewTest : public BrowserWithTestWindowTest { |
| 26 public: |
| 27 BookmarkBubbleViewTest() {} |
| 28 |
| 29 // testing::Test: |
| 30 virtual void SetUp() OVERRIDE { |
| 31 BrowserWithTestWindowTest::SetUp(); |
| 32 |
| 33 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 34 command_line->AppendSwitch(switches::kEnableBookmarkSyncPromo); |
| 35 |
| 36 profile()->CreateBookmarkModel(true); |
| 37 ui_test_utils::WaitForBookmarkModelToLoad(profile()); |
| 38 |
| 39 bookmark_utils::AddIfNotBookmarked( |
| 40 BookmarkModelFactory::GetForProfile(profile()), |
| 41 GURL(kTestBookmarkURL), |
| 42 string16()); |
| 43 } |
| 44 |
| 45 virtual void TearDown() OVERRIDE { |
| 46 // Make sure the bubble is destroyed before the profile to avoid a crash. |
| 47 bubble_.reset(); |
| 48 |
| 49 BrowserWithTestWindowTest::TearDown(); |
| 50 } |
| 51 |
| 52 protected: |
| 53 // Creates a bookmark bubble view. |
| 54 void CreateBubbleView() { |
| 55 scoped_ptr<BookmarkBubbleDelegate> delegate; |
| 56 bubble_.reset(new BookmarkBubbleView(NULL, |
| 57 NULL, |
| 58 delegate.Pass(), |
| 59 profile(), |
| 60 GURL(kTestBookmarkURL), |
| 61 true)); |
| 62 } |
| 63 |
| 64 void CreateSigninManager(const std::string& username) { |
| 65 SigninManagerBase* signin_manager = |
| 66 static_cast<SigninManagerBase*>( |
| 67 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
| 68 profile(), |
| 69 &BookmarkBubbleViewTest::BuildFakeSignInManager)); |
| 70 signin_manager->Initialize(profile(), NULL); |
| 71 |
| 72 if (!username.empty()) { |
| 73 ASSERT_TRUE(signin_manager); |
| 74 signin_manager->SetAuthenticatedUsername(username); |
| 75 } |
| 76 } |
| 77 |
| 78 scoped_ptr<BookmarkBubbleView> bubble_; |
| 79 |
| 80 private: |
| 81 static BrowserContextKeyedService* BuildFakeSignInManager( |
| 82 content::BrowserContext* profile) { |
| 83 #if defined(OS_CHROMEOS) |
| 84 return new FakeSigninManagerBase(); |
| 85 #else // !defined(OS_CHROMEOS) |
| 86 return new FakeSigninManager(static_cast<Profile*>(profile)); |
| 87 #endif |
| 88 } |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleViewTest); |
| 91 }; |
| 92 |
| 93 // Verifies that the sync promo is not displayed for a signed in user. |
| 94 TEST_F(BookmarkBubbleViewTest, SyncPromoSignedIn) { |
| 95 CreateSigninManager("fake_username"); |
| 96 CreateBubbleView(); |
| 97 bubble_->Init(); |
| 98 EXPECT_FALSE(bubble_->sync_promo_view_); |
| 99 } |
| 100 |
| 101 // Verifies that the sync promo is displayed for a user that is not signed in. |
| 102 TEST_F(BookmarkBubbleViewTest, SyncPromoNotSignedIn) { |
| 103 CreateBubbleView(); |
| 104 bubble_->Init(); |
| 105 #if defined(OS_CHROMEOS) |
| 106 EXPECT_FALSE(bubble_->sync_promo_view_); |
| 107 #else // !defined(OS_CHROMEOS) |
| 108 EXPECT_TRUE(bubble_->sync_promo_view_); |
| 109 #endif |
| 110 } |
| OLD | NEW |