Chromium Code Reviews| 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(); | |
|
Roger Tawa OOO till Jul 10th
2013/07/22 18:35:00
For my own info, why do we need wait here?
nasko
2013/07/22 18:44:31
This is to ensure that we don't continue execution
| |
| 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 // Register an observer that will navigate back immediately on the commit of | |
| 213 // the NTP. This will allow us to hit the race condition of navigating back | |
| 214 // before the DidStopLoading message of NTP gets delivered. | |
| 215 BackOnNTPCommitObserver commit_observer(web_contents); | |
| 216 | |
| 217 // Simulate clicking on the Skip for now link by navigating to the URL. | |
| 218 ui_test_utils::NavigateToURL(browser(), skip_url); | |
|
Roger Tawa OOO till Jul 10th
2013/07/22 18:35:00
This call does a wait for the load to stop. Why d
nasko
2013/07/22 18:44:31
The extra wait is to ensure the test has enough ti
| |
| 219 | |
| 220 // Since the navigation to the blank URL is monitored for, the | |
| 221 // OneClickSigninHelper initiates immediately a navigation to the NTP. | |
| 222 // Thus, we expect the visible URL to be the NTP. | |
| 223 EXPECT_EQ(skip_url, web_contents->GetLastCommittedURL()); | |
| 224 EXPECT_EQ(ntp_url, web_contents->GetActiveURL()); | |
| 225 | |
| 226 content::WindowedNotificationObserver observer( | |
| 227 content::NOTIFICATION_LOAD_STOP, | |
| 228 content::NotificationService::AllSources()); | |
| 229 observer.Wait(); | |
| 230 EXPECT_EQ(skip_url, web_contents->GetLastCommittedURL()); | |
| 231 EXPECT_EQ(ntp_url, web_contents->GetActiveURL()); | |
|
Roger Tawa OOO till Jul 10th
2013/07/22 18:35:00
I'm not sure why these two tests are the same as l
nasko
2013/07/22 18:44:31
Did you have a chance to read my timeline explanat
| |
| 232 } | |
| 164 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | 233 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ |
| OLD | NEW |