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

Unified Diff: ios/crnet/test/crnet_http_tests.mm

Issue 2206283003: [Cronet] Add CrNet.setUserAgent method on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@crnetgn
Patch Set: Sync Created 4 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
« ios/crnet/CrNet.h ('K') | « ios/crnet/crnet_environment.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/crnet/test/crnet_http_tests.mm
diff --git a/ios/crnet/test/crnet_http_tests.mm b/ios/crnet/test/crnet_http_tests.mm
index 8aee1afde8e5dade3b2f8b6e27c4635982c46b32..b3c8e9ab8876c1f02b60ba8ca1afc4a325dca6c3 100644
--- a/ios/crnet/test/crnet_http_tests.mm
+++ b/ios/crnet/test/crnet_http_tests.mm
@@ -11,6 +11,7 @@
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/third_party/gcdwebserver/src/GCDWebServer/Core/GCDWebServer.h"
+#import "ios/third_party/gcdwebserver/src/GCDWebServer/Responses/GCDWebServerDataResponse.h"
#include "net/base/mac/url_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
@@ -99,6 +100,7 @@
// base::TimeDelta would normally be ideal for this but it does not support
// nanosecond resolution.
static const int64_t ns_in_second = 1000000000LL;
+const char kUserAgent[] = "CrNetTest/1.0.0.0";
class HttpTest : public ::testing::Test {
protected:
@@ -106,7 +108,7 @@ class HttpTest : public ::testing::Test {
~HttpTest() override {}
void SetUp() override {
- [CrNet setPartialUserAgent:@"CrNetTest/1.0.0.0"];
+ [CrNet setUserAgent:base::SysUTF8ToNSString(kUserAgent)];
[CrNet install];
NSURLSessionConfiguration* config =
[NSURLSessionConfiguration ephemeralSessionConfiguration];
@@ -208,11 +210,11 @@ TEST_F(HttpTest, NSURLSessionReceivesData) {
}
TEST_F(HttpTest, SdchDisabledByDefault) {
- const char kPath[] = "/foo";
+ const char kPath[] = "/sdchtest";
RegisterPathHandler(kPath,
^GCDWebServerResponse* (GCDWebServerRequest* req) {
EXPECT_FALSE(HeaderValueContains(req, "Accept-Encoding", "sdch"));
- return nil;
+ return [GCDWebServerDataResponse responseWithText:@"woot!"];
});
StartWebServer();
NSURL* url = net::NSURLWithGURL(GetURL(kPath));
@@ -222,6 +224,21 @@ TEST_F(HttpTest, SdchDisabledByDefault) {
EXPECT_TRUE([delegate_ receivedBytes]);
}
+TEST_F(HttpTest, SetUserAgentIsExact) {
+ const char kPath[] = "/uatest";
+ RegisterPathHandler(kPath, ^GCDWebServerResponse*(GCDWebServerRequest* req) {
+ EXPECT_STREQ(kUserAgent,
+ [[req.headers valueForKey:@"User-Agent"] UTF8String]);
+ return [GCDWebServerDataResponse responseWithText:@"yay!"];
+ });
+ StartWebServer();
+ NSURL* url = net::NSURLWithGURL(GetURL(kPath));
+ NSURLSessionDataTask* task = [session_ dataTaskWithURL:url];
+ StartDataTaskAndWaitForCompletion(task);
+ EXPECT_EQ(nil, [delegate_ error]);
+ EXPECT_TRUE([delegate_ receivedBytes]);
+}
+
// TODO(ellyjones): There needs to be a test that enabling SDCH works, but
// because CrNet is static and 'uninstall' only disables it, there is no way to
// have an individual test enable or disable SDCH.
« ios/crnet/CrNet.h ('K') | « ios/crnet/crnet_environment.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698