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 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ |
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/browser/signin/signin_manager.h" | 9 #include "chrome/browser/signin/signin_manager.h" |
10 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/singleton_tabs.h" | 12 #include "chrome/browser/ui/singleton_tabs.h" |
13 #include "chrome/browser/ui/sync/sync_promo_ui.h" | 13 #include "chrome/browser/ui/sync/sync_promo_ui.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/signin/login_ui_service.h" | 15 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.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/notification_types.h" |
20 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_observer.h" |
23 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
24 #include "google_apis/gaia/gaia_urls.h" | 27 #include "google_apis/gaia/gaia_urls.h" |
25 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
26 | 29 |
27 namespace { | 30 namespace { |
28 const char kNonSigninURL[] = "www.google.com"; | 31 const char kNonSigninURL[] = "www.google.com"; |
29 } | 32 } |
30 | 33 |
31 class SigninBrowserTest : public InProcessBrowserTest { | 34 class SigninBrowserTest : public InProcessBrowserTest { |
32 public: | 35 public: |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 157 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
155 EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess()); | 158 EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess()); |
156 | 159 |
157 // Navigating away should clear the sign-in process. | 160 // Navigating away should clear the sign-in process. |
158 GURL redirect_url("https://accounts.google.com/server-redirect?" | 161 GURL redirect_url("https://accounts.google.com/server-redirect?" |
159 "https://foo.com?service=chromiumsync"); | 162 "https://foo.com?service=chromiumsync"); |
160 ui_test_utils::NavigateToURL(browser(), redirect_url); | 163 ui_test_utils::NavigateToURL(browser(), redirect_url); |
161 EXPECT_FALSE(signin->HasSigninProcess()); | 164 EXPECT_FALSE(signin->HasSigninProcess()); |
162 } | 165 } |
163 | 166 |
| 167 class BackOnNTPCommitObserver : public content::WebContentsObserver { |
| 168 public: |
| 169 explicit BackOnNTPCommitObserver(content::WebContents* web_contents) |
| 170 : content::WebContentsObserver(web_contents) { |
| 171 } |
| 172 |
| 173 virtual void DidCommitProvisionalLoadForFrame( |
| 174 int64 frame_id, |
| 175 bool is_main_frame, |
| 176 const GURL& url, |
| 177 content::PageTransition transition_type, |
| 178 content::RenderViewHost* render_view_host) OVERRIDE { |
| 179 if (url == GURL(chrome::kChromeUINewTabURL)) { |
| 180 content::WindowedNotificationObserver observer( |
| 181 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 182 content::NotificationService::AllSources()); |
| 183 web_contents()->GetController().GoBack(); |
| 184 observer.Wait(); |
| 185 } |
| 186 } |
| 187 |
| 188 private: |
| 189 DISALLOW_COPY_AND_ASSIGN(BackOnNTPCommitObserver); |
| 190 }; |
| 191 |
| 192 // This is a test for http://crbug.com/257277. It simulates the navigations |
| 193 // that occur if the user clicks on the "Skip for now" link at the signin page |
| 194 // and initiates a back navigation between the point of Commit and |
| 195 // DidStopLoading of the NTP. |
| 196 IN_PROC_BROWSER_TEST_F(SigninBrowserTest, SigninSkipForNowAndGoBack) { |
| 197 GURL ntp_url(chrome::kChromeUINewTabURL); |
| 198 GURL start_url = |
| 199 SyncPromoUI::GetSyncPromoURL(SyncPromoUI::SOURCE_START_PAGE, true); |
| 200 GURL skip_url(SyncPromoUI::GetSyncLandingURL("ntp", 1)); |
| 201 |
| 202 SigninManager* signin = SigninManagerFactory::GetForProfile( |
| 203 browser()->profile()); |
| 204 EXPECT_FALSE(signin->HasSigninProcess()); |
| 205 |
| 206 ui_test_utils::NavigateToURL(browser(), start_url); |
| 207 EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess()); |
| 208 |
| 209 content::WebContents* web_contents = |
| 210 browser()->tab_strip_model()->GetActiveWebContents(); |
| 211 |
| 212 // Simulate clicking on the Skip for now link by navigating to the URL. |
| 213 ui_test_utils::NavigateToURL(browser(), skip_url); |
| 214 |
| 215 // Register an observer that will navigate back immediately on the commit of |
| 216 // the NTP. This will allow us to hit the race condition of navigating back |
| 217 // before the DidStopLoading message of NTP gets delivered. This must be |
| 218 // created after the navigation to the skip_url has finished loading, |
| 219 // otherwise this observer will navigate back, before the history cleaner |
| 220 // has had a chance to remove the navigation entry. |
| 221 BackOnNTPCommitObserver commit_observer(web_contents); |
| 222 |
| 223 // Since the navigation to the blank URL is monitored for, the |
| 224 // OneClickSigninHelper initiates immediately a navigation to the NTP. |
| 225 // Thus, we expect the visible URL to be the NTP. |
| 226 EXPECT_EQ(skip_url, web_contents->GetLastCommittedURL()); |
| 227 EXPECT_EQ(ntp_url, web_contents->GetVisibleURL()); |
| 228 |
| 229 content::WindowedNotificationObserver observer( |
| 230 content::NOTIFICATION_LOAD_STOP, |
| 231 content::NotificationService::AllSources()); |
| 232 observer.Wait(); |
| 233 EXPECT_EQ(start_url, web_contents->GetLastCommittedURL()); |
| 234 } |
164 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | 235 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ |
OLD | NEW |