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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/webp_transcode/webp_network_client_factory.mm ('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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/webp_transcode/webp_network_client.h"
6
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "net/http/http_request_headers.h"
12 #include "net/url_request/url_request_test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #import "third_party/ocmock/OCMock/OCMock.h"
15
16 namespace {
17 class WebPNetworkClientTest : public testing::Test {
18 public:
19 WebPNetworkClientTest() {
20 // Set up mock original network client proxy.
21 OCMockObject* mockProxy_ = [[OCMockObject
22 niceMockForProtocol:@protocol(CRNNetworkClientProtocol)] retain];
23 mockWebProxy_.reset(mockProxy_);
24
25 // Link all the mock objects into the WebPNetworkClient.
26 webp_client_.reset([[WebPNetworkClient alloc]
27 initWithTaskRunner:base::ThreadTaskRunnerHandle::Get()]);
28 [webp_client_
29 setUnderlyingClient:(id<CRNNetworkClientProtocol>)mockWebProxy_];
30 }
31
32 protected:
33 base::MessageLoop loop_;
34 base::scoped_nsobject<WebPNetworkClient> webp_client_;
35 // Holds a mock CRNNetworkClientProtocol object.
36 base::scoped_nsobject<OCMockObject> mockWebProxy_;
37 };
38 } // namespace
39
40 TEST_F(WebPNetworkClientTest, TestAcceptHeaders) {
41 const struct {
42 const std::string header_in;
43 const std::string header_out;
44 } tests[] = {
45 {"", "image/webp"},
46 {"*/*", "*/*,image/webp"},
47 {"image/webp", "image/webp"},
48 {"text/html,*/*", "text/html,*/*,image/webp"},
49 // Desktop Chrome default without image/webp.
50 {"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
51 "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,"
52 "image/webp"},
53 // Desktop Chrome default.
54 {"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,"
55 "*/*;q=0.8",
56 "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,"
57 "*/*;q=0.8"}};
58 GURL url("http://www.google.com");
59 scoped_ptr<net::URLRequestContext> request_context(
60 new net::TestURLRequestContext(false));
61 for (size_t i = 0; i < arraysize(tests); ++i) {
62 scoped_ptr<net::URLRequest> request =
63 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, nullptr,
64 nullptr).Pass();
65 if (!tests[i].header_in.empty())
66 request->SetExtraRequestHeaderByName("Accept", tests[i].header_in, true);
67 [webp_client_ didCreateNativeRequest:request.get()];
68 const net::HttpRequestHeaders& headers = request->extra_request_headers();
69 std::string acceptHeader;
70 EXPECT_TRUE(headers.GetHeader("Accept", &acceptHeader));
71 EXPECT_EQ(tests[i].header_out, acceptHeader);
72 }
73 }
OLDNEW
« 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