Index: chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc |
diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc |
index 15b5556b27d917b67165a33261a999ad57736850..7a88182187b25a6141beb4e81dbd56e07b98e9cd 100644 |
--- a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc |
+++ b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc |
@@ -6,9 +6,11 @@ |
#include "base/file_util.h" |
#include "base/files/file_path.h" |
+#include "base/strings/string_number_conversions.h" |
#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/extensions/api/identity/identity_api.h" |
#include "chrome/browser/extensions/api/management/management_api.h" |
#include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
#include "chrome/browser/extensions/extension_apitest.h" |
@@ -18,6 +20,12 @@ |
#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/extensions/webstore_installer.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
+#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
+#include "chrome/browser/signin/fake_signin_manager.h" |
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
+#include "chrome/browser/signin/signin_manager.h" |
+#include "chrome/browser/signin/signin_manager_factory.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/common/chrome_switches.h" |
@@ -86,11 +94,21 @@ class WebstoreInstallListener : public WebstoreInstaller::Delegate { |
std::string error_; |
}; |
+// A trivial factory to build a null service. |
+KeyedService* BuildNullService(content::BrowserContext* context) { |
+ return NULL; |
+} |
+ |
} // namespace |
// A base class for tests below. |
class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { |
public: |
+ ExtensionWebstorePrivateApiTest() |
+ : signin_manager_(NULL), |
+ token_service_(NULL) {} |
+ virtual ~ExtensionWebstorePrivateApiTest() {} |
+ |
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
ExtensionApiTest::SetUpCommandLine(command_line); |
command_line->AppendSwitchASCII( |
@@ -101,13 +119,40 @@ class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { |
} |
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
+ ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
+ |
// Start up the test server and get us ready for calling the install |
// API functions. |
host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
- ASSERT_TRUE(test_server()->Start()); |
+ ASSERT_TRUE(StartSpawnedTestServer()); |
ExtensionInstallUI::set_disable_failure_ui_for_tests(); |
} |
+ virtual void SetUpOnMainThread() OVERRIDE { |
+ ExtensionApiTest::SetUpOnMainThread(); |
+ |
+ // Shutdown the existing identity API service, as it is not designed to |
+ // handle a fake signin manager or token service being installed. |
+ IdentityAPI::GetFactoryInstance()->SetTestingFactory( |
+ profile(), BuildNullService); |
+ |
+ // Install a fake signin manager and token service, and grab references to |
+ // them. |
+ signin_manager_ = |
+ static_cast<FakeSigninManagerForTesting*>( |
+ SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
+ profile(), &FakeSigninManagerBase::Build)); |
+ ASSERT_TRUE(signin_manager_); |
+ // TODO(isherman): This fails due to observers that don't unregister when |
+ // the service is swapped. |
+ /*token_service_ = |
+ static_cast<FakeProfileOAuth2TokenService*>( |
+ ProfileOAuth2TokenServiceFactory::GetInstance() |
+ ->SetTestingFactoryAndUse( |
+ profile(), &BuildFakeProfileOAuth2TokenService)); |
+ ASSERT_TRUE(token_service_);*/ |
Ilya Sherman
2014/03/26 08:21:39
I'm having no end of trouble from trying to substi
|
+ } |
+ |
protected: |
// Returns a test server URL, but with host 'www.example.com' so it matches |
// the web store app's extent that we set up via command line flags. |
@@ -142,9 +187,31 @@ class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { |
#endif |
} |
+ // Navigates to |page| and waits for the API call. |
+ void StartSignInTest(const std::string& page) { |
+ ui_test_utils::NavigateToURL(browser(), GetTestServerURL(page)); |
+ |
+ // Wait for the API to be called. A simple way to wait for this is to run |
+ // some other JavaScript in the page and wait for a round-trip back to the |
+ // browser process. |
+ bool result = false; |
+ ASSERT_TRUE( |
+ content::ExecuteScriptAndExtractBool( |
+ GetWebContents(), "window.domAutomationController.send(true)", |
+ &result)); |
+ ASSERT_TRUE(result); |
+ } |
+ |
+ content::WebContents* GetWebContents() { |
+ return browser()->tab_strip_model()->GetActiveWebContents(); |
+ } |
+ |
ExtensionService* service() { |
return browser()->profile()->GetExtensionService(); |
} |
+ |
+ FakeSigninManagerForTesting* signin_manager_; |
+ FakeProfileOAuth2TokenService* token_service_; |
}; |
// Test cases for webstore origin frame blocking. |
@@ -152,11 +219,9 @@ class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { |
// Chromium, see crbug.com/226018. |
IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
DISABLED_FrameWebstorePageBlocked) { |
- content::WebContents* contents = |
- browser()->tab_strip_model()->GetActiveWebContents(); |
base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); |
base::string16 failure_title = base::UTF8ToUTF16("FAIL"); |
- content::TitleWatcher watcher(contents, expected_title); |
+ content::TitleWatcher watcher(GetWebContents(), expected_title); |
watcher.AlsoWaitForTitle(failure_title); |
GURL url = test_server()->GetURL( |
"files/extensions/api_test/webstore_private/noframe.html"); |
@@ -169,11 +234,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
// Chromium, see crbug.com/226018. |
IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
DISABLED_FrameErrorPageBlocked) { |
- content::WebContents* contents = |
- browser()->tab_strip_model()->GetActiveWebContents(); |
base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); |
base::string16 failure_title = base::UTF8ToUTF16("FAIL"); |
- content::TitleWatcher watcher(contents, expected_title); |
+ content::TitleWatcher watcher(GetWebContents(), expected_title); |
watcher.AlsoWaitForTitle(failure_title); |
GURL url = test_server()->GetURL( |
"files/extensions/api_test/webstore_private/noframe2.html"); |
@@ -367,4 +430,121 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) { |
RunTest(webgl_allowed); |
} |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_MissingContinueUrl) { |
+ GURL page_url = GetTestServerURL("sign_in_missing_continue_url.html"); |
+ ASSERT_TRUE(RunPageTest(page_url.spec())); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_InvalidContinueUrl) { |
+ GURL page_url = GetTestServerURL("sign_in_invalid_continue_url.html"); |
+ ASSERT_TRUE(RunPageTest(page_url.spec())); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_ContinueUrlOnDifferentOrigin) { |
+ GURL page_url = |
+ GetTestServerURL("sign_in_continue_url_on_different_origin.html"); |
+ ASSERT_TRUE(RunPageTest(page_url.spec())); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_DisallowedInIncognito) { |
+ // Make sure that the test is testing something more than the absence of a |
+ // sign-in manager for this profile. |
+ ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile())); |
+ |
+ GURL page_url = |
+ GetTestServerURL("sign_in_disallowed_in_incognito.html"); |
+ ASSERT_TRUE( |
+ RunPageTest(page_url.spec(), ExtensionApiTest::kFlagUseIncognito)); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_DisabledWhenWebBasedSigninIsEnabled) { |
+ // Make sure that the test is testing something more than the absence of a |
+ // sign-in manager for this profile. |
+ ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile())); |
+ |
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ switches::kEnableWebBasedSignin); |
+ GURL page_url = GetTestServerURL( |
+ "sign_in_disabled_when_web_based_signin_is_enabled.html"); |
+ ASSERT_TRUE(RunPageTest(page_url.spec())); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_AlreadySignedIn) { |
+ signin_manager_->SetAuthenticatedUsername("user@example.com"); |
+ GURL page_url = GetTestServerURL("sign_in_already_signed_in.html"); |
+ ASSERT_TRUE(RunPageTest(page_url.spec())); |
+} |
+ |
+// The FakeSignInManager class is not implemented for ChromeOS, so there's no |
+// straightforward way to test these flows on that platform. |
+#if !defined(OS_CHROMEOS) |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_AuthInProgress_Fails) { |
+ // Initiate an authentication that will be in progress when the sign-in API is |
+ // called. |
+ signin_manager_->set_auth_in_progress("user@example.com"); |
+ |
+ // Navigate to the page, which will cause the sign-in API to be called. |
+ // Then, complete the authentication in a failed state. |
+ ResultCatcher catcher; |
+ StartSignInTest("sign_in_auth_in_progress_fails.html"); |
+ signin_manager_->FailSignin(GoogleServiceAuthError::AuthErrorNone()); |
+ ASSERT_TRUE(catcher.GetNextResult()); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_AuthInProgress_MergeSessionFails) { |
+ // TODO(isherman): Implement this test. How do I interpose an event after |
+ // navigating to the test URL but before waiting for a success or failure |
+ // result? |
+ GURL page_url = |
+ GetTestServerURL("sign_in_auth_in_progress_merge_session_fails.html"); |
+ ASSERT_TRUE(RunPageTest(page_url.spec())); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_AuthInProgress_Succeeds) { |
+ // Initiate an authentication that will be in progress when the sign-in API is |
+ // called. |
+ signin_manager_->set_auth_in_progress("user@example.com"); |
+ |
+ // Navigate to the page, which will cause the sign-in API to be called. |
+ // Then, complete the authentication in a successful state. |
+ ResultCatcher catcher; |
+ StartSignInTest("sign_in_auth_in_progress_succeeds.html"); |
+ // TODO(isherman): Need merge session to happen, not for the sign-in to |
+ // succeed. That requires a token to be successfully merged. Then, we've got |
+ // to somehow trigger a call to MergeSessionCompleted -- which can either be |
+ // through the SigninManagerFactory or through the AccountReconcilorFactory. |
+ // *sigh*. |
+ signin_manager_->CompletePendingSignin(); |
+ //token_service_->IssueRefreshToken("token"); |
+ ASSERT_TRUE(catcher.GetNextResult()); |
+} |
+#endif // !defined (OS_CHROMEOS) |
+ |
+IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
+ SignIn_RedirectToSignIn) { |
+ GURL signin_url( |
+ "chrome://chrome-signin/?source=5&continue_url=http%3A%2F%2F" |
+ "www.example.com%3A" + |
+ base::IntToString(test_server()->host_port_pair().port()) + |
+ "%2Fcontinue"); |
+ ui_test_utils::UrlLoadObserver observer( |
+ signin_url, |
+ content::Source<content::NavigationController>( |
+ &GetWebContents()->GetController())); |
+ StartSignInTest("sign_in_redirect_to_sign_in.html"); |
+ observer.Wait(); |
+ |
+ // TODO(isherman): Also test the redirect back to the continue URL once |
+ // sign-in completes? |
+} |
+ |
} // namespace extensions |