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

Side by Side Diff: chrome/test/base/ui_test_utils.cc

Issue 2901583002: Fold AppModalDialog into its only subclass, JavaScriptAppModalDialog. (Closed)
Patch Set: fix collapse Created 3 years, 6 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
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | components/app_modal/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/test/base/ui_test_utils.h" 5 #include "chrome/test/base/ui_test_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 22 matching lines...) Expand all
33 #include "chrome/browser/ui/browser_navigator.h" 33 #include "chrome/browser/ui/browser_navigator.h"
34 #include "chrome/browser/ui/browser_navigator_params.h" 34 #include "chrome/browser/ui/browser_navigator_params.h"
35 #include "chrome/browser/ui/browser_window.h" 35 #include "chrome/browser/ui/browser_window.h"
36 #include "chrome/browser/ui/find_bar/find_notification_details.h" 36 #include "chrome/browser/ui/find_bar/find_notification_details.h"
37 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 37 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
38 #include "chrome/browser/ui/location_bar/location_bar.h" 38 #include "chrome/browser/ui/location_bar/location_bar.h"
39 #include "chrome/browser/ui/tabs/tab_strip_model.h" 39 #include "chrome/browser/ui/tabs/tab_strip_model.h"
40 #include "chrome/common/chrome_paths.h" 40 #include "chrome/common/chrome_paths.h"
41 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
42 #include "chrome/test/base/find_in_page_observer.h" 42 #include "chrome/test/base/find_in_page_observer.h"
43 #include "components/app_modal/app_modal_dialog.h"
44 #include "components/app_modal/app_modal_dialog_queue.h" 43 #include "components/app_modal/app_modal_dialog_queue.h"
45 #include "components/app_modal/javascript_app_modal_dialog.h" 44 #include "components/app_modal/javascript_app_modal_dialog.h"
46 #include "components/bookmarks/browser/bookmark_model.h" 45 #include "components/bookmarks/browser/bookmark_model.h"
47 #include "components/history/core/browser/history_service_observer.h" 46 #include "components/history/core/browser/history_service_observer.h"
48 #include "components/omnibox/browser/autocomplete_controller.h" 47 #include "components/omnibox/browser/autocomplete_controller.h"
49 #include "components/omnibox/browser/omnibox_edit_model.h" 48 #include "components/omnibox/browser/omnibox_edit_model.h"
50 #include "components/prefs/pref_service.h" 49 #include "components/prefs/pref_service.h"
51 #include "content/public/browser/download_item.h" 50 #include "content/public/browser/download_item.h"
52 #include "content/public/browser/download_manager.h" 51 #include "content/public/browser/download_manager.h"
53 #include "content/public/browser/navigation_controller.h" 52 #include "content/public/browser/navigation_controller.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 DCHECK(!base::ContainsKey(excluded_browsers, new_browser)); 101 DCHECK(!base::ContainsKey(excluded_browsers, new_browser));
103 } 102 }
104 return new_browser; 103 return new_browser;
105 } 104 }
106 105
107 class AppModalDialogWaiter : public app_modal::AppModalDialogObserver { 106 class AppModalDialogWaiter : public app_modal::AppModalDialogObserver {
108 public: 107 public:
109 AppModalDialogWaiter() : dialog_(nullptr) {} 108 AppModalDialogWaiter() : dialog_(nullptr) {}
110 ~AppModalDialogWaiter() override {} 109 ~AppModalDialogWaiter() override {}
111 110
112 app_modal::AppModalDialog* Wait() { 111 app_modal::JavaScriptAppModalDialog* Wait() {
113 if (dialog_) 112 if (dialog_)
114 return dialog_; 113 return dialog_;
115 message_loop_runner_ = new content::MessageLoopRunner; 114 message_loop_runner_ = new content::MessageLoopRunner;
116 message_loop_runner_->Run(); 115 message_loop_runner_->Run();
117 EXPECT_TRUE(dialog_); 116 EXPECT_TRUE(dialog_);
118 return dialog_; 117 return dialog_;
119 } 118 }
120 119
121 // AppModalDialogObserver: 120 // AppModalDialogObserver:
122 void Notify(app_modal::AppModalDialog* dialog) override { 121 void Notify(app_modal::JavaScriptAppModalDialog* dialog) override {
123 DCHECK(!dialog_); 122 DCHECK(!dialog_);
124 dialog_ = dialog; 123 dialog_ = dialog;
125 CheckForHangMonitorDisabling(dialog); 124 CheckForHangMonitorDisabling(dialog);
126 if (message_loop_runner_.get() && message_loop_runner_->loop_running()) 125 if (message_loop_runner_.get() && message_loop_runner_->loop_running())
127 message_loop_runner_->Quit(); 126 message_loop_runner_->Quit();
128 } 127 }
129 128
130 static void CheckForHangMonitorDisabling(app_modal::AppModalDialog* dialog) { 129 static void CheckForHangMonitorDisabling(
130 app_modal::JavaScriptAppModalDialog* dialog) {
131 // If a test waits for a beforeunload dialog but hasn't disabled the 131 // If a test waits for a beforeunload dialog but hasn't disabled the
132 // beforeunload hang timer before triggering it, there will be a race 132 // beforeunload hang timer before triggering it, there will be a race
133 // between the dialog and the timer and the test will be flaky. We can't 133 // between the dialog and the timer and the test will be flaky. We can't
134 // disable the timer here, as it's too late, but we can tell when we've won 134 // disable the timer here, as it's too late, but we can tell when we've won
135 // a race that we shouldn't have been in. 135 // a race that we shouldn't have been in.
136 if (!dialog->IsJavaScriptModalDialog()) 136 if (!dialog->is_before_unload_dialog())
137 return;
138
139 auto* js_dialog = static_cast<app_modal::JavaScriptAppModalDialog*>(dialog);
140 if (!js_dialog->is_before_unload_dialog())
141 return; 137 return;
142 138
143 // Unfortunately we don't know which frame spawned this dialog and should 139 // Unfortunately we don't know which frame spawned this dialog and should
144 // have the hang monitor disabled, so we cheat a bit and search for *a* 140 // have the hang monitor disabled, so we cheat a bit and search for *a*
145 // frame with the hang monitor disabled. The failure case that's worrisome 141 // frame with the hang monitor disabled. The failure case that's worrisome
146 // is someone who doesn't know the requirement to disable the hang monitor, 142 // is someone who doesn't know the requirement to disable the hang monitor,
147 // and this will catch that case. 143 // and this will catch that case.
148 auto* contents = dialog->web_contents(); 144 auto* contents = dialog->web_contents();
149 for (auto* frame : contents->GetAllFrames()) 145 for (auto* frame : contents->GetAllFrames())
150 if (frame->IsBeforeUnloadHangMonitorDisabledForTesting()) 146 if (frame->IsBeforeUnloadHangMonitorDisabledForTesting())
151 return; 147 return;
152 148
153 FAIL() << "If waiting for a beforeunload dialog, the beforeunload timer " 149 FAIL() << "If waiting for a beforeunload dialog, the beforeunload timer "
154 "must be disabled on the spawning frame to avoid flakiness."; 150 "must be disabled on the spawning frame to avoid flakiness.";
155 } 151 }
156 152
157 private: 153 private:
158 app_modal::AppModalDialog* dialog_; 154 app_modal::JavaScriptAppModalDialog* dialog_;
159 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 155 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
160 156
161 DISALLOW_COPY_AND_ASSIGN(AppModalDialogWaiter); 157 DISALLOW_COPY_AND_ASSIGN(AppModalDialogWaiter);
162 }; 158 };
163 159
164 } // namespace 160 } // namespace
165 161
166 bool GetCurrentTabTitle(const Browser* browser, base::string16* title) { 162 bool GetCurrentTabTitle(const Browser* browser, base::string16* title) {
167 WebContents* web_contents = 163 WebContents* web_contents =
168 browser->tab_strip_model()->GetActiveWebContents(); 164 browser->tab_strip_model()->GetActiveWebContents();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 325
330 // Create a relative path. 326 // Create a relative path.
331 *build_dir = base::FilePath(); 327 *build_dir = base::FilePath();
332 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) 328 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr)
333 *build_dir = build_dir->Append(FILE_PATH_LITERAL("..")); 329 *build_dir = build_dir->Append(FILE_PATH_LITERAL(".."));
334 for (; match < exe_size; ++match) 330 for (; match < exe_size; ++match)
335 *build_dir = build_dir->Append(exe_parts[match]); 331 *build_dir = build_dir->Append(exe_parts[match]);
336 return true; 332 return true;
337 } 333 }
338 334
339 app_modal::AppModalDialog* WaitForAppModalDialog() { 335 app_modal::JavaScriptAppModalDialog* WaitForAppModalDialog() {
340 app_modal::AppModalDialogQueue* dialog_queue = 336 app_modal::AppModalDialogQueue* dialog_queue =
341 app_modal::AppModalDialogQueue::GetInstance(); 337 app_modal::AppModalDialogQueue::GetInstance();
342 if (dialog_queue->HasActiveDialog()) { 338 if (dialog_queue->HasActiveDialog()) {
343 AppModalDialogWaiter::CheckForHangMonitorDisabling( 339 AppModalDialogWaiter::CheckForHangMonitorDisabling(
344 dialog_queue->active_dialog()); 340 dialog_queue->active_dialog());
345 return dialog_queue->active_dialog(); 341 return dialog_queue->active_dialog();
346 } 342 }
347 AppModalDialogWaiter waiter; 343 AppModalDialogWaiter waiter;
348 return waiter.Wait(); 344 return waiter.Wait();
349 } 345 }
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (browser != browser_) 592 if (browser != browser_)
597 return; 593 return;
598 594
599 observed_ = true; 595 observed_ = true;
600 BrowserList::RemoveObserver(this); 596 BrowserList::RemoveObserver(this);
601 if (message_loop_runner_.get() && message_loop_runner_->loop_running()) 597 if (message_loop_runner_.get() && message_loop_runner_->loop_running())
602 message_loop_runner_->Quit(); 598 message_loop_runner_->Quit();
603 } 599 }
604 600
605 } // namespace ui_test_utils 601 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | components/app_modal/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698