Home | History | Annotate | Download | only in bookmarks
      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/bookmarks/bookmark_bubble_sign_in_delegate.h"
      6 
      7 #include "base/memory/scoped_ptr.h"
      8 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
      9 #include "chrome/browser/ui/browser.h"
     10 #include "chrome/browser/ui/browser_list.h"
     11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
     12 #include "chrome/test/base/browser_with_test_window_test.h"
     13 #include "ui/base/events/event_constants.h"
     14 #include "ui/base/range/range.h"
     15 
     16 typedef BrowserWithTestWindowTest BookmarkBubbleSignInDelegateTest;
     17 
     18 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) {
     19   int starting_tab_count = browser()->tab_strip_model()->count();
     20 
     21   scoped_ptr<BookmarkBubbleDelegate> delegate;
     22   delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
     23 
     24   delegate->OnSignInLinkClicked();
     25 
     26   // A new tab should have been opened.
     27   int tab_count = browser()->tab_strip_model()->count();
     28   EXPECT_EQ(starting_tab_count + 1, tab_count);
     29 }
     30 
     31 // Verifies that the sign in page can be loaded in a different browser
     32 // if the provided browser is invalidated.
     33 TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) {
     34   // Create an extra browser.
     35   scoped_ptr<BrowserWindow> extra_window;
     36   extra_window.reset(CreateBrowserWindow());
     37 
     38   Browser::CreateParams params(browser()->profile(),
     39                                browser()->host_desktop_type());
     40   params.window = extra_window.get();
     41   scoped_ptr<Browser> extra_browser;
     42   extra_browser.reset(new Browser(params));
     43 
     44   int starting_tab_count = extra_browser->tab_strip_model()->count();
     45 
     46   scoped_ptr<BookmarkBubbleDelegate> delegate;
     47   delegate.reset(new BookmarkBubbleSignInDelegate(browser()));
     48 
     49   BrowserList::SetLastActive(extra_browser.get());
     50 
     51   browser()->tab_strip_model()->CloseAllTabs();
     52   set_browser(NULL);
     53 
     54   delegate->OnSignInLinkClicked();
     55 
     56   // A new tab should have been opened in the extra browser.
     57   int tab_count = extra_browser->tab_strip_model()->count();
     58   EXPECT_EQ(starting_tab_count + 1, tab_count);
     59 
     60   // Required to avoid a crash when the browser is deleted.
     61   extra_browser->tab_strip_model()->CloseAllTabs();
     62 }
     63