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

Side by Side Diff: sync/notifier/gcm_network_channel_unittest.cc

Issue 217653002: Cleanup changes in gcm_network_channel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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 unified diff | Download patch
« no previous file with comments | « sync/notifier/gcm_network_channel.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/run_loop.h" 5 #include "base/run_loop.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "google_apis/gaia/google_service_auth_error.h" 7 #include "google_apis/gaia/google_service_auth_error.h"
8 #include "net/url_request/test_url_fetcher_factory.h" 8 #include "net/url_request/test_url_fetcher_factory.h"
9 #include "net/url_request/url_request_test_util.h" 9 #include "net/url_request/url_request_test_util.h"
10 #include "sync/notifier/gcm_network_channel.h" 10 #include "sync/notifier/gcm_network_channel.h"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 TEST_F(GCMNetworkChannelTest, RequestTokenNeverCompletes) { 373 TEST_F(GCMNetworkChannelTest, RequestTokenNeverCompletes) {
374 network_channel()->SendMessage("abra.cadabra"); 374 network_channel()->SendMessage("abra.cadabra");
375 // Return valid registration id. 375 // Return valid registration id.
376 delegate()->register_callback.Run("registration.id", gcm::GCMClient::SUCCESS); 376 delegate()->register_callback.Run("registration.id", gcm::GCMClient::SUCCESS);
377 // RequestToken should be called by now. Let's not complete and see what 377 // RequestToken should be called by now. Let's not complete and see what
378 // happens. 378 // happens.
379 EXPECT_FALSE(delegate()->request_token_callback.is_null()); 379 EXPECT_FALSE(delegate()->request_token_callback.is_null());
380 } 380 }
381 381
382 #if !defined(ANDROID)
383 TEST_F(GCMNetworkChannelTest, BuildUrl) {
384 GURL url = BuildUrl("registration.id");
385 EXPECT_TRUE(url.SchemeIsHTTPOrHTTPS());
386 EXPECT_FALSE(url.host().empty());
387 EXPECT_FALSE(url.path().empty());
388 std::vector<std::string> parts;
389 Tokenize(url.path(), "/", &parts);
390 std::string buffer;
391 EXPECT_TRUE(Base64DecodeURLSafe(parts[parts.size() - 1], &buffer));
392 }
393 #endif
394
395 TEST_F(GCMNetworkChannelTest, Base64EncodeDecode) { 382 TEST_F(GCMNetworkChannelTest, Base64EncodeDecode) {
396 std::string input; 383 std::string input;
397 std::string plain; 384 std::string plain;
398 std::string base64; 385 std::string base64;
399 // Empty string. 386 // Empty string.
400 Base64EncodeURLSafe(input, &base64); 387 Base64EncodeURLSafe(input, &base64);
401 EXPECT_TRUE(base64.empty()); 388 EXPECT_TRUE(base64.empty());
402 EXPECT_TRUE(Base64DecodeURLSafe(base64, &plain)); 389 EXPECT_TRUE(Base64DecodeURLSafe(base64, &plain));
403 EXPECT_EQ(input, plain); 390 EXPECT_EQ(input, plain);
404 // String length: 1..7. 391 // String length: 1..7.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, get_last_invalidator_state()); 430 EXPECT_EQ(TRANSIENT_INVALIDATION_ERROR, get_last_invalidator_state());
444 // Network change to something else should trigger retry. 431 // Network change to something else should trigger retry.
445 network_channel()->OnNetworkChanged( 432 network_channel()->OnNetworkChanged(
446 net::NetworkChangeNotifier::CONNECTION_WIFI); 433 net::NetworkChangeNotifier::CONNECTION_WIFI);
447 EXPECT_EQ(INVALIDATIONS_ENABLED, get_last_invalidator_state()); 434 EXPECT_EQ(INVALIDATIONS_ENABLED, get_last_invalidator_state());
448 network_channel()->OnNetworkChanged( 435 network_channel()->OnNetworkChanged(
449 net::NetworkChangeNotifier::CONNECTION_NONE); 436 net::NetworkChangeNotifier::CONNECTION_NONE);
450 EXPECT_EQ(INVALIDATIONS_ENABLED, get_last_invalidator_state()); 437 EXPECT_EQ(INVALIDATIONS_ENABLED, get_last_invalidator_state());
451 } 438 }
452 439
453 #if !defined(ANDROID) 440 #if !defined(OS_ANDROID)
441 TEST_F(GCMNetworkChannelTest, BuildUrl) {
442 GURL url = BuildUrl("registration.id");
443 EXPECT_TRUE(url.SchemeIsHTTPOrHTTPS());
444 EXPECT_FALSE(url.host().empty());
445 EXPECT_FALSE(url.path().empty());
446 std::vector<std::string> parts;
447 Tokenize(url.path(), "/", &parts);
448 std::string buffer;
449 EXPECT_TRUE(Base64DecodeURLSafe(parts[parts.size() - 1], &buffer));
450 }
451
454 TEST_F(GCMNetworkChannelTest, EchoToken) { 452 TEST_F(GCMNetworkChannelTest, EchoToken) {
455 url_fetcher_factory()->SetFakeResponse(GURL("http://test.url.com"), 453 url_fetcher_factory()->SetFakeResponse(GURL("http://test.url.com"),
456 std::string(), 454 std::string(),
457 net::HTTP_OK, 455 net::HTTP_OK,
458 net::URLRequestStatus::SUCCESS); 456 net::URLRequestStatus::SUCCESS);
459 // After construction GCMNetworkChannel should have called Register. 457 // After construction GCMNetworkChannel should have called Register.
460 // Return valid registration id. 458 // Return valid registration id.
461 delegate()->register_callback.Run("registration.id", gcm::GCMClient::SUCCESS); 459 delegate()->register_callback.Run("registration.id", gcm::GCMClient::SUCCESS);
462 460
463 network_channel()->SendMessage("abra.cadabra"); 461 network_channel()->SendMessage("abra.cadabra");
(...skipping 23 matching lines...) Expand all
487 delegate()->request_token_callback.Run( 485 delegate()->request_token_callback.Run(
488 GoogleServiceAuthError::AuthErrorNone(), "access.token"); 486 GoogleServiceAuthError::AuthErrorNone(), "access.token");
489 RunLoopUntilIdle(); 487 RunLoopUntilIdle();
490 EXPECT_EQ(url_fetchers_created_count(), 3); 488 EXPECT_EQ(url_fetchers_created_count(), 3);
491 // Echo_token should be from second message. 489 // Echo_token should be from second message.
492 EXPECT_EQ("echo.token", get_last_echo_token()); 490 EXPECT_EQ("echo.token", get_last_echo_token());
493 } 491 }
494 #endif 492 #endif
495 493
496 } // namespace syncer 494 } // namespace syncer
OLDNEW
« 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