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

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

Issue 9968007: [protector] Support for collapsing multiple changes into a single one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tried to compile after merge. Created 8 years, 8 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 17912ffe1c99ec6e105d6063dc61e3653a922c2c..bf662ace5df747b8af24164c3d19fa36e66f1261 100644
--- a/chrome/browser/protector/protector_service_browsertest.cc
+++ b/chrome/browser/protector/protector_service_browsertest.cc
@@ -34,12 +34,13 @@ class ProtectorServiceTest : public InProcessBrowserTest {
protected:
GlobalError* GetGlobalError(BaseSettingChange* 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();
+ 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;
}
// Checks that |protector_service_| has an error instance corresponding to
@@ -67,6 +68,7 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) {
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
+ EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) {
@@ -76,9 +78,11 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) {
protector_service_->ShowChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
+ EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
protector_service_->DismissChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
+ EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) {
@@ -167,6 +171,7 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) {
protector_service_->ShowChange(mock_change_);
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
+ EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
// ProtectService will own this change instance as well.
MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
@@ -177,6 +182,7 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) {
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
+ EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
// Apply the first change, the second should still be active.
EXPECT_CALL(*mock_change_, Apply(browser()));
@@ -184,6 +190,7 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) {
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
+ EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
// Finally apply the second change.
EXPECT_CALL(*mock_change2, Apply(browser()));
@@ -191,6 +198,7 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) {
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
+ EXPECT_FALSE(protector_service_->GetLastChange());
}
IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
@@ -320,6 +328,217 @@ IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
}
+IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleDifferentKeys) {
+ // Show the first change with some non-empty key.
+ EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change_, GetApplyKeyword()).WillRepeatedly(Return("K1"));
+ protector_service_->ShowChange(mock_change_);
+ ui_test_utils::RunAllPendingInMessageLoop();
+ EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
+ EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
+
+ // ProtectService will own this change instance as well.
+ MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
+ // Show the second change with another non-empty key.
+ EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change2, GetApplyKeyword()).WillRepeatedly(Return("K2"));
+ protector_service_->ShowChange(mock_change2);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // Both changes are shown separately, not composited.
+ 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);
+ ui_test_utils::RunAllPendingInMessageLoop();
+ EXPECT_FALSE(protector_service_->GetLastChange());
+}
+
+IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismiss) {
+ const std::string key1 = "K1";
+
+ // Show the first change.
+ EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change_, GetApplyKeyword()).WillRepeatedly(Return(key1));
+ protector_service_->ShowChange(mock_change_);
+ ui_test_utils::RunAllPendingInMessageLoop();
+ EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
+ EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
+
+ // The first bubble view has been displayed.
+ GlobalError* error = GetGlobalError(mock_change_);
+ ASSERT_TRUE(error);
+ EXPECT_TRUE(error->HasShownBubbleView());
+
+ // ProtectService will own this change instance as well.
+ MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
+ // Show the second change.
+ EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change2, GetApplyKeyword()).WillRepeatedly(Return(key1));
+ protector_service_->ShowChange(mock_change2);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // Now ProtectorService should be showing a single composite change.
+ 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));
+
+ // The second (composite) bubble view has been displayed.
+ GlobalError* error2 = GetGlobalError(composite_change);
+ ASSERT_TRUE(error2);
+ EXPECT_TRUE(error2->HasShownBubbleView());
+
+ protector_service_->DismissChange(composite_change);
+ ui_test_utils::RunAllPendingInMessageLoop();
+ EXPECT_FALSE(IsGlobalErrorActive(composite_change));
+ EXPECT_FALSE(protector_service_->GetLastChange());
+
+ // Show the third change.
+ MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
+ EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change3, GetApplyKeyword()).WillRepeatedly(Return(key1));
+ protector_service_->ShowChange(mock_change3);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // The third change should not be composed with the previous.
+ EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
+ EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
+
+ protector_service_->DismissChange(mock_change3);
+ ui_test_utils::RunAllPendingInMessageLoop();
+ EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
+ EXPECT_FALSE(protector_service_->GetLastChange());
+}
+
+IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndOther) {
+ const std::string key1 = "K1";
+ const std::string key2 = "K2";
+
+ // Show the first change.
+ EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change_, GetApplyKeyword()).WillRepeatedly(Return(key1));
+ protector_service_->ShowChange(mock_change_);
+ ui_test_utils::RunAllPendingInMessageLoop();
+ EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
+ EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
+
+ // ProtectService will own this change instance as well.
+ MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
+ // Show the second change.
+ EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change2, GetApplyKeyword()).WillRepeatedly(Return(key1));
+ protector_service_->ShowChange(mock_change2);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // Now ProtectorService should be showing a single composite change.
+ BaseSettingChange* composite_change = protector_service_->GetLastChange();
+ ASSERT_TRUE(composite_change);
+ EXPECT_TRUE(IsGlobalErrorActive(composite_change));
+
+ // Show the third change, with the same key as 1st and 2nd.
+ MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
+ EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change3, GetApplyKeyword()).WillRepeatedly(Return(key1));
+ protector_service_->ShowChange(mock_change3);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // The third change should be composed with the previous.
+ EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
+ EXPECT_EQ(composite_change, protector_service_->GetLastChange());
+ EXPECT_TRUE(IsGlobalErrorActive(composite_change));
+
+ // Show the 4th change, now with a different key.
+ MockSettingChange* mock_change4 = new NiceMock<MockSettingChange>();
+ EXPECT_CALL(*mock_change4, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change4, GetApplyKeyword()).WillRepeatedly(Return(key2));
+ protector_service_->ShowChange(mock_change4);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // The 4th change is shown independently.
+ 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);
+ ui_test_utils::RunAllPendingInMessageLoop();
+ EXPECT_FALSE(IsGlobalErrorActive(composite_change));
+ EXPECT_FALSE(IsGlobalErrorActive(mock_change4));
+ EXPECT_FALSE(protector_service_->GetLastChange());
+}
+
+IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismissSingle) {
+ const std::string key1 = "K1";
+ const std::string key2 = "K2";
+
+ // Show the first change.
+ EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change_, GetApplyKeyword()).WillRepeatedly(Return(key1));
+ protector_service_->ShowChange(mock_change_);
+ ui_test_utils::RunAllPendingInMessageLoop();
+ EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
+ EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
+
+ // ProtectService will own this change instance as well.
+ MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
+ // Show the second change.
+ EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change2, GetApplyKeyword()).WillRepeatedly(Return(key1));
+ protector_service_->ShowChange(mock_change2);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // Now ProtectorService should be showing a single composite change.
+ 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));
+
+ // Show the third change with a different key.
+ MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
+ EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_change3, GetApplyKeyword()).WillRepeatedly(Return(key2));
+ protector_service_->ShowChange(mock_change3);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // The third change should not be composed with the previous.
+ EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
+ EXPECT_TRUE(IsGlobalErrorActive(composite_change));
+ EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
+
+ // Now dismiss the first change.
+ protector_service_->DismissChange(mock_change_);
+ ui_test_utils::RunAllPendingInMessageLoop();
+
+ // This should effectively dismiss the whole composite change.
+ EXPECT_FALSE(IsGlobalErrorActive(composite_change));
+ EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
+ EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
+
+ protector_service_->DismissChange(mock_change3);
+ ui_test_utils::RunAllPendingInMessageLoop();
+ EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
+ EXPECT_FALSE(protector_service_->GetLastChange());
+}
+
// TODO(ivankr): Timeout test.
} // namespace protector

Powered by Google App Engine
This is Rietveld 408576698