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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/run_loop.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
9 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" | 11 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_commands.h" | 13 #include "chrome/browser/ui/browser_commands.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
18 #include "components/app_modal/app_modal_dialog.h" | |
19 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
21 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
22 #include "ui/base/test/ui_controls.h" | 23 #include "ui/base/test/ui_controls.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 class MouseLeaveTest : public InProcessBrowserTest { | 27 class MouseLeaveTest : public InProcessBrowserTest { |
27 public: | 28 public: |
28 MouseLeaveTest() {} | 29 MouseLeaveTest() {} |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 #else | 152 #else |
152 #define MAYBE_ModalDialog ModalDialog | 153 #define MAYBE_ModalDialog ModalDialog |
153 #endif | 154 #endif |
154 | 155 |
155 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) { | 156 IN_PROC_BROWSER_TEST_F(MouseLeaveTest, MAYBE_ModalDialog) { |
156 content::WebContents* tab = | 157 content::WebContents* tab = |
157 browser()->tab_strip_model()->GetActiveWebContents(); | 158 browser()->tab_strip_model()->GetActiveWebContents(); |
158 | 159 |
159 EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab)); | 160 EXPECT_NO_FATAL_FAILURE(LoadTestPageAndWaitForMouseOver(tab)); |
160 | 161 |
| 162 JavaScriptDialogTabHelper* js_helper = |
| 163 JavaScriptDialogTabHelper::FromWebContents(tab); |
| 164 base::RunLoop dialog_wait; |
| 165 js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure()); |
161 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); | 166 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
162 app_modal::AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 167 dialog_wait.Run(); |
| 168 |
163 // Cancel the dialog. | 169 // Cancel the dialog. |
164 alert->CloseModalDialog(); | 170 js_helper->HandleJavaScriptDialog(tab, false, nullptr); |
165 | 171 |
166 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16("done()")); | 172 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::ASCIIToUTF16("done()")); |
167 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); | 173 const base::string16 success_title = base::ASCIIToUTF16("without mouseleave"); |
168 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); | 174 const base::string16 failure_title = base::ASCIIToUTF16("with mouseleave"); |
169 content::TitleWatcher done_title_watcher(tab, success_title); | 175 content::TitleWatcher done_title_watcher(tab, success_title); |
170 done_title_watcher.AlsoWaitForTitle(failure_title); | 176 done_title_watcher.AlsoWaitForTitle(failure_title); |
171 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); | 177 EXPECT_EQ(success_title, done_title_watcher.WaitAndGetTitle()); |
172 } | 178 } |
173 | 179 |
174 } // namespace | 180 } // namespace |
OLD | NEW |