Index: chrome/browser/ui/search/search_tab_helper_unittest.cc |
diff --git a/chrome/browser/ui/search/search_tab_helper_unittest.cc b/chrome/browser/ui/search/search_tab_helper_unittest.cc |
index cd277ace38b8f428150f81d8a8c7ae2abd885735..92a3124e9513e7ee8cbcfac1fd4513a97b0a5cdc 100644 |
--- a/chrome/browser/ui/search/search_tab_helper_unittest.cc |
+++ b/chrome/browser/ui/search/search_tab_helper_unittest.cc |
@@ -12,6 +12,9 @@ |
#include "chrome/browser/search_engines/template_url_service_factory.h" |
#include "chrome/browser/signin/fake_signin_manager.h" |
#include "chrome/browser/signin/signin_manager_factory.h" |
+#include "chrome/browser/sync/profile_sync_service.h" |
+#include "chrome/browser/sync/profile_sync_service_factory.h" |
+#include "chrome/browser/sync/profile_sync_service_mock.h" |
#include "chrome/browser/ui/search/search_ipc_router.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/common/chrome_switches.h" |
@@ -36,6 +39,8 @@ |
#include "ui/base/l10n/l10n_util.h" |
#include "url/gurl.h" |
+using testing::Return; |
+ |
namespace { |
class MockSearchIPCRouterDelegate : public SearchIPCRouter::Delegate { |
@@ -71,12 +76,16 @@ class SearchTabHelperTest : public ChromeRenderViewHostTestHarness { |
TestingProfile::Builder builder; |
builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
FakeSigninManagerBase::Build); |
+ builder.AddTestingFactory( |
+ ProfileSyncServiceFactory::GetInstance(), |
+ ProfileSyncServiceMock::BuildMockProfileSyncService); |
return builder.Build().release(); |
} |
// Creates a sign-in manager for tests. If |username| is not empty, the |
// testing profile of the WebContents will be connected to the given account. |
- void CreateSigninManager(const std::string& username) { |
+ // The account can be configured to |sync_history| or not. |
+ void CreateSigninManager(const std::string& username, bool sync_history) { |
SigninManagerBase* signin_manager = static_cast<SigninManagerBase*>( |
SigninManagerFactory::GetForProfile(profile())); |
@@ -84,6 +93,17 @@ class SearchTabHelperTest : public ChromeRenderViewHostTestHarness { |
ASSERT_TRUE(signin_manager); |
signin_manager->SetAuthenticatedUsername(username); |
} |
+ |
+ ProfileSyncServiceMock* sync_service = static_cast<ProfileSyncServiceMock*>( |
+ ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile())); |
+ |
+ EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(true)); |
+ syncer::ModelTypeSet result; |
+ if (sync_history) { |
+ result.Put(syncer::HISTORY_DELETE_DIRECTIVES); |
+ } |
+ EXPECT_CALL(*sync_service, GetActiveDataTypes()) |
+ .WillRepeatedly(Return(result)); |
} |
bool MessageWasSent(uint32 id) { |
@@ -146,7 +166,7 @@ TEST_F(SearchTabHelperTest, PageURLDoesntBelongToInstantRenderer) { |
TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatch) { |
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
- CreateSigninManager(std::string("foo@bar.com")); |
+ CreateSigninManager(std::string("foo@bar.com"), true); |
SearchTabHelper* search_tab_helper = |
SearchTabHelper::FromWebContents(web_contents()); |
ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
@@ -166,7 +186,7 @@ TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatch) { |
TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMismatch) { |
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
- CreateSigninManager(std::string("foo@bar.com")); |
+ CreateSigninManager(std::string("foo@bar.com"), true); |
SearchTabHelper* search_tab_helper = |
SearchTabHelper::FromWebContents(web_contents()); |
ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
@@ -187,6 +207,9 @@ TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMismatch) { |
TEST_F(SearchTabHelperTest, OnChromeIdentityCheckSignedOutMatch) { |
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
// This test does not sign in. |
+ ProfileSyncServiceMock* sync_service = static_cast<ProfileSyncServiceMock*>( |
+ ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile())); |
+ EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(false)); |
SearchTabHelper* search_tab_helper = |
SearchTabHelper::FromWebContents(web_contents()); |
ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
@@ -201,12 +224,15 @@ TEST_F(SearchTabHelperTest, OnChromeIdentityCheckSignedOutMatch) { |
ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
EXPECT_EQ(test_identity, params.a); |
- ASSERT_TRUE(params.b); |
+ ASSERT_FALSE(params.b); |
} |
TEST_F(SearchTabHelperTest, OnChromeIdentityCheckSignedOutMismatch) { |
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
// This test does not sign in. |
+ ProfileSyncServiceMock* sync_service = static_cast<ProfileSyncServiceMock*>( |
+ ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile())); |
+ EXPECT_CALL(*sync_service, sync_initialized()).WillRepeatedly(Return(false)); |
SearchTabHelper* search_tab_helper = |
SearchTabHelper::FromWebContents(web_contents()); |
ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
@@ -224,6 +250,26 @@ TEST_F(SearchTabHelperTest, OnChromeIdentityCheckSignedOutMismatch) { |
ASSERT_FALSE(params.b); |
} |
+TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatchNotSyncing) { |
+ NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); |
+ CreateSigninManager(std::string("foo@bar.com"), false); |
+ SearchTabHelper* search_tab_helper = |
+ SearchTabHelper::FromWebContents(web_contents()); |
+ ASSERT_NE(static_cast<SearchTabHelper*>(NULL), search_tab_helper); |
+ |
+ const base::string16 test_identity = base::ASCIIToUTF16("foo@bar.com"); |
+ search_tab_helper->OnChromeIdentityCheck(test_identity); |
+ |
+ const IPC::Message* message = process()->sink().GetUniqueMessageMatching( |
+ ChromeViewMsg_ChromeIdentityCheckResult::ID); |
+ ASSERT_TRUE(message != NULL); |
+ |
+ ChromeViewMsg_ChromeIdentityCheckResult::Param params; |
+ ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); |
+ EXPECT_EQ(test_identity, params.a); |
+ ASSERT_FALSE(params.b); |
+} |
+ |
class TabTitleObserver : public content::WebContentsObserver { |
public: |
explicit TabTitleObserver(content::WebContents* contents) |