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

Side by Side Diff: components/web_modal/web_contents_modal_dialog_manager_unittest.cc

Issue 1917673002: Convert //components/[u-z]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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
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 "components/web_modal/web_contents_modal_dialog_manager.h" 5 #include "components/web_modal/web_contents_modal_dialog_manager.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory>
8 9
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/ptr_util.h"
11 #include "components/web_modal/single_web_contents_dialog_manager.h" 12 #include "components/web_modal/single_web_contents_dialog_manager.h"
12 #include "components/web_modal/test_web_contents_modal_dialog_manager_delegate.h " 13 #include "components/web_modal/test_web_contents_modal_dialog_manager_delegate.h "
13 #include "content/public/test/test_renderer_host.h" 14 #include "content/public/test/test_renderer_host.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace web_modal { 17 namespace web_modal {
17 18
18 // Tracks persistent state changes of the native WC-modal dialog manager. 19 // Tracks persistent state changes of the native WC-modal dialog manager.
19 class NativeManagerTracker { 20 class NativeManagerTracker {
20 public: 21 public:
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 109 }
109 110
110 protected: 111 protected:
111 gfx::NativeWindow MakeFakeDialog() { 112 gfx::NativeWindow MakeFakeDialog() {
112 // WebContentsModalDialogManager treats the dialog window as an opaque 113 // WebContentsModalDialogManager treats the dialog window as an opaque
113 // type, so creating fake dialog windows using reinterpret_cast is valid. 114 // type, so creating fake dialog windows using reinterpret_cast is valid.
114 return reinterpret_cast<gfx::NativeWindow>(next_dialog_id++); 115 return reinterpret_cast<gfx::NativeWindow>(next_dialog_id++);
115 } 116 }
116 117
117 int next_dialog_id; 118 int next_dialog_id;
118 scoped_ptr<TestWebContentsModalDialogManagerDelegate> delegate; 119 std::unique_ptr<TestWebContentsModalDialogManagerDelegate> delegate;
119 WebContentsModalDialogManager* manager; 120 WebContentsModalDialogManager* manager;
120 scoped_ptr<WebContentsModalDialogManager::TestApi> test_api; 121 std::unique_ptr<WebContentsModalDialogManager::TestApi> test_api;
121 122
122 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManagerTest); 123 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManagerTest);
123 }; 124 };
124 125
125 SingleWebContentsDialogManager* 126 SingleWebContentsDialogManager*
126 WebContentsModalDialogManager::CreateNativeWebModalManager( 127 WebContentsModalDialogManager::CreateNativeWebModalManager(
127 gfx::NativeWindow dialog, 128 gfx::NativeWindow dialog,
128 SingleWebContentsDialogManagerDelegate* native_delegate) { 129 SingleWebContentsDialogManagerDelegate* native_delegate) {
129 NOTREACHED(); 130 NOTREACHED();
130 return new TestNativeWebContentsModalDialogManager( 131 return new TestNativeWebContentsModalDialogManager(
131 dialog, 132 dialog,
132 native_delegate, 133 native_delegate,
133 &unused_tracker); 134 &unused_tracker);
134 } 135 }
135 136
136 // Test that the dialog is shown immediately when the delegate indicates the web 137 // Test that the dialog is shown immediately when the delegate indicates the web
137 // contents is visible. 138 // contents is visible.
138 TEST_F(WebContentsModalDialogManagerTest, WebContentsVisible) { 139 TEST_F(WebContentsModalDialogManagerTest, WebContentsVisible) {
139 // Dialog should be shown while WebContents is visible. 140 // Dialog should be shown while WebContents is visible.
140 const gfx::NativeWindow dialog = MakeFakeDialog(); 141 const gfx::NativeWindow dialog = MakeFakeDialog();
141 142
142 NativeManagerTracker tracker; 143 NativeManagerTracker tracker;
143 TestNativeWebContentsModalDialogManager* native_manager = 144 TestNativeWebContentsModalDialogManager* native_manager =
144 new TestNativeWebContentsModalDialogManager(dialog, manager, &tracker); 145 new TestNativeWebContentsModalDialogManager(dialog, manager, &tracker);
145 manager->ShowDialogWithManager( 146 manager->ShowDialogWithManager(dialog, base::WrapUnique(native_manager));
146 dialog, scoped_ptr<SingleWebContentsDialogManager>(native_manager));
147 147
148 EXPECT_EQ(NativeManagerTracker::SHOWN, tracker.state_); 148 EXPECT_EQ(NativeManagerTracker::SHOWN, tracker.state_);
149 EXPECT_TRUE(manager->IsDialogActive()); 149 EXPECT_TRUE(manager->IsDialogActive());
150 EXPECT_TRUE(delegate->web_contents_blocked()); 150 EXPECT_TRUE(delegate->web_contents_blocked());
151 EXPECT_TRUE(tracker.was_shown_); 151 EXPECT_TRUE(tracker.was_shown_);
152 152
153 native_manager->StopTracking(); 153 native_manager->StopTracking();
154 } 154 }
155 155
156 // Test that the dialog is not shown immediately when the delegate indicates the 156 // Test that the dialog is not shown immediately when the delegate indicates the
157 // web contents is not visible. 157 // web contents is not visible.
158 TEST_F(WebContentsModalDialogManagerTest, WebContentsNotVisible) { 158 TEST_F(WebContentsModalDialogManagerTest, WebContentsNotVisible) {
159 // Dialog should not be shown while WebContents is not visible. 159 // Dialog should not be shown while WebContents is not visible.
160 delegate->set_web_contents_visible(false); 160 delegate->set_web_contents_visible(false);
161 161
162 const gfx::NativeWindow dialog = MakeFakeDialog(); 162 const gfx::NativeWindow dialog = MakeFakeDialog();
163 163
164 NativeManagerTracker tracker; 164 NativeManagerTracker tracker;
165 TestNativeWebContentsModalDialogManager* native_manager = 165 TestNativeWebContentsModalDialogManager* native_manager =
166 new TestNativeWebContentsModalDialogManager(dialog, manager, &tracker); 166 new TestNativeWebContentsModalDialogManager(dialog, manager, &tracker);
167 manager->ShowDialogWithManager( 167 manager->ShowDialogWithManager(dialog, base::WrapUnique(native_manager));
168 dialog, scoped_ptr<SingleWebContentsDialogManager>(native_manager));
169 168
170 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker.state_); 169 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker.state_);
171 EXPECT_TRUE(manager->IsDialogActive()); 170 EXPECT_TRUE(manager->IsDialogActive());
172 EXPECT_TRUE(delegate->web_contents_blocked()); 171 EXPECT_TRUE(delegate->web_contents_blocked());
173 EXPECT_FALSE(tracker.was_shown_); 172 EXPECT_FALSE(tracker.was_shown_);
174 173
175 native_manager->StopTracking(); 174 native_manager->StopTracking();
176 } 175 }
177 176
178 // Test that only the first of multiple dialogs is shown. 177 // Test that only the first of multiple dialogs is shown.
179 TEST_F(WebContentsModalDialogManagerTest, ShowDialogs) { 178 TEST_F(WebContentsModalDialogManagerTest, ShowDialogs) {
180 const gfx::NativeWindow dialog1 = MakeFakeDialog(); 179 const gfx::NativeWindow dialog1 = MakeFakeDialog();
181 const gfx::NativeWindow dialog2 = MakeFakeDialog(); 180 const gfx::NativeWindow dialog2 = MakeFakeDialog();
182 const gfx::NativeWindow dialog3 = MakeFakeDialog(); 181 const gfx::NativeWindow dialog3 = MakeFakeDialog();
183 182
184 NativeManagerTracker tracker1; 183 NativeManagerTracker tracker1;
185 NativeManagerTracker tracker2; 184 NativeManagerTracker tracker2;
186 NativeManagerTracker tracker3; 185 NativeManagerTracker tracker3;
187 TestNativeWebContentsModalDialogManager* native_manager1 = 186 TestNativeWebContentsModalDialogManager* native_manager1 =
188 new TestNativeWebContentsModalDialogManager(dialog1, manager, &tracker1); 187 new TestNativeWebContentsModalDialogManager(dialog1, manager, &tracker1);
189 TestNativeWebContentsModalDialogManager* native_manager2 = 188 TestNativeWebContentsModalDialogManager* native_manager2 =
190 new TestNativeWebContentsModalDialogManager(dialog2, manager, &tracker2); 189 new TestNativeWebContentsModalDialogManager(dialog2, manager, &tracker2);
191 TestNativeWebContentsModalDialogManager* native_manager3 = 190 TestNativeWebContentsModalDialogManager* native_manager3 =
192 new TestNativeWebContentsModalDialogManager(dialog3, manager, &tracker3); 191 new TestNativeWebContentsModalDialogManager(dialog3, manager, &tracker3);
193 manager->ShowDialogWithManager( 192 manager->ShowDialogWithManager(dialog1, base::WrapUnique(native_manager1));
194 dialog1, scoped_ptr<SingleWebContentsDialogManager>(native_manager1)); 193 manager->ShowDialogWithManager(dialog2, base::WrapUnique(native_manager2));
195 manager->ShowDialogWithManager( 194 manager->ShowDialogWithManager(dialog3, base::WrapUnique(native_manager3));
196 dialog2, scoped_ptr<SingleWebContentsDialogManager>(native_manager2));
197 manager->ShowDialogWithManager(
198 dialog3, scoped_ptr<SingleWebContentsDialogManager>(native_manager3));
199 195
200 EXPECT_TRUE(delegate->web_contents_blocked()); 196 EXPECT_TRUE(delegate->web_contents_blocked());
201 EXPECT_EQ(NativeManagerTracker::SHOWN, tracker1.state_); 197 EXPECT_EQ(NativeManagerTracker::SHOWN, tracker1.state_);
202 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker2.state_); 198 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker2.state_);
203 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker3.state_); 199 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker3.state_);
204 200
205 native_manager1->StopTracking(); 201 native_manager1->StopTracking();
206 native_manager2->StopTracking(); 202 native_manager2->StopTracking();
207 native_manager3->StopTracking(); 203 native_manager3->StopTracking();
208 } 204 }
209 205
210 // Test that the dialog is shown/hidden when the WebContents is shown/hidden. 206 // Test that the dialog is shown/hidden when the WebContents is shown/hidden.
211 TEST_F(WebContentsModalDialogManagerTest, VisibilityObservation) { 207 TEST_F(WebContentsModalDialogManagerTest, VisibilityObservation) {
212 const gfx::NativeWindow dialog = MakeFakeDialog(); 208 const gfx::NativeWindow dialog = MakeFakeDialog();
213 209
214 NativeManagerTracker tracker; 210 NativeManagerTracker tracker;
215 TestNativeWebContentsModalDialogManager* native_manager = 211 TestNativeWebContentsModalDialogManager* native_manager =
216 new TestNativeWebContentsModalDialogManager(dialog, manager, &tracker); 212 new TestNativeWebContentsModalDialogManager(dialog, manager, &tracker);
217 manager->ShowDialogWithManager( 213 manager->ShowDialogWithManager(dialog, base::WrapUnique(native_manager));
218 dialog, scoped_ptr<SingleWebContentsDialogManager>(native_manager));
219 214
220 EXPECT_TRUE(manager->IsDialogActive()); 215 EXPECT_TRUE(manager->IsDialogActive());
221 EXPECT_TRUE(delegate->web_contents_blocked()); 216 EXPECT_TRUE(delegate->web_contents_blocked());
222 EXPECT_EQ(NativeManagerTracker::SHOWN, tracker.state_); 217 EXPECT_EQ(NativeManagerTracker::SHOWN, tracker.state_);
223 218
224 test_api->WebContentsWasHidden(); 219 test_api->WebContentsWasHidden();
225 220
226 EXPECT_TRUE(manager->IsDialogActive()); 221 EXPECT_TRUE(manager->IsDialogActive());
227 EXPECT_TRUE(delegate->web_contents_blocked()); 222 EXPECT_TRUE(delegate->web_contents_blocked());
228 EXPECT_EQ(NativeManagerTracker::HIDDEN, tracker.state_); 223 EXPECT_EQ(NativeManagerTracker::HIDDEN, tracker.state_);
(...skipping 11 matching lines...) Expand all
240 TEST_F(WebContentsModalDialogManagerTest, InterstitialPage) { 235 TEST_F(WebContentsModalDialogManagerTest, InterstitialPage) {
241 const gfx::NativeWindow dialog1 = MakeFakeDialog(); 236 const gfx::NativeWindow dialog1 = MakeFakeDialog();
242 const gfx::NativeWindow dialog2 = MakeFakeDialog(); 237 const gfx::NativeWindow dialog2 = MakeFakeDialog();
243 238
244 NativeManagerTracker tracker1; 239 NativeManagerTracker tracker1;
245 NativeManagerTracker tracker2; 240 NativeManagerTracker tracker2;
246 TestNativeWebContentsModalDialogManager* native_manager1 = 241 TestNativeWebContentsModalDialogManager* native_manager1 =
247 new TestNativeWebContentsModalDialogManager(dialog1, manager, &tracker1); 242 new TestNativeWebContentsModalDialogManager(dialog1, manager, &tracker1);
248 TestNativeWebContentsModalDialogManager* native_manager2 = 243 TestNativeWebContentsModalDialogManager* native_manager2 =
249 new TestNativeWebContentsModalDialogManager(dialog2, manager, &tracker2); 244 new TestNativeWebContentsModalDialogManager(dialog2, manager, &tracker2);
250 manager->ShowDialogWithManager( 245 manager->ShowDialogWithManager(dialog1, base::WrapUnique(native_manager1));
251 dialog1, scoped_ptr<SingleWebContentsDialogManager>(native_manager1)); 246 manager->ShowDialogWithManager(dialog2, base::WrapUnique(native_manager2));
252 manager->ShowDialogWithManager(
253 dialog2, scoped_ptr<SingleWebContentsDialogManager>(native_manager2));
254 247
255 test_api->DidAttachInterstitialPage(); 248 test_api->DidAttachInterstitialPage();
256 249
257 EXPECT_EQ(NativeManagerTracker::CLOSED, tracker1.state_); 250 EXPECT_EQ(NativeManagerTracker::CLOSED, tracker1.state_);
258 EXPECT_EQ(NativeManagerTracker::CLOSED, tracker2.state_); 251 EXPECT_EQ(NativeManagerTracker::CLOSED, tracker2.state_);
259 252
260 EXPECT_TRUE(tracker1.was_shown_); 253 EXPECT_TRUE(tracker1.was_shown_);
261 EXPECT_FALSE(tracker2.was_shown_); 254 EXPECT_FALSE(tracker2.was_shown_);
262 } 255 }
263 256
(...skipping 12 matching lines...) Expand all
276 NativeManagerTracker tracker3; 269 NativeManagerTracker tracker3;
277 NativeManagerTracker tracker4; 270 NativeManagerTracker tracker4;
278 TestNativeWebContentsModalDialogManager* native_manager1 = 271 TestNativeWebContentsModalDialogManager* native_manager1 =
279 new TestNativeWebContentsModalDialogManager(dialog1, manager, &tracker1); 272 new TestNativeWebContentsModalDialogManager(dialog1, manager, &tracker1);
280 TestNativeWebContentsModalDialogManager* native_manager2 = 273 TestNativeWebContentsModalDialogManager* native_manager2 =
281 new TestNativeWebContentsModalDialogManager(dialog2, manager, &tracker2); 274 new TestNativeWebContentsModalDialogManager(dialog2, manager, &tracker2);
282 TestNativeWebContentsModalDialogManager* native_manager3 = 275 TestNativeWebContentsModalDialogManager* native_manager3 =
283 new TestNativeWebContentsModalDialogManager(dialog3, manager, &tracker3); 276 new TestNativeWebContentsModalDialogManager(dialog3, manager, &tracker3);
284 TestNativeWebContentsModalDialogManager* native_manager4 = 277 TestNativeWebContentsModalDialogManager* native_manager4 =
285 new TestNativeWebContentsModalDialogManager(dialog4, manager, &tracker4); 278 new TestNativeWebContentsModalDialogManager(dialog4, manager, &tracker4);
286 manager->ShowDialogWithManager( 279 manager->ShowDialogWithManager(dialog1, base::WrapUnique(native_manager1));
287 dialog1, scoped_ptr<SingleWebContentsDialogManager>(native_manager1)); 280 manager->ShowDialogWithManager(dialog2, base::WrapUnique(native_manager2));
288 manager->ShowDialogWithManager( 281 manager->ShowDialogWithManager(dialog3, base::WrapUnique(native_manager3));
289 dialog2, scoped_ptr<SingleWebContentsDialogManager>(native_manager2)); 282 manager->ShowDialogWithManager(dialog4, base::WrapUnique(native_manager4));
290 manager->ShowDialogWithManager(
291 dialog3, scoped_ptr<SingleWebContentsDialogManager>(native_manager3));
292 manager->ShowDialogWithManager(
293 dialog4, scoped_ptr<SingleWebContentsDialogManager>(native_manager4));
294 283
295 native_manager1->Close(); 284 native_manager1->Close();
296 285
297 EXPECT_TRUE(manager->IsDialogActive()); 286 EXPECT_TRUE(manager->IsDialogActive());
298 EXPECT_TRUE(delegate->web_contents_blocked()); 287 EXPECT_TRUE(delegate->web_contents_blocked());
299 EXPECT_EQ(NativeManagerTracker::CLOSED, tracker1.state_); 288 EXPECT_EQ(NativeManagerTracker::CLOSED, tracker1.state_);
300 EXPECT_EQ(NativeManagerTracker::SHOWN, tracker2.state_); 289 EXPECT_EQ(NativeManagerTracker::SHOWN, tracker2.state_);
301 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker3.state_); 290 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker3.state_);
302 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker4.state_); 291 EXPECT_EQ(NativeManagerTracker::NOT_SHOWN, tracker4.state_);
303 292
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // Test that CloseAllDialogs does what it says. 327 // Test that CloseAllDialogs does what it says.
339 TEST_F(WebContentsModalDialogManagerTest, CloseAllDialogs) { 328 TEST_F(WebContentsModalDialogManagerTest, CloseAllDialogs) {
340 const int kWindowCount = 4; 329 const int kWindowCount = 4;
341 NativeManagerTracker trackers[kWindowCount]; 330 NativeManagerTracker trackers[kWindowCount];
342 TestNativeWebContentsModalDialogManager* native_managers[kWindowCount]; 331 TestNativeWebContentsModalDialogManager* native_managers[kWindowCount];
343 for (int i = 0; i < kWindowCount; i++) { 332 for (int i = 0; i < kWindowCount; i++) {
344 const gfx::NativeWindow dialog = MakeFakeDialog(); 333 const gfx::NativeWindow dialog = MakeFakeDialog();
345 native_managers[i] = 334 native_managers[i] =
346 new TestNativeWebContentsModalDialogManager( 335 new TestNativeWebContentsModalDialogManager(
347 dialog, manager, &(trackers[i])); 336 dialog, manager, &(trackers[i]));
348 manager->ShowDialogWithManager( 337 manager->ShowDialogWithManager(dialog,
349 dialog, scoped_ptr<SingleWebContentsDialogManager>(native_managers[i])); 338 base::WrapUnique(native_managers[i]));
350 } 339 }
351 340
352 for (int i = 0; i < kWindowCount; i++) 341 for (int i = 0; i < kWindowCount; i++)
353 EXPECT_NE(NativeManagerTracker::CLOSED, trackers[i].state_); 342 EXPECT_NE(NativeManagerTracker::CLOSED, trackers[i].state_);
354 343
355 test_api->CloseAllDialogs(); 344 test_api->CloseAllDialogs();
356 345
357 EXPECT_FALSE(delegate->web_contents_blocked()); 346 EXPECT_FALSE(delegate->web_contents_blocked());
358 EXPECT_FALSE(manager->IsDialogActive()); 347 EXPECT_FALSE(manager->IsDialogActive());
359 for (int i = 0; i < kWindowCount; i++) 348 for (int i = 0; i < kWindowCount; i++)
360 EXPECT_EQ(NativeManagerTracker::CLOSED, trackers[i].state_); 349 EXPECT_EQ(NativeManagerTracker::CLOSED, trackers[i].state_);
361 } 350 }
362 351
363 } // namespace web_modal 352 } // namespace web_modal
OLDNEW
« no previous file with comments | « components/web_modal/web_contents_modal_dialog_manager.cc ('k') | components/web_resource/eula_accepted_notifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698