OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "chrome/browser/background/background_mode_manager.h" | 9 #include "chrome/browser/background/background_mode_manager.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/browser_shutdown.h" | 11 #include "chrome/browser/browser_shutdown.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/defaults.h" | 13 #include "chrome/browser/defaults.h" |
14 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 14 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
15 #include "chrome/browser/download/download_prefs.h" | 15 #include "chrome/browser/download/download_prefs.h" |
16 #include "chrome/browser/download/download_service.h" | 16 #include "chrome/browser/download/download_service.h" |
17 #include "chrome/browser/download/download_service_factory.h" | 17 #include "chrome/browser/download/download_service_factory.h" |
18 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
19 #include "chrome/browser/lifetime/browser_close_manager.h" | 19 #include "chrome/browser/lifetime/browser_close_manager.h" |
20 #include "chrome/browser/net/url_request_mock_util.h" | 20 #include "chrome/browser/net/url_request_mock_util.h" |
21 #include "chrome/browser/prefs/session_startup_pref.h" | 21 #include "chrome/browser/prefs/session_startup_pref.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
24 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | |
25 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | |
26 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
28 #include "chrome/browser/ui/browser_iterator.h" | 26 #include "chrome/browser/ui/browser_iterator.h" |
29 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
31 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
33 #include "chrome/test/base/in_process_browser_test.h" | 31 #include "chrome/test/base/in_process_browser_test.h" |
34 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
33 #include "components/app_modal_dialogs/javascript_app_modal_dialog.h" | |
34 #include "components/app_modal_dialogs/native_app_modal_dialog.h" | |
35 #include "content/public/browser/browser_context.h" | 35 #include "content/public/browser/browser_context.h" |
36 #include "content/public/browser/download_item.h" | 36 #include "content/public/browser/download_item.h" |
37 #include "content/public/browser/download_manager.h" | 37 #include "content/public/browser/download_manager.h" |
38 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
39 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
40 #include "content/public/test/download_test_observer.h" | 40 #include "content/public/test/download_test_observer.h" |
41 #include "content/public/test/test_navigation_observer.h" | 41 #include "content/public/test/test_navigation_observer.h" |
42 #include "content/test/net/url_request_slow_download_job.h" | 42 #include "content/test/net/url_request_slow_download_job.h" |
43 #include "net/test/embedded_test_server/embedded_test_server.h" | 43 #include "net/test/embedded_test_server/embedded_test_server.h" |
44 #include "net/test/url_request/url_request_mock_http_job.h" | 44 #include "net/test/url_request/url_request_mock_http_job.h" |
45 | 45 |
46 #if defined(OS_CHROMEOS) | 46 #if defined(OS_CHROMEOS) |
47 #include "chromeos/chromeos_switches.h" | 47 #include "chromeos/chromeos_switches.h" |
48 #endif | 48 #endif |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
52 class AppModalDialogObserver { | 52 class AppModalDialogObserver { |
53 public: | 53 public: |
54 AppModalDialogObserver() {} | 54 AppModalDialogObserver() {} |
55 | 55 |
56 void Start() { | 56 void Start() { |
57 observer_.reset(new content::WindowedNotificationObserver( | 57 waiter_ = ui_test_utils::CreateAppModalDialogWaiter(); |
58 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, | |
59 content::NotificationService::AllSources())); | |
60 } | 58 } |
61 | 59 |
62 void AcceptClose() { | 60 void AcceptClose() { |
63 NativeAppModalDialog* dialog = GetNextDialog(); | 61 NativeAppModalDialog* dialog = GetNextDialog(); |
64 ASSERT_TRUE(dialog); | 62 ASSERT_TRUE(dialog); |
65 dialog->AcceptAppModalDialog(); | 63 dialog->AcceptAppModalDialog(); |
66 } | 64 } |
67 | 65 |
68 void CancelClose() { | 66 void CancelClose() { |
69 NativeAppModalDialog* dialog = GetNextDialog(); | 67 NativeAppModalDialog* dialog = GetNextDialog(); |
70 ASSERT_TRUE(dialog); | 68 ASSERT_TRUE(dialog); |
71 dialog->CancelAppModalDialog(); | 69 dialog->CancelAppModalDialog(); |
72 } | 70 } |
73 | 71 |
74 private: | 72 private: |
75 NativeAppModalDialog* GetNextDialog() { | 73 NativeAppModalDialog* GetNextDialog() { |
76 DCHECK(observer_); | 74 DCHECK(waiter_.get()); |
77 observer_->Wait(); | 75 AppModalDialog* dialog = waiter_->Wait(); |
78 if (observer_->source() == content::NotificationService::AllSources()) | |
79 return NULL; | |
80 | |
81 AppModalDialog* dialog = | |
82 content::Source<AppModalDialog>(observer_->source()).ptr(); | |
83 EXPECT_TRUE(dialog->IsJavaScriptModalDialog()); | 76 EXPECT_TRUE(dialog->IsJavaScriptModalDialog()); |
84 JavaScriptAppModalDialog* js_dialog = | 77 JavaScriptAppModalDialog* js_dialog = |
85 static_cast<JavaScriptAppModalDialog*>(dialog); | 78 static_cast<JavaScriptAppModalDialog*>(dialog); |
86 observer_.reset(new content::WindowedNotificationObserver( | 79 // Reset before creation because only one instance of the waiter is allowd. |
msw
2014/10/22 22:53:31
nit: "allowed"; for one-liner: s/instance of the w
| |
87 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, | 80 waiter_.reset(); |
88 content::NotificationService::AllSources())); | 81 waiter_ = ui_test_utils::CreateAppModalDialogWaiter(); |
msw
2014/10/22 22:53:31
Why not just have a GetNextDialog-local |waiter|?
oshima
2014/10/23 00:44:11
Sure, done.
msw
2014/10/23 18:41:21
The class isn't needed, but it's still a great imp
oshima
2014/10/23 21:44:18
I see. Removed the class and replaced with functio
msw
2014/10/23 22:01:24
Great, thank you!
| |
89 return js_dialog->native_dialog(); | 82 return js_dialog->native_dialog(); |
90 } | 83 } |
91 | 84 |
92 scoped_ptr<content::WindowedNotificationObserver> observer_; | 85 scoped_ptr<AppModalDialogWaiter> waiter_; |
93 | 86 |
94 DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver); | 87 DISALLOW_COPY_AND_ASSIGN(AppModalDialogObserver); |
95 }; | 88 }; |
96 | 89 |
97 class RepeatedNotificationObserver : public content::NotificationObserver { | 90 class RepeatedNotificationObserver : public content::NotificationObserver { |
98 public: | 91 public: |
99 explicit RepeatedNotificationObserver(int type, int count) | 92 explicit RepeatedNotificationObserver(int type, int count) |
100 : num_outstanding_(count), running_(false) { | 93 : num_outstanding_(count), running_(false) { |
101 registrar_.Add(this, type, content::NotificationService::AllSources()); | 94 registrar_.Add(this, type, content::NotificationService::AllSources()); |
102 } | 95 } |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
976 | 969 |
977 chrome::CloseAllBrowsers(); | 970 chrome::CloseAllBrowsers(); |
978 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); | 971 EXPECT_FALSE(browser_shutdown::IsTryingToQuit()); |
979 EXPECT_TRUE(chrome::BrowserIterator().done()); | 972 EXPECT_TRUE(chrome::BrowserIterator().done()); |
980 EXPECT_TRUE(IsBackgroundModeSuspended()); | 973 EXPECT_TRUE(IsBackgroundModeSuspended()); |
981 } | 974 } |
982 | 975 |
983 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, | 976 INSTANTIATE_TEST_CASE_P(BrowserCloseManagerWithBackgroundModeBrowserTest, |
984 BrowserCloseManagerWithBackgroundModeBrowserTest, | 977 BrowserCloseManagerWithBackgroundModeBrowserTest, |
985 testing::Bool()); | 978 testing::Bool()); |
OLD | NEW |