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

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: Addressing review comments 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
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..d58e54c1f3855e6a52f6a8bd809af0dae86a35d5 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
@@ -46,11 +48,10 @@ class HttpPostTest : public testing::Test {
bool ResponsePassedThrough(int response_code, const std::string& response) {
pending_post_ = new HttpPost(context_getter_.get(),
std::string("http://") + kFakeServerHost,
- kRPCName,
- "",
- proto_);
+ kRPCName);
pending_post_->Start(base::Bind(&HttpPostTest::TestResponseCallback,
- base::Unretained(this)));
+ base::Unretained(this)),
+ proto_);
net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(
HttpPost::kUrlFetcherId);
fetcher->set_response_code(response_code);
@@ -61,6 +62,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_;
@@ -77,30 +98,31 @@ TEST_F(HttpPostTest, OKResponse) {
// "Send" the proto to the "server".
HttpPost* post = new HttpPost(context_getter_.get(),
std::string("http://") + kFakeServerHost,
- kRPCName,
- kTracingToken,
- proto_);
+ kRPCName);
+ post->set_api_key(kApiKey);
+ post->set_tracing_token(kTracingToken);
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);
+ base::Unretained(this)),
+ proto_);
+
+ // 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;

Powered by Google App Engine
This is Rietveld 408576698