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 |
| 30 | |
|
Charlie Reis
2013/07/18 21:53:38
nit: Remove extra line.
nasko
2013/07/19 23:03:41
Done.
| |
| 27 namespace { | 31 namespace { |
| 28 const char kNonSigninURL[] = "www.google.com"; | 32 const char kNonSigninURL[] = "www.google.com"; |
| 29 } | 33 } |
| 30 | 34 |
| 31 class SigninBrowserTest : public InProcessBrowserTest { | 35 class SigninBrowserTest : public InProcessBrowserTest { |
| 32 public: | 36 public: |
| 33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 34 https_server_.reset(new net::SpawnedTestServer( | 38 https_server_.reset(new net::SpawnedTestServer( |
| 35 net::SpawnedTestServer::TYPE_HTTPS, | 39 net::SpawnedTestServer::TYPE_HTTPS, |
| 36 net::SpawnedTestServer::kLocalhost, | 40 net::SpawnedTestServer::kLocalhost, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 158 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 155 EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess()); | 159 EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess()); |
| 156 | 160 |
| 157 // Navigating away should clear the sign-in process. | 161 // Navigating away should clear the sign-in process. |
| 158 GURL redirect_url("https://accounts.google.com/server-redirect?" | 162 GURL redirect_url("https://accounts.google.com/server-redirect?" |
| 159 "https://foo.com?service=chromiumsync"); | 163 "https://foo.com?service=chromiumsync"); |
| 160 ui_test_utils::NavigateToURL(browser(), redirect_url); | 164 ui_test_utils::NavigateToURL(browser(), redirect_url); |
| 161 EXPECT_FALSE(signin->HasSigninProcess()); | 165 EXPECT_FALSE(signin->HasSigninProcess()); |
| 162 } | 166 } |
| 163 | 167 |
| 168 class CommitWebContentsObserver : public content::WebContentsObserver { | |
|
Charlie Reis
2013/07/18 21:53:38
Maybe BackOnNTPCommitObserver? CommitWebContentsO
nasko
2013/07/19 23:03:41
Done.
| |
| 169 public: | |
| 170 CommitWebContentsObserver(content::WebContents* web_contents) | |
| 171 : content::WebContentsObserver(web_contents) { | |
| 172 } | |
| 173 | |
| 174 virtual void DidCommitProvisionalLoadForFrame( | |
| 175 int64 frame_id, | |
| 176 bool is_main_frame, | |
| 177 const GURL& url, | |
| 178 content::PageTransition transition_type, | |
| 179 content::RenderViewHost* render_view_host) OVERRIDE { | |
| 180 if (url == GURL(chrome::kChromeUINewTabURL)) { | |
| 181 { | |
|
Charlie Reis
2013/07/18 21:53:38
nit: Extra braces not needed.
nasko
2013/07/19 23:03:41
Yeah, a few things are left over from the mess tha
| |
| 182 content::WindowedNotificationObserver observer( | |
| 183 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 184 content::NotificationService::AllSources()); | |
| 185 web_contents()->GetController().GoBack(); | |
| 186 observer.Wait(); | |
| 187 } | |
| 188 } | |
| 189 } | |
| 190 | |
| 191 private: | |
| 192 Browser* browser_; | |
| 193 | |
| 194 DISALLOW_COPY_AND_ASSIGN(CommitWebContentsObserver); | |
| 195 }; | |
| 196 | |
| 197 IN_PROC_BROWSER_TEST_F(SigninBrowserTest, SkipForNowAndGoBack) { | |
|
Charlie Reis
2013/07/18 21:53:38
nit: Add a comment referencing the bug.
nasko
2013/07/19 23:03:41
Done.
| |
| 198 GURL ntp_url(chrome::kChromeUINewTabURL); | |
| 199 GURL start_url = | |
| 200 SyncPromoUI::GetSyncPromoURL(SyncPromoUI::SOURCE_START_PAGE, true); | |
| 201 GURL skip_url(SyncPromoUI::GetSyncLandingURL("ntp", 1)); | |
| 202 | |
| 203 SigninManager* signin = SigninManagerFactory::GetForProfile( | |
| 204 browser()->profile()); | |
| 205 EXPECT_FALSE(signin->HasSigninProcess()); | |
| 206 | |
| 207 ui_test_utils::NavigateToURL(browser(), start_url); | |
| 208 EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess()); | |
| 209 | |
| 210 content::WebContents* web_contents = | |
| 211 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 212 | |
| 213 // Simulate clicking on the Skip for now link by navigating to the URL. | |
| 214 ui_test_utils::NavigateToURL(browser(), skip_url); | |
| 215 | |
| 216 // Since the navigation to the blank URL causes a "redirect" to NTP, we expect | |
|
Charlie Reis
2013/07/18 21:53:38
How do they cause this "redirect"? Is it started
nasko
2013/07/19 23:03:41
Done.
| |
| 217 // the visible URL to be the NTP. | |
| 218 EXPECT_EQ(skip_url, web_contents->GetLastCommittedURL()); | |
| 219 EXPECT_EQ(ntp_url, web_contents->GetActiveURL()); | |
|
Charlie Reis
2013/07/18 21:53:38
It's GetVisibleURL now, right? :)
nasko
2013/07/19 23:03:41
Sadly, not yet : (. But I put the comment intentio
| |
| 220 | |
| 221 // Register an observer that will navigate back immediately on the commit of | |
| 222 // the NTP. This will allow us to hit the race condition of navigating back | |
| 223 // before the DidStopLoading message of NTP gets delivered. | |
|
Charlie Reis
2013/07/18 21:53:38
Nice! That sounds like the right approach to me,
nasko
2013/07/19 23:03:41
Done.
| |
| 224 CommitWebContentsObserver commit_observer(web_contents); | |
|
Charlie Reis
2013/07/18 21:53:38
Are we guaranteed that the NTP navigation can't co
nasko
2013/07/19 23:03:41
I can't guarantee anything in complex systems ;) s
| |
| 225 | |
| 226 { | |
|
Charlie Reis
2013/07/18 21:53:38
nit: Braces aren't needed here. They're mainly us
nasko
2013/07/19 23:03:41
Done.
| |
| 227 content::WindowedNotificationObserver observer( | |
| 228 content::NOTIFICATION_LOAD_STOP, | |
| 229 content::NotificationService::AllSources()); | |
| 230 observer.Wait(); | |
| 231 EXPECT_EQ(skip_url, web_contents->GetLastCommittedURL()); | |
| 232 EXPECT_EQ(ntp_url, web_contents->GetActiveURL()); | |
|
Charlie Reis
2013/07/18 21:53:38
I don't understand this part. It looks like the s
nasko
2013/07/19 23:03:41
Since we navigated back during the NTP commit, we
| |
| 233 } | |
| 234 } | |
| 164 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | 235 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ |
| OLD | NEW |