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/webui/options/options_ui_browsertest.h" | 5 #include "chrome/browser/ui/webui/options/options_ui_browsertest.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/scoped_observer.h" |
8 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | |
11 #include "chrome/browser/signin/signin_manager.h" | 11 #include "chrome/browser/signin/signin_manager.h" |
12 #include "chrome/browser/signin/signin_manager_factory.h" | 12 #include "chrome/browser/signin/signin_manager_factory.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/browser/ui/webui/options/options_ui.h" | 15 #include "chrome/browser/ui/webui/options/options_ui.h" |
16 #include "chrome/browser/ui/webui/uber/uber_ui.h" | 16 #include "chrome/browser/ui/webui/uber/uber_ui.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
20 #include "content/public/browser/notification_service.h" | |
21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
22 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
23 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
24 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
25 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
26 | 25 |
27 #if !defined(OS_CHROMEOS) | 26 #if !defined(OS_CHROMEOS) |
28 #include <string> | 27 #include <string> |
29 | 28 |
30 #include "base/basictypes.h" | 29 #include "base/basictypes.h" |
31 #include "base/bind.h" | 30 #include "base/bind.h" |
32 #include "base/callback.h" | 31 #include "base/callback.h" |
33 #include "base/files/file_path.h" | 32 #include "base/files/file_path.h" |
34 #include "base/run_loop.h" | 33 #include "base/run_loop.h" |
35 #include "chrome/browser/browser_process.h" | 34 #include "chrome/browser/browser_process.h" |
36 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
37 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
38 #include "chrome/browser/ui/browser_commands.h" | 37 #include "chrome/browser/ui/browser_commands.h" |
39 #include "content/public/test/test_navigation_observer.h" | 38 #include "content/public/test/test_navigation_observer.h" |
40 #include "ui/base/window_open_disposition.h" | 39 #include "ui/base/window_open_disposition.h" |
41 #include "url/gurl.h" | 40 #include "url/gurl.h" |
42 #endif | 41 #endif |
43 | 42 |
44 using content::MessageLoopRunner; | 43 using content::MessageLoopRunner; |
45 | 44 |
46 namespace options { | 45 namespace options { |
47 | 46 |
48 namespace { | 47 namespace { |
49 | 48 |
| 49 class SignOutWaiter : public SigninManagerBase::Observer { |
| 50 public: |
| 51 SignOutWaiter(SigninManagerBase* signin_manager) |
| 52 : seen_(false), running_(false), scoped_observer_(this) { |
| 53 scoped_observer_.Add(signin_manager); |
| 54 } |
| 55 virtual ~SignOutWaiter() {} |
| 56 |
| 57 void Wait() { |
| 58 if (seen_) |
| 59 return; |
| 60 |
| 61 running_ = true; |
| 62 message_loop_runner_ = new MessageLoopRunner; |
| 63 message_loop_runner_->Run(); |
| 64 EXPECT_TRUE(seen_); |
| 65 } |
| 66 |
| 67 virtual void GoogleSignedOut(const std::string& username) OVERRIDE { |
| 68 seen_ = true; |
| 69 if (!running_) |
| 70 return; |
| 71 |
| 72 message_loop_runner_->Quit(); |
| 73 running_ = false; |
| 74 } |
| 75 |
| 76 private: |
| 77 bool seen_; |
| 78 bool running_; |
| 79 ScopedObserver<SigninManagerBase, SignOutWaiter> scoped_observer_; |
| 80 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 81 }; |
| 82 |
50 #if !defined(OS_CHROMEOS) | 83 #if !defined(OS_CHROMEOS) |
51 void RunClosureWhenProfileInitialized(const base::Closure& closure, | 84 void RunClosureWhenProfileInitialized(const base::Closure& closure, |
52 Profile* profile, | 85 Profile* profile, |
53 Profile::CreateStatus status) { | 86 Profile::CreateStatus status) { |
54 if (status == Profile::CREATE_STATUS_INITIALIZED) | 87 if (status == Profile::CREATE_STATUS_INITIALIZED) |
55 closure.Run(); | 88 closure.Run(); |
56 } | 89 } |
57 #endif | 90 #endif |
58 | 91 |
59 } // namespace | 92 } // namespace |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 162 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
130 browser()->tab_strip_model()->GetActiveWebContents(), | 163 browser()->tab_strip_model()->GetActiveWebContents(), |
131 "var dialog = $('sync-setup-stop-syncing');" | 164 "var dialog = $('sync-setup-stop-syncing');" |
132 "var original_status = dialog.hidden;" | 165 "var original_status = dialog.hidden;" |
133 "$('start-stop-sync').click();" | 166 "$('start-stop-sync').click();" |
134 "domAutomationController.send(original_status && !dialog.hidden);", | 167 "domAutomationController.send(original_status && !dialog.hidden);", |
135 &result)); | 168 &result)); |
136 | 169 |
137 EXPECT_TRUE(result); | 170 EXPECT_TRUE(result); |
138 | 171 |
139 content::WindowedNotificationObserver wait_for_signout( | 172 SignOutWaiter sign_out_waiter(signin); |
140 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
141 content::NotificationService::AllSources()); | |
142 | 173 |
143 ASSERT_TRUE(content::ExecuteScript( | 174 ASSERT_TRUE(content::ExecuteScript( |
144 browser()->tab_strip_model()->GetActiveWebContents(), | 175 browser()->tab_strip_model()->GetActiveWebContents(), |
145 "$('stop-syncing-ok').click();")); | 176 "$('stop-syncing-ok').click();")); |
146 | 177 |
147 wait_for_signout.Wait(); | 178 sign_out_waiter.Wait(); |
148 | 179 |
149 EXPECT_TRUE(browser()->profile()->GetProfileName() != user); | 180 EXPECT_TRUE(browser()->profile()->GetProfileName() != user); |
150 EXPECT_TRUE(signin->GetAuthenticatedUsername().empty()); | 181 EXPECT_TRUE(signin->GetAuthenticatedUsername().empty()); |
151 } | 182 } |
152 | 183 |
153 // Regression test for http://crbug.com/301436, excluded on Chrome OS because | 184 // Regression test for http://crbug.com/301436, excluded on Chrome OS because |
154 // profile management in the settings UI exists on desktop platforms only. | 185 // profile management in the settings UI exists on desktop platforms only. |
155 IN_PROC_BROWSER_TEST_F(OptionsUIBrowserTest, NavigateBackFromOverlayDialog) { | 186 IN_PROC_BROWSER_TEST_F(OptionsUIBrowserTest, NavigateBackFromOverlayDialog) { |
156 NavigateToSettingsFrame(); | 187 NavigateToSettingsFrame(); |
157 | 188 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 run_loop.Run(); | 223 run_loop.Run(); |
193 | 224 |
194 // Verify that the settings page has updated and lists two profiles. | 225 // Verify that the settings page has updated and lists two profiles. |
195 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 226 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
196 contents, javascript, &profiles)); | 227 contents, javascript, &profiles)); |
197 EXPECT_EQ(2, profiles); | 228 EXPECT_EQ(2, profiles); |
198 } | 229 } |
199 #endif | 230 #endif |
200 | 231 |
201 } // namespace options | 232 } // namespace options |
OLD | NEW |