| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/native_web_contents_modal_dialog_manager.h" | |
| 6 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" | |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 8 #include "content/public/test/test_browser_thread.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 using content::BrowserThread; | |
| 12 | |
| 13 class WebContentsModalDialogManagerTest | |
| 14 : public ChromeRenderViewHostTestHarness { | |
| 15 public: | |
| 16 WebContentsModalDialogManagerTest() | |
| 17 : ChromeRenderViewHostTestHarness(), | |
| 18 ui_thread_(BrowserThread::UI, &message_loop_) { | |
| 19 } | |
| 20 | |
| 21 virtual void SetUp() { | |
| 22 ChromeRenderViewHostTestHarness::SetUp(); | |
| 23 WebContentsModalDialogManager::CreateForWebContents(web_contents()); | |
| 24 } | |
| 25 | |
| 26 private: | |
| 27 content::TestBrowserThread ui_thread_; | |
| 28 }; | |
| 29 | |
| 30 class NativeWebContentsModalDialogManagerCloseTest | |
| 31 : public NativeWebContentsModalDialogManager { | |
| 32 public: | |
| 33 NativeWebContentsModalDialogManagerCloseTest( | |
| 34 NativeWebContentsModalDialogManagerDelegate* delegate) | |
| 35 : delegate_(delegate) {} | |
| 36 virtual void ManageDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | |
| 37 } | |
| 38 virtual void ShowDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | |
| 39 } | |
| 40 virtual void HideDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | |
| 41 } | |
| 42 virtual void CloseDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | |
| 43 delegate_->WillClose(dialog); | |
| 44 close_count++; | |
| 45 } | |
| 46 virtual void FocusDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | |
| 47 } | |
| 48 virtual void PulseDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | |
| 49 } | |
| 50 | |
| 51 int close_count; | |
| 52 NativeWebContentsModalDialogManagerDelegate* delegate_; | |
| 53 }; | |
| 54 | |
| 55 TEST_F(WebContentsModalDialogManagerTest, WebContentsModalDialogs) { | |
| 56 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | |
| 57 WebContentsModalDialogManager::FromWebContents(web_contents()); | |
| 58 WebContentsModalDialogManager::TestApi test_api( | |
| 59 web_contents_modal_dialog_manager); | |
| 60 | |
| 61 NativeWebContentsModalDialogManagerCloseTest* native_manager = | |
| 62 new NativeWebContentsModalDialogManagerCloseTest( | |
| 63 web_contents_modal_dialog_manager); | |
| 64 native_manager->close_count = 0; | |
| 65 | |
| 66 test_api.ResetNativeManager(native_manager); | |
| 67 | |
| 68 const int kWindowCount = 4; | |
| 69 for (int i = 0; i < kWindowCount; i++) | |
| 70 // WebContentsModalDialogManager treats the NativeWebContentsModalDialog as | |
| 71 // an opaque type, so creating fake NativeWebContentsModalDialogs using | |
| 72 // reinterpret_cast is valid. | |
| 73 web_contents_modal_dialog_manager->ShowDialog( | |
| 74 reinterpret_cast<NativeWebContentsModalDialog>(i)); | |
| 75 EXPECT_EQ(native_manager->close_count, 0); | |
| 76 | |
| 77 test_api.CloseAllDialogs(); | |
| 78 EXPECT_EQ(native_manager->close_count, kWindowCount); | |
| 79 } | |
| OLD | NEW |