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 "chrome/browser/ui/native_web_contents_modal_dialog_manager.h" | 5 #include "components/web_modal/native_web_contents_modal_dialog_manager.h" |
6 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" | 6 #include "components/web_modal/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" | 7 #include "content/public/test/test_browser_thread.h" |
| 8 #include "content/public/test/test_renderer_host.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 using content::BrowserThread; | 11 using content::BrowserThread; |
12 | 12 |
| 13 namespace web_modal { |
| 14 |
13 class WebContentsModalDialogManagerTest | 15 class WebContentsModalDialogManagerTest |
14 : public ChromeRenderViewHostTestHarness { | 16 : public content::RenderViewHostTestHarness { |
15 public: | 17 public: |
16 WebContentsModalDialogManagerTest() | 18 WebContentsModalDialogManagerTest() |
17 : ChromeRenderViewHostTestHarness(), | 19 : ui_thread_(BrowserThread::UI, &message_loop_) { |
18 ui_thread_(BrowserThread::UI, &message_loop_) { | |
19 } | 20 } |
20 | 21 |
21 virtual void SetUp() { | 22 virtual void SetUp() { |
22 ChromeRenderViewHostTestHarness::SetUp(); | 23 content::RenderViewHostTestHarness::SetUp(); |
23 WebContentsModalDialogManager::CreateForWebContents(web_contents()); | 24 WebContentsModalDialogManager::CreateForWebContents(web_contents()); |
24 } | 25 } |
25 | 26 |
26 private: | 27 private: |
27 content::TestBrowserThread ui_thread_; | 28 content::TestBrowserThread ui_thread_; |
28 }; | 29 }; |
29 | 30 |
30 class NativeWebContentsModalDialogManagerCloseTest | 31 class NativeWebContentsModalDialogManagerCloseTest |
31 : public NativeWebContentsModalDialogManager { | 32 : public NativeWebContentsModalDialogManager { |
32 public: | 33 public: |
(...skipping 12 matching lines...) Expand all Loading... |
45 } | 46 } |
46 virtual void FocusDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | 47 virtual void FocusDialog(NativeWebContentsModalDialog dialog) OVERRIDE { |
47 } | 48 } |
48 virtual void PulseDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | 49 virtual void PulseDialog(NativeWebContentsModalDialog dialog) OVERRIDE { |
49 } | 50 } |
50 | 51 |
51 int close_count; | 52 int close_count; |
52 NativeWebContentsModalDialogManagerDelegate* delegate_; | 53 NativeWebContentsModalDialogManagerDelegate* delegate_; |
53 }; | 54 }; |
54 | 55 |
| 56 NativeWebContentsModalDialogManager* WebContentsModalDialogManager:: |
| 57 CreateNativeManager( |
| 58 NativeWebContentsModalDialogManagerDelegate* native_delegate) { |
| 59 return new NativeWebContentsModalDialogManagerCloseTest(native_delegate); |
| 60 } |
| 61 |
55 TEST_F(WebContentsModalDialogManagerTest, WebContentsModalDialogs) { | 62 TEST_F(WebContentsModalDialogManagerTest, WebContentsModalDialogs) { |
56 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 63 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
57 WebContentsModalDialogManager::FromWebContents(web_contents()); | 64 WebContentsModalDialogManager::FromWebContents(web_contents()); |
58 WebContentsModalDialogManager::TestApi test_api( | 65 WebContentsModalDialogManager::TestApi test_api( |
59 web_contents_modal_dialog_manager); | 66 web_contents_modal_dialog_manager); |
60 | 67 |
61 NativeWebContentsModalDialogManagerCloseTest* native_manager = | 68 NativeWebContentsModalDialogManagerCloseTest* native_manager = |
62 new NativeWebContentsModalDialogManagerCloseTest( | 69 new NativeWebContentsModalDialogManagerCloseTest( |
63 web_contents_modal_dialog_manager); | 70 web_contents_modal_dialog_manager); |
64 native_manager->close_count = 0; | 71 native_manager->close_count = 0; |
65 | 72 |
66 test_api.ResetNativeManager(native_manager); | 73 test_api.ResetNativeManager(native_manager); |
67 | 74 |
68 const int kWindowCount = 4; | 75 const int kWindowCount = 4; |
69 for (int i = 0; i < kWindowCount; i++) | 76 for (int i = 0; i < kWindowCount; i++) |
70 // WebContentsModalDialogManager treats the NativeWebContentsModalDialog as | 77 // WebContentsModalDialogManager treats the NativeWebContentsModalDialog as |
71 // an opaque type, so creating fake NativeWebContentsModalDialogs using | 78 // an opaque type, so creating fake NativeWebContentsModalDialogs using |
72 // reinterpret_cast is valid. | 79 // reinterpret_cast is valid. |
73 web_contents_modal_dialog_manager->ShowDialog( | 80 web_contents_modal_dialog_manager->ShowDialog( |
74 reinterpret_cast<NativeWebContentsModalDialog>(i)); | 81 reinterpret_cast<NativeWebContentsModalDialog>(i)); |
75 EXPECT_EQ(native_manager->close_count, 0); | 82 EXPECT_EQ(native_manager->close_count, 0); |
76 | 83 |
77 test_api.CloseAllDialogs(); | 84 test_api.CloseAllDialogs(); |
78 EXPECT_EQ(native_manager->close_count, kWindowCount); | 85 EXPECT_EQ(native_manager->close_count, kWindowCount); |
79 } | 86 } |
| 87 |
| 88 } // namespace web_modal |
OLD | NEW |