Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bubble_view_unittest.cc

Issue 18603006: Bookmark sync promo for Views. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle incognito browser removed Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 FakeSigninManager* signin_manager = static_cast<FakeSigninManager*>(
66 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
67 profile(),
68 &BookmarkBubbleViewTest::BuildFakeSignInManager));
69 signin_manager->Initialize(profile(), NULL);
70
71 if (!username.empty()) {
72 ASSERT_TRUE(signin_manager);
73 signin_manager->SetAuthenticatedUsername(username);
74 }
75 }
76
77 scoped_ptr<BookmarkBubbleView> bubble_;
78
79 private:
80 static BrowserContextKeyedService* BuildFakeSignInManager(
81 content::BrowserContext* profile) {
82 return new FakeSigninManager(static_cast<Profile*>(profile));
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 EXPECT_TRUE(bubble_->sync_promo_view_);
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698