| OLD | NEW |
| 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "components/web_modal/native_web_contents_modal_dialog_manager.h" | 8 #include "components/web_modal/native_web_contents_modal_dialog_manager.h" |
| 9 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 9 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // Test that the dialog is shown immediately when the delegate indicates the web | 165 // Test that the dialog is shown immediately when the delegate indicates the web |
| 166 // contents is visible. | 166 // contents is visible. |
| 167 TEST_F(WebContentsModalDialogManagerTest, WebContentsVisible) { | 167 TEST_F(WebContentsModalDialogManagerTest, WebContentsVisible) { |
| 168 // Dialog should be shown while WebContents is visible. | 168 // Dialog should be shown while WebContents is visible. |
| 169 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); | 169 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); |
| 170 | 170 |
| 171 manager->ShowDialog(dialog1); | 171 manager->ShowDialog(dialog1); |
| 172 | 172 |
| 173 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, | 173 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, |
| 174 native_manager->GetDialogState(dialog1)); | 174 native_manager->GetDialogState(dialog1)); |
| 175 EXPECT_TRUE(manager->IsShowingDialog()); | 175 EXPECT_TRUE(manager->IsDialogActive()); |
| 176 EXPECT_TRUE(delegate->web_contents_blocked()); | 176 EXPECT_TRUE(delegate->web_contents_blocked()); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Test that the dialog is not shown immediately when the delegate indicates the | 179 // Test that the dialog is not shown immediately when the delegate indicates the |
| 180 // web contents is not visible. | 180 // web contents is not visible. |
| 181 TEST_F(WebContentsModalDialogManagerTest, WebContentsNotVisible) { | 181 TEST_F(WebContentsModalDialogManagerTest, WebContentsNotVisible) { |
| 182 // Dialog should not be shown while WebContents is not visible. | 182 // Dialog should not be shown while WebContents is not visible. |
| 183 delegate->set_web_contents_visible(false); | 183 delegate->set_web_contents_visible(false); |
| 184 | 184 |
| 185 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); | 185 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); |
| 186 | 186 |
| 187 manager->ShowDialog(dialog1); | 187 manager->ShowDialog(dialog1); |
| 188 | 188 |
| 189 EXPECT_EQ(TestNativeWebContentsModalDialogManager::NOT_SHOWN, | 189 EXPECT_EQ(TestNativeWebContentsModalDialogManager::NOT_SHOWN, |
| 190 native_manager->GetDialogState(dialog1)); | 190 native_manager->GetDialogState(dialog1)); |
| 191 EXPECT_TRUE(manager->IsShowingDialog()); | 191 EXPECT_TRUE(manager->IsDialogActive()); |
| 192 EXPECT_TRUE(delegate->web_contents_blocked()); | 192 EXPECT_TRUE(delegate->web_contents_blocked()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Test that only the first of multiple dialogs is shown. | 195 // Test that only the first of multiple dialogs is shown. |
| 196 TEST_F(WebContentsModalDialogManagerTest, ShowDialogs) { | 196 TEST_F(WebContentsModalDialogManagerTest, ShowDialogs) { |
| 197 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); | 197 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); |
| 198 const NativeWebContentsModalDialog dialog2 = MakeFakeDialog(); | 198 const NativeWebContentsModalDialog dialog2 = MakeFakeDialog(); |
| 199 const NativeWebContentsModalDialog dialog3 = MakeFakeDialog(); | 199 const NativeWebContentsModalDialog dialog3 = MakeFakeDialog(); |
| 200 | 200 |
| 201 manager->ShowDialog(dialog1); | 201 manager->ShowDialog(dialog1); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 212 } | 212 } |
| 213 | 213 |
| 214 // Test that the dialog is shown/hidden on | 214 // Test that the dialog is shown/hidden on |
| 215 // NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED. | 215 // NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED. |
| 216 TEST_F(WebContentsModalDialogManagerTest, VisibilityObservation) { | 216 TEST_F(WebContentsModalDialogManagerTest, VisibilityObservation) { |
| 217 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); | 217 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); |
| 218 bool web_contents_visible = true; | 218 bool web_contents_visible = true; |
| 219 | 219 |
| 220 manager->ShowDialog(dialog1); | 220 manager->ShowDialog(dialog1); |
| 221 | 221 |
| 222 EXPECT_TRUE(manager->IsShowingDialog()); | 222 EXPECT_TRUE(manager->IsDialogActive()); |
| 223 EXPECT_TRUE(delegate->web_contents_blocked()); | 223 EXPECT_TRUE(delegate->web_contents_blocked()); |
| 224 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, | 224 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, |
| 225 native_manager->GetDialogState(dialog1)); | 225 native_manager->GetDialogState(dialog1)); |
| 226 | 226 |
| 227 web_contents_visible = false; | 227 web_contents_visible = false; |
| 228 manager->Observe(content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 228 manager->Observe(content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 229 content::NotificationService::AllSources(), | 229 content::NotificationService::AllSources(), |
| 230 content::Details<bool>(&web_contents_visible)); | 230 content::Details<bool>(&web_contents_visible)); |
| 231 | 231 |
| 232 EXPECT_TRUE(manager->IsShowingDialog()); | 232 EXPECT_TRUE(manager->IsDialogActive()); |
| 233 EXPECT_TRUE(delegate->web_contents_blocked()); | 233 EXPECT_TRUE(delegate->web_contents_blocked()); |
| 234 EXPECT_EQ(TestNativeWebContentsModalDialogManager::HIDDEN, | 234 EXPECT_EQ(TestNativeWebContentsModalDialogManager::HIDDEN, |
| 235 native_manager->GetDialogState(dialog1)); | 235 native_manager->GetDialogState(dialog1)); |
| 236 | 236 |
| 237 web_contents_visible = true; | 237 web_contents_visible = true; |
| 238 manager->Observe(content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 238 manager->Observe(content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 239 content::NotificationService::AllSources(), | 239 content::NotificationService::AllSources(), |
| 240 content::Details<bool>(&web_contents_visible)); | 240 content::Details<bool>(&web_contents_visible)); |
| 241 | 241 |
| 242 EXPECT_TRUE(manager->IsShowingDialog()); | 242 EXPECT_TRUE(manager->IsDialogActive()); |
| 243 EXPECT_TRUE(delegate->web_contents_blocked()); | 243 EXPECT_TRUE(delegate->web_contents_blocked()); |
| 244 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, | 244 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, |
| 245 native_manager->GetDialogState(dialog1)); | 245 native_manager->GetDialogState(dialog1)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 // Test that attaching an interstitial WebUI page closes dialogs configured to | 248 // Test that attaching an interstitial WebUI page closes dialogs configured to |
| 249 // close on interstitial WebUI. | 249 // close on interstitial WebUI. |
| 250 TEST_F(WebContentsModalDialogManagerTest, InterstitialWebUI) { | 250 TEST_F(WebContentsModalDialogManagerTest, InterstitialWebUI) { |
| 251 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); | 251 const NativeWebContentsModalDialog dialog1 = MakeFakeDialog(); |
| 252 const NativeWebContentsModalDialog dialog2 = MakeFakeDialog(); | 252 const NativeWebContentsModalDialog dialog2 = MakeFakeDialog(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 278 const NativeWebContentsModalDialog dialog3 = MakeFakeDialog(); | 278 const NativeWebContentsModalDialog dialog3 = MakeFakeDialog(); |
| 279 const NativeWebContentsModalDialog dialog4 = MakeFakeDialog(); | 279 const NativeWebContentsModalDialog dialog4 = MakeFakeDialog(); |
| 280 | 280 |
| 281 manager->ShowDialog(dialog1); | 281 manager->ShowDialog(dialog1); |
| 282 manager->ShowDialog(dialog2); | 282 manager->ShowDialog(dialog2); |
| 283 manager->ShowDialog(dialog3); | 283 manager->ShowDialog(dialog3); |
| 284 manager->ShowDialog(dialog4); | 284 manager->ShowDialog(dialog4); |
| 285 | 285 |
| 286 native_manager->CloseDialog(dialog1); | 286 native_manager->CloseDialog(dialog1); |
| 287 | 287 |
| 288 EXPECT_TRUE(manager->IsShowingDialog()); | 288 EXPECT_TRUE(manager->IsDialogActive()); |
| 289 EXPECT_TRUE(delegate->web_contents_blocked()); | 289 EXPECT_TRUE(delegate->web_contents_blocked()); |
| 290 EXPECT_EQ(TestNativeWebContentsModalDialogManager::CLOSED, | 290 EXPECT_EQ(TestNativeWebContentsModalDialogManager::CLOSED, |
| 291 native_manager->GetDialogState(dialog1)); | 291 native_manager->GetDialogState(dialog1)); |
| 292 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, | 292 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, |
| 293 native_manager->GetDialogState(dialog2)); | 293 native_manager->GetDialogState(dialog2)); |
| 294 EXPECT_EQ(TestNativeWebContentsModalDialogManager::NOT_SHOWN, | 294 EXPECT_EQ(TestNativeWebContentsModalDialogManager::NOT_SHOWN, |
| 295 native_manager->GetDialogState(dialog3)); | 295 native_manager->GetDialogState(dialog3)); |
| 296 EXPECT_EQ(TestNativeWebContentsModalDialogManager::NOT_SHOWN, | 296 EXPECT_EQ(TestNativeWebContentsModalDialogManager::NOT_SHOWN, |
| 297 native_manager->GetDialogState(dialog4)); | 297 native_manager->GetDialogState(dialog4)); |
| 298 | 298 |
| 299 native_manager->CloseDialog(dialog3); | 299 native_manager->CloseDialog(dialog3); |
| 300 | 300 |
| 301 EXPECT_TRUE(manager->IsShowingDialog()); | 301 EXPECT_TRUE(manager->IsDialogActive()); |
| 302 EXPECT_TRUE(delegate->web_contents_blocked()); | 302 EXPECT_TRUE(delegate->web_contents_blocked()); |
| 303 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, | 303 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, |
| 304 native_manager->GetDialogState(dialog2)); | 304 native_manager->GetDialogState(dialog2)); |
| 305 EXPECT_EQ(TestNativeWebContentsModalDialogManager::CLOSED, | 305 EXPECT_EQ(TestNativeWebContentsModalDialogManager::CLOSED, |
| 306 native_manager->GetDialogState(dialog3)); | 306 native_manager->GetDialogState(dialog3)); |
| 307 EXPECT_EQ(TestNativeWebContentsModalDialogManager::NOT_SHOWN, | 307 EXPECT_EQ(TestNativeWebContentsModalDialogManager::NOT_SHOWN, |
| 308 native_manager->GetDialogState(dialog4)); | 308 native_manager->GetDialogState(dialog4)); |
| 309 | 309 |
| 310 native_manager->CloseDialog(dialog2); | 310 native_manager->CloseDialog(dialog2); |
| 311 | 311 |
| 312 EXPECT_TRUE(manager->IsShowingDialog()); | 312 EXPECT_TRUE(manager->IsDialogActive()); |
| 313 EXPECT_TRUE(delegate->web_contents_blocked()); | 313 EXPECT_TRUE(delegate->web_contents_blocked()); |
| 314 EXPECT_EQ(TestNativeWebContentsModalDialogManager::CLOSED, | 314 EXPECT_EQ(TestNativeWebContentsModalDialogManager::CLOSED, |
| 315 native_manager->GetDialogState(dialog2)); | 315 native_manager->GetDialogState(dialog2)); |
| 316 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, | 316 EXPECT_EQ(TestNativeWebContentsModalDialogManager::SHOWN, |
| 317 native_manager->GetDialogState(dialog4)); | 317 native_manager->GetDialogState(dialog4)); |
| 318 | 318 |
| 319 native_manager->CloseDialog(dialog4); | 319 native_manager->CloseDialog(dialog4); |
| 320 | 320 |
| 321 EXPECT_FALSE(manager->IsShowingDialog()); | 321 EXPECT_FALSE(manager->IsDialogActive()); |
| 322 EXPECT_FALSE(delegate->web_contents_blocked()); | 322 EXPECT_FALSE(delegate->web_contents_blocked()); |
| 323 EXPECT_EQ(TestNativeWebContentsModalDialogManager::CLOSED, | 323 EXPECT_EQ(TestNativeWebContentsModalDialogManager::CLOSED, |
| 324 native_manager->GetDialogState(dialog4)); | 324 native_manager->GetDialogState(dialog4)); |
| 325 } | 325 } |
| 326 | 326 |
| 327 // Test that CloseAllDialogs does what it says. | 327 // Test that CloseAllDialogs does what it says. |
| 328 TEST_F(WebContentsModalDialogManagerTest, CloseAllDialogs) { | 328 TEST_F(WebContentsModalDialogManagerTest, CloseAllDialogs) { |
| 329 const int kWindowCount = 4; | 329 const int kWindowCount = 4; |
| 330 for (int i = 0; i < kWindowCount; i++) | 330 for (int i = 0; i < kWindowCount; i++) |
| 331 manager->ShowDialog(MakeFakeDialog()); | 331 manager->ShowDialog(MakeFakeDialog()); |
| 332 | 332 |
| 333 EXPECT_EQ(0, native_manager->GetCloseCount()); | 333 EXPECT_EQ(0, native_manager->GetCloseCount()); |
| 334 | 334 |
| 335 test_api->CloseAllDialogs(); | 335 test_api->CloseAllDialogs(); |
| 336 EXPECT_FALSE(delegate->web_contents_blocked()); | 336 EXPECT_FALSE(delegate->web_contents_blocked()); |
| 337 EXPECT_FALSE(manager->IsShowingDialog()); | 337 EXPECT_FALSE(manager->IsDialogActive()); |
| 338 EXPECT_EQ(kWindowCount, native_manager->GetCloseCount()); | 338 EXPECT_EQ(kWindowCount, native_manager->GetCloseCount()); |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace web_modal | 341 } // namespace web_modal |
| OLD | NEW |