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

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

Powered by Google App Engine
This is Rietveld 408576698