#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/protector/mock_setting_change.h"
#include "chrome/browser/protector/protector_service.h"
#include "chrome/browser/protector/protector_service_factory.h"
#include "chrome/browser/protector/settings_change_global_error.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/global_error/global_error.h"
#include "chrome/browser/ui/global_error/global_error_bubble_view_base.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
using ::testing::InvokeWithoutArgs;
using ::testing::NiceMock;
using ::testing::Return;
namespace protector {
class ProtectorServiceTest : public InProcessBrowserTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kProtector);
}
virtual void SetUpOnMainThread() OVERRIDE {
protector_service_ =
ProtectorServiceFactory::GetForProfile(browser()->profile());
mock_change_ = new NiceMock<MockSettingChange>();
}
protected:
GlobalError* GetGlobalError(BaseSettingChange* change) {
for (ProtectorService::Items::iterator item =
protector_service_->items_.begin();
item != protector_service_->items_.end(); item++) {
if (item->change.get() == change)
return item->error.get();
}
return NULL;
}
bool IsGlobalErrorActive(BaseSettingChange* change) {
GlobalError* error = GetGlobalError(change);
if (!error)
return false;
if (!GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
GetGlobalErrorByMenuItemCommandID(error->MenuItemCommandID())) {
return false;
}
return protector_service_->IsShowingChange();
}
ProtectorService* protector_service_;
MockSettingChange* mock_change_;
};
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(false));
protector_service_->ShowChange(mock_change_);
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
protector_service_->DismissChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_CALL(*mock_change_, Apply(browser()));
protector_service_->ApplyChange(mock_change_, browser());
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
}
#if defined(OS_WIN)
#define MAYBE_ShowAndApplyManually DISABLED_ShowAndApplyManually
#else
#define MAYBE_ShowAndApplyManually ShowAndApplyManually
#endif
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, MAYBE_ShowAndApplyManually) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_CALL(*mock_change_, Apply(browser()));
GlobalError* error = GetGlobalError(mock_change_);
ASSERT_TRUE(error);
error->BubbleViewCancelButtonPressed(browser());
error->GetBubbleView()->CloseBubbleView();
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscard) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_CALL(*mock_change_, Discard(browser()));
protector_service_->DiscardChange(mock_change_, browser());
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
}
#if defined(OS_WIN)
#define MAYBE_ShowAndDiscardManually FLAKY_ShowAndDiscardManually
#else
#define MAYBE_ShowAndDiscardManually ShowAndDiscardManually
#endif
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, MAYBE_ShowAndDiscardManually) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_CALL(*mock_change_, Discard(browser()));
GlobalError* error = GetGlobalError(mock_change_);
ASSERT_TRUE(error);
error->BubbleViewAcceptButtonPressed(browser());
error->GetBubbleView()->CloseBubbleView();
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
GlobalError* error = GetGlobalError(mock_change_);
ASSERT_TRUE(error);
GlobalErrorBubbleViewBase* bubble_view = error->GetBubbleView();
ASSERT_TRUE(bubble_view);
EXPECT_CALL(*mock_change_, Apply(browser())).WillOnce(InvokeWithoutArgs(
bubble_view, &GlobalErrorBubbleViewBase::CloseBubbleView));
error->BubbleViewCancelButtonPressed(browser());
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
EXPECT_CALL(*mock_change_, Apply(browser()));
protector_service_->ApplyChange(mock_change_, browser());
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
EXPECT_CALL(*mock_change2, Apply(browser()));
protector_service_->ApplyChange(mock_change2, browser());
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
ShowMultipleChangesDismissAndApply) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
protector_service_->DismissChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
EXPECT_CALL(*mock_change2, Apply(browser()));
protector_service_->ApplyChange(mock_change2, browser());
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
ShowMultipleChangesAndApplyManually) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
GlobalError* error = GetGlobalError(mock_change_);
ASSERT_TRUE(error);
ASSERT_TRUE(error->HasShownBubbleView());
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
GlobalError* error2 = GetGlobalError(mock_change2);
ASSERT_TRUE(error2);
EXPECT_FALSE(error2->HasShownBubbleView());
EXPECT_CALL(*mock_change_, Apply(browser()));
error->BubbleViewCancelButtonPressed(browser());
error->GetBubbleView()->CloseBubbleView();
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
ASSERT_TRUE(error2->HasShownBubbleView());
EXPECT_CALL(*mock_change2, Apply(browser()));
error2->BubbleViewCancelButtonPressed(browser());
error2->GetBubbleView()->CloseBubbleView();
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
ShowMultipleChangesAndApplyManuallyBeforeOther) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
GlobalError* error = GetGlobalError(mock_change_);
ASSERT_TRUE(error);
ASSERT_TRUE(error->HasShownBubbleView());
EXPECT_CALL(*mock_change_, Apply(browser()));
error->BubbleViewCancelButtonPressed(browser());
error->GetBubbleView()->CloseBubbleView();
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
GlobalError* error2 = GetGlobalError(mock_change2);
ASSERT_TRUE(error2);
ASSERT_TRUE(error2->HasShownBubbleView());
EXPECT_CALL(*mock_change2, Apply(browser()));
error2->BubbleViewCancelButtonPressed(browser());
error2->GetBubbleView()->CloseBubbleView();
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleDifferentURLs) {
GURL url1("http://example.com/");
GURL url2("http://example.net/");
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
protector_service_->DismissChange(mock_change_);
protector_service_->DismissChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismiss) {
GURL url1("http://example.com/");
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
GlobalError* error = GetGlobalError(mock_change_);
ASSERT_TRUE(error);
EXPECT_TRUE(error->HasShownBubbleView());
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
BaseSettingChange* composite_change = protector_service_->GetLastChange();
ASSERT_TRUE(composite_change);
EXPECT_TRUE(IsGlobalErrorActive(composite_change));
GlobalError* error2 = GetGlobalError(composite_change);
ASSERT_TRUE(error2);
EXPECT_TRUE(error2->HasShownBubbleView());
protector_service_->DismissChange(composite_change);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(composite_change));
EXPECT_FALSE(protector_service_->GetLastChange());
MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change3);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
protector_service_->DismissChange(mock_change3);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndOther) {
GURL url1("http://example.com/");
GURL url2("http://example.net/");
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
BaseSettingChange* composite_change = protector_service_->GetLastChange();
ASSERT_TRUE(composite_change);
EXPECT_TRUE(IsGlobalErrorActive(composite_change));
MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change3);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
EXPECT_EQ(composite_change, protector_service_->GetLastChange());
EXPECT_TRUE(IsGlobalErrorActive(composite_change));
MockSettingChange* mock_change4 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change4, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change4, GetNewSettingURL()).WillRepeatedly(Return(url2));
EXPECT_CALL(*mock_change4, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change4);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(composite_change));
EXPECT_TRUE(IsGlobalErrorActive(mock_change4));
EXPECT_EQ(mock_change4, protector_service_->GetLastChange());
protector_service_->DismissChange(composite_change);
protector_service_->DismissChange(mock_change4);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(composite_change));
EXPECT_FALSE(IsGlobalErrorActive(mock_change4));
EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismissSingle) {
GURL url1("http://example.com/");
GURL url2("http://example.net/");
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
BaseSettingChange* composite_change = protector_service_->GetLastChange();
ASSERT_TRUE(composite_change);
EXPECT_TRUE(IsGlobalErrorActive(composite_change));
MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url2));
EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change3);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
EXPECT_TRUE(IsGlobalErrorActive(composite_change));
EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
protector_service_->DismissChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(composite_change));
EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
protector_service_->DismissChange(mock_change3);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, SameDomainDifferentURLs) {
GURL url1("http://www.example.com/abc");
GURL url2("http://example.com/def");
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
BaseSettingChange* composite_change = protector_service_->GetLastChange();
ASSERT_TRUE(composite_change);
EXPECT_TRUE(IsGlobalErrorActive(composite_change));
protector_service_->DismissChange(composite_change);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(composite_change));
EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, DifferentGoogleDomains) {
GURL url1("http://www.google.com/search?q=");
GURL url2("http://google.ru/search?q=");
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change_);
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
WillOnce(Return(true));
EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2));
EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
protector_service_->ShowChange(mock_change2);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
BaseSettingChange* composite_change = protector_service_->GetLastChange();
ASSERT_TRUE(composite_change);
EXPECT_TRUE(IsGlobalErrorActive(composite_change));
protector_service_->DismissChange(composite_change);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(composite_change));
EXPECT_FALSE(protector_service_->GetLastChange());
}
}