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

Unified Diff: chrome/browser/ui/app_list/speech_auth_helper_unittest.cc

Issue 778393002: Add OAuth2 authentication for some voice transcription requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/app_list/speech_auth_helper.cc ('k') | chrome/browser/ui/app_list/speech_recognizer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/app_list/speech_auth_helper_unittest.cc
diff --git a/chrome/browser/ui/app_list/speech_auth_helper_unittest.cc b/chrome/browser/ui/app_list/speech_auth_helper_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7302af1529f328dcfe0ee1da4c3f7e4342ba98b8
--- /dev/null
+++ b/chrome/browser/ui/app_list/speech_auth_helper_unittest.cc
@@ -0,0 +1,122 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/app_list/speech_auth_helper.h"
+
+#include <utility>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/test/simple_test_clock.h"
+#include "chrome/browser/prefs/pref_service_syncable.h"
+#include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
+#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
+#include "chrome/browser/signin/signin_manager_factory.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_profile.h"
+#include "chrome/test/base/testing_profile_manager.h"
+#include "components/signin/core/browser/signin_manager.h"
+#include "components/signin/core/browser/signin_manager_base.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "google_apis/gaia/google_service_auth_error.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace app_list {
+
+static const char* kTestUser = "test.user@chromium.org.test";
+static const char* kScope = "https://www.googleapis.com/auth/webhistory";
+static const char* kAccessToken = "fake_access_token";
+
+class SpeechAuthHelperTest : public testing::Test {
+ public:
+ SpeechAuthHelperTest()
+ : testing_profile_manager_(new TestingProfileManager(
+ TestingBrowserProcess::GetGlobal())) {
+ }
+
+ void SetUp() override {
+ // Set up FakeProfileOAuth2TokenService.
+ TestingProfile::TestingFactories factories;
+ factories.push_back(std::make_pair(
+ ProfileOAuth2TokenServiceFactory::GetInstance(),
+ &BuildAutoIssuingFakeProfileOAuth2TokenService));
+
+ ASSERT_TRUE(testing_profile_manager_->SetUp());
+ profile_ = testing_profile_manager_->CreateTestingProfile(
+ kTestUser,
+ scoped_ptr<PrefServiceSyncable>(),
+ base::UTF8ToUTF16(kTestUser),
+ 0,
+ std::string(),
+ factories);
+
+ // Set up the authenticated user name and ID.
+ SigninManagerFactory::GetForProfile(profile_)->SetAuthenticatedUsername(
+ kTestUser);
+ }
+
+ protected:
+ void SetupRefreshToken() {
+ GetFakeProfileOAuth2TokenService()->IssueRefreshTokenForUser(
+ kTestUser, "fake_refresh_token");
+ }
+
+ FakeProfileOAuth2TokenService* GetFakeProfileOAuth2TokenService() {
+ return static_cast<FakeProfileOAuth2TokenService*>(
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile_));
+ }
+
+ base::SimpleTestClock test_clock_;
+ content::TestBrowserThreadBundle thread_bundle;
+ scoped_ptr<TestingProfileManager> testing_profile_manager_;
+ Profile* profile_;
+ scoped_ptr<SpeechAuthHelper> auth_helper_;
+};
+
+TEST_F(SpeechAuthHelperTest, TokenFetch) {
+ SetupRefreshToken();
+ SpeechAuthHelper helper(profile_, &test_clock_);
+ EXPECT_TRUE(helper.GetToken().empty());
+
+ OAuth2TokenService::ScopeSet scopes;
+ scopes.insert(kScope);
+ GetFakeProfileOAuth2TokenService()->IssueTokenForScope(scopes,
+ kAccessToken,
+ base::Time::Max());
+
+ EXPECT_EQ(kAccessToken, helper.GetToken());
+ EXPECT_EQ(kScope, helper.GetScope());
+}
+
+TEST_F(SpeechAuthHelperTest, TokenFetchDelayedRefreshToken) {
+ SpeechAuthHelper helper(profile_, &test_clock_);
+ SetupRefreshToken();
+ EXPECT_TRUE(helper.GetToken().empty());
+
+ OAuth2TokenService::ScopeSet scopes;
+ scopes.insert(kScope);
+ GetFakeProfileOAuth2TokenService()->IssueTokenForScope(scopes,
+ kAccessToken,
+ base::Time::Max());
+
+ EXPECT_EQ(kAccessToken, helper.GetToken());
+ EXPECT_EQ(kScope, helper.GetScope());
+}
+
+TEST_F(SpeechAuthHelperTest, TokenFetchFailed) {
+ SetupRefreshToken();
+ SpeechAuthHelper helper(profile_, &test_clock_);
+ EXPECT_TRUE(helper.GetToken().empty());
+
+ OAuth2TokenService::ScopeSet scopes;
+ scopes.insert(kScope);
+ GetFakeProfileOAuth2TokenService()->IssueErrorForScope(
+ scopes, GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR));
+
+ EXPECT_TRUE(helper.GetToken().empty());
+ EXPECT_EQ(kScope, helper.GetScope());
+}
+
+} // namespace app_list
« no previous file with comments | « chrome/browser/ui/app_list/speech_auth_helper.cc ('k') | chrome/browser/ui/app_list/speech_recognizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698