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

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

Issue 196783002: Export a private webstore API to call into the new inline sign-in flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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/file_util.h" 8 #include "base/file_util.h"
8 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
11 #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"
12 #include "chrome/browser/extensions/api/management/management_api.h" 15 #include "chrome/browser/extensions/api/management/management_api.h"
13 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" 16 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
14 #include "chrome/browser/extensions/extension_apitest.h" 17 #include "chrome/browser/extensions/extension_apitest.h"
15 #include "chrome/browser/extensions/extension_function_test_utils.h" 18 #include "chrome/browser/extensions/extension_function_test_utils.h"
16 #include "chrome/browser/extensions/extension_install_prompt.h" 19 #include "chrome/browser/extensions/extension_install_prompt.h"
17 #include "chrome/browser/extensions/extension_install_ui.h" 20 #include "chrome/browser/extensions/extension_install_ui.h"
18 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
19 #include "chrome/browser/extensions/webstore_installer.h" 22 #include "chrome/browser/extensions/webstore_installer.h"
20 #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"
21 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
24 #include "chrome/test/base/ui_test_utils.h" 32 #include "chrome/test/base/ui_test_utils.h"
33 #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"
25 #include "content/public/browser/gpu_data_manager.h" 36 #include "content/public/browser/gpu_data_manager.h"
26 #include "content/public/browser/notification_observer.h" 37 #include "content/public/browser/notification_observer.h"
27 #include "content/public/browser/notification_registrar.h" 38 #include "content/public/browser/notification_registrar.h"
28 #include "content/public/test/browser_test_utils.h" 39 #include "content/public/test/browser_test_utils.h"
29 #include "gpu/config/gpu_feature_type.h" 40 #include "gpu/config/gpu_feature_type.h"
30 #include "gpu/config/gpu_info.h" 41 #include "gpu/config/gpu_info.h"
31 #include "net/dns/mock_host_resolver.h" 42 #include "net/dns/mock_host_resolver.h"
32 #include "ui/gl/gl_switches.h" 43 #include "ui/gl/gl_switches.h"
33 44
34 using gpu::GpuFeatureType; 45 using gpu::GpuFeatureType;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 bool waiting_; 95 bool waiting_;
85 std::string id_; 96 std::string id_;
86 std::string error_; 97 std::string error_;
87 }; 98 };
88 99
89 } // namespace 100 } // namespace
90 101
91 // A base class for tests below. 102 // A base class for tests below.
92 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { 103 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest {
93 public: 104 public:
105 ExtensionWebstorePrivateApiTest()
106 : signin_manager_(NULL),
107 token_service_(NULL) {}
108 virtual ~ExtensionWebstorePrivateApiTest() {}
109
94 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 110 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
95 ExtensionApiTest::SetUpCommandLine(command_line); 111 ExtensionApiTest::SetUpCommandLine(command_line);
96 command_line->AppendSwitchASCII( 112 command_line->AppendSwitchASCII(
97 switches::kAppsGalleryURL, 113 switches::kAppsGalleryURL,
98 "http://www.example.com/files/extensions/api_test"); 114 "http://www.example.com/files/extensions/api_test");
99 command_line->AppendSwitchASCII( 115 command_line->AppendSwitchASCII(
100 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); 116 switches::kAppsGalleryInstallAutoConfirmForTests, "accept");
101 } 117 }
102 118
103 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 119 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
120 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
121
104 // Start up the test server and get us ready for calling the install 122 // Start up the test server and get us ready for calling the install
105 // API functions. 123 // API functions.
106 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 124 host_resolver()->AddRule("www.example.com", "127.0.0.1");
107 ASSERT_TRUE(test_server()->Start()); 125 ASSERT_TRUE(StartSpawnedTestServer());
108 ExtensionInstallUI::set_disable_failure_ui_for_tests(); 126 ExtensionInstallUI::set_disable_failure_ui_for_tests();
127
128 will_create_browser_context_services_subscription_ =
129 BrowserContextDependencyManager::GetInstance()->
130 RegisterWillCreateBrowserContextServicesCallbackForTesting(
131 base::Bind(
132 &ExtensionWebstorePrivateApiTest::
133 OnWillCreateBrowserContextServices,
134 base::Unretained(this))).Pass();
135 }
136
137 void OnWillCreateBrowserContextServices(content::BrowserContext* context) {
138 // Replace the signin manager and token service with fakes. Do this ahead of
139 // creating the browser so that a bunch of classes don't register as
140 // observers and end up needing to unregister when the fake is substituted.
141 SigninManagerFactory::GetInstance()->SetTestingFactory(
142 context, &FakeSigninManagerBase::Build);
143 ProfileOAuth2TokenServiceFactory::GetInstance()->SetTestingFactory(
144 context, &BuildFakeProfileOAuth2TokenService);
145 }
146
147 virtual void SetUpOnMainThread() OVERRIDE {
148 ExtensionApiTest::SetUpOnMainThread();
149
150 // Grab references to the fake signin manager and token service.
151 signin_manager_ =
152 static_cast<FakeSigninManagerForTesting*>(
153 SigninManagerFactory::GetInstance()->GetForProfile(profile()));
154 ASSERT_TRUE(signin_manager_);
155 token_service_ =
156 static_cast<FakeProfileOAuth2TokenService*>(
157 ProfileOAuth2TokenServiceFactory::GetInstance()->GetForProfile(
158 profile()));
159 ASSERT_TRUE(token_service_);
109 } 160 }
110 161
111 protected: 162 protected:
112 // Returns a test server URL, but with host 'www.example.com' so it matches 163 // Returns a test server URL, but with host 'www.example.com' so it matches
113 // the web store app's extent that we set up via command line flags. 164 // the web store app's extent that we set up via command line flags.
114 virtual GURL GetTestServerURL(const std::string& path) { 165 virtual GURL GetTestServerURL(const std::string& path) {
115 GURL url = test_server()->GetURL( 166 GURL url = test_server()->GetURL(
116 std::string("files/extensions/api_test/webstore_private/") + path); 167 std::string("files/extensions/api_test/webstore_private/") + path);
117 168
118 // Replace the host with 'www.example.com' so it matches the web store 169 // Replace the host with 'www.example.com' so it matches the web store
(...skipping 16 matching lines...) Expand all
135 #else 186 #else
136 GURL crx_url = GetTestServerURL(crx_file); 187 GURL crx_url = GetTestServerURL(crx_file);
137 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 188 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
138 switches::kAppsGalleryUpdateURL, crx_url.spec()); 189 switches::kAppsGalleryUpdateURL, crx_url.spec());
139 190
140 GURL page_url = GetTestServerURL(page); 191 GURL page_url = GetTestServerURL(page);
141 return RunPageTest(page_url.spec()); 192 return RunPageTest(page_url.spec());
142 #endif 193 #endif
143 } 194 }
144 195
196 // Navigates to |page| and waits for the API call.
197 void StartSignInTest(const std::string& page) {
198 ui_test_utils::NavigateToURL(browser(), GetTestServerURL(page));
199
200 // Wait for the API to be called. A simple way to wait for this is to run
201 // some other JavaScript in the page and wait for a round-trip back to the
202 // browser process.
203 bool result = false;
204 ASSERT_TRUE(
205 content::ExecuteScriptAndExtractBool(
206 GetWebContents(), "window.domAutomationController.send(true)",
207 &result));
208 ASSERT_TRUE(result);
209 }
210
211 content::WebContents* GetWebContents() {
212 return browser()->tab_strip_model()->GetActiveWebContents();
213 }
214
145 ExtensionService* service() { 215 ExtensionService* service() {
146 return browser()->profile()->GetExtensionService(); 216 return browser()->profile()->GetExtensionService();
147 } 217 }
218
219 FakeSigninManagerForTesting* signin_manager_;
220 FakeProfileOAuth2TokenService* token_service_;
221
222 private:
223 scoped_ptr<base::CallbackList<void(content::BrowserContext*)>::Subscription>
224 will_create_browser_context_services_subscription_;
225
148 }; 226 };
149 227
150 // Test cases for webstore origin frame blocking. 228 // Test cases for webstore origin frame blocking.
151 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into 229 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into
152 // Chromium, see crbug.com/226018. 230 // Chromium, see crbug.com/226018.
153 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, 231 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
154 DISABLED_FrameWebstorePageBlocked) { 232 DISABLED_FrameWebstorePageBlocked) {
155 content::WebContents* contents =
156 browser()->tab_strip_model()->GetActiveWebContents();
157 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); 233 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank");
158 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); 234 base::string16 failure_title = base::UTF8ToUTF16("FAIL");
159 content::TitleWatcher watcher(contents, expected_title); 235 content::TitleWatcher watcher(GetWebContents(), expected_title);
160 watcher.AlsoWaitForTitle(failure_title); 236 watcher.AlsoWaitForTitle(failure_title);
161 GURL url = test_server()->GetURL( 237 GURL url = test_server()->GetURL(
162 "files/extensions/api_test/webstore_private/noframe.html"); 238 "files/extensions/api_test/webstore_private/noframe.html");
163 ui_test_utils::NavigateToURL(browser(), url); 239 ui_test_utils::NavigateToURL(browser(), url);
164 base::string16 final_title = watcher.WaitAndGetTitle(); 240 base::string16 final_title = watcher.WaitAndGetTitle();
165 EXPECT_EQ(expected_title, final_title); 241 EXPECT_EQ(expected_title, final_title);
166 } 242 }
167 243
168 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into 244 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into
169 // Chromium, see crbug.com/226018. 245 // Chromium, see crbug.com/226018.
170 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, 246 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
171 DISABLED_FrameErrorPageBlocked) { 247 DISABLED_FrameErrorPageBlocked) {
172 content::WebContents* contents =
173 browser()->tab_strip_model()->GetActiveWebContents();
174 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); 248 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank");
175 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); 249 base::string16 failure_title = base::UTF8ToUTF16("FAIL");
176 content::TitleWatcher watcher(contents, expected_title); 250 content::TitleWatcher watcher(GetWebContents(), expected_title);
177 watcher.AlsoWaitForTitle(failure_title); 251 watcher.AlsoWaitForTitle(failure_title);
178 GURL url = test_server()->GetURL( 252 GURL url = test_server()->GetURL(
179 "files/extensions/api_test/webstore_private/noframe2.html"); 253 "files/extensions/api_test/webstore_private/noframe2.html");
180 ui_test_utils::NavigateToURL(browser(), url); 254 ui_test_utils::NavigateToURL(browser(), url);
181 base::string16 final_title = watcher.WaitAndGetTitle(); 255 base::string16 final_title = watcher.WaitAndGetTitle();
182 EXPECT_EQ(expected_title, final_title); 256 EXPECT_EQ(expected_title, final_title);
183 } 257 }
184 258
185 // Test cases where the user accepts the install confirmation dialog. 259 // Test cases where the user accepts the install confirmation dialog.
186 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) { 260 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 gpu::GPUInfo gpu_info; 434 gpu::GPUInfo gpu_info;
361 content::GpuDataManager::GetInstance()->InitializeForTesting( 435 content::GpuDataManager::GetInstance()->InitializeForTesting(
362 json_blacklist, gpu_info); 436 json_blacklist, gpu_info);
363 EXPECT_TRUE(content::GpuDataManager::GetInstance()->IsFeatureBlacklisted( 437 EXPECT_TRUE(content::GpuDataManager::GetInstance()->IsFeatureBlacklisted(
364 gpu::GPU_FEATURE_TYPE_WEBGL)); 438 gpu::GPU_FEATURE_TYPE_WEBGL));
365 439
366 bool webgl_allowed = false; 440 bool webgl_allowed = false;
367 RunTest(webgl_allowed); 441 RunTest(webgl_allowed);
368 } 442 }
369 443
444 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
445 SignIn_UserGestureRequired) {
446 GURL page_url = GetTestServerURL("sign_in_user_gesture_required.html");
447 ASSERT_TRUE(RunPageTest(page_url.spec()));
448 }
449
450 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
451 SignIn_MissingContinueUrl) {
452 GURL page_url = GetTestServerURL("sign_in_missing_continue_url.html");
453 ASSERT_TRUE(RunPageTest(page_url.spec()));
454 }
455
456 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
457 SignIn_InvalidContinueUrl) {
458 GURL page_url = GetTestServerURL("sign_in_invalid_continue_url.html");
459 ASSERT_TRUE(RunPageTest(page_url.spec()));
460 }
461
462 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
463 SignIn_ContinueUrlOnDifferentOrigin) {
464 GURL page_url =
465 GetTestServerURL("sign_in_continue_url_on_different_origin.html");
466 ASSERT_TRUE(RunPageTest(page_url.spec()));
467 }
468
469 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
470 SignIn_DisallowedInIncognito) {
471 // Make sure that the test is testing something more than the absence of a
472 // sign-in manager for this profile.
473 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile()));
474
475 GURL page_url =
476 GetTestServerURL("sign_in_disallowed_in_incognito.html");
477 ASSERT_TRUE(
478 RunPageTest(page_url.spec(), ExtensionApiTest::kFlagUseIncognito));
479 }
480
481 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
482 SignIn_DisabledWhenWebBasedSigninIsEnabled) {
483 // Make sure that the test is testing something more than the absence of a
484 // sign-in manager for this profile.
485 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile()));
486
487 CommandLine::ForCurrentProcess()->AppendSwitch(
488 switches::kEnableWebBasedSignin);
489 GURL page_url = GetTestServerURL(
490 "sign_in_disabled_when_web_based_signin_is_enabled.html");
491 ASSERT_TRUE(RunPageTest(page_url.spec()));
492 }
493
494 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
495 SignIn_AlreadySignedIn) {
496 signin_manager_->SetAuthenticatedUsername("user@example.com");
497 GURL page_url = GetTestServerURL("sign_in_already_signed_in.html");
498 ASSERT_TRUE(RunPageTest(page_url.spec()));
499 }
500
501 // The FakeSignInManager class is not implemented for ChromeOS, so there's no
502 // straightforward way to test these flows on that platform.
503 #if !defined(OS_CHROMEOS)
504 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
505 SignIn_AuthInProgress_Fails) {
506 // Initiate an authentication that will be in progress when the sign-in API is
507 // called.
508 signin_manager_->set_auth_in_progress("user@example.com");
509
510 // Navigate to the page, which will cause the sign-in API to be called.
511 // Then, complete the authentication in a failed state.
512 ResultCatcher catcher;
513 StartSignInTest("sign_in_auth_in_progress_fails.html");
514 signin_manager_->FailSignin(GoogleServiceAuthError::AuthErrorNone());
515 ASSERT_TRUE(catcher.GetNextResult());
516 }
517
518 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
519 SignIn_AuthInProgress_MergeSessionFails) {
520 // Initiate an authentication that will be in progress when the sign-in API is
521 // called.
522 signin_manager_->set_auth_in_progress("user@example.com");
523
524 // Navigate to the page, which will cause the sign-in API to be called.
525 // Then, complete the authentication in a successful state.
526 ResultCatcher catcher;
527 StartSignInTest("sign_in_auth_in_progress_merge_session_fails.html");
528 signin_manager_->CompletePendingSignin();
529 token_service_->IssueRefreshToken("token");
530 signin_manager_->NotifyMergeSessionObservers(
531 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
532 ASSERT_TRUE(catcher.GetNextResult());
533 }
534
535 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
536 SignIn_AuthInProgress_Succeeds) {
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_succeeds.html");
545 signin_manager_->CompletePendingSignin();
546 token_service_->IssueRefreshToken("token");
547 signin_manager_->NotifyMergeSessionObservers(
548 GoogleServiceAuthError::AuthErrorNone());
549 ASSERT_TRUE(catcher.GetNextResult());
550 }
551 #endif // !defined (OS_CHROMEOS)
552
553 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
554 SignIn_RedirectToSignIn) {
555 GURL signin_url(
556 "chrome://chrome-signin/?source=5&"
557 "continue=http%3A%2F%2Fwww.example.com%3A" +
558 base::IntToString(test_server()->host_port_pair().port()) +
559 "%2Fcontinue");
560 ui_test_utils::UrlLoadObserver observer(
561 signin_url,
562 content::Source<content::NavigationController>(
563 &GetWebContents()->GetController()));
564 StartSignInTest("sign_in_redirect_to_sign_in.html");
565 observer.Wait();
566
567 // TODO(isherman): Also test the redirect back to the continue URL once
568 // sign-in completes?
569 }
570
370 } // namespace extensions 571 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/webstore_private/webstore_private_api.cc ('k') | chrome/browser/signin/fake_signin_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698