OLD | NEW |
---|---|
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.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" |
25 #include "content/public/browser/gpu_data_manager.h" | 33 #include "content/public/browser/gpu_data_manager.h" |
26 #include "content/public/browser/notification_observer.h" | 34 #include "content/public/browser/notification_observer.h" |
27 #include "content/public/browser/notification_registrar.h" | 35 #include "content/public/browser/notification_registrar.h" |
28 #include "content/public/test/browser_test_utils.h" | 36 #include "content/public/test/browser_test_utils.h" |
29 #include "gpu/config/gpu_feature_type.h" | 37 #include "gpu/config/gpu_feature_type.h" |
30 #include "gpu/config/gpu_info.h" | 38 #include "gpu/config/gpu_info.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 const std::string& id() const { return id_; } | 87 const std::string& id() const { return id_; } |
80 | 88 |
81 private: | 89 private: |
82 bool received_failure_; | 90 bool received_failure_; |
83 bool received_success_; | 91 bool received_success_; |
84 bool waiting_; | 92 bool waiting_; |
85 std::string id_; | 93 std::string id_; |
86 std::string error_; | 94 std::string error_; |
87 }; | 95 }; |
88 | 96 |
97 // A trivial factory to build a null service. | |
98 KeyedService* BuildNullService(content::BrowserContext* context) { | |
99 return NULL; | |
100 } | |
101 | |
89 } // namespace | 102 } // namespace |
90 | 103 |
91 // A base class for tests below. | 104 // A base class for tests below. |
92 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { | 105 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { |
93 public: | 106 public: |
107 ExtensionWebstorePrivateApiTest() | |
108 : signin_manager_(NULL), | |
109 token_service_(NULL) {} | |
110 virtual ~ExtensionWebstorePrivateApiTest() {} | |
111 | |
94 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 112 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
95 ExtensionApiTest::SetUpCommandLine(command_line); | 113 ExtensionApiTest::SetUpCommandLine(command_line); |
96 command_line->AppendSwitchASCII( | 114 command_line->AppendSwitchASCII( |
97 switches::kAppsGalleryURL, | 115 switches::kAppsGalleryURL, |
98 "http://www.example.com/files/extensions/api_test"); | 116 "http://www.example.com/files/extensions/api_test"); |
99 command_line->AppendSwitchASCII( | 117 command_line->AppendSwitchASCII( |
100 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); | 118 switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); |
101 } | 119 } |
102 | 120 |
103 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 121 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
122 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | |
123 | |
104 // Start up the test server and get us ready for calling the install | 124 // Start up the test server and get us ready for calling the install |
105 // API functions. | 125 // API functions. |
106 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 126 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
107 ASSERT_TRUE(test_server()->Start()); | 127 ASSERT_TRUE(StartSpawnedTestServer()); |
108 ExtensionInstallUI::set_disable_failure_ui_for_tests(); | 128 ExtensionInstallUI::set_disable_failure_ui_for_tests(); |
109 } | 129 } |
110 | 130 |
131 virtual void SetUpOnMainThread() OVERRIDE { | |
132 ExtensionApiTest::SetUpOnMainThread(); | |
133 | |
134 // Shutdown the existing identity API service, as it is not designed to | |
135 // handle a fake signin manager or token service being installed. | |
136 IdentityAPI::GetFactoryInstance()->SetTestingFactory( | |
137 profile(), BuildNullService); | |
138 | |
139 // Install a fake signin manager and token service, and grab references to | |
140 // them. | |
141 signin_manager_ = | |
142 static_cast<FakeSigninManagerForTesting*>( | |
143 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( | |
144 profile(), &FakeSigninManagerBase::Build)); | |
145 ASSERT_TRUE(signin_manager_); | |
146 // TODO(isherman): This fails due to observers that don't unregister when | |
147 // the service is swapped. | |
148 /*token_service_ = | |
149 static_cast<FakeProfileOAuth2TokenService*>( | |
150 ProfileOAuth2TokenServiceFactory::GetInstance() | |
151 ->SetTestingFactoryAndUse( | |
152 profile(), &BuildFakeProfileOAuth2TokenService)); | |
153 ASSERT_TRUE(token_service_);*/ | |
Ilya Sherman
2014/03/26 08:21:39
I'm having no end of trouble from trying to substi
| |
154 } | |
155 | |
111 protected: | 156 protected: |
112 // Returns a test server URL, but with host 'www.example.com' so it matches | 157 // 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. | 158 // the web store app's extent that we set up via command line flags. |
114 virtual GURL GetTestServerURL(const std::string& path) { | 159 virtual GURL GetTestServerURL(const std::string& path) { |
115 GURL url = test_server()->GetURL( | 160 GURL url = test_server()->GetURL( |
116 std::string("files/extensions/api_test/webstore_private/") + path); | 161 std::string("files/extensions/api_test/webstore_private/") + path); |
117 | 162 |
118 // Replace the host with 'www.example.com' so it matches the web store | 163 // Replace the host with 'www.example.com' so it matches the web store |
119 // app's extent. | 164 // app's extent. |
120 GURL::Replacements replace_host; | 165 GURL::Replacements replace_host; |
(...skipping 14 matching lines...) Expand all Loading... | |
135 #else | 180 #else |
136 GURL crx_url = GetTestServerURL(crx_file); | 181 GURL crx_url = GetTestServerURL(crx_file); |
137 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 182 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
138 switches::kAppsGalleryUpdateURL, crx_url.spec()); | 183 switches::kAppsGalleryUpdateURL, crx_url.spec()); |
139 | 184 |
140 GURL page_url = GetTestServerURL(page); | 185 GURL page_url = GetTestServerURL(page); |
141 return RunPageTest(page_url.spec()); | 186 return RunPageTest(page_url.spec()); |
142 #endif | 187 #endif |
143 } | 188 } |
144 | 189 |
190 // Navigates to |page| and waits for the API call. | |
191 void StartSignInTest(const std::string& page) { | |
192 ui_test_utils::NavigateToURL(browser(), GetTestServerURL(page)); | |
193 | |
194 // Wait for the API to be called. A simple way to wait for this is to run | |
195 // some other JavaScript in the page and wait for a round-trip back to the | |
196 // browser process. | |
197 bool result = false; | |
198 ASSERT_TRUE( | |
199 content::ExecuteScriptAndExtractBool( | |
200 GetWebContents(), "window.domAutomationController.send(true)", | |
201 &result)); | |
202 ASSERT_TRUE(result); | |
203 } | |
204 | |
205 content::WebContents* GetWebContents() { | |
206 return browser()->tab_strip_model()->GetActiveWebContents(); | |
207 } | |
208 | |
145 ExtensionService* service() { | 209 ExtensionService* service() { |
146 return browser()->profile()->GetExtensionService(); | 210 return browser()->profile()->GetExtensionService(); |
147 } | 211 } |
212 | |
213 FakeSigninManagerForTesting* signin_manager_; | |
214 FakeProfileOAuth2TokenService* token_service_; | |
148 }; | 215 }; |
149 | 216 |
150 // Test cases for webstore origin frame blocking. | 217 // Test cases for webstore origin frame blocking. |
151 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into | 218 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into |
152 // Chromium, see crbug.com/226018. | 219 // Chromium, see crbug.com/226018. |
153 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | 220 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
154 DISABLED_FrameWebstorePageBlocked) { | 221 DISABLED_FrameWebstorePageBlocked) { |
155 content::WebContents* contents = | |
156 browser()->tab_strip_model()->GetActiveWebContents(); | |
157 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); | 222 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); |
158 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); | 223 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); |
159 content::TitleWatcher watcher(contents, expected_title); | 224 content::TitleWatcher watcher(GetWebContents(), expected_title); |
160 watcher.AlsoWaitForTitle(failure_title); | 225 watcher.AlsoWaitForTitle(failure_title); |
161 GURL url = test_server()->GetURL( | 226 GURL url = test_server()->GetURL( |
162 "files/extensions/api_test/webstore_private/noframe.html"); | 227 "files/extensions/api_test/webstore_private/noframe.html"); |
163 ui_test_utils::NavigateToURL(browser(), url); | 228 ui_test_utils::NavigateToURL(browser(), url); |
164 base::string16 final_title = watcher.WaitAndGetTitle(); | 229 base::string16 final_title = watcher.WaitAndGetTitle(); |
165 EXPECT_EQ(expected_title, final_title); | 230 EXPECT_EQ(expected_title, final_title); |
166 } | 231 } |
167 | 232 |
168 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into | 233 // TODO(mkwst): Disabled until new X-Frame-Options behavior rolls into |
169 // Chromium, see crbug.com/226018. | 234 // Chromium, see crbug.com/226018. |
170 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | 235 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, |
171 DISABLED_FrameErrorPageBlocked) { | 236 DISABLED_FrameErrorPageBlocked) { |
172 content::WebContents* contents = | |
173 browser()->tab_strip_model()->GetActiveWebContents(); | |
174 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); | 237 base::string16 expected_title = base::UTF8ToUTF16("PASS: about:blank"); |
175 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); | 238 base::string16 failure_title = base::UTF8ToUTF16("FAIL"); |
176 content::TitleWatcher watcher(contents, expected_title); | 239 content::TitleWatcher watcher(GetWebContents(), expected_title); |
177 watcher.AlsoWaitForTitle(failure_title); | 240 watcher.AlsoWaitForTitle(failure_title); |
178 GURL url = test_server()->GetURL( | 241 GURL url = test_server()->GetURL( |
179 "files/extensions/api_test/webstore_private/noframe2.html"); | 242 "files/extensions/api_test/webstore_private/noframe2.html"); |
180 ui_test_utils::NavigateToURL(browser(), url); | 243 ui_test_utils::NavigateToURL(browser(), url); |
181 base::string16 final_title = watcher.WaitAndGetTitle(); | 244 base::string16 final_title = watcher.WaitAndGetTitle(); |
182 EXPECT_EQ(expected_title, final_title); | 245 EXPECT_EQ(expected_title, final_title); |
183 } | 246 } |
184 | 247 |
185 // Test cases where the user accepts the install confirmation dialog. | 248 // Test cases where the user accepts the install confirmation dialog. |
186 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) { | 249 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 gpu::GPUInfo gpu_info; | 423 gpu::GPUInfo gpu_info; |
361 content::GpuDataManager::GetInstance()->InitializeForTesting( | 424 content::GpuDataManager::GetInstance()->InitializeForTesting( |
362 json_blacklist, gpu_info); | 425 json_blacklist, gpu_info); |
363 EXPECT_TRUE(content::GpuDataManager::GetInstance()->IsFeatureBlacklisted( | 426 EXPECT_TRUE(content::GpuDataManager::GetInstance()->IsFeatureBlacklisted( |
364 gpu::GPU_FEATURE_TYPE_WEBGL)); | 427 gpu::GPU_FEATURE_TYPE_WEBGL)); |
365 | 428 |
366 bool webgl_allowed = false; | 429 bool webgl_allowed = false; |
367 RunTest(webgl_allowed); | 430 RunTest(webgl_allowed); |
368 } | 431 } |
369 | 432 |
433 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
434 SignIn_MissingContinueUrl) { | |
435 GURL page_url = GetTestServerURL("sign_in_missing_continue_url.html"); | |
436 ASSERT_TRUE(RunPageTest(page_url.spec())); | |
437 } | |
438 | |
439 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
440 SignIn_InvalidContinueUrl) { | |
441 GURL page_url = GetTestServerURL("sign_in_invalid_continue_url.html"); | |
442 ASSERT_TRUE(RunPageTest(page_url.spec())); | |
443 } | |
444 | |
445 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
446 SignIn_ContinueUrlOnDifferentOrigin) { | |
447 GURL page_url = | |
448 GetTestServerURL("sign_in_continue_url_on_different_origin.html"); | |
449 ASSERT_TRUE(RunPageTest(page_url.spec())); | |
450 } | |
451 | |
452 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
453 SignIn_DisallowedInIncognito) { | |
454 // Make sure that the test is testing something more than the absence of a | |
455 // sign-in manager for this profile. | |
456 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile())); | |
457 | |
458 GURL page_url = | |
459 GetTestServerURL("sign_in_disallowed_in_incognito.html"); | |
460 ASSERT_TRUE( | |
461 RunPageTest(page_url.spec(), ExtensionApiTest::kFlagUseIncognito)); | |
462 } | |
463 | |
464 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
465 SignIn_DisabledWhenWebBasedSigninIsEnabled) { | |
466 // Make sure that the test is testing something more than the absence of a | |
467 // sign-in manager for this profile. | |
468 ASSERT_TRUE(SigninManagerFactory::GetForProfile(profile())); | |
469 | |
470 CommandLine::ForCurrentProcess()->AppendSwitch( | |
471 switches::kEnableWebBasedSignin); | |
472 GURL page_url = GetTestServerURL( | |
473 "sign_in_disabled_when_web_based_signin_is_enabled.html"); | |
474 ASSERT_TRUE(RunPageTest(page_url.spec())); | |
475 } | |
476 | |
477 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
478 SignIn_AlreadySignedIn) { | |
479 signin_manager_->SetAuthenticatedUsername("user@example.com"); | |
480 GURL page_url = GetTestServerURL("sign_in_already_signed_in.html"); | |
481 ASSERT_TRUE(RunPageTest(page_url.spec())); | |
482 } | |
483 | |
484 // The FakeSignInManager class is not implemented for ChromeOS, so there's no | |
485 // straightforward way to test these flows on that platform. | |
486 #if !defined(OS_CHROMEOS) | |
487 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
488 SignIn_AuthInProgress_Fails) { | |
489 // Initiate an authentication that will be in progress when the sign-in API is | |
490 // called. | |
491 signin_manager_->set_auth_in_progress("user@example.com"); | |
492 | |
493 // Navigate to the page, which will cause the sign-in API to be called. | |
494 // Then, complete the authentication in a failed state. | |
495 ResultCatcher catcher; | |
496 StartSignInTest("sign_in_auth_in_progress_fails.html"); | |
497 signin_manager_->FailSignin(GoogleServiceAuthError::AuthErrorNone()); | |
498 ASSERT_TRUE(catcher.GetNextResult()); | |
499 } | |
500 | |
501 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
502 SignIn_AuthInProgress_MergeSessionFails) { | |
503 // TODO(isherman): Implement this test. How do I interpose an event after | |
504 // navigating to the test URL but before waiting for a success or failure | |
505 // result? | |
506 GURL page_url = | |
507 GetTestServerURL("sign_in_auth_in_progress_merge_session_fails.html"); | |
508 ASSERT_TRUE(RunPageTest(page_url.spec())); | |
509 } | |
510 | |
511 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
512 SignIn_AuthInProgress_Succeeds) { | |
513 // Initiate an authentication that will be in progress when the sign-in API is | |
514 // called. | |
515 signin_manager_->set_auth_in_progress("user@example.com"); | |
516 | |
517 // Navigate to the page, which will cause the sign-in API to be called. | |
518 // Then, complete the authentication in a successful state. | |
519 ResultCatcher catcher; | |
520 StartSignInTest("sign_in_auth_in_progress_succeeds.html"); | |
521 // TODO(isherman): Need merge session to happen, not for the sign-in to | |
522 // succeed. That requires a token to be successfully merged. Then, we've got | |
523 // to somehow trigger a call to MergeSessionCompleted -- which can either be | |
524 // through the SigninManagerFactory or through the AccountReconcilorFactory. | |
525 // *sigh*. | |
526 signin_manager_->CompletePendingSignin(); | |
527 //token_service_->IssueRefreshToken("token"); | |
528 ASSERT_TRUE(catcher.GetNextResult()); | |
529 } | |
530 #endif // !defined (OS_CHROMEOS) | |
531 | |
532 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, | |
533 SignIn_RedirectToSignIn) { | |
534 GURL signin_url( | |
535 "chrome://chrome-signin/?source=5&continue_url=http%3A%2F%2F" | |
536 "www.example.com%3A" + | |
537 base::IntToString(test_server()->host_port_pair().port()) + | |
538 "%2Fcontinue"); | |
539 ui_test_utils::UrlLoadObserver observer( | |
540 signin_url, | |
541 content::Source<content::NavigationController>( | |
542 &GetWebContents()->GetController())); | |
543 StartSignInTest("sign_in_redirect_to_sign_in.html"); | |
544 observer.Wait(); | |
545 | |
546 // TODO(isherman): Also test the redirect back to the continue URL once | |
547 // sign-in completes? | |
548 } | |
549 | |
370 } // namespace extensions | 550 } // namespace extensions |
OLD | NEW |