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

Unified Diff: components/webp_transcode/webp_network_client_unittest.mm

Issue 1022813002: [iOS] Upstream WebP network client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 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 | « components/webp_transcode/webp_network_client_factory.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/webp_transcode/webp_network_client_unittest.mm
diff --git a/components/webp_transcode/webp_network_client_unittest.mm b/components/webp_transcode/webp_network_client_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..da0ec0b954086bed75d6c5a828e5288913142cc5
--- /dev/null
+++ b/components/webp_transcode/webp_network_client_unittest.mm
@@ -0,0 +1,73 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/webp_transcode/webp_network_client.h"
+
+#include "base/mac/scoped_nsobject.h"
+#include "base/memory/weak_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "base/thread_task_runner_handle.h"
+#include "net/http/http_request_headers.h"
+#include "net/url_request/url_request_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#import "third_party/ocmock/OCMock/OCMock.h"
+
+namespace {
+class WebPNetworkClientTest : public testing::Test {
+ public:
+ WebPNetworkClientTest() {
+ // Set up mock original network client proxy.
+ OCMockObject* mockProxy_ = [[OCMockObject
+ niceMockForProtocol:@protocol(CRNNetworkClientProtocol)] retain];
+ mockWebProxy_.reset(mockProxy_);
+
+ // Link all the mock objects into the WebPNetworkClient.
+ webp_client_.reset([[WebPNetworkClient alloc]
+ initWithTaskRunner:base::ThreadTaskRunnerHandle::Get()]);
+ [webp_client_
+ setUnderlyingClient:(id<CRNNetworkClientProtocol>)mockWebProxy_];
+ }
+
+ protected:
+ base::MessageLoop loop_;
+ base::scoped_nsobject<WebPNetworkClient> webp_client_;
+ // Holds a mock CRNNetworkClientProtocol object.
+ base::scoped_nsobject<OCMockObject> mockWebProxy_;
+};
+} // namespace
+
+TEST_F(WebPNetworkClientTest, TestAcceptHeaders) {
+ const struct {
+ const std::string header_in;
+ const std::string header_out;
+ } tests[] = {
+ {"", "image/webp"},
+ {"*/*", "*/*,image/webp"},
+ {"image/webp", "image/webp"},
+ {"text/html,*/*", "text/html,*/*,image/webp"},
+ // Desktop Chrome default without image/webp.
+ {"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
+ "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,"
+ "image/webp"},
+ // Desktop Chrome default.
+ {"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,"
+ "*/*;q=0.8",
+ "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,"
+ "*/*;q=0.8"}};
+ GURL url("http://www.google.com");
+ scoped_ptr<net::URLRequestContext> request_context(
+ new net::TestURLRequestContext(false));
+ for (size_t i = 0; i < arraysize(tests); ++i) {
+ scoped_ptr<net::URLRequest> request =
+ request_context->CreateRequest(url, net::DEFAULT_PRIORITY, nullptr,
+ nullptr).Pass();
+ if (!tests[i].header_in.empty())
+ request->SetExtraRequestHeaderByName("Accept", tests[i].header_in, true);
+ [webp_client_ didCreateNativeRequest:request.get()];
+ const net::HttpRequestHeaders& headers = request->extra_request_headers();
+ std::string acceptHeader;
+ EXPECT_TRUE(headers.GetHeader("Accept", &acceptHeader));
+ EXPECT_EQ(tests[i].header_out, acceptHeader);
+ }
+}
« no previous file with comments | « components/webp_transcode/webp_network_client_factory.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698