Chromium Code Reviews| 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h" | 8 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/test/base/browser_with_test_window_test.h" | 12 #include "chrome/test/base/browser_with_test_window_test.h" |
| 13 #include "chrome/test/base/testing_profile.h" | |
| 13 #include "ui/base/events/event_constants.h" | 14 #include "ui/base/events/event_constants.h" |
| 14 #include "ui/base/range/range.h" | 15 #include "ui/base/range/range.h" |
| 15 | 16 |
| 16 typedef BrowserWithTestWindowTest BookmarkBubbleSignInDelegateTest; | 17 class BookmarkBubbleSignInDelegateTest : public BrowserWithTestWindowTest { |
| 18 public: | |
| 19 BookmarkBubbleSignInDelegateTest() {} | |
| 20 | |
| 21 protected: | |
| 22 class Window : public TestBrowserWindow { | |
| 23 public: | |
| 24 Window() : show_count_(0) {} | |
| 25 | |
| 26 // ui::BaseWindow: | |
| 27 virtual void Show() OVERRIDE { | |
|
tfarina
2013/08/31 01:32:05
can this be in private section?
also
// TestBrow
fdoray
2013/09/03 01:38:57
Done.
| |
| 28 ++show_count_; | |
| 29 } | |
| 30 | |
| 31 // Number of times that the Show() method has been called. | |
| 32 int show_count_; | |
|
tfarina
2013/08/31 01:32:05
please, make this private, add a public getter for
fdoray
2013/09/03 01:38:57
Done.
| |
| 33 }; | |
| 34 | |
| 35 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE { | |
| 36 return new Window(); | |
| 37 } | |
| 38 }; | |
| 17 | 39 |
| 18 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { | 40 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClicked) { |
| 19 int starting_tab_count = browser()->tab_strip_model()->count(); | 41 int starting_tab_count = browser()->tab_strip_model()->count(); |
| 20 | 42 |
| 21 scoped_ptr<BookmarkBubbleDelegate> delegate; | 43 scoped_ptr<BookmarkBubbleDelegate> delegate; |
| 22 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 44 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
| 23 | 45 |
| 24 delegate->OnSignInLinkClicked(); | 46 delegate->OnSignInLinkClicked(); |
| 25 | 47 |
| 26 // A new tab should have been opened. | 48 // A new tab should have been opened and the browser should be visible. |
| 27 int tab_count = browser()->tab_strip_model()->count(); | 49 int tab_count = browser()->tab_strip_model()->count(); |
| 28 EXPECT_EQ(starting_tab_count + 1, tab_count); | 50 EXPECT_EQ(starting_tab_count + 1, tab_count); |
| 51 EXPECT_EQ(1, | |
| 52 static_cast<BookmarkBubbleSignInDelegateTest::Window*>( | |
| 53 browser()->window())->show_count_); | |
| 54 } | |
| 55 | |
| 56 TEST_F(BookmarkBubbleSignInDelegateTest, OnSignInLinkClickedIncognito) { | |
| 57 // Create an incognito browser. | |
| 58 TestingProfile::Builder incognito_profile_builder; | |
| 59 incognito_profile_builder.SetIncognito(); | |
| 60 scoped_ptr<TestingProfile> incognito_profile = | |
| 61 incognito_profile_builder.Build(); | |
| 62 incognito_profile->SetOriginalProfile(profile()); | |
| 63 profile()->SetOffTheRecordProfile(incognito_profile.Pass()); | |
| 64 | |
| 65 scoped_ptr<BrowserWindow> incognito_window; | |
| 66 incognito_window.reset(CreateBrowserWindow()); | |
| 67 Browser::CreateParams params(browser()->profile()->GetOffTheRecordProfile(), | |
| 68 browser()->host_desktop_type()); | |
| 69 params.window = incognito_window.get(); | |
| 70 scoped_ptr<Browser> incognito_browser; | |
| 71 incognito_browser.reset(new Browser(params)); | |
| 72 | |
| 73 int starting_tab_count_normal = browser()->tab_strip_model()->count(); | |
| 74 int starting_tab_count_incognito = | |
| 75 incognito_browser.get()->tab_strip_model()->count(); | |
| 76 | |
| 77 scoped_ptr<BookmarkBubbleDelegate> delegate; | |
| 78 delegate.reset(new BookmarkBubbleSignInDelegate(incognito_browser.get())); | |
| 79 | |
| 80 delegate->OnSignInLinkClicked(); | |
| 81 | |
| 82 // A new tab should have been opened in the normal browser, which should be | |
| 83 // visible. | |
| 84 int tab_count_normal = browser()->tab_strip_model()->count(); | |
| 85 EXPECT_EQ(starting_tab_count_normal + 1, tab_count_normal); | |
| 86 EXPECT_EQ(1, | |
| 87 static_cast<BookmarkBubbleSignInDelegateTest::Window*>( | |
| 88 browser()->window())->show_count_); | |
| 89 | |
| 90 // No effect is expected on the incognito browser. | |
| 91 int tab_count_incognito = incognito_browser->tab_strip_model()->count(); | |
| 92 EXPECT_EQ(starting_tab_count_incognito, tab_count_incognito); | |
| 93 EXPECT_EQ(0, | |
| 94 static_cast<BookmarkBubbleSignInDelegateTest::Window*>( | |
| 95 incognito_window.get())->show_count_); | |
| 29 } | 96 } |
| 30 | 97 |
| 31 // Verifies that the sign in page can be loaded in a different browser | 98 // Verifies that the sign in page can be loaded in a different browser |
| 32 // if the provided browser is invalidated. | 99 // if the provided browser is invalidated. |
| 33 TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { | 100 TEST_F(BookmarkBubbleSignInDelegateTest, BrowserRemoved) { |
| 34 // Create an extra browser. | 101 // Create an extra browser. |
| 35 scoped_ptr<BrowserWindow> extra_window; | 102 scoped_ptr<BrowserWindow> extra_window; |
| 36 extra_window.reset(CreateBrowserWindow()); | 103 extra_window.reset(CreateBrowserWindow()); |
| 37 | 104 |
| 38 Browser::CreateParams params(browser()->profile(), | 105 Browser::CreateParams params(browser()->profile(), |
| 39 browser()->host_desktop_type()); | 106 browser()->host_desktop_type()); |
| 40 params.window = extra_window.get(); | 107 params.window = extra_window.get(); |
| 41 scoped_ptr<Browser> extra_browser; | 108 scoped_ptr<Browser> extra_browser; |
| 42 extra_browser.reset(new Browser(params)); | 109 extra_browser.reset(new Browser(params)); |
| 43 | 110 |
| 44 int starting_tab_count = extra_browser->tab_strip_model()->count(); | 111 int starting_tab_count = extra_browser->tab_strip_model()->count(); |
| 45 | 112 |
| 46 scoped_ptr<BookmarkBubbleDelegate> delegate; | 113 scoped_ptr<BookmarkBubbleDelegate> delegate; |
| 47 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); | 114 delegate.reset(new BookmarkBubbleSignInDelegate(browser())); |
| 48 | 115 |
| 49 BrowserList::SetLastActive(extra_browser.get()); | 116 BrowserList::SetLastActive(extra_browser.get()); |
| 50 | 117 |
| 51 browser()->tab_strip_model()->CloseAllTabs(); | 118 browser()->tab_strip_model()->CloseAllTabs(); |
| 52 set_browser(NULL); | 119 set_browser(NULL); |
| 53 | 120 |
| 54 delegate->OnSignInLinkClicked(); | 121 delegate->OnSignInLinkClicked(); |
| 55 | 122 |
| 56 // A new tab should have been opened in the extra browser. | 123 // A new tab should have been opened in the extra browser, which should be |
| 124 // visible. | |
| 57 int tab_count = extra_browser->tab_strip_model()->count(); | 125 int tab_count = extra_browser->tab_strip_model()->count(); |
| 58 EXPECT_EQ(starting_tab_count + 1, tab_count); | 126 EXPECT_EQ(starting_tab_count + 1, tab_count); |
| 127 EXPECT_EQ(1, | |
| 128 static_cast<BookmarkBubbleSignInDelegateTest::Window*>( | |
| 129 extra_window.get())->show_count_); | |
| 59 | 130 |
| 60 // Required to avoid a crash when the browser is deleted. | 131 // Required to avoid a crash when the browser is deleted. |
| 61 extra_browser->tab_strip_model()->CloseAllTabs(); | 132 extra_browser->tab_strip_model()->CloseAllTabs(); |
| 62 } | 133 } |
| OLD | NEW |