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

Unified Diff: sync/notifier/gcm_network_channel_unittest.cc

Issue 182333003: Build correct URL for cacheinvalidation endpoint. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@RollCacheInvalidations
Patch Set: fix build Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/notifier/gcm_network_channel.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/notifier/gcm_network_channel_unittest.cc
diff --git a/sync/notifier/gcm_network_channel_unittest.cc b/sync/notifier/gcm_network_channel_unittest.cc
index a8ef9ac32ae3a375901f9cf602307f1445b6b001..00fc5dc2f05b2a7ca53868c78bcf2f0f856f5b4b 100644
--- a/sync/notifier/gcm_network_channel_unittest.cc
+++ b/sync/notifier/gcm_network_channel_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/run_loop.h"
+#include "base/strings/string_util.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_test_util.h"
@@ -10,7 +11,6 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
-namespace {
class TestGCMNetworkChannelDelegate : public GCMNetworkChannelDelegate {
public:
@@ -73,6 +73,13 @@ class TestGCMNetworkChannel : public GCMNetworkChannel {
: GCMNetworkChannel(request_context_getter, delegate.Pass()) {
ResetRegisterBackoffEntryForTest(&kTestBackoffPolicy);
}
+
+ protected:
+ // On Android GCMNetworkChannel::BuildUrl hits NOTREACHED(). I still want
+ // tests to run.
+ virtual GURL BuildUrl(const std::string& registration_id) OVERRIDE {
+ return GURL("http://test.url.com");
+ }
};
class GCMNetworkChannelTest
@@ -110,6 +117,21 @@ class GCMNetworkChannelTest
gcm_network_channel_->RemoveObserver(this);
}
+ // Helper functions to call private methods from test
+ GURL BuildUrl(const std::string& registration_id) {
+ return gcm_network_channel_->GCMNetworkChannel::BuildUrl(registration_id);
+ }
+
+ static void Base64EncodeURLSafe(const std::string& input,
+ std::string* output) {
+ GCMNetworkChannel::Base64EncodeURLSafe(input, output);
+ }
+
+ static bool Base64DecodeURLSafe(const std::string& input,
+ std::string* output) {
+ return GCMNetworkChannel::Base64DecodeURLSafe(input, output);
+ }
+
virtual void OnNetworkChannelStateChanged(
InvalidatorState invalidator_state) OVERRIDE {
}
@@ -159,8 +181,9 @@ class GCMNetworkChannelTest
};
TEST_F(GCMNetworkChannelTest, HappyCase) {
- GURL url("http://invalid.url.com");
- url_fetcher_factory()->SetFakeResponse(url, std::string(), net::HTTP_OK,
+ url_fetcher_factory()->SetFakeResponse(GURL("http://test.url.com"),
+ std::string(),
+ net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
// After construction GCMNetworkChannel should have called Register.
@@ -209,9 +232,10 @@ TEST_F(GCMNetworkChannelTest, FailedRegister) {
}
TEST_F(GCMNetworkChannelTest, RegisterFinishesAfterSendMessage) {
- GURL url("http://invalid.url.com");
- url_fetcher_factory()->SetFakeResponse(url, "", net::HTTP_OK,
- net::URLRequestStatus::SUCCESS);
+ url_fetcher_factory()->SetFakeResponse(GURL("http://test.url.com"),
+ "",
+ net::HTTP_OK,
+ net::URLRequestStatus::SUCCESS);
// After construction GCMNetworkChannel should have called Register.
EXPECT_FALSE(delegate()->register_callback.is_null());
@@ -254,9 +278,10 @@ TEST_F(GCMNetworkChannelTest, RequestTokenFailure) {
TEST_F(GCMNetworkChannelTest, AuthErrorFromServer) {
// Setup fake response to return AUTH_ERROR.
- GURL url("http://invalid.url.com");
- url_fetcher_factory()->SetFakeResponse(url, "", net::HTTP_UNAUTHORIZED,
- net::URLRequestStatus::SUCCESS);
+ url_fetcher_factory()->SetFakeResponse(GURL("http://test.url.com"),
+ "",
+ net::HTTP_UNAUTHORIZED,
+ net::URLRequestStatus::SUCCESS);
// After construction GCMNetworkChannel should have called Register.
EXPECT_FALSE(delegate()->register_callback.is_null());
@@ -293,5 +318,44 @@ TEST_F(GCMNetworkChannelTest, RequestTokenNeverCompletes) {
EXPECT_FALSE(delegate()->request_token_callback.is_null());
}
-} // namespace
+#if !defined(ANDROID)
+TEST_F(GCMNetworkChannelTest, BuildUrl) {
+ GURL url = BuildUrl("registration.id");
+ EXPECT_TRUE(url.SchemeIsHTTPOrHTTPS());
+ EXPECT_FALSE(url.host().empty());
+ EXPECT_FALSE(url.path().empty());
+ std::vector<std::string> parts;
+ Tokenize(url.path(), "/", &parts);
+ std::string buffer;
+ EXPECT_TRUE(Base64DecodeURLSafe(parts[parts.size() - 1], &buffer));
+}
+#endif
+
+TEST_F(GCMNetworkChannelTest, Base64EncodeDecode) {
+ std::string input;
+ std::string plain;
+ std::string base64;
+ // Empty string.
+ Base64EncodeURLSafe(input, &base64);
+ EXPECT_TRUE(base64.empty());
+ EXPECT_TRUE(Base64DecodeURLSafe(base64, &plain));
+ EXPECT_EQ(input, plain);
+ // String length: 1..7.
+ for (int length = 1; length < 8; length++) {
+ input = "abra.cadabra";
+ input.resize(length);
+ Base64EncodeURLSafe(input, &base64);
+ // Ensure no padding at the end.
+ EXPECT_NE(base64[base64.size() - 1], '=');
+ EXPECT_TRUE(Base64DecodeURLSafe(base64, &plain));
+ EXPECT_EQ(input, plain);
+ }
+ // Presence of '-', '_'.
+ input = "\xfb\xff";
+ Base64EncodeURLSafe(input, &base64);
+ EXPECT_EQ("-_8", base64);
+ EXPECT_TRUE(Base64DecodeURLSafe(base64, &plain));
+ EXPECT_EQ(input, plain);
+}
+
} // namespace syncer
« no previous file with comments | « sync/notifier/gcm_network_channel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698