| 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/gtk/bookmarks/bookmark_bubble_gtk.h" | |
| 6 | |
| 7 #include "base/compiler_specific.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | |
| 10 #include "chrome/browser/bookmarks/bookmark_utils.h" | |
| 11 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "chrome/browser/ui/browser_window.h" | |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 15 #include "chrome/test/base/in_process_browser_test.h" | |
| 16 #include "chrome/test/base/ui_test_utils.h" | |
| 17 #include "components/signin/core/browser/signin_manager.h" | |
| 18 #include "content/public/browser/web_contents.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | |
| 20 | |
| 21 namespace { | |
| 22 const char kTestBookmarkURL[] = "http://www.google.com"; | |
| 23 } // namespace | |
| 24 | |
| 25 class BookmarkBubbleGtkBrowserTest : public InProcessBrowserTest { | |
| 26 public: | |
| 27 BookmarkBubbleGtkBrowserTest() {} | |
| 28 | |
| 29 // content::BrowserTestBase: | |
| 30 virtual void SetUpOnMainThread() OVERRIDE { | |
| 31 bookmark_utils::AddIfNotBookmarked( | |
| 32 BookmarkModelFactory::GetForProfile(browser()->profile()), | |
| 33 GURL(kTestBookmarkURL), | |
| 34 base::string16()); | |
| 35 } | |
| 36 | |
| 37 protected: | |
| 38 // Creates a bookmark bubble. | |
| 39 void CreateBookmarkBubble() { | |
| 40 BookmarkBubbleGtk::Show(GTK_WIDGET(browser()->window()->GetNativeWindow()), | |
| 41 browser()->profile(), | |
| 42 GURL(kTestBookmarkURL), | |
| 43 true); | |
| 44 } | |
| 45 | |
| 46 private: | |
| 47 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleGtkBrowserTest); | |
| 48 }; | |
| 49 | |
| 50 // Verifies that the sync promo is not displayed for a signed in user. | |
| 51 IN_PROC_BROWSER_TEST_F(BookmarkBubbleGtkBrowserTest, SyncPromoSignedIn) { | |
| 52 SigninManager* signin = SigninManagerFactory::GetForProfile( | |
| 53 browser()->profile()); | |
| 54 signin->SetAuthenticatedUsername("fake_username"); | |
| 55 | |
| 56 CreateBookmarkBubble(); | |
| 57 EXPECT_FALSE(BookmarkBubbleGtk::bookmark_bubble_->promo_); | |
| 58 } | |
| 59 | |
| 60 // Verifies that the sync promo is displayed for a user that is not signed in. | |
| 61 IN_PROC_BROWSER_TEST_F(BookmarkBubbleGtkBrowserTest, SyncPromoNotSignedIn) { | |
| 62 CreateBookmarkBubble(); | |
| 63 EXPECT_TRUE(BookmarkBubbleGtk::bookmark_bubble_->promo_); | |
| 64 } | |
| 65 | |
| 66 // Verifies that a new tab is opened when the "Sign in" link is clicked. | |
| 67 IN_PROC_BROWSER_TEST_F(BookmarkBubbleGtkBrowserTest, SyncPromoLink) { | |
| 68 GURL initial_url = | |
| 69 browser()->tab_strip_model()->GetActiveWebContents()->GetVisibleURL(); | |
| 70 CreateBookmarkBubble(); | |
| 71 | |
| 72 // Simulate clicking the "Sign in" link. | |
| 73 BookmarkBubbleGtk::bookmark_bubble_->OnSignInClicked(NULL, NULL); | |
| 74 | |
| 75 EXPECT_NE( | |
| 76 initial_url, | |
| 77 browser()->tab_strip_model()->GetActiveWebContents()->GetVisibleURL()); | |
| 78 } | |
| 79 | |
| OLD | NEW |