Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2393)

Unified Diff: chrome/browser/protector/protector_service_browsertest.cc

Issue 9500020: ProtectorService supports multiple change instances. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/protector/protector_service_browsertest.cc
diff --git a/chrome/browser/protector/protector_service_browsertest.cc b/chrome/browser/protector/protector_service_browsertest.cc
index 610af7eb61812a1594341fa9fe4a7e3374dc8489..55eccaa39cf071f9c2806e1b2ae010f6e0ca17e7 100644
--- a/chrome/browser/protector/protector_service_browsertest.cc
+++ b/chrome/browser/protector/protector_service_browsertest.cc
@@ -33,17 +33,32 @@ class ProtectorServiceTest : public InProcessBrowserTest {
}
protected:
- GlobalError* GetGlobalError() {
- return protector_service_->error_.get();
+ // Default NULL value for |change| argument means using |mock_change_|.
+
+ GlobalError* GetGlobalError(BaseSettingChange* change = NULL) {
+ if (!change)
+ change = mock_change_;
+ std::vector<ProtectorService::Item>::iterator item =
+ std::find_if(protector_service_->items_.begin(),
+ protector_service_->items_.end(),
+ ProtectorService::MatchItemByChange(change));
+ return item == protector_service_->items_.end() ?
+ NULL : item->error.get();
}
- void ExpectGlobalErrorActive(bool active) {
- GlobalError* error =
- GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
- GetGlobalErrorByMenuItemCommandID(IDC_SHOW_SETTINGS_CHANGES);
- EXPECT_EQ(active, error != NULL);
- EXPECT_EQ(active, GetGlobalError() != NULL);
- EXPECT_EQ(active, protector_service_->IsShowingChange());
+ // Checks that |protector_service_| has an error instance corresponding to
+ // |change| and that GlobalErrorService knows about it.
+ bool IsGlobalErrorActive(BaseSettingChange* change = NULL) {
+ if (!change)
+ change = mock_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_;
@@ -55,9 +70,9 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) {
EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
WillOnce(Return(false));
protector_service_->ShowChange(mock_change_);
- ExpectGlobalErrorActive(false);
+ EXPECT_FALSE(IsGlobalErrorActive());
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(false);
+ EXPECT_FALSE(IsGlobalErrorActive());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) {
@@ -66,10 +81,10 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) {
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(true);
- protector_service_->DismissChange();
+ EXPECT_TRUE(IsGlobalErrorActive());
+ protector_service_->DismissChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(false);
+ EXPECT_FALSE(IsGlobalErrorActive());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) {
@@ -78,11 +93,11 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) {
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(true);
+ EXPECT_TRUE(IsGlobalErrorActive());
EXPECT_CALL(*mock_change_, Apply(browser()));
- protector_service_->ApplyChange(browser());
+ protector_service_->ApplyChange(mock_change_, browser());
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(false);
+ EXPECT_FALSE(IsGlobalErrorActive());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApplyManually) {
@@ -91,14 +106,14 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApplyManually) {
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(true);
+ EXPECT_TRUE(IsGlobalErrorActive());
EXPECT_CALL(*mock_change_, Apply(browser()));
// Pressing Cancel applies the change.
GlobalError* error = GetGlobalError();
error->BubbleViewCancelButtonPressed(browser());
error->GetBubbleView()->CloseBubbleView();
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(false);
+ EXPECT_FALSE(IsGlobalErrorActive());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscard) {
@@ -107,11 +122,11 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscard) {
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(true);
+ EXPECT_TRUE(IsGlobalErrorActive());
EXPECT_CALL(*mock_change_, Discard(browser()));
- protector_service_->DiscardChange(browser());
+ protector_service_->DiscardChange(mock_change_, browser());
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(false);
+ EXPECT_FALSE(IsGlobalErrorActive());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscardManually) {
@@ -120,14 +135,14 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscardManually) {
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(true);
+ EXPECT_TRUE(IsGlobalErrorActive());
EXPECT_CALL(*mock_change_, Discard(browser()));
// Pressing Apply discards the change.
GlobalError* error = GetGlobalError();
error->BubbleViewAcceptButtonPressed(browser());
error->GetBubbleView()->CloseBubbleView();
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(false);
+ EXPECT_FALSE(IsGlobalErrorActive());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) {
@@ -135,7 +150,7 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) {
WillOnce(Return(true));
protector_service_->ShowChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(true);
+ EXPECT_TRUE(IsGlobalErrorActive());
GlobalError* error = GetGlobalError();
GlobalErrorBubbleViewBase* bubble_view = error->GetBubbleView();
@@ -146,7 +161,7 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) {
// Pressing Cancel applies the change.
error->BubbleViewCancelButtonPressed(browser());
ui_test_utils::RunAllPendingInMessageLoop();
- ExpectGlobalErrorActive(false);
+ EXPECT_FALSE(IsGlobalErrorActive());
}
// TODO(ivankr): Timeout test.

Powered by Google App Engine
This is Rietveld 408576698