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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/protector/mock_setting_change.h" 8 #include "chrome/browser/protector/mock_setting_change.h"
9 #include "chrome/browser/protector/protector_service.h" 9 #include "chrome/browser/protector/protector_service.h"
10 #include "chrome/browser/protector/protector_service_factory.h" 10 #include "chrome/browser/protector/protector_service_factory.h"
(...skipping 15 matching lines...) Expand all
26 class ProtectorServiceTest : public InProcessBrowserTest { 26 class ProtectorServiceTest : public InProcessBrowserTest {
27 public: 27 public:
28 virtual void SetUpOnMainThread() { 28 virtual void SetUpOnMainThread() {
29 protector_service_ = 29 protector_service_ =
30 ProtectorServiceFactory::GetForProfile(browser()->profile()); 30 ProtectorServiceFactory::GetForProfile(browser()->profile());
31 // ProtectService will own this change instance. 31 // ProtectService will own this change instance.
32 mock_change_ = new NiceMock<MockSettingChange>(); 32 mock_change_ = new NiceMock<MockSettingChange>();
33 } 33 }
34 34
35 protected: 35 protected:
36 GlobalError* GetGlobalError() { 36 // Default NULL value for |change| argument means using |mock_change_|.
37 return protector_service_->error_.get(); 37
38 GlobalError* GetGlobalError(BaseSettingChange* change = NULL) {
39 if (!change)
40 change = mock_change_;
41 std::vector<ProtectorService::Item>::iterator item =
42 std::find_if(protector_service_->items_.begin(),
43 protector_service_->items_.end(),
44 ProtectorService::MatchItemByChange(change));
45 return item == protector_service_->items_.end() ?
46 NULL : item->error.get();
38 } 47 }
39 48
40 void ExpectGlobalErrorActive(bool active) { 49 // Checks that |protector_service_| has an error instance corresponding to
41 GlobalError* error = 50 // |change| and that GlobalErrorService knows about it.
42 GlobalErrorServiceFactory::GetForProfile(browser()->profile())-> 51 bool IsGlobalErrorActive(BaseSettingChange* change = NULL) {
43 GetGlobalErrorByMenuItemCommandID(IDC_SHOW_SETTINGS_CHANGES); 52 if (!change)
44 EXPECT_EQ(active, error != NULL); 53 change = mock_change_;
45 EXPECT_EQ(active, GetGlobalError() != NULL); 54 GlobalError* error = GetGlobalError(change);
46 EXPECT_EQ(active, protector_service_->IsShowingChange()); 55 if (!error)
56 return false;
57 if (!GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
58 GetGlobalErrorByMenuItemCommandID(error->MenuItemCommandID())) {
59 return false;
60 }
61 return protector_service_->IsShowingChange();
47 } 62 }
48 63
49 ProtectorService* protector_service_; 64 ProtectorService* protector_service_;
50 MockSettingChange* mock_change_; 65 MockSettingChange* mock_change_;
51 }; 66 };
52 67
53 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) { 68 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) {
54 // Init fails and causes the change to be ignored. 69 // Init fails and causes the change to be ignored.
55 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 70 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
56 WillOnce(Return(false)); 71 WillOnce(Return(false));
57 protector_service_->ShowChange(mock_change_); 72 protector_service_->ShowChange(mock_change_);
58 ExpectGlobalErrorActive(false); 73 EXPECT_FALSE(IsGlobalErrorActive());
59 ui_test_utils::RunAllPendingInMessageLoop(); 74 ui_test_utils::RunAllPendingInMessageLoop();
60 ExpectGlobalErrorActive(false); 75 EXPECT_FALSE(IsGlobalErrorActive());
61 } 76 }
62 77
63 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) { 78 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) {
64 // Show the change and immediately dismiss it. 79 // Show the change and immediately dismiss it.
65 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 80 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
66 WillOnce(Return(true)); 81 WillOnce(Return(true));
67 protector_service_->ShowChange(mock_change_); 82 protector_service_->ShowChange(mock_change_);
68 ui_test_utils::RunAllPendingInMessageLoop(); 83 ui_test_utils::RunAllPendingInMessageLoop();
69 ExpectGlobalErrorActive(true); 84 EXPECT_TRUE(IsGlobalErrorActive());
70 protector_service_->DismissChange(); 85 protector_service_->DismissChange(mock_change_);
71 ui_test_utils::RunAllPendingInMessageLoop(); 86 ui_test_utils::RunAllPendingInMessageLoop();
72 ExpectGlobalErrorActive(false); 87 EXPECT_FALSE(IsGlobalErrorActive());
73 } 88 }
74 89
75 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) { 90 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) {
76 // Show the change and apply it. 91 // Show the change and apply it.
77 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 92 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
78 WillOnce(Return(true)); 93 WillOnce(Return(true));
79 protector_service_->ShowChange(mock_change_); 94 protector_service_->ShowChange(mock_change_);
80 ui_test_utils::RunAllPendingInMessageLoop(); 95 ui_test_utils::RunAllPendingInMessageLoop();
81 ExpectGlobalErrorActive(true); 96 EXPECT_TRUE(IsGlobalErrorActive());
82 EXPECT_CALL(*mock_change_, Apply(browser())); 97 EXPECT_CALL(*mock_change_, Apply(browser()));
83 protector_service_->ApplyChange(browser()); 98 protector_service_->ApplyChange(mock_change_, browser());
84 ui_test_utils::RunAllPendingInMessageLoop(); 99 ui_test_utils::RunAllPendingInMessageLoop();
85 ExpectGlobalErrorActive(false); 100 EXPECT_FALSE(IsGlobalErrorActive());
86 } 101 }
87 102
88 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApplyManually) { 103 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApplyManually) {
89 // Show the change and apply it, mimicking a button click. 104 // Show the change and apply it, mimicking a button click.
90 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 105 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
91 WillOnce(Return(true)); 106 WillOnce(Return(true));
92 protector_service_->ShowChange(mock_change_); 107 protector_service_->ShowChange(mock_change_);
93 ui_test_utils::RunAllPendingInMessageLoop(); 108 ui_test_utils::RunAllPendingInMessageLoop();
94 ExpectGlobalErrorActive(true); 109 EXPECT_TRUE(IsGlobalErrorActive());
95 EXPECT_CALL(*mock_change_, Apply(browser())); 110 EXPECT_CALL(*mock_change_, Apply(browser()));
96 // Pressing Cancel applies the change. 111 // Pressing Cancel applies the change.
97 GlobalError* error = GetGlobalError(); 112 GlobalError* error = GetGlobalError();
98 error->BubbleViewCancelButtonPressed(browser()); 113 error->BubbleViewCancelButtonPressed(browser());
99 error->GetBubbleView()->CloseBubbleView(); 114 error->GetBubbleView()->CloseBubbleView();
100 ui_test_utils::RunAllPendingInMessageLoop(); 115 ui_test_utils::RunAllPendingInMessageLoop();
101 ExpectGlobalErrorActive(false); 116 EXPECT_FALSE(IsGlobalErrorActive());
102 } 117 }
103 118
104 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscard) { 119 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscard) {
105 // Show the change and discard it. 120 // Show the change and discard it.
106 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 121 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
107 WillOnce(Return(true)); 122 WillOnce(Return(true));
108 protector_service_->ShowChange(mock_change_); 123 protector_service_->ShowChange(mock_change_);
109 ui_test_utils::RunAllPendingInMessageLoop(); 124 ui_test_utils::RunAllPendingInMessageLoop();
110 ExpectGlobalErrorActive(true); 125 EXPECT_TRUE(IsGlobalErrorActive());
111 EXPECT_CALL(*mock_change_, Discard(browser())); 126 EXPECT_CALL(*mock_change_, Discard(browser()));
112 protector_service_->DiscardChange(browser()); 127 protector_service_->DiscardChange(mock_change_, browser());
113 ui_test_utils::RunAllPendingInMessageLoop(); 128 ui_test_utils::RunAllPendingInMessageLoop();
114 ExpectGlobalErrorActive(false); 129 EXPECT_FALSE(IsGlobalErrorActive());
115 } 130 }
116 131
117 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscardManually) { 132 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscardManually) {
118 // Show the change and discard it, mimicking a button click. 133 // Show the change and discard it, mimicking a button click.
119 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 134 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
120 WillOnce(Return(true)); 135 WillOnce(Return(true));
121 protector_service_->ShowChange(mock_change_); 136 protector_service_->ShowChange(mock_change_);
122 ui_test_utils::RunAllPendingInMessageLoop(); 137 ui_test_utils::RunAllPendingInMessageLoop();
123 ExpectGlobalErrorActive(true); 138 EXPECT_TRUE(IsGlobalErrorActive());
124 EXPECT_CALL(*mock_change_, Discard(browser())); 139 EXPECT_CALL(*mock_change_, Discard(browser()));
125 // Pressing Apply discards the change. 140 // Pressing Apply discards the change.
126 GlobalError* error = GetGlobalError(); 141 GlobalError* error = GetGlobalError();
127 error->BubbleViewAcceptButtonPressed(browser()); 142 error->BubbleViewAcceptButtonPressed(browser());
128 error->GetBubbleView()->CloseBubbleView(); 143 error->GetBubbleView()->CloseBubbleView();
129 ui_test_utils::RunAllPendingInMessageLoop(); 144 ui_test_utils::RunAllPendingInMessageLoop();
130 ExpectGlobalErrorActive(false); 145 EXPECT_FALSE(IsGlobalErrorActive());
131 } 146 }
132 147
133 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) { 148 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) {
134 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 149 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
135 WillOnce(Return(true)); 150 WillOnce(Return(true));
136 protector_service_->ShowChange(mock_change_); 151 protector_service_->ShowChange(mock_change_);
137 ui_test_utils::RunAllPendingInMessageLoop(); 152 ui_test_utils::RunAllPendingInMessageLoop();
138 ExpectGlobalErrorActive(true); 153 EXPECT_TRUE(IsGlobalErrorActive());
139 154
140 GlobalError* error = GetGlobalError(); 155 GlobalError* error = GetGlobalError();
141 GlobalErrorBubbleViewBase* bubble_view = error->GetBubbleView(); 156 GlobalErrorBubbleViewBase* bubble_view = error->GetBubbleView();
142 EXPECT_TRUE(bubble_view); 157 EXPECT_TRUE(bubble_view);
143 EXPECT_CALL(*mock_change_, Apply(browser())).WillOnce(InvokeWithoutArgs( 158 EXPECT_CALL(*mock_change_, Apply(browser())).WillOnce(InvokeWithoutArgs(
144 bubble_view, &GlobalErrorBubbleViewBase::CloseBubbleView)); 159 bubble_view, &GlobalErrorBubbleViewBase::CloseBubbleView));
145 160
146 // Pressing Cancel applies the change. 161 // Pressing Cancel applies the change.
147 error->BubbleViewCancelButtonPressed(browser()); 162 error->BubbleViewCancelButtonPressed(browser());
148 ui_test_utils::RunAllPendingInMessageLoop(); 163 ui_test_utils::RunAllPendingInMessageLoop();
149 ExpectGlobalErrorActive(false); 164 EXPECT_FALSE(IsGlobalErrorActive());
150 } 165 }
151 166
152 // TODO(ivankr): Timeout test. 167 // TODO(ivankr): Timeout test.
153 168
154 } // namespace protector 169 } // namespace protector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698