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

Unified Diff: components/copresence/rpc/http_post_unittest.cc

Issue 469883002: Using API key specified from js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing API build Created 6 years, 4 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 | « components/copresence/rpc/http_post.cc ('k') | components/copresence/rpc/rpc_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/copresence/rpc/http_post_unittest.cc
diff --git a/components/copresence/rpc/http_post_unittest.cc b/components/copresence/rpc/http_post_unittest.cc
index 5fc45fdad5a1c9fc564b365f7c2ca222c3283754..46a85b1a69e005bd3e12d5b5453928e81bd0d83a 100644
--- a/components/copresence/rpc/http_post_unittest.cc
+++ b/components/copresence/rpc/http_post_unittest.cc
@@ -11,12 +11,14 @@
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
namespace {
const char kFakeServerHost[] = "test.server.google.com";
const char kRPCName[] = "testRpc";
const char kTracingToken[] = "trace me!";
+const char kApiKey[] = "unlock ALL the APIz";
} // namespace
@@ -48,6 +50,7 @@ class HttpPostTest : public testing::Test {
std::string("http://") + kFakeServerHost,
kRPCName,
"",
+ kApiKey,
proto_);
pending_post_->Start(base::Bind(&HttpPostTest::TestResponseCallback,
base::Unretained(this)));
@@ -61,6 +64,26 @@ class HttpPostTest : public testing::Test {
received_response_ == response;
}
+ net::TestURLFetcher* GetFetcher() {
+ return fetcher_factory_.GetFetcherByID(HttpPost::kUrlFetcherId);
+ }
+
+ const std::string GetApiKeySent() {
+ std::string api_key_sent;
+ net::GetValueForKeyInQuery(GetFetcher()->GetOriginalURL(),
+ HttpPost::kApiKeyField,
+ &api_key_sent);
+ return api_key_sent;
+ }
+
+ const std::string GetTracingTokenSent() {
+ std::string tracing_token_sent;
+ net::GetValueForKeyInQuery(GetFetcher()->GetOriginalURL(),
+ HttpPost::kTracingTokenField,
+ &tracing_token_sent);
+ return tracing_token_sent;
+ }
+
net::TestURLFetcherFactory fetcher_factory_;
scoped_refptr<net::TestURLRequestContextGetter> context_getter_;
@@ -79,28 +102,29 @@ TEST_F(HttpPostTest, OKResponse) {
std::string("http://") + kFakeServerHost,
kRPCName,
kTracingToken,
+ kApiKey,
proto_);
post->Start(base::Bind(&HttpPostTest::TestResponseCallback,
base::Unretained(this)));
- // Verify that the right data got sent to the right place.
- net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(
- HttpPost::kUrlFetcherId);
- EXPECT_EQ(kFakeServerHost, fetcher->GetOriginalURL().host());
- EXPECT_EQ(std::string("/") + kRPCName, fetcher->GetOriginalURL().path());
- std::string tracing_token_sent;
- EXPECT_TRUE(net::GetValueForKeyInQuery(fetcher->GetOriginalURL(),
- HttpPost::kTracingTokenField,
- &tracing_token_sent));
- EXPECT_EQ(std::string("token:") + kTracingToken, tracing_token_sent);
+ // Verify that the data was sent to the right place.
+ GURL requested_url = GetFetcher()->GetOriginalURL();
+ EXPECT_EQ(kFakeServerHost, requested_url.host());
+ EXPECT_EQ(std::string("/") + kRPCName, requested_url.path());
+
+ // Check query parameters.
+ EXPECT_EQ(kApiKey, GetApiKeySent());
+ EXPECT_EQ(std::string("token:") + kTracingToken, GetTracingTokenSent());
+
+ // Verify that the right data was sent.
std::string upload_data;
ASSERT_TRUE(proto_.SerializeToString(&upload_data));
- EXPECT_EQ(upload_data, fetcher->upload_data());
+ EXPECT_EQ(upload_data, GetFetcher()->upload_data());
// Send a response and check that it's passed along correctly.
- fetcher->set_response_code(net::HTTP_OK);
- fetcher->SetResponseString("Hello World!");
- fetcher->delegate()->OnURLFetchComplete(fetcher);
+ GetFetcher()->set_response_code(net::HTTP_OK);
+ GetFetcher()->SetResponseString("Hello World!");
+ GetFetcher()->delegate()->OnURLFetchComplete(GetFetcher());
EXPECT_EQ(net::HTTP_OK, received_response_code_);
EXPECT_EQ("Hello World!", received_response_);
delete post;
« no previous file with comments | « components/copresence/rpc/http_post.cc ('k') | components/copresence/rpc/rpc_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698