This source file includes following definitions.
- CreateTestWebContents
- TEST_F
- window_bookmark_bar_state
- SetUp
- CreateBrowserWindow
- bookmark_bar_state_
- set_browser
- bookmark_bar_state
- BookmarkBarStateChanged
- OnActiveTabChanged
- TEST_F
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/web_contents_tester.h"
#if !defined(OS_ANDROID) && !defined(OS_IOS)
using content::SiteInstance;
using content::WebContents;
using content::WebContentsTester;
class BrowserUnitTest : public BrowserWithTestWindowTest {
public:
BrowserUnitTest() {}
virtual ~BrowserUnitTest() {}
WebContents* CreateTestWebContents() {
return WebContentsTester::CreateTestWebContents(
profile(), SiteInstance::Create(profile()));
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserUnitTest);
};
TEST_F(BrowserUnitTest, ReloadCrashedTab) {
TabStripModel* tab_strip_model = browser()->tab_strip_model();
WebContents* contents1 = CreateTestWebContents();
tab_strip_model->AppendWebContents(contents1, true);
WebContentsTester::For(contents1)->NavigateAndCommit(GURL("about:blank"));
WebContentsTester::For(contents1)->TestSetIsLoading(false);
EXPECT_TRUE(tab_strip_model->IsTabSelected(0));
EXPECT_FALSE(contents1->IsLoading());
WebContents* contents2 = CreateTestWebContents();
tab_strip_model->AppendWebContents(contents2, false);
WebContentsTester::For(contents2)->NavigateAndCommit(GURL("about:blank"));
WebContentsTester::For(contents2)->TestSetIsLoading(false);
EXPECT_EQ(2, browser()->tab_strip_model()->count());
EXPECT_TRUE(tab_strip_model->IsTabSelected(0));
EXPECT_FALSE(contents2->IsLoading());
contents2->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED, -1);
EXPECT_TRUE(contents2->IsCrashed());
tab_strip_model->ActivateTabAt(1, true);
EXPECT_TRUE(tab_strip_model->IsTabSelected(1));
EXPECT_FALSE(contents2->IsLoading());
EXPECT_TRUE(contents2->IsCrashed());
}
class BrowserBookmarkBarTest : public BrowserWithTestWindowTest {
public:
BrowserBookmarkBarTest() {}
virtual ~BrowserBookmarkBarTest() {}
protected:
BookmarkBar::State window_bookmark_bar_state() const {
return static_cast<BookmarkBarStateTestBrowserWindow*>(
browser()->window())->bookmark_bar_state();
}
virtual void SetUp() OVERRIDE {
BrowserWithTestWindowTest::SetUp();
static_cast<BookmarkBarStateTestBrowserWindow*>(
browser()->window())->set_browser(browser());
}
virtual BrowserWindow* CreateBrowserWindow() OVERRIDE {
return new BookmarkBarStateTestBrowserWindow();
}
private:
class BookmarkBarStateTestBrowserWindow : public TestBrowserWindow {
public:
BookmarkBarStateTestBrowserWindow()
: browser_(NULL),
bookmark_bar_state_(BookmarkBar::HIDDEN) {}
virtual ~BookmarkBarStateTestBrowserWindow() {}
void set_browser(Browser* browser) { browser_ = browser; }
BookmarkBar::State bookmark_bar_state() const {
return bookmark_bar_state_;
}
private:
virtual void BookmarkBarStateChanged(
BookmarkBar::AnimateChangeType change_type) OVERRIDE {
bookmark_bar_state_ = browser_->bookmark_bar_state();
TestBrowserWindow::BookmarkBarStateChanged(change_type);
}
virtual void OnActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) OVERRIDE {
bookmark_bar_state_ = browser_->bookmark_bar_state();
TestBrowserWindow::OnActiveTabChanged(old_contents, new_contents, index,
reason);
}
Browser* browser_;
BookmarkBar::State bookmark_bar_state_;
DISALLOW_COPY_AND_ASSIGN(BookmarkBarStateTestBrowserWindow);
};
DISALLOW_COPY_AND_ASSIGN(BrowserBookmarkBarTest);
};
TEST_F(BrowserBookmarkBarTest, StateOnActiveTabChanged) {
ASSERT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
ASSERT_EQ(BookmarkBar::HIDDEN, window_bookmark_bar_state());
GURL ntp_url("chrome://newtab");
GURL non_ntp_url("http://foo");
AddTab(browser(), ntp_url);
EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state());
EXPECT_EQ(BookmarkBar::DETACHED, window_bookmark_bar_state());
NavigateAndCommitActiveTab(non_ntp_url);
EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
EXPECT_EQ(BookmarkBar::HIDDEN, window_bookmark_bar_state());
AddTab(browser(), ntp_url);
EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state());
EXPECT_EQ(BookmarkBar::DETACHED, window_bookmark_bar_state());
browser()->tab_strip_model()->ActivateTabAt(1, true);
EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
EXPECT_EQ(BookmarkBar::HIDDEN, window_bookmark_bar_state());
chrome::ToggleBookmarkBar(browser());
EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
EXPECT_EQ(BookmarkBar::SHOW, window_bookmark_bar_state());
browser()->tab_strip_model()->ActivateTabAt(0, true);
EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
EXPECT_EQ(BookmarkBar::SHOW, window_bookmark_bar_state());
browser()->tab_strip_model()->ActivateTabAt(1, true);
EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
EXPECT_EQ(BookmarkBar::SHOW, window_bookmark_bar_state());
}
#endif