Chromium Code Reviews| Index: chrome/browser/extensions/api/identity/identity_apitest.cc |
| diff --git a/chrome/browser/extensions/api/identity/identity_apitest.cc b/chrome/browser/extensions/api/identity/identity_apitest.cc |
| index b18c138e9bed9d098d5365e1294e9c2fa6945971..36e8cc66785a28d12865ab4a5579bf86ec1f262a 100644 |
| --- a/chrome/browser/extensions/api/identity/identity_apitest.cc |
| +++ b/chrome/browser/extensions/api/identity/identity_apitest.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/stringprintf.h" |
| #include "base/values.h" |
| #include "chrome/browser/extensions/api/identity/identity_api.h" |
| +#include "chrome/browser/extensions/component_loader.h" |
| #include "chrome/browser/extensions/extension_apitest.h" |
| #include "chrome/browser/extensions/extension_browsertest.h" |
| #include "chrome/browser/extensions/extension_function_test_utils.h" |
| @@ -189,6 +190,35 @@ BrowserContextKeyedService* IdentityAPITestFactory( |
| return new IdentityAPI(static_cast<Profile*>(profile)); |
| } |
| +// Waits for a specific GURL to generate a NOTIFICATION_LOAD_STOP |
| +// event, and closes the window embedding the webcontents. |
| +class WaitForGURLAndCloseWindow : public content::WindowedNotificationObserver { |
| + public: |
| + explicit WaitForGURLAndCloseWindow(GURL url) |
| + : WindowedNotificationObserver( |
| + content::NOTIFICATION_LOAD_STOP, |
| + content::NotificationService::AllSources()), |
| + url_(url) {} |
| + |
| + // NotificationObserver: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE { |
| + content::NavigationController* web_auth_flow_controller = |
| + content::Source<content::NavigationController>(source).ptr(); |
| + content::WebContents* web_contents = |
| + web_auth_flow_controller->GetWebContents(); |
| + |
| + if (web_contents->GetURL() == url_) { |
| + web_contents->GetEmbedderWebContents()->Close(); |
| + content::WindowedNotificationObserver::Observe(type, source, details); |
|
miket_OOO
2013/05/24 16:37:56
Did you mean to call the inherited behavior only c
Michael Courage
2013/05/30 22:27:03
Yes, added a comment to that effect.
|
| + } |
| + } |
| + |
| + private: |
| + GURL url_; |
| +}; |
| + |
| } // namespace |
| class MockGetAuthTokenFunction : public IdentityGetAuthTokenFunction { |
| @@ -545,6 +575,23 @@ IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| } |
| IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| + InteractiveApprovalLoadFailed) { |
| + scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| + func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| + EXPECT_CALL(*func.get(), HasLoginToken()) |
| + .WillOnce(Return(true)); |
| + TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| + TestOAuth2MintTokenFlow::ISSUE_ADVICE_SUCCESS, func.get()); |
| + EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| + func->set_scope_ui_failure(GaiaWebAuthFlow::LOAD_FAILED); |
| + std::string error = utils::RunFunctionAndReturnError( |
| + func.get(), "[{\"interactive\": true}]", browser()); |
| + EXPECT_EQ(std::string(errors::kPageLoadFailure), error); |
| + EXPECT_FALSE(func->login_ui_shown()); |
| + EXPECT_TRUE(func->scope_ui_shown()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| InteractiveApprovalInvalidRedirect) { |
| scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| @@ -940,6 +987,16 @@ IN_PROC_BROWSER_TEST_F(RemoveCachedAuthTokenFunctionTest, MatchingToken) { |
| class LaunchWebAuthFlowFunctionTest : public AsyncExtensionBrowserTest { |
| public: |
| + void LoadComponent() { |
| + // Normally the ComponentLoader won't load the component in tests. |
| + ExtensionService* service = extensions::ExtensionSystem::Get( |
| + profile())->extension_service(); |
| + |
| + service->component_loader()->Add( |
| + IDR_IDENTITY_API_SCOPE_APPROVAL_MANIFEST, |
| + base::FilePath(FILE_PATH_LITERAL("identity_scope_approval_dialog"))); |
| + } |
| + |
| virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| // Reduce performance test variance by disabling background networking. |
| command_line->AppendSwitch(switches::kDisableBackgroundNetworking); |
| @@ -947,6 +1004,7 @@ class LaunchWebAuthFlowFunctionTest : public AsyncExtensionBrowserTest { |
| }; |
| IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, UserCloseWindow) { |
| + LoadComponent(); |
| net::SpawnedTestServer https_server( |
| net::SpawnedTestServer::TYPE_HTTPS, |
| net::SpawnedTestServer::kLocalhost, |
| @@ -961,21 +1019,19 @@ IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, UserCloseWindow) { |
| utils::CreateEmptyExtension()); |
| function->set_extension(empty_extension.get()); |
| - content::WindowedNotificationObserver popup_observer( |
| - chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| - content::NotificationService::AllSources()); |
| + WaitForGURLAndCloseWindow popup_observer(auth_url); |
| std::string args = "[{\"interactive\": true, \"url\": \"" + |
| auth_url.spec() + "\"}]"; |
| RunFunctionAsync(function, args); |
| popup_observer.Wait(); |
| - content::Source<Browser>(popup_observer.source())->window()->Close(); |
| EXPECT_EQ(std::string(errors::kUserRejected), WaitForError(function)); |
| } |
| IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, InteractionRequired) { |
| + LoadComponent(); |
| net::SpawnedTestServer https_server( |
| net::SpawnedTestServer::TYPE_HTTPS, |
| net::SpawnedTestServer::kLocalhost, |
| @@ -998,7 +1054,32 @@ IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, InteractionRequired) { |
| EXPECT_EQ(std::string(errors::kInteractionRequired), error); |
| } |
| +IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, LoadFailed) { |
| + LoadComponent(); |
| + net::SpawnedTestServer https_server( |
| + net::SpawnedTestServer::TYPE_HTTPS, |
| + net::SpawnedTestServer::kLocalhost, |
| + base::FilePath(FILE_PATH_LITERAL( |
| + "chrome/test/data/extensions/api_test/identity"))); |
| + ASSERT_TRUE(https_server.Start()); |
| + GURL auth_url(https_server.GetURL("files/five_hundred.html")); |
| + |
| + scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| + new IdentityLaunchWebAuthFlowFunction()); |
| + scoped_refptr<Extension> empty_extension( |
| + utils::CreateEmptyExtension()); |
| + function->set_extension(empty_extension.get()); |
| + |
| + std::string args = "[{\"interactive\": true, \"url\": \"" + |
| + auth_url.spec() + "\"}]"; |
| + std::string error = utils::RunFunctionAndReturnError(function, args, |
| + browser()); |
| + |
| + EXPECT_EQ(std::string(errors::kPageLoadFailure), error); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, NonInteractiveSuccess) { |
| + LoadComponent(); |
| scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| new IdentityLaunchWebAuthFlowFunction()); |
| scoped_refptr<Extension> empty_extension( |
| @@ -1020,6 +1101,7 @@ IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, NonInteractiveSuccess) { |
| IN_PROC_BROWSER_TEST_F( |
| LaunchWebAuthFlowFunctionTest, InteractiveFirstNavigationSuccess) { |
| + LoadComponent(); |
| scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| new IdentityLaunchWebAuthFlowFunction()); |
| scoped_refptr<Extension> empty_extension( |
| @@ -1041,6 +1123,7 @@ IN_PROC_BROWSER_TEST_F( |
| IN_PROC_BROWSER_TEST_F( |
| LaunchWebAuthFlowFunctionTest, InteractiveSecondNavigationSuccess) { |
| + LoadComponent(); |
| net::SpawnedTestServer https_server( |
| net::SpawnedTestServer::TYPE_HTTPS, |
| net::SpawnedTestServer::kLocalhost, |