Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc

Issue 482293003: Remove webstore code for signin that is no longer used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/callback_list.h" 7 #include "base/callback_list.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/extensions/api/identity/identity_api.h" 14 #include "chrome/browser/extensions/api/identity/identity_api.h"
15 #include "chrome/browser/extensions/api/management/management_api.h" 15 #include "chrome/browser/extensions/api/management/management_api.h"
16 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" 16 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
17 #include "chrome/browser/extensions/extension_apitest.h" 17 #include "chrome/browser/extensions/extension_apitest.h"
18 #include "chrome/browser/extensions/extension_function_test_utils.h" 18 #include "chrome/browser/extensions/extension_function_test_utils.h"
19 #include "chrome/browser/extensions/extension_install_prompt.h" 19 #include "chrome/browser/extensions/extension_install_prompt.h"
20 #include "chrome/browser/extensions/extension_install_ui.h" 20 #include "chrome/browser/extensions/extension_install_ui.h"
21 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/webstore_installer.h" 22 #include "chrome/browser/extensions/webstore_installer.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
25 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
26 #include "chrome/browser/signin/fake_signin_manager.h"
27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
28 #include "chrome/browser/signin/signin_manager_factory.h"
29 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
32 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
33 #include "components/keyed_service/content/browser_context_dependency_manager.h" 28 #include "components/keyed_service/content/browser_context_dependency_manager.h"
34 #include "components/signin/core/browser/signin_manager.h"
35 #include "components/signin/core/browser/test_signin_client.h"
36 #include "content/public/browser/gpu_data_manager.h" 29 #include "content/public/browser/gpu_data_manager.h"
37 #include "content/public/browser/notification_observer.h" 30 #include "content/public/browser/notification_observer.h"
38 #include "content/public/browser/notification_registrar.h" 31 #include "content/public/browser/notification_registrar.h"
39 #include "content/public/test/browser_test_utils.h" 32 #include "content/public/test/browser_test_utils.h"
40 #include "extensions/browser/extension_system.h" 33 #include "extensions/browser/extension_system.h"
41 #include "gpu/config/gpu_feature_type.h" 34 #include "gpu/config/gpu_feature_type.h"
42 #include "gpu/config/gpu_info.h" 35 #include "gpu/config/gpu_info.h"
43 #include "net/dns/mock_host_resolver.h" 36 #include "net/dns/mock_host_resolver.h"
44 #include "ui/gl/gl_switches.h" 37 #include "ui/gl/gl_switches.h"
45 38
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 bool waiting_; 89 bool waiting_;
97 std::string id_; 90 std::string id_;
98 std::string error_; 91 std::string error_;
99 }; 92 };
100 93
101 } // namespace 94 } // namespace
102 95
103 // A base class for tests below. 96 // A base class for tests below.
104 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { 97 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest {
105 public: 98 public:
106 ExtensionWebstorePrivateApiTest() 99 ExtensionWebstorePrivateApiTest() {}
107 : signin_manager_(NULL),
108 token_service_(NULL) {}
109 virtual ~ExtensionWebstorePrivateApiTest() {} 100 virtual ~ExtensionWebstorePrivateApiTest() {}
110 101
111 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 102 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
112 ExtensionApiTest::SetUpCommandLine(command_line); 103 ExtensionApiTest::SetUpCommandLine(command_line);
113 command_line->AppendSwitchASCII( 104 command_line->AppendSwitchASCII(
114 switches::kAppsGalleryURL, 105 switches::kAppsGalleryURL,
115 "http://www.example.com/files/extensions/api_test"); 106 "http://www.example.com/files/extensions/api_test");
116 } 107 }
117 108
118 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 109 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
119 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); 110 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
120 111
121 // Start up the test server and get us ready for calling the install 112 // Start up the test server and get us ready for calling the install
122 // API functions. 113 // API functions.
123 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 114 host_resolver()->AddRule("www.example.com", "127.0.0.1");
124 ASSERT_TRUE(StartSpawnedTestServer()); 115 ASSERT_TRUE(StartSpawnedTestServer());
125 ExtensionInstallUI::set_disable_failure_ui_for_tests(); 116 ExtensionInstallUI::set_disable_failure_ui_for_tests();
126
127 will_create_browser_context_services_subscription_ =
128 BrowserContextDependencyManager::GetInstance()->
129 RegisterWillCreateBrowserContextServicesCallbackForTesting(
130 base::Bind(
131 &ExtensionWebstorePrivateApiTest::
132 OnWillCreateBrowserContextServices,
133 base::Unretained(this))).Pass();
134 }
135
136 void OnWillCreateBrowserContextServices(content::BrowserContext* context) {
137 // Replace the signin manager and token service with fakes. Do this ahead of
138 // creating the browser so that a bunch of classes don't register as
139 // observers and end up needing to unregister when the fake is substituted.
140 SigninManagerFactory::GetInstance()->SetTestingFactory(
141 context, &FakeSigninManagerBase::Build);
142 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory(
143 context, &BuildFakeProfileOAuth2TokenService);
144 } 117 }
145 118
146 virtual void SetUpOnMainThread() OVERRIDE { 119 virtual void SetUpOnMainThread() OVERRIDE {
147 ExtensionApiTest::SetUpOnMainThread(); 120 ExtensionApiTest::SetUpOnMainThread();
148 121
149 ExtensionInstallPrompt::g_auto_confirm_for_tests = 122 ExtensionInstallPrompt::g_auto_confirm_for_tests =
150 ExtensionInstallPrompt::ACCEPT; 123 ExtensionInstallPrompt::ACCEPT;
151 124
152 // Grab references to the fake signin manager and token service.
153 signin_manager_ =
154 static_cast<FakeSigninManagerForTesting*>(
155 SigninManagerFactory::GetInstance()->GetForProfile(profile()));
156 ASSERT_TRUE(signin_manager_);
157 token_service_ =
158 static_cast<FakeProfileOAuth2TokenService*>(
159 ProfileOAuth2TokenServiceFactory::GetInstance()->GetForProfile(
160 profile()));
161 ASSERT_TRUE(token_service_);
162
163 ASSERT_TRUE(webstore_install_dir_.CreateUniqueTempDir()); 125 ASSERT_TRUE(webstore_install_dir_.CreateUniqueTempDir());
164 webstore_install_dir_copy_ = webstore_install_dir_.path(); 126 webstore_install_dir_copy_ = webstore_install_dir_.path();
165 WebstoreInstaller::SetDownloadDirectoryForTests( 127 WebstoreInstaller::SetDownloadDirectoryForTests(
166 &webstore_install_dir_copy_); 128 &webstore_install_dir_copy_);
167 } 129 }
168 130
169 protected: 131 protected:
170 // Returns a test server URL, but with host 'www.example.com' so it matches 132 // Returns a test server URL, but with host 'www.example.com' so it matches
171 // the web store app's extent that we set up via command line flags. 133 // the web store app's extent that we set up via command line flags.
172 GURL DoGetTestServerURL(const std::string& path) { 134 GURL DoGetTestServerURL(const std::string& path) {
(...skipping 24 matching lines...) Expand all
197 #else 159 #else
198 GURL crx_url = GetTestServerURL(crx_file); 160 GURL crx_url = GetTestServerURL(crx_file);
199 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 161 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
200 switches::kAppsGalleryUpdateURL, crx_url.spec()); 162 switches::kAppsGalleryUpdateURL, crx_url.spec());
201 163
202 GURL page_url = GetTestServerURL(page); 164 GURL page_url = GetTestServerURL(page);
203 return RunPageTest(page_url.spec()); 165 return RunPageTest(page_url.spec());
204 #endif 166 #endif
205 } 167 }
206 168
207 // Navigates to |page| and waits for the API call.
208 void StartSignInTest(const std::string& page) {
209 ui_test_utils::NavigateToURL(browser(), GetTestServerURL(page));
210
211 // Wait for the API to be called. A simple way to wait for this is to run
212 // some other JavaScript in the page and wait for a round-trip back to the
213 // browser process.
214 bool result = false;
215 ASSERT_TRUE(
216 content::ExecuteScriptAndExtractBool(
217 GetWebContents(), "window.domAutomationController.send(true)",
218 &result));
219 ASSERT_TRUE(result);
220 }
221
222 content::WebContents* GetWebContents() { 169 content::WebContents* GetWebContents() {
223 return browser()->tab_strip_model()->GetActiveWebContents(); 170 return browser()->tab_strip_model()->GetActiveWebContents();
224 } 171 }
225 172
226 ExtensionService* service() { 173 ExtensionService* service() {
227 return ExtensionSystem::Get(browser()->profile())->extension_service(); 174 return ExtensionSystem::Get(browser()->profile())->extension_service();
228 } 175 }
229 176
230 FakeSigninManagerForTesting* signin_manager_;
231 FakeProfileOAuth2TokenService* token_service_;
232
233 private: 177 private:
234 scoped_ptr<base::CallbackList<void(content::BrowserContext*)>::Subscription>
235 will_create_browser_context_services_subscription_;
236
237 base::ScopedTempDir webstore_install_dir_; 178 base::ScopedTempDir webstore_install_dir_;
238 // WebstoreInstaller needs a reference to a FilePath when setting the download 179 // WebstoreInstaller needs a reference to a FilePath when setting the download
239 // directory for testing. 180 // directory for testing.
240 base::FilePath webstore_install_dir_copy_; 181 base::FilePath webstore_install_dir_copy_;
241 }; 182 };
242 183
243 // Test cases for webstore origin frame blocking. 184 // Test cases for webstore origin frame blocking.
244 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into 185 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into
245 // Chromium, see crbug.com/226018. 186 // Chromium, see crbug.com/226018.
246 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, 187 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 gpu::GPUInfo gpu_info; 392 gpu::GPUInfo gpu_info;
452 content::GpuDataManager::GetInstance()->InitializeForTesting( 393 content::GpuDataManager::GetInstance()->InitializeForTesting(
453 json_blacklist, gpu_info); 394 json_blacklist, gpu_info);
454 EXPECT_TRUE(content::GpuDataManager::GetInstance()->IsFeatureBlacklisted( 395 EXPECT_TRUE(content::GpuDataManager::GetInstance()->IsFeatureBlacklisted(
455 gpu::GPU_FEATURE_TYPE_WEBGL)); 396 gpu::GPU_FEATURE_TYPE_WEBGL));
456 397
457 bool webgl_allowed = false; 398 bool webgl_allowed = false;
458 RunTest(webgl_allowed); 399 RunTest(webgl_allowed);
459 } 400 }
460 401
461 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
462 SignIn_UserGestureRequired) {
463 GURL page_url = GetTestServerURL("sign_in_user_gesture_required.html");
464 ASSERT_TRUE(RunPageTest(page_url.spec()));
465 }
466
467 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
468 SignIn_MissingContinueUrl) {
469 GURL page_url = GetTestServerURL("sign_in_missing_continue_url.html");
470 ASSERT_TRUE(RunPageTest(page_url.spec()));
471 }
472
473 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
474 SignIn_InvalidContinueUrl) {
475 GURL page_url = GetTestServerURL("sign_in_invalid_continue_url.html");
476 ASSERT_TRUE(RunPageTest(page_url.spec()));
477 }
478
479 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
480 SignIn_ContinueUrlOnDifferentOrigin) {
481 GURL page_url =
482 GetTestServerURL("sign_in_continue_url_on_different_origin.html");
483 ASSERT_TRUE(RunPageTest(page_url.spec()));
484 }
485
486 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
487 SignIn_DisallowedInIncognito) {
488 // Make sure that the test is testing something more than the absence of a
489 // sign-in manager for this profile.
490 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile()));
491
492 GURL page_url =
493 GetTestServerURL("sign_in_disallowed_in_incognito.html");
494 ASSERT_TRUE(
495 RunPageTest(page_url.spec(), ExtensionApiTest::kFlagUseIncognito));
496 }
497
498 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
499 SignIn_DisabledWhenWebBasedSigninIsEnabled) {
500 // Make sure that the test is testing something more than the absence of a
501 // sign-in manager for this profile.
502 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile()));
503
504 CommandLine::ForCurrentProcess()->AppendSwitch(
505 switches::kEnableWebBasedSignin);
506 GURL page_url = GetTestServerURL(
507 "sign_in_disabled_when_web_based_signin_is_enabled.html");
508 ASSERT_TRUE(RunPageTest(page_url.spec()));
509 }
510
511 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
512 SignIn_AlreadySignedIn) {
513 signin_manager_->SetAuthenticatedUsername("user@example.com");
514 GURL page_url = GetTestServerURL("sign_in_already_signed_in.html");
515 ASSERT_TRUE(RunPageTest(page_url.spec()));
516 }
517
518 // The FakeSignInManager class is not implemented for ChromeOS, so there's no
519 // straightforward way to test these flows on that platform.
520 #if !defined(OS_CHROMEOS)
521 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
522 SignIn_AuthInProgress_Fails) {
523 // Initiate an authentication that will be in progress when the sign-in API is
524 // called.
525 signin_manager_->set_auth_in_progress("user@example.com");
526
527 // Navigate to the page, which will cause the sign-in API to be called.
528 // Then, complete the authentication in a failed state.
529 ResultCatcher catcher;
530 StartSignInTest("sign_in_auth_in_progress_fails.html");
531 signin_manager_->FailSignin(GoogleServiceAuthError::AuthErrorNone());
532 ASSERT_TRUE(catcher.GetNextResult());
533 }
534
535 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
536 SignIn_AuthInProgress_MergeSessionFails) {
537 // Initiate an authentication that will be in progress when the sign-in API is
538 // called.
539 signin_manager_->set_auth_in_progress("user@example.com");
540
541 // Navigate to the page, which will cause the sign-in API to be called.
542 // Then, complete the authentication in a successful state.
543 ResultCatcher catcher;
544 StartSignInTest("sign_in_auth_in_progress_merge_session_fails.html");
545 signin_manager_->CompletePendingSignin();
546 token_service_->IssueRefreshTokenForUser("user@example.com", "token");
547 signin_manager_->NotifyMergeSessionObservers(
548 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
549 ASSERT_TRUE(catcher.GetNextResult());
550 }
551
552 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
553 SignIn_AuthInProgress_Succeeds) {
554 // Initiate an authentication that will be in progress when the sign-in API is
555 // called.
556 signin_manager_->set_auth_in_progress("user@example.com");
557
558 // Navigate to the page, which will cause the sign-in API to be called.
559 // Then, complete the authentication in a successful state.
560 ResultCatcher catcher;
561 StartSignInTest("sign_in_auth_in_progress_succeeds.html");
562 signin_manager_->CompletePendingSignin();
563 token_service_->IssueRefreshTokenForUser("user@example.com", "token");
564 signin_manager_->NotifyMergeSessionObservers(
565 GoogleServiceAuthError::AuthErrorNone());
566 ASSERT_TRUE(catcher.GetNextResult());
567 }
568 #endif // !defined (OS_CHROMEOS)
569
570 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
571 SignIn_RedirectToSignIn) {
572 GURL signin_url(
573 "chrome://chrome-signin/?source=5&"
574 "continue=http%3A%2F%2Fwww.example.com%3A" +
575 base::IntToString(test_server()->host_port_pair().port()) +
576 "%2Fcontinue");
577 ui_test_utils::UrlLoadObserver observer(
578 signin_url,
579 content::Source<content::NavigationController>(
580 &GetWebContents()->GetController()));
581 StartSignInTest("sign_in_redirect_to_sign_in.html");
582 observer.Wait();
583
584 // TODO(isherman): Also test the redirect back to the continue URL once
585 // sign-in completes?
586 }
587
588 class EphemeralAppWebstorePrivateApiTest 402 class EphemeralAppWebstorePrivateApiTest
589 : public ExtensionWebstorePrivateApiTest { 403 : public ExtensionWebstorePrivateApiTest {
590 public: 404 public:
591 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 405 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
592 ExtensionWebstorePrivateApiTest::SetUpInProcessBrowserTestFixture(); 406 ExtensionWebstorePrivateApiTest::SetUpInProcessBrowserTestFixture();
593 407
594 net::HostPortPair host_port = test_server()->host_port_pair(); 408 net::HostPortPair host_port = test_server()->host_port_pair();
595 std::string test_gallery_url = base::StringPrintf( 409 std::string test_gallery_url = base::StringPrintf(
596 "http://www.example.com:%d/files/extensions/platform_apps/" 410 "http://www.example.com:%d/files/extensions/platform_apps/"
597 "ephemeral_launcher", 411 "ephemeral_launcher",
(...skipping 16 matching lines...) Expand all
614 } 428 }
615 429
616 // Run tests when the --enable-ephemeral-apps switch is enabled. 430 // Run tests when the --enable-ephemeral-apps switch is enabled.
617 IN_PROC_BROWSER_TEST_F(EphemeralAppWebstorePrivateApiTest, LaunchEphemeralApp) { 431 IN_PROC_BROWSER_TEST_F(EphemeralAppWebstorePrivateApiTest, LaunchEphemeralApp) {
618 CommandLine::ForCurrentProcess()->AppendSwitch( 432 CommandLine::ForCurrentProcess()->AppendSwitch(
619 switches::kEnableEphemeralApps); 433 switches::kEnableEphemeralApps);
620 ASSERT_TRUE(RunInstallTest("webstore_launch_app.html", "app.crx")); 434 ASSERT_TRUE(RunInstallTest("webstore_launch_app.html", "app.crx"));
621 } 435 }
622 436
623 } // namespace extensions 437 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698