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

Unified Diff: chrome/browser/extensions/app_notify_channel_setup_unittest.cc

Issue 8526015: Integrate AppNotifyChannelSetup with TokenService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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/extensions/app_notify_channel_setup.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/app_notify_channel_setup_unittest.cc
===================================================================
--- chrome/browser/extensions/app_notify_channel_setup_unittest.cc (revision 108943)
+++ chrome/browser/extensions/app_notify_channel_setup_unittest.cc (working copy)
@@ -8,16 +8,23 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "chrome/browser/extensions/app_notify_channel_setup.h"
+#include "chrome/browser/extensions/app_notify_channel_ui.h"
+#include "chrome/browser/net/gaia/token_service.h"
+#include "chrome/browser/net/gaia/token_service_unittest.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net/gaia/gaia_urls.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service.h"
#include "chrome/test/base/testing_profile.h"
#include "content/test/test_browser_thread.h"
#include "content/test/test_url_fetcher_factory.h"
#include "googleurl/src/gurl.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
+using testing::_;
+using testing::Return;
namespace {
@@ -25,6 +32,36 @@
const int kCallbackId = 5;
const char* kFakeExtensionId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+class MockTokenService : public TokenService {
+ public:
+ MockTokenService() { }
+ virtual ~MockTokenService() { }
+
+ bool AreCredentialsValid() const OVERRIDE {
+ return true;
+ }
+
+ MOCK_CONST_METHOD1(HasTokenForService, bool(const char*));
+};
+
+class TestProfile : public TestingProfile {
+ public:
+ TestProfile() : TestingProfile() { }
+ virtual ~TestProfile() { }
+
+ virtual TokenService* GetTokenService() OVERRIDE {
+ return &token_service_;
+ }
+
+ void SetTokenServiceHasTokenResult(bool result) {
+ EXPECT_CALL(token_service_, HasTokenForService(_))
+ .WillRepeatedly(Return(result));
+ }
+
+ private:
+ MockTokenService token_service_;
+};
+
class TestDelegate : public AppNotifyChannelSetup::Delegate,
public base::SupportsWeakPtr<TestDelegate> {
public:
@@ -127,13 +164,13 @@
virtual AppNotifyChannelSetup* CreateInstance() {
GURL page_url("http://www.google.com");
return new AppNotifyChannelSetup(&profile_,
- kFakeExtensionId,
- "1234",
- page_url,
- kRouteId,
- kCallbackId,
- ui_.release(),
- delegate_.AsWeakPtr());
+ kFakeExtensionId,
+ "1234",
+ page_url,
+ kRouteId,
+ kCallbackId,
+ ui_.release(),
+ delegate_.AsWeakPtr());
}
virtual void SetupLogin(bool should_succeed) {
@@ -143,6 +180,16 @@
ui_->SetSyncSetupResult(false);
}
+ virtual void SetupFetchTokens(bool should_have_tokens, bool should_succeed) {
+ profile_.SetTokenServiceHasTokenResult(should_have_tokens);
+ if (!should_have_tokens) {
+ factory_.SetFakeResponse(
+ GaiaUrls::GetInstance()->issue_auth_token_url(),
+ "some_token",
+ should_succeed);
+ }
+ }
+
virtual void SetupRecordGrant(bool should_succeed) {
factory_.SetFakeResponse(
AppNotifyChannelSetup::GetOAuth2IssueTokenURL().spec(),
@@ -157,7 +204,6 @@
should_succeed);
}
-
virtual void RunServerTest(AppNotifyChannelSetup* setup,
const std::string& expected_code,
const std::string& expected_error) {
@@ -169,30 +215,48 @@
protected:
MessageLoop message_loop_;
content::TestBrowserThread ui_thread_;
- TestingProfile profile_;
+ TestProfile profile_;
TestDelegate delegate_;
scoped_ptr<TestUI> ui_;
FakeURLFetcherFactory factory_;
};
TEST_F(AppNotifyChannelSetupTest, LoginFailure) {
- // Set login to fail.
SetupLogin(false);
scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance();
RunServerTest(setup, "", "canceled_by_user");
}
-TEST_F(AppNotifyChannelSetupTest, RecordGrantFailure) {
+TEST_F(AppNotifyChannelSetupTest, FetchTokensFailure) {
SetupLogin(true);
+ SetupFetchTokens(false, false);
+
+ scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance();
+ RunServerTest(setup, "", "internal_error");
+}
+
+TEST_F(AppNotifyChannelSetupTest, TokensAvailableRecordGrantFailure) {
+ SetupLogin(true);
+ SetupFetchTokens(true, false);
SetupRecordGrant(false);
scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance();
RunServerTest(setup, "", "internal_error");
}
+TEST_F(AppNotifyChannelSetupTest, TokenFetchSuccessAndRecordGrantFailure) {
+ SetupLogin(true);
+ SetupFetchTokens(false , true);
+ SetupRecordGrant(false);
+
+ scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance();
+ RunServerTest(setup, "", "internal_error");
+}
+
TEST_F(AppNotifyChannelSetupTest, GetChannelIdFailure) {
SetupLogin(true);
+ SetupFetchTokens(true, false);
SetupRecordGrant(true);
SetupGetChannelId(false);
@@ -202,6 +266,7 @@
TEST_F(AppNotifyChannelSetupTest, ServerSuccess) {
SetupLogin(true);
+ SetupFetchTokens(true, false);
SetupRecordGrant(true);
SetupGetChannelId(true);
« no previous file with comments | « chrome/browser/extensions/app_notify_channel_setup.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698