| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" | 5 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/extensions/test_extension_service.h" |
| 11 #include "chrome/browser/extensions/test_extension_system.h" |
| 9 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h" | 12 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h" |
| 10 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/test/base/browser_with_test_window_test.h" | 16 #include "chrome/test/base/browser_with_test_window_test.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 15 #include "ui/events/event_constants.h" | 18 #include "ui/events/event_constants.h" |
| 16 #include "ui/gfx/range/range.h" | 19 #include "ui/gfx/range/range.h" |
| 17 | 20 |
| 18 class BookmarkBubbleSignInDelegateTest : public BrowserWithTestWindowTest { | 21 class BookmarkBubbleSignInDelegateTest : public BrowserWithTestWindowTest { |
| 19 public: | 22 public: |
| 20 BookmarkBubbleSignInDelegateTest() {} | 23 BookmarkBubbleSignInDelegateTest() {} |
| 21 | 24 |
| 25 virtual void SetUp() OVERRIDE; |
| 26 |
| 22 protected: | 27 protected: |
| 23 class Window : public TestBrowserWindow { | 28 class Window : public TestBrowserWindow { |
| 24 public: | 29 public: |
| 25 Window() : show_count_(0) {} | 30 Window() : show_count_(0) {} |
| 26 | 31 |
| 27 int show_count() { return show_count_; } | 32 int show_count() { return show_count_; } |
| 28 | 33 |
| 29 private: | 34 private: |
| 30 // TestBrowserWindow: | 35 // TestBrowserWindow: |
| 31 virtual void Show() OVERRIDE { | 36 virtual void Show() OVERRIDE { |
| 32 ++show_count_; | 37 ++show_count_; |
| 33 } | 38 } |
| 34 | 39 |
| 35 // Number of times that the Show() method has been called. | 40 // Number of times that the Show() method has been called. |
| 36 int show_count_; | 41 int show_count_; |
| 37 | 42 |
| 38 DISALLOW_COPY_AND_ASSIGN(Window); | 43 DISALLOW_COPY_AND_ASSIGN(Window); |
| 39 }; | 44 }; |
| 40 | 45 |
| 41 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE { | 46 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE { |
| 42 return new Window(); | 47 return new Window(); |
| 43 } | 48 } |
| 44 | 49 |
| 45 private: | 50 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); | 51 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleSignInDelegateTest); |
| 47 }; | 52 }; |
| 48 | 53 |
| 54 void BookmarkBubbleSignInDelegateTest::SetUp() { |
| 55 BrowserWithTestWindowTest::SetUp(); |
| 56 // Adds TestExtensionSystem, since signin uses the gaia auth extension. |
| 57 extensions::TestExtensionSystem* extension_system( |
| 58 static_cast<extensions::TestExtensionSystem*>( |
| 59 extensions::ExtensionSystem::Get(profile()))); |
| 60 extension_system->CreateExtensionService( |
| 61 CommandLine::ForCurrentProcess(), base::FilePath(), false); |
| 62 } |
| 63 |
| 49 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { | 64 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { |
| 50 int starting_tab_count = browser()->tab_strip_model()->count(); | 65 int starting_tab_count = browser()->tab_strip_model()->count(); |
| 51 | 66 |
| 52 scoped_ptr<BookmarkBubbleDelegate> delegate; | 67 scoped_ptr<BookmarkBubbleDelegate> delegate; |
| 53 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 68 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
| 54 | 69 |
| 55 delegate->OnSignInLinkClicked(); | 70 delegate->OnSignInLinkClicked(); |
| 56 | 71 |
| 57 // A new tab should have been opened and the browser should be visible. | 72 // A new tab should have been opened and the browser should be visible. |
| 58 int tab_count = browser()->tab_strip_model()->count(); | 73 int tab_count = browser()->tab_strip_model()->count(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // visible. | 148 // visible. |
| 134 int tab_count = extra_browser->tab_strip_model()->count(); | 149 int tab_count = extra_browser->tab_strip_model()->count(); |
| 135 EXPECT_EQ(starting_tab_count + 1, tab_count); | 150 EXPECT_EQ(starting_tab_count + 1, tab_count); |
| 136 EXPECT_LE(1, | 151 EXPECT_LE(1, |
| 137 static_cast<BookmarkBubbleSignInDelegateTest::Window*>( | 152 static_cast<BookmarkBubbleSignInDelegateTest::Window*>( |
| 138 extra_window.get())->show_count()); | 153 extra_window.get())->show_count()); |
| 139 | 154 |
| 140 // Required to avoid a crash when the browser is deleted. | 155 // Required to avoid a crash when the browser is deleted. |
| 141 extra_browser->tab_strip_model()->CloseAllTabs(); | 156 extra_browser->tab_strip_model()->CloseAllTabs(); |
| 142 } | 157 } |
| OLD | NEW |